Index: trunk/nv/gfx/keyframed_mesh.hh
===================================================================
--- trunk/nv/gfx/keyframed_mesh.hh	(revision 222)
+++ trunk/nv/gfx/keyframed_mesh.hh	(revision 223)
@@ -18,13 +18,13 @@
 	public:
 		keyframed_mesh( context* a_context, keyframed_mesh_data* a_data, program* a_program );
+		size_t get_max_frames() const;
 		mat4 get_tag( const std::string& tag ) const;
-		size_t get_max_frames() const;
-		void set_frame( uint32 frame );
-		void setup_animation( uint32 start, uint32 count, uint32 fps, bool loop );
-		void update( uint32 ms );
-		void draw( render_state& rstate );
+		virtual void setup_animation( uint32 start, uint32 count, uint32 fps, bool loop );
+		virtual void set_frame( uint32 frame );
+		virtual void update( uint32 ms );
+		virtual void draw( render_state& rstate );
 		program* get_program() { return m_program; }
-		~keyframed_mesh();
-	private:
+		virtual ~keyframed_mesh();
+	protected:
 		context*             m_context;
 		keyframed_mesh_data* m_data;
@@ -32,18 +32,39 @@
 		vertex_array*        m_va;
 
+		uint32 m_start_frame;
+		uint32 m_stop_frame;
+		uint32 m_last_frame;
+		uint32 m_next_frame;
+		uint32 m_time;
+		uint32 m_fps;
+		f32    m_interpolation;
+		bool   m_looping;
+		bool   m_active;
+	};
+
+
+	class keyframed_mesh_gpu : public keyframed_mesh
+	{
+	public:
+		keyframed_mesh_gpu( context* a_context, keyframed_mesh_data* a_data, program* a_program );
+		void draw( render_state& rstate );
+	private:
 		int m_loc_next_position;
 		int m_loc_next_normal;
 
-		uint32 m_last_frame;
-		uint32 m_next_frame;
 		uint32 m_gpu_last_frame;
 		uint32 m_gpu_next_frame;
-		f32    m_interpolation;
-		uint32 m_start_frame;
-		uint32 m_stop_frame;
-		uint32 m_time;
-		uint32 m_fps;
-		bool   m_looping;
-		bool   m_active;
+	};
+
+	class keyframed_mesh_cpu : public keyframed_mesh
+	{
+	public:
+		keyframed_mesh_cpu( context* a_context, keyframed_mesh_data* a_data, program* a_program );
+		void update( uint32 ms );
+	private:
+		std::vector<vec3> m_position;
+		std::vector<vec3> m_normal;
+		vertex_buffer* m_vb_position;
+		vertex_buffer* m_vb_normal;
 	};
 
Index: trunk/src/gfx/keyframed_mesh.cc
===================================================================
--- trunk/src/gfx/keyframed_mesh.cc	(revision 222)
+++ trunk/src/gfx/keyframed_mesh.cc	(revision 223)
@@ -20,34 +20,20 @@
 	, m_program( a_program )
 	, m_va( nullptr )
-	, m_loc_next_position( 0 )
-	, m_loc_next_normal( 0 )
+	, m_start_frame( false )
+	, m_stop_frame( false )
 	, m_last_frame( 0 )
 	, m_next_frame( 0 )
-	, m_gpu_last_frame( 0xFFFFFFFF )
-	, m_gpu_next_frame( 0xFFFFFFFF )
+	, m_time( 0 )
+	, m_fps( 0 )
 	, m_interpolation( 0.0f )
-	, m_start_frame( false )
-	, m_stop_frame( false )
 	, m_looping( false )
 	, m_active( false )
 {
 	m_va = m_context->get_device()->create_vertex_array();
-
-	nv::vertex_buffer* vb;
-	m_loc_next_position = m_program->get_attribute( "nv_next_position" )->get_location();
-	m_loc_next_normal   = m_program->get_attribute( "nv_next_normal" )->get_location();
-
-	vb = m_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 = m_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 = m_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 = m_context->get_device()->create_index_buffer( nv::STATIC_DRAW, m_data->get_index_count() * sizeof( nv::uint16 ), (void*)m_data->get_indices().data() );
-	m_va->set_index_buffer( ib, nv::USHORT, true );
+}
+
+size_t keyframed_mesh::get_max_frames() const
+{
+	return m_data->get_frame_count();
 }
 
@@ -56,17 +42,4 @@
 	const std::vector< nv::mat4 >& transforms = m_data->get_tag_map().at( tag );
 	return glm::interpolate( transforms[ m_last_frame ], transforms[ m_next_frame ], m_interpolation );
-}
-
-size_t keyframed_mesh::get_max_frames() const
-{
-	return m_data->get_frame_count();
-}
-
-void keyframed_mesh::set_frame( uint32 frame )
-{
-	m_last_frame    = frame;
-	m_next_frame    = frame;
-	m_interpolation = 0.0f;
-	m_active        = false;
 }
 
