Index: trunk/src/gfx/keyframed_mesh.cc
===================================================================
--- trunk/src/gfx/keyframed_mesh.cc	(revision 296)
+++ trunk/src/gfx/keyframed_mesh.cc	(revision 299)
@@ -15,5 +15,5 @@
 using namespace nv;
 
-nv::keyframed_mesh::keyframed_mesh( device* a_device, const mesh_data* a_data, const mesh_nodes_data* a_tag_map )
+nv::keyframed_mesh::keyframed_mesh( const mesh_data* a_data, const mesh_nodes_data* a_tag_map )
 	: animated_mesh()
 	, m_mesh_data( a_data )
@@ -24,6 +24,4 @@
 	, m_active( false )
 {
-	m_va = a_device->create_vertex_array();
-
 	m_index_count  = m_mesh_data->get_index_channel()->count;
 	m_vertex_count = m_mesh_data->get_channel<vertex_t>()->count;
@@ -123,6 +121,6 @@
 }
 
-nv::keyframed_mesh_gpu::keyframed_mesh_gpu( device* a_device, const mesh_data* a_data, const mesh_nodes_data* a_tag_map )
-	: keyframed_mesh( a_device, a_data, a_tag_map )
+nv::keyframed_mesh_gpu::keyframed_mesh_gpu( context* a_context, const mesh_data* a_data, const mesh_nodes_data* a_tag_map )
+	: keyframed_mesh( a_data, a_tag_map )
 	, m_loc_next_position( -1 )
 	, m_loc_next_normal( -1 )
@@ -131,5 +129,5 @@
 	, m_gpu_next_frame( 0xFFFFFFFF )
 {
-	m_va = a_device->create_vertex_array( a_data, STATIC_DRAW );
+	m_va = a_context->get_device()->create_vertex_array( a_data, STATIC_DRAW );
 }
 
@@ -177,14 +175,16 @@
 }
 
-nv::keyframed_mesh_cpu::keyframed_mesh_cpu( device* a_device, const mesh_data* a_data, const mesh_nodes_data* a_tag_map )
-	: keyframed_mesh( a_device, a_data, a_tag_map )
-{
-	m_vb = a_device->create_vertex_buffer( nv::STATIC_DRAW, m_vertex_count * m_vsize, (void*)m_vchannel->data );
+nv::keyframed_mesh_cpu::keyframed_mesh_cpu( context* a_context, const mesh_data* a_data, const mesh_nodes_data* a_tag_map )
+	: keyframed_mesh( a_data, a_tag_map )
+	, m_context( a_context )
+{
+	m_va = m_context->get_device()->create_vertex_array();
+	m_vb = m_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_vertex_count * m_vsize, (void*)m_vchannel->data );
 	m_va->add_vertex_buffers( m_vb, m_vchannel );
 
-	nv::vertex_buffer* vb = a_device->create_vertex_buffer( nv::STATIC_DRAW, m_vertex_count * sizeof( nv::vec2 ), (void*)m_mesh_data->get_channel<vertex_t>()->data );
+	nv::vertex_buffer* vb = m_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_vertex_count * sizeof( nv::vec2 ), (void*)m_mesh_data->get_channel<vertex_t>()->data );
 	m_va->add_vertex_buffers( vb, m_mesh_data->get_channel<vertex_t>() );
 
-	nv::index_buffer* ib = a_device->create_index_buffer( nv::STATIC_DRAW, m_mesh_data->get_index_channel()->size(), (void*)m_mesh_data->get_index_channel()->data );
+	nv::index_buffer* ib = m_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()->desc.slots[0].etype, true );
 
@@ -224,7 +224,5 @@
 	}
 
-	m_vb->bind();
-	m_vb->update( m_data, 0, m_vertex_count * m_vsize );
-	m_vb->unbind();
+	m_context->update( m_vb, m_data, 0, m_vertex_count * m_vsize );
 }
 
Index: trunk/src/gfx/skeletal_mesh.cc
===================================================================
--- trunk/src/gfx/skeletal_mesh.cc	(revision 296)
+++ trunk/src/gfx/skeletal_mesh.cc	(revision 299)
@@ -11,6 +11,7 @@
 
 
-nv::skeletal_mesh_cpu::skeletal_mesh_cpu( device* a_device, const mesh_data* a_mesh_data, const mesh_nodes_data* bones )
+nv::skeletal_mesh_cpu::skeletal_mesh_cpu( context* a_context, const mesh_data* a_mesh_data, const mesh_nodes_data* bones )
 	: skeletal_mesh()
+	, m_context( a_context )
 	, m_data( a_mesh_data )
 {
@@ -26,5 +27,5 @@
 	m_vtx_data  = a_mesh_data->get_channel_data<md5_vtx_pntiw>();
 	m_indices   = a_mesh_data->get_count();
-	m_va        = a_device->create_vertex_array( a_mesh_data, nv::STREAM_DRAW );
+	m_va        = a_context->get_device()->create_vertex_array( a_mesh_data, nv::STREAM_DRAW );
 }
 
