Index: trunk/src/gfx/keyframed_mesh.cc
===================================================================
--- trunk/src/gfx/keyframed_mesh.cc	(revision 237)
+++ trunk/src/gfx/keyframed_mesh.cc	(revision 239)
@@ -15,7 +15,8 @@
 using namespace nv;
 
-keyframed_mesh::keyframed_mesh( context* a_context, mesh_data_old* a_data )
+nv::keyframed_mesh::keyframed_mesh( context* a_context, mesh_data* a_data, tag_map* a_tag_map )
 	: animated_mesh()
-	, m_data( a_data )
+	, m_mesh_data( a_data )
+	, m_tag_map( a_tag_map )
 	, m_start_frame( false )
 	, m_stop_frame( false )
@@ -29,15 +30,21 @@
 {
 	m_va = a_context->get_device()->create_vertex_array();
+
+	m_index_count  = m_mesh_data->get_index_channel()->count;
+	m_vertex_count = m_mesh_data->get_channel_data()[1]->count;
+	m_frame_count  = m_mesh_data->get_channel_data()[0]->count / m_vertex_count;
 }
 
 size_t keyframed_mesh::get_max_frames() const
 {
-	return m_data->get_frame_count();
+	return m_frame_count;
 }
 
 transform keyframed_mesh::get_tag( const std::string& tag ) const
 {
-	const std::vector< transform >& transforms = m_data->get_tag_map().at( tag );
-	return interpolate( transforms[ m_last_frame ], transforms[ m_next_frame ], m_interpolation );
+	NV_ASSERT( m_tag_map, "TAGMAP FAIL" );
+	const std::vector< transform >* transforms = m_tag_map->get_tag( tag );
+	NV_ASSERT( transforms, "TAG FAIL" );
+	return interpolate( (*transforms)[ m_last_frame ], (*transforms)[ m_next_frame ], m_interpolation );
 }
 
@@ -115,6 +122,6 @@
 }
 
-keyframed_mesh_gpu::keyframed_mesh_gpu( context* a_context, mesh_data_old* a_data, program* a_program )
-	: keyframed_mesh( a_context, a_data )
+nv::keyframed_mesh_gpu::keyframed_mesh_gpu( context* a_context, mesh_data* a_data, tag_map* a_tag_map, program* a_program )
+	: keyframed_mesh( a_context, a_data, a_tag_map )
 	, m_loc_next_position( 0 )
 	, m_loc_next_normal( 0 )
@@ -122,21 +129,12 @@
 	, m_gpu_next_frame( 0xFFFFFFFF )
 {
-	nv::vertex_buffer* vb;
 	m_loc_next_position = a_program->get_attribute( "nv_next_position" )->get_location();
 	m_loc_next_normal   = a_program->get_attribute( "nv_next_normal" )->get_location();
+	m_va = a_context->get_device()->create_vertex_array( a_data, nv::STATIC_DRAW );
+	vertex_buffer* vb = m_va->find_buffer( nv::POSITION );
+	m_va->add_vertex_buffer( m_loc_next_position, vb, nv::FLOAT, 3, 0,              sizeof( vertex_pn ), false );
+	m_va->add_vertex_buffer( m_loc_next_normal,   vb, nv::FLOAT, 3, sizeof( vec3 ), sizeof( vertex_pn ), false );
+}
 
-	vb = a_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_data->get_vertex_count() * sizeof( nv::vec3 ) * m_data->get_frame_count(), (void*)m_data->get_positions().data() );
-	m_va->add_vertex_buffer( m_loc_next_position, vb, nv::FLOAT, 3, 0, 0, false );
-	m_va->add_vertex_buffer( nv::POSITION, vb, nv::FLOAT, 3 );
-
-	vb = a_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_data->get_vertex_count() * sizeof( nv::vec3 ) * m_data->get_frame_count(), (void*)m_data->get_normals().data() );
-	m_va->add_vertex_buffer( m_loc_next_normal, vb, nv::FLOAT, 3, 0, 0, false );
-	m_va->add_vertex_buffer( nv::NORMAL, vb, nv::FLOAT, 3 );
-
-	vb = a_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_data->get_vertex_count() * sizeof( nv::vec2 ), (void*)m_data->get_texcoords().data() );
-	m_va->add_vertex_buffer( nv::slot::TEXCOORD, vb, nv::FLOAT, 2 );
-	nv::index_buffer* ib = a_context->get_device()->create_index_buffer( nv::STATIC_DRAW, m_data->get_index_count() * sizeof( nv::uint32 ), (void*)m_data->get_indices().data() );
-	m_va->set_index_buffer( ib, nv::UINT, true );
-}
 
 void nv::keyframed_mesh_gpu::update( uint32 ms )
@@ -144,38 +142,31 @@
 	keyframed_mesh::update( ms );
 