@@ -78,8 +51,16 @@
 	m_fps           = fps;
 	m_active        = count > 1;
+	m_time          = 0;
 	m_last_frame    = start;
 	m_next_frame    = (count > 1 ? start + 1 : start );
 	m_interpolation = 0.0f;
-	m_time          = 0;
+}
+
+void nv::keyframed_mesh::set_frame( uint32 frame )
+{
+	m_last_frame    = frame;
+	m_next_frame    = frame;
+	m_active        = false;
+	m_interpolation = 0.0f;
 }
 
@@ -122,4 +103,40 @@
 void nv::keyframed_mesh::draw( render_state& rstate )
 {
+	m_program->set_opt_uniform( "nv_interpolate", m_interpolation );
+	m_context->draw( nv::TRIANGLES, rstate, m_program, m_va, m_data->get_index_count() );
+}
+
+nv::keyframed_mesh::~keyframed_mesh()
+{
+	delete m_va;
+}
+
+keyframed_mesh_gpu::keyframed_mesh_gpu( context* a_context, keyframed_mesh_data* a_data, program* a_program )
+	: keyframed_mesh( a_context, a_data, a_program )
+	, m_loc_next_position( 0 )
+	, m_loc_next_normal( 0 )
+	, m_gpu_last_frame( 0xFFFFFFFF )
+	, m_gpu_next_frame( 0xFFFFFFFF )
+{
+	nv::vertex_buffer* vb;
+	m_loc_next_position = m_program->get_attribute( "nv_next_position" )->get_location();
+	m_loc_next_normal   = m_program->get_attribute( "nv_next_normal" )->get_location();
+
+	vb = m_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 = m_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 = m_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 = m_context->get_device()->create_index_buffer( nv::STATIC_DRAW, m_data->get_index_count() * sizeof( nv::uint16 ), (void*)m_data->get_indices().data() );
+	m_va->set_index_buffer( ib, nv::USHORT, true );
+}
+
+void nv::keyframed_mesh_gpu::draw( render_state& rstate )
+{
 	size_t vtx_count = m_data->get_vertex_count();
 	if ( m_gpu_last_frame != m_last_frame )
@@ -135,10 +152,50 @@
 		m_gpu_next_frame = m_next_frame;
 	}
-	m_program->set_uniform( "nv_interpolate", m_interpolation );
-	m_context->draw( nv::TRIANGLES, rstate, m_program, m_va, m_data->get_index_count() );
-}
-
-nv::keyframed_mesh::~keyframed_mesh()
-{
-	delete m_va;
-}
+	keyframed_mesh::draw( rstate );
+}
+
+
+nv::keyframed_mesh_cpu::keyframed_mesh_cpu( context* a_context, keyframed_mesh_data* a_data, program* a_program )
+	: keyframed_mesh( a_context, a_data, a_program )
+{
+	m_vb_position = m_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_position_data(0) );
+	m_va->add_vertex_buffer( nv::slot::POSITION, m_vb_position, nv::FLOAT, 3 );
+
+	m_vb_normal   = m_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_normal_data(0) );
+	m_va->add_vertex_buffer( nv::slot::NORMAL, m_vb_normal, nv::FLOAT, 3 );
+
+	nv::vertex_buffer* vb;
+	vb = m_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 = m_context->get_device()->create_index_buffer( nv::STATIC_DRAW, m_data->get_index_count() * sizeof( nv::uint16 ), (void*)m_data->get_indices().data() );
+	m_va->set_index_buffer( ib, nv::USHORT, true );
+
+	m_position.resize( m_data->get_vertex_count() );
+	m_normal.resize( m_data->get_vertex_count() );
+}
+
+void nv::keyframed_mesh_cpu::update( uint32 ms )
+{
+	keyframed_mesh::update( ms );
+
+	size_t vtx_count = m_data->get_vertex_count();
+	const vec3* prev_position = m_data->get_position_data( m_last_frame );
+	const vec3* next_position = m_data->get_position_data( m_next_frame );
+	const vec3* prev_normal   = m_data->get_normal_data( m_last_frame );
+	const vec3* next_normal   = m_data->get_normal_data( m_next_frame );
+
+	for ( size_t i = 0; i < vtx_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_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();
+}
Index: trunk/tests/md2_test/md2_test.cc
===================================================================
--- trunk/tests/md2_test/md2_test.cc	(revision 222)
+++ trunk/tests/md2_test/md2_test.cc	(revision 223)
@@ -47,5 +47,5 @@
 		{
 			NV_PROFILE("create_mesh");
-			m_mesh      = new nv::keyframed_mesh( window->get_context(), m_mesh_data, program );
+			m_mesh      = new nv::keyframed_mesh_gpu( window->get_context(), m_mesh_data, program );
 		}
 
@@ -85,5 +85,5 @@
 private:
 	nv::keyframed_mesh_data* m_mesh_data;
-	nv::keyframed_mesh*      m_mesh;
+	nv::keyframed_mesh_gpu*  m_mesh;
 };
 