@@ -63,7 +64,5 @@
 
 		vertex_buffer* vb = m_va->find_buffer( nv::slot::POSITION );
-		vb->bind();
-		vb->update( m_pntdata.data(), 0, m_pntdata.raw_size() );
-		vb->unbind();
+		m_context->update( vb, m_pntdata.data(), 0, m_pntdata.raw_size() );
 	}
 }
@@ -200,8 +199,8 @@
 }
 
-nv::skeletal_mesh_gpu::skeletal_mesh_gpu( device* a_device, const mesh_data* a_mesh, const mesh_nodes_data* a_bone_data )
+nv::skeletal_mesh_gpu::skeletal_mesh_gpu( context* a_context, const mesh_data* a_mesh, const mesh_nodes_data* a_bone_data )
 	: skeletal_mesh(), m_bone_data( a_bone_data ), m_transform( nullptr )
 {
-	m_va          = a_device->create_vertex_array( a_mesh, nv::STATIC_DRAW );
+	m_va          = a_context->get_device()->create_vertex_array( a_mesh, nv::STATIC_DRAW );
 	m_index_count = a_mesh->get_count();
 	if ( m_bone_data )
Index: trunk/src/gl/gl_context.cc
===================================================================
--- trunk/src/gl/gl_context.cc	(revision 296)
+++ trunk/src/gl/gl_context.cc	(revision 299)
@@ -8,6 +8,111 @@
 #include "nv/lib/gl.hh"
 #include "nv/lib/sdl.hh"
+#include "nv/gl/gl_texture2d.hh"
+#include "nv/gl/gl_program.hh"
+#include "nv/gl/gl_vertex_buffer.hh"
 
 using namespace nv;
+
+void gl_context::bind( texture2d* texture, texture_slot slot )
+{
+	GLuint id = static_cast< gl_texture2d* >( texture )->m_name.get_value();
+	glActiveTexture( GL_TEXTURE0 + static_cast< GLenum >( slot ) );
+	glBindTexture( GL_TEXTURE_2D, id );
+}
+
+void nv::gl_context::bind( program* p )
+{
+	gl_program* glp = static_cast< gl_program* >( p );
+	glUseProgram( glp->m_name.get_value() );
+	glp->update_uniforms();
+}
+
+void nv::gl_context::bind( vertex_buffer* b )
+{
+	GLuint id = static_cast< gl_vertex_buffer* >( b )->m_name.get_value();
+	glBindBuffer( GL_ARRAY_BUFFER, id );
+}
+
+void nv::gl_context::bind( index_buffer* b )
+{
+	GLuint id = static_cast< gl_index_buffer* >( b )->m_name.get_value();
+	glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, id );
+}
+
+void nv::gl_context::bind( vertex_array* va )
+{
+	for ( vertex_buffer_attribute_map::iterator i = va->m_map.begin(); 	i != va->m_map.end(); ++i ) 
+	{
+		uint32 location             = static_cast<uint32>( i->first );
+		vertex_buffer_attribute* va = i->second;
+		vertex_buffer*           vb = va->get_buffer();
+		glEnableVertexAttribArray( location );
+		bind( vb );
+		glVertexAttribPointer( 
+			location, 
+			static_cast<GLint>( va->get_components() ), 
+			nv::datatype_to_gl_enum( va->get_datatype() ),
+			GL_FALSE,
+			static_cast<GLsizei>( va->get_stride() ),
+			(void*)va->get_offset()
+			);
+		unbind( vb );
+	}
+
+	if ( va->m_index )
+	{
+		bind( va->m_index );
+	}
+}
+
+void nv::gl_context::unbind( program* )
+{
+	glUseProgram( 0 );
+}
+
+void nv::gl_context::unbind( vertex_buffer* )
+{
+	glBindBuffer( GL_ARRAY_BUFFER, 0 );
+}
+
+void nv::gl_context::unbind( index_buffer* )
+{
+	glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );
+}
+
+void nv::gl_context::unbind( vertex_array* va )
+{
+	if ( va->m_index )
+	{
+		unbind( va->m_index );
+	}
+
+	for ( vertex_buffer_attribute_map::iterator i = va->m_map.begin(); 	i != va->m_map.end(); ++i ) 
+	{
+		glDisableVertexAttribArray( static_cast<uint32>( i->first ) );
+	}
+}
+
+void gl_context::update( texture2d* texture, void* data )
+{
+	GLuint id = static_cast< gl_texture2d* >( texture )->m_name.get_value();
+	image_format format = texture->get_format();
+	ivec2        size   = texture->get_size();
+
+	glBindTexture( GL_TEXTURE_2D, id );
+	glTexImage2D( GL_TEXTURE_2D, 0, (GLint)nv::image_format_to_enum(format.format), size.x, size.y, 0, nv::image_format_to_enum(format.format), nv::datatype_to_gl_enum(format.type), data );
+}
+
+void gl_context::update( vertex_buffer* b, const void* data, size_t offset, size_t size )
+{
+	bind( b );
+	glBufferSubData( GL_ARRAY_BUFFER, (GLintptr)offset, (GLsizeiptr)size, data );
+}
+
+void gl_context::update( index_buffer* b, const void* data, size_t offset, size_t size )
+{
+	bind( b );
+	glBufferSubData( GL_ELEMENT_ARRAY_BUFFER, (GLintptr)offset, (GLsizeiptr)size, data );
+}
 
 void gl_context::clear( const clear_state& cs )