-	size_t vtx_count = m_data->get_vertex_count();
 	if ( m_gpu_last_frame != m_last_frame )
 	{
-		m_va->update_vertex_buffer( slot::POSITION, m_last_frame * vtx_count * sizeof( nv::vec3 ) );
-		m_va->update_vertex_buffer( slot::NORMAL,   m_last_frame * vtx_count * sizeof( nv::vec3 ) );
+		m_va->update_vertex_buffer( slot::POSITION, m_last_frame * m_vertex_count * sizeof( vertex_pn ) );
+		m_va->update_vertex_buffer( slot::NORMAL,   m_last_frame * m_vertex_count * sizeof( vertex_pn ) + sizeof( vec3 ) );
 		m_gpu_last_frame = m_last_frame;
 	}
 	if ( m_gpu_next_frame != m_next_frame )
 	{
-		m_va->update_vertex_buffer( m_loc_next_position, m_next_frame * vtx_count * sizeof( nv::vec3 ) );
-		m_va->update_vertex_buffer( m_loc_next_normal,   m_next_frame * vtx_count * sizeof( nv::vec3 ) );
+		m_va->update_vertex_buffer( m_loc_next_position, m_next_frame * m_vertex_count * sizeof( vertex_pn ) );
+		m_va->update_vertex_buffer( m_loc_next_normal,   m_next_frame * m_vertex_count * sizeof( vertex_pn ) + sizeof( vec3 ) );
 		m_gpu_next_frame = m_next_frame;
 	}
 }
 
+nv::keyframed_mesh_cpu::keyframed_mesh_cpu( context* a_context, mesh_data* a_data, tag_map* a_tag_map )
+	: keyframed_mesh( a_context, a_data, a_tag_map )
+{
+	m_vb = a_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_vertex_count * sizeof( vertex_pn ), (void*)m_mesh_data->get_channel_data()[0]->data );
+	m_va->add_vertex_buffers( m_vb, m_mesh_data->get_channel_data()[0] );
 
-nv::keyframed_mesh_cpu::keyframed_mesh_cpu( context* a_context, mesh_data_old* a_data )
-	: keyframed_mesh( a_context, a_data )
-{
-	m_vb_position = a_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_data->get_vertex_count() * sizeof( nv::vec3 ), (void*)m_data->get_position_frame(0) );
-	m_va->add_vertex_buffer( nv::slot::POSITION, m_vb_position, nv::FLOAT, 3 );
+	nv::vertex_buffer* vb = a_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_vertex_count * sizeof( nv::vec2 ), (void*)m_mesh_data->get_channel_data()[1]->data );
+	m_va->add_vertex_buffers( vb, m_mesh_data->get_channel_data()[1] );
 
-	m_vb_normal   = a_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_data->get_vertex_count() * sizeof( nv::vec3 ), (void*)m_data->get_normal_frame(0) );
-	m_va->add_vertex_buffer( nv::slot::NORMAL, m_vb_normal, nv::FLOAT, 3 );
+	nv::index_buffer* ib = a_context->get_device()->create_index_buffer( nv::STATIC_DRAW, m_mesh_data->get_index_channel()->size, (void*)m_mesh_data->get_index_channel()->data );
+	m_va->set_index_buffer( ib, m_mesh_data->get_index_channel()->etype, true );
 
-	nv::vertex_buffer* vb;
-	vb = a_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_data->get_vertex_count() * sizeof( nv::vec2 ), (void*)m_data->get_texcoords().data() );
-	m_va->add_vertex_buffer( nv::slot::TEXCOORD, vb, nv::FLOAT, 2 );
-
-	nv::index_buffer* ib = a_context->get_device()->create_index_buffer( nv::STATIC_DRAW, m_data->get_index_count() * sizeof( nv::uint32 ), (void*)m_data->get_indices().data() );
-	m_va->set_index_buffer( ib, nv::UINT, true );
-
-	m_position.resize( m_data->get_vertex_count() );
-	m_normal.resize( m_data->get_vertex_count() );
+	m_vertex.resize( m_vertex_count );
 }
 
@@ -184,22 +175,16 @@
 	keyframed_mesh::update( ms );
 
-	size_t vtx_count = m_data->get_vertex_count();
-	const vec3* prev_position = m_data->get_position_frame( m_last_frame );
-	const vec3* next_position = m_data->get_position_frame( m_next_frame );
-	const vec3* prev_normal   = m_data->get_normal_frame( m_last_frame );
-	const vec3* next_normal   = m_data->get_normal_frame( m_next_frame );
+	const vertex_pn* data = (const vertex_pn*)(m_mesh_data->get_channel_data()[0]->data);
+	const vertex_pn* prev = data + m_vertex_count * m_last_frame;
+	const vertex_pn* next = data + m_vertex_count * m_next_frame;
 
-	for ( size_t i = 0; i < vtx_count; ++i )
+	for ( size_t i = 0; i < m_vertex_count; ++i )
 	{
-		m_position[i] = glm::mix( prev_position[i], next_position[i], m_interpolation );
-		m_normal[i]   = glm::mix( prev_normal[i],   next_normal[i],   m_interpolation );
+		m_vertex[i].position = glm::mix( prev[i].position, next[i].position, m_interpolation );
+		m_vertex[i].normal   = glm::mix( prev[i].normal,   next[i].normal,   m_interpolation );
 	}
 