@@ -372,5 +477,4 @@
 }
 
-
 void gl_context::draw( primitive prim, const render_state& rs, program* p, vertex_array* va, size_t count )
 {
@@ -378,6 +482,6 @@
 	if ( count > 0 )
 	{
-		p->bind();
-		va->bind();
+		bind( p );
+		bind( va );
 		if ( va->has_index_buffer() )
 		{
@@ -388,6 +492,6 @@
 			glDrawArrays( primitive_to_enum(prim), 0, static_cast<GLsizei>( count ) );
 		}
-		va->unbind();
-		p->unbind();
+		unbind( va );
+		//unbind( p );
 	}
 }
Index: trunk/src/gl/gl_device.cc
===================================================================
--- trunk/src/gl/gl_device.cc	(revision 296)
+++ trunk/src/gl/gl_device.cc	(revision 299)
@@ -67,5 +67,5 @@
 vertex_array* gl_device::create_vertex_array()
 {
-	return new gl_vertex_array();
+	return new vertex_array();
 }
 
Index: trunk/src/gl/gl_program.cc
===================================================================
--- trunk/src/gl/gl_program.cc	(revision 296)
+++ trunk/src/gl/gl_program.cc	(revision 299)
@@ -125,15 +125,4 @@
 	load_uniforms();
 	return true;
-}
-
-void gl_program::bind()
-{
-	glUseProgram( m_name.get_value() );
-	update_uniforms();
-}
-
-void gl_program::unbind()
-{
-	glUseProgram( 0 );
 }
 
Index: trunk/src/gl/gl_texture2d.cc
===================================================================
--- trunk/src/gl/gl_texture2d.cc	(revision 296)
+++ trunk/src/gl/gl_texture2d.cc	(revision 299)
@@ -31,28 +31,8 @@
 	if (data)
 	{
-		assign(data);
+		glBindTexture( GL_TEXTURE_2D, m_name.get_value() );
+		glTexImage2D( GL_TEXTURE_2D, 0, (GLint)nv::image_format_to_enum(m_format.format), m_size.x, m_size.y, 0, nv::image_format_to_enum(m_format.format), nv::datatype_to_gl_enum(m_format.type), data );
+		glBindTexture( GL_TEXTURE_2D, 0 );
 	}
 }
 
-void nv::gl_texture2d::assign( void* data )
-{
-	glBindTexture( GL_TEXTURE_2D, m_name.get_value() );
-	glTexImage2D( GL_TEXTURE_2D, 0, (GLint)nv::image_format_to_enum(m_format.format), m_size.x, m_size.y, 0, nv::image_format_to_enum(m_format.format), nv::datatype_to_gl_enum(m_format.type), data );
-	glBindTexture( GL_TEXTURE_2D, 0 );
-}
-
-void nv::gl_texture2d::bind( size_t slot )
-{
-	glActiveTexture( GL_TEXTURE0 + static_cast< GLenum >( slot ) );
-	glBindTexture( GL_TEXTURE_2D, m_name.get_value() );
-}
-
-void nv::gl_texture2d::unbind()
-{
-	glBindTexture( GL_TEXTURE_2D, 0 );
-}
-
-bool nv::gl_texture2d::is_valid() const
-{
-	return m_name.is_valid();
-}
Index: trunk/src/gl/gl_vertex_buffer.cc
===================================================================
--- trunk/src/gl/gl_vertex_buffer.cc	(revision 296)
+++ trunk/src/gl/gl_vertex_buffer.cc	(revision 299)
@@ -13,29 +13,7 @@
 	: vertex_buffer( hint, size ), m_name()
 {
-	bind();
+	glBindBuffer( GL_ARRAY_BUFFER, m_name.get_value() );
 	glBufferData( GL_ARRAY_BUFFER, (GLsizeiptr)m_size, data, buffer_hint_to_enum( m_hint ) );
-	unbind();
-}
-
-void gl_vertex_buffer::update( const void* data, size_t offset, size_t size )
-{
-	// IMPORTANT - THIS DOES NOT BIND, SHOULD IT?
-	glBufferSubData( GL_ARRAY_BUFFER, (GLintptr)offset, (GLsizeiptr)size, data );
-}
-
-
-void gl_vertex_buffer::bind()
-{
-	glBindBuffer( GL_ARRAY_BUFFER, m_name.get_value() );
-}
-
-void gl_vertex_buffer::unbind()
-{
 	glBindBuffer( GL_ARRAY_BUFFER, 0 );
-}
-
-bool gl_vertex_buffer::is_valid() const
-{
-	return m_name.is_valid();
 }
 