-	m_vb_position->bind();
-	m_vb_position->update( m_position.data(), 0, vtx_count * sizeof( nv::vec3 ) );
-	m_vb_position->unbind();
-
-	m_vb_normal->bind();
-	m_vb_normal->update( m_normal.data(), 0, vtx_count * sizeof( nv::vec3 ) );
-	m_vb_normal->unbind();
+	m_vb->bind();
+	m_vb->update( m_vertex.data(), 0, m_vertex_count * sizeof( vertex_pn ) );
+	m_vb->unbind();
 }
Index: trunk/src/gfx/skeletal_mesh.cc
===================================================================
--- trunk/src/gfx/skeletal_mesh.cc	(revision 237)
+++ trunk/src/gfx/skeletal_mesh.cc	(revision 239)
@@ -11,24 +11,12 @@
 
 
-nv::skeletal_mesh::skeletal_mesh( context* a_context, md5_loader* a_loader )
+nv::skeletal_mesh::skeletal_mesh( context* a_context, md5_mesh_data* a_mesh_data )
 	: animated_mesh()
-	, m_data( a_loader )
+	, m_mesh_data( a_mesh_data )
 	, m_animation( nullptr )
 {
-	nv::uint32 vcount = a_loader->get_vertex_count(0);
-	m_va = a_context->get_device()->create_vertex_array();
+	m_va = a_context->get_device()->create_vertex_array( a_mesh_data, nv::STREAM_DRAW );
+}
 
-	m_vb_position = a_context->get_device()->create_vertex_buffer( nv::STREAM_DRAW, vcount * sizeof( nv::vec3 ), (const void*)a_loader->get_positions(0).data() );
-	m_va->add_vertex_buffer( nv::slot::POSITION, m_vb_position, nv::FLOAT, 3, 0, 0, false );
-	m_vb_normal = a_context->get_device()->create_vertex_buffer( nv::STREAM_DRAW, vcount * sizeof( nv::vec3 ), (const void*)a_loader->get_normals(0).data()  );
-	m_va->add_vertex_buffer( nv::slot::NORMAL,   m_vb_normal, nv::FLOAT, 3, 0, 0, false );
-	m_vb_tangent = a_context->get_device()->create_vertex_buffer( nv::STREAM_DRAW, vcount * sizeof( nv::vec3 ), (const void*)a_loader->get_tangents(0).data() );
-	m_va->add_vertex_buffer( nv::slot::TANGENT,  m_vb_tangent, nv::FLOAT, 3, 0, 0, false );
-
-	nv::vertex_buffer* vb = a_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, vcount * sizeof( nv::vec2 ), (const void*)a_loader->get_texcoords(0).data() );
-	m_va->add_vertex_buffer( nv::slot::TEXCOORD, vb, nv::FLOAT, 2 );
-	nv::index_buffer* ib = a_context->get_device()->create_index_buffer( nv::STATIC_DRAW, a_loader->get_index_count(0) * sizeof( nv::uint32 ), (const void*)a_loader->get_indices(0).data() );
-	m_va->set_index_buffer( ib, nv::UINT, true );
-}
 
 void nv::skeletal_mesh::setup_animation( md5_animation* a_anim )
@@ -45,21 +33,11 @@
 	{
 		m_animation->update( ms * 0.001f );
-		m_data->apply( *m_animation );
+		m_mesh_data->apply( *m_animation );
+		vertex_buffer* vb = m_va->find_buffer( nv::POSITION );
+		const mesh_raw_channel* pch = m_mesh_data->get_channel_data()[0];
+		vb->bind();
+		vb->update( (const void*)pch->data, 0, pch->size );
+		vb->unbind();
 	}
-
-	nv::uint32 usize = m_data->get_vertex_count(0) * sizeof( nv::vec3 );
-	m_vb_position->bind();
-	m_vb_position->update( (const void*)m_data->get_positions(0).data(), 0, usize );
-	m_vb_normal  ->bind();
-	m_vb_normal  ->update( (const void*)m_data->get_normals(0).data(),   0, usize );
-	m_vb_tangent ->bind();
-	m_vb_tangent ->update( (const void*)m_data->get_tangents(0).data(),  0, usize );
-
-	// Technically this is not needed, because the va is just a fake class, 
-	// but if it's real it will be needed?
-// 	m_va->update_vertex_buffer( nv::slot::POSITION, m_vb_position, false );
-// 	m_va->update_vertex_buffer( nv::slot::NORMAL,   m_vb_normal,   false );
-// 	m_va->update_vertex_buffer( nv::slot::TANGENT,  m_vb_tangent,  false );
-	// TODO: answer is - probably not
 }
 
@@ -67,4 +45,5 @@
 {
 	delete m_va;
+	delete m_mesh_data;
 }
 