@@ -43,70 +21,7 @@
 	: index_buffer( hint, size ), m_name()
 {
-	bind();
+	glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, m_name.get_value() );
 	glBufferData( GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)m_size, data, buffer_hint_to_enum( m_hint ) );
-	unbind();
-}
-
-void gl_index_buffer::update( const void* data, size_t offset, size_t size )
-{
-	glBufferSubData( GL_ELEMENT_ARRAY_BUFFER, (GLintptr)offset, (GLsizeiptr)size, data );
-}
-
-void gl_index_buffer::bind()
-{
-	glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, m_name.get_value() );
-}
-
-void gl_index_buffer::unbind()
-{
 	glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );
 }
 
-bool gl_index_buffer::is_valid() const
-{
-	return m_name.is_valid();
-}
-
-gl_vertex_array::gl_vertex_array()
-{
-
-}
-
-void gl_vertex_array::bind()
-{
-	for ( vertex_buffer_attribute_map::iterator i = m_map.begin(); 	i != m_map.end(); ++i ) 
-	{
-		uint32 location             = static_cast<uint32>( i->first );
-		vertex_buffer_attribute* va = i->second;
-		vertex_buffer*           vb = va->get_buffer();
-		glEnableVertexAttribArray( location );
-		vb->bind();
-		glVertexAttribPointer( 
-			location, 
-			static_cast<GLint>( va->get_components() ), 
-			nv::datatype_to_gl_enum( va->get_datatype() ),
-			GL_FALSE,
-			static_cast<GLsizei>( va->get_stride() ),
-			(void*)va->get_offset()
-			);
-		vb->unbind();
-	}
-
-	if ( m_index )
-	{
-		m_index->bind();
-	}
-}
-
-void gl_vertex_array::unbind()
-{
-	if ( m_index )
-	{
-		m_index->unbind();
-	}
-
-	for ( vertex_buffer_attribute_map::iterator i = m_map.begin(); 	i != m_map.end(); ++i ) 
-	{
-		glDisableVertexAttribArray( static_cast<uint32>( i->first ) );
-	}
-}
Index: trunk/src/gui/gui_renderer.cc
===================================================================
--- trunk/src/gui/gui_renderer.cc	(revision 296)
+++ trunk/src/gui/gui_renderer.cc	(revision 299)
@@ -65,6 +65,6 @@
 {
 public:
-	screen_render_data( device* dev, size_t initial_size )
-		: buffer( dev, nv::DYNAMIC_DRAW, initial_size ), varray( nullptr ), shader(nullptr), texture(nullptr) 
+	screen_render_data( context* ctx, size_t initial_size )
+		: buffer( ctx, nv::DYNAMIC_DRAW, initial_size ), varray( nullptr ), shader(nullptr), texture(nullptr) 
 	{
 
@@ -98,4 +98,5 @@
 	, m_reupload( true )
 {
+	m_context = w->get_context();
 	m_area.dim( dimension( w->get_width(), w->get_height() ) );
 	region white = m_atlas.get_region( ivec2(3,3) );
@@ -107,5 +108,5 @@
 	delete[] wfill;
 
-	screen_render_data* sr = new screen_render_data( w->get_device(), 1024 );
+	screen_render_data* sr = new screen_render_data( w->get_context(), 1024 );
 	m_render_data = sr;
 	// ** EXTREMELY TEMPORARY!
@@ -261,5 +262,5 @@
 	if ( m_reupload )
 	{
-		sr->texture->assign( (void*)m_atlas.get_data() );
+		m_context->update( sr->texture, (void*)m_atlas.get_data() );
 		m_reupload = false;
 	}
@@ -272,6 +273,6 @@
 		sr->varray->update_vertex_buffer( nv::slot::COLOR,    vb, false );
 	}
-	sr->texture->bind( nv::TEX_DIFFUSE );
-	m_window->get_context()->draw( TRIANGLES, m_render_state, m_scene_state, sr->shader, sr->varray, sr->buffer.get_size() * 6 );
+	m_context->bind( sr->texture, TEX_DIFFUSE );
+	m_context->draw( TRIANGLES, m_render_state, m_scene_state, sr->shader, sr->varray, sr->buffer.get_size() * 6 );
 }
 
