Index: trunk/src/formats/assimp_loader.cc
===================================================================
--- trunk/src/formats/assimp_loader.cc	(revision 301)
+++ trunk/src/formats/assimp_loader.cc	(revision 302)
@@ -317,5 +317,4 @@
 			{
 				mesh_raw_channel* channel = meshes[m].get_raw_channels()[0];
-				NV_ASSERT( !channel->is_index(), "index channel in release_merged!" );
 				assimp_skinned_vtx* va = (assimp_skinned_vtx*)channel->data;
 				for ( unsigned v = 0; v < channel->count; ++v )
Index: trunk/src/gfx/debug_draw.cc
===================================================================
--- trunk/src/gfx/debug_draw.cc	(revision 301)
+++ trunk/src/gfx/debug_draw.cc	(revision 302)
@@ -29,5 +29,5 @@
 
 nv::debug_data::debug_data( device* a_device )
-	: m_device( a_device ), m_program( nullptr ), m_va( nullptr )
+	: m_device( a_device ), m_program( nullptr ), m_va()
 {
 	m_program = m_device->create_program( nv_debug_draw_vertex_shader, nv_debug_draw_fragment_shader );
@@ -36,5 +36,5 @@
 void nv::debug_data::update()
 {
-	delete m_va;
+	m_device->release( m_va );
 	m_va = m_device->create_vertex_array( m_data, nv::STATIC_DRAW );
 }
@@ -75,5 +75,5 @@
 nv::debug_data::~debug_data()
 {
-	delete m_va;
+	m_device->release( m_va );
 	delete m_program;
 }
Index: trunk/src/gfx/keyframed_mesh.cc
===================================================================
--- trunk/src/gfx/keyframed_mesh.cc	(revision 301)
+++ trunk/src/gfx/keyframed_mesh.cc	(revision 302)
@@ -15,6 +15,7 @@
 using namespace nv;
 
-nv::keyframed_mesh::keyframed_mesh( const mesh_data* a_data, const mesh_nodes_data* a_tag_map )
+nv::keyframed_mesh::keyframed_mesh( context* a_context, const mesh_data* a_data, const mesh_nodes_data* a_tag_map )
 	: animated_mesh()
+	, m_context( a_context )
 	, m_mesh_data( a_data )
 	, m_tag_map( a_tag_map )
@@ -36,4 +37,5 @@
 	}
 	m_frame_count  = m_vchannel->count / m_vertex_count;
+	m_pbuffer      = buffer();
 }
 
@@ -103,5 +105,5 @@
 nv::keyframed_mesh::~keyframed_mesh()
 {
-	delete m_va;
+	m_context->get_device()->release( m_va );
 }
 
@@ -122,5 +124,5 @@
 
 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 )
+	: keyframed_mesh( a_context, a_data, a_tag_map )
 	, m_loc_next_position( -1 )
 	, m_loc_next_normal( -1 )
@@ -129,5 +131,6 @@
 	, m_gpu_next_frame( 0xFFFFFFFF )
 {
-	m_va = a_context->get_device()->create_vertex_array( a_data, STATIC_DRAW );
+	m_va      = a_context->get_device()->create_vertex_array( a_data, STATIC_DRAW );
+	m_pbuffer = a_context->get_device()->find_buffer( m_va, slot::POSITION );
 }
 
@@ -137,12 +140,13 @@
 	if ( m_loc_next_position == -1 ) return;
 	animated_mesh::update( ms );
-
+	device* dev = m_context->get_device();
 	if ( m_gpu_last_frame != m_last_frame )
 	{
-		m_va->update_vertex_buffer( slot::POSITION, m_last_frame * m_vertex_count * m_vsize );
-		m_va->update_vertex_buffer( slot::NORMAL,   m_last_frame * m_vertex_count * m_vsize + sizeof( vec3 ) );
+		uint32 base_offset = m_last_frame * m_vertex_count * m_vsize; 
+		dev->update_attribute_offset( m_va, slot::POSITION, base_offset );
+		dev->update_attribute_offset( m_va, slot::NORMAL,   base_offset + sizeof( vec3 ) );
 		if ( m_has_tangent && m_loc_next_tangent != -1 )
 		{
-			m_va->update_vertex_buffer( slot::TANGENT,   m_last_frame * m_vertex_count * m_vsize + 2*sizeof( vec3 ) );
+			dev->update_attribute_offset( m_va, slot::TANGENT, base_offset + 2*sizeof( vec3 ) );
 		}
 		m_gpu_last_frame = m_last_frame;
@@ -150,7 +154,11 @@
 	if ( m_loc_next_position != -1 && m_gpu_next_frame != m_next_frame )
 	{
-		m_va->update_vertex_buffer( m_loc_next_position, m_next_frame * m_vertex_count * m_vsize );
-		m_va->update_vertex_buffer( m_loc_next_normal,   m_next_frame * m_vertex_count * m_vsize + sizeof( vec3 ) );
-		m_va->update_vertex_buffer( m_loc_next_tangent,   m_next_frame * m_vertex_count * m_vsize + 2*sizeof( vec3 ) );
+		uint32 base_offset = m_next_frame * m_vertex_count * m_vsize; 
+		dev->update_attribute_offset( m_va, (slot)m_loc_next_position, base_offset );
+		dev->update_attribute_offset( m_va, (slot)m_loc_next_normal, base_offset + sizeof( vec3 ) );
+		if ( m_has_tangent && m_loc_next_tangent != -1 )
+		{
+			dev->update_attribute_offset( m_va, (slot)m_loc_next_tangent, base_offset + 2*sizeof( vec3 ) );
+		}
 		m_gpu_next_frame = m_next_frame;
 	}
@@ -166,9 +174,9 @@
 			m_loc_next_tangent  = a_program->get_attribute( "nv_next_tangent" )->get_location();
 
-		vertex_buffer* vb = m_va->find_buffer( slot::POSITION );
-		m_va->add_vertex_buffer( m_loc_next_position, vb, FLOAT, 3, 0, m_vsize, false );
-		m_va->add_vertex_buffer( m_loc_next_normal,   vb, FLOAT, 3, sizeof( vec3 ), m_vsize, false );
+		device* dev = m_context->get_device();
+		dev->add_vertex_buffer( m_va, (slot)m_loc_next_position, m_pbuffer, FLOAT, 3, 0, m_vsize, false );
+		dev->add_vertex_buffer( m_va, (slot)m_loc_next_normal,   m_pbuffer, FLOAT, 3, sizeof( vec3 ), m_vsize, false );
 		if ( m_has_tangent )
-			m_va->add_vertex_buffer( m_loc_next_tangent, vb, FLOAT, 4, 2*sizeof( vec3 ), m_vsize, false );
+			dev->add_vertex_buffer( m_va, (slot)m_loc_next_tangent, m_pbuffer, FLOAT, 4, 2*sizeof( vec3 ), m_vsize, false );
 	}
 	keyframed_mesh::update( a_program );
@@ -176,16 +184,16 @@
 
 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 = 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 = 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 );
+	: keyframed_mesh( a_context, a_data, a_tag_map )
+{
+	m_va      = m_context->get_device()->create_vertex_array();
+	m_pbuffer = m_context->get_device()->create_buffer( VERTEX_BUFFER, STATIC_DRAW, m_vertex_count * m_vsize, (void*)m_vchannel->data );
+	m_context->get_device()->add_vertex_buffers( m_va, m_pbuffer, m_vchannel );
+
+	buffer  vb = m_context->get_device()->create_buffer( VERTEX_BUFFER, STATIC_DRAW, m_vertex_count * sizeof( vec2 ), (void*)m_mesh_data->get_channel<vertex_t>()->data );
+	m_context->get_device()->add_vertex_buffers( m_va, vb, m_mesh_data->get_channel<vertex_t>() );
+
+	buffer  ib = m_context->get_device()->create_buffer( INDEX_BUFFER, STATIC_DRAW, m_mesh_data->get_index_channel()->size(), (void*)m_mesh_data->get_index_channel()->data );
+
+	m_context->get_device()->set_index_buffer( m_va, ib, m_mesh_data->get_index_channel()->desc.slots[0].etype, true );
 
 	m_data = new uint8[ m_vertex_count * m_vsize ];
@@ -224,5 +232,5 @@
 	}
 
-	m_context->update( m_vb, m_data, 0, m_vertex_count * m_vsize );
+	m_context->update( m_pbuffer, m_data, 0, m_vertex_count * m_vsize );
 }
 
Index: trunk/src/gfx/mesh_creator.cc
===================================================================
--- trunk/src/gfx/mesh_creator.cc	(revision 301)
+++ trunk/src/gfx/mesh_creator.cc	(revision 302)
@@ -430,8 +430,8 @@
 	{
 		mesh_raw_channel* old = m_data->m_channels[c];
-		size_t frame_count = ( old->is_index() ? 1 : old->count / size );
+		size_t frame_count = ( old->get_buffer_type() == INDEX_BUFFER ? 1 : old->count / size );
 		m_data->m_channels[c] = append_channels( old, other->m_channels[c], frame_count );
 		NV_ASSERT( m_data->m_channels[c], "Merge problem!" );
-		if ( old->is_index() )
+		if ( old->get_buffer_type() == INDEX_BUFFER )
 		{
 			switch ( old->desc.slots[0].etype )
Index: trunk/src/gfx/skeletal_mesh.cc
===================================================================
--- trunk/src/gfx/skeletal_mesh.cc	(revision 301)
+++ trunk/src/gfx/skeletal_mesh.cc	(revision 302)
@@ -12,6 +12,5 @@
 
 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 )
+	: skeletal_mesh( a_context )
 	, m_data( a_mesh_data )
 {
@@ -27,5 +26,7 @@
 	m_vtx_data  = a_mesh_data->get_channel_data<md5_vtx_pntiw>();
 	m_indices   = a_mesh_data->get_count();
-	m_va        = a_context->get_device()->create_vertex_array( a_mesh_data, nv::STREAM_DRAW );
+	m_va        = a_context->get_device()->create_vertex_array( a_mesh_data, 
+STREAM_DRAW );
+	m_pbuffer   = a_context->get_device()->find_buffer( m_va, slot::POSITION );
 }
 
@@ -63,6 +64,5 @@
 		}
 
-		vertex_buffer* vb = m_va->find_buffer( nv::slot::POSITION );
-		m_context->update( vb, m_pntdata.data(), 0, m_pntdata.raw_size() );
+		m_context->update( m_pbuffer, m_pntdata.data(), 0, m_pntdata.raw_size() );
 	}
 }
@@ -80,11 +80,4 @@
 		skeleton[i] = m_node_data->get_node(i)->data->get_transform( frame_num );
 	}
-}
-
-
-
-nv::skeletal_mesh_cpu::~skeletal_mesh_cpu()
-{
-	delete m_va;
 }
 
@@ -200,5 +193,5 @@
 
 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 )
+	: skeletal_mesh( a_context ), m_bone_data( a_bone_data ), m_transform( nullptr )
 {
 	m_va          = a_context->get_device()->create_vertex_array( a_mesh, nv::STATIC_DRAW );
Index: trunk/src/gl/gl_context.cc
===================================================================
--- trunk/src/gl/gl_context.cc	(revision 301)
+++ trunk/src/gl/gl_context.cc	(revision 302)
@@ -10,5 +10,4 @@
 #include "nv/gl/gl_device.hh"
 #include "nv/gl/gl_program.hh"
-#include "nv/gl/gl_vertex_buffer.hh"
 
 using namespace nv;
@@ -31,39 +30,39 @@
 }
 
-void nv::gl_context::bind( vertex_buffer* b )
-{
-	GLuint id = static_cast< gl_vertex_buffer* >( b )->glid;
-	glBindBuffer( GL_ARRAY_BUFFER, id );
-}
-
-void nv::gl_context::bind( index_buffer* b )
-{
-	GLuint id = static_cast< gl_index_buffer* >( b )->glid;
-	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::bind( buffer b )
+{
+	const gl_buffer_info* info = static_cast< const gl_buffer_info* >( m_device->get_buffer_info( b ) );
+	if ( info )
+	{
+		glBindBuffer( buffer_type_to_enum( info->type ), info->glid );
+	}
+}
+
+void nv::gl_context::bind( vertex_array va )
+{
+	vertex_array_info* info = get_vertex_array_info( va );
+	if ( info )
+	{
+		for ( uint32 i = 0; i < info->count; ++i ) 
+		{
+			const vertex_buffer_attribute& vba = info->attr[i];
+			uint32 location                    = static_cast<uint32>( vba.location );
+			glEnableVertexAttribArray( location );
+			bind( vba.vbuffer );
+			glVertexAttribPointer( 
+				location, 
+				static_cast<GLint>( vba.components ), 
+				nv::datatype_to_gl_enum( vba.dtype ),
+				GL_FALSE,
+				static_cast<GLsizei>( vba.stride ),
+				(void*)vba.offset
+				);
+			unbind( vba.vbuffer );
+		}
+
+		if ( info->index.is_valid() )
+		{
+			bind( info->index );
+		}
 	}
 }
@@ -74,24 +73,27 @@
 }
 
-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 nv::gl_context::unbind( buffer b )
+{
+	const gl_buffer_info* info = static_cast< const gl_buffer_info* >( m_device->get_buffer_info( b ) );
+	if ( info )
+	{
+		glBindBuffer( buffer_type_to_enum( info->type ), 0 );
+	}
+}
+
+void nv::gl_context::unbind( vertex_array va )
+{
+	vertex_array_info* info = get_vertex_array_info( va );
+	if ( info )
+	{
+		if ( info->index.is_valid() )
+		{
+			unbind( info->index );
+		}
+
+		for ( uint32 i = 0; i < info->count; ++i ) 
+		{
+			glDisableVertexAttribArray( static_cast<uint32>( info->attr[i].location ) );
+		}
 	}
 }
@@ -110,14 +112,12 @@
 }
 
-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::update( buffer b, const void* data, size_t offset, size_t size )
+{
+	const gl_buffer_info* info = static_cast< const gl_buffer_info* >( m_device->get_buffer_info( b ) );
+	if ( info )
+	{
+		bind( b );
+		glBufferSubData( buffer_type_to_enum( info->type ), (GLintptr)offset, (GLsizeiptr)size, data );
+	}
 }
 
@@ -483,14 +483,15 @@
 }
 
-void gl_context::draw( primitive prim, const render_state& rs, program* p, vertex_array* va, size_t count )
+void gl_context::draw( primitive prim, const render_state& rs, program* p, vertex_array va, size_t count )
 {
 	apply_render_state( rs );
-	if ( count > 0 )
+	vertex_array_info* info = get_vertex_array_info( va );
+	if ( count > 0 && info )
 	{
 		bind( p );
 		bind( va );
-		if ( va->has_index_buffer() )
-		{
-			glDrawElements( primitive_to_enum(prim), static_cast<GLsizei>( count ), datatype_to_gl_enum( va->get_index_buffer_type() ), 0 );
+		if ( info->index.is_valid() )
+		{
+			glDrawElements( primitive_to_enum(prim), static_cast<GLsizei>( count ), datatype_to_gl_enum( info->index_type ), 0 );
 		}
 		else
Index: trunk/src/gl/gl_device.cc
===================================================================
--- trunk/src/gl/gl_device.cc	(revision 301)
+++ trunk/src/gl/gl_device.cc	(revision 302)
@@ -7,5 +7,4 @@
 #include "nv/gl/gl_window.hh"
 #include "nv/gl/gl_program.hh"
-#include "nv/gl/gl_vertex_buffer.hh"
 #include "nv/logging.hh"
 #include "nv/lib/sdl.hh"
@@ -56,19 +55,4 @@
 }
 
-vertex_buffer* gl_device::create_vertex_buffer( buffer_hint hint, size_t size, const void* source /*= nullptr */ )
-{
-	return new gl_vertex_buffer( hint, size, source );
-}
-
-index_buffer* gl_device::create_index_buffer( buffer_hint hint, size_t size, const void* source /*= nullptr */ )
-{
-	return new gl_index_buffer( hint, size, source );
-}
-
-vertex_array* gl_device::create_vertex_array()
-{
-	return new vertex_array();
-}
-
 // this is a temporary function that will be removed once we find a way to 
 // pass binary file data around
@@ -101,6 +85,8 @@
 gl_device::~gl_device()
 {
-	// TODO: better use release_texture
-	for ( auto& t : m_textures ) glDeleteTextures( 1, &t.glid );
+	while ( m_textures.size() > 0 )
+		release( m_textures.get_handle(0) );
+	while ( m_buffers.size() > 0 )
+		release( m_buffers.get_handle(0) );
 
 	SDL_Quit();
@@ -142,11 +128,27 @@
 }
 
-void nv::gl_device::release_texture( texture t )
+void nv::gl_device::release( texture t )
 {
 	gl_texture_info* info = m_textures.get( t );
 	if ( info )
 	{
-		glDeleteTextures( 1, &(info->glid) );
+		if ( info->glid != 0 )
+		{
+			glDeleteTextures( 1, &(info->glid) );
+		}
 		m_textures.destroy( t );
+	}
+}
+
+void nv::gl_device::release( buffer b )
+{
+	gl_buffer_info* info = m_buffers.get( b );
+	if ( info )
+	{
+		if ( info->glid != 0 )
+		{
+			glDeleteBuffers( 1, &(info->glid) );
+		}
+		m_buffers.destroy( b );
 	}
 }
@@ -157,2 +159,25 @@
 }
 
+nv::buffer nv::gl_device::create_buffer( buffer_type type, buffer_hint hint, size_t size, const void* source /*= nullptr */ )
+{
+	unsigned glid   = 0;
+	unsigned glenum = buffer_type_to_enum( type );
+	glGenBuffers( 1, &glid );
+
+	glBindBuffer( glenum, glid );
+	glBufferData( glenum, (GLsizeiptr)size, source, buffer_hint_to_enum( hint ) );
+	glBindBuffer( glenum, 0 );
+
+	buffer result = m_buffers.create();
+	gl_buffer_info* info = m_buffers.get( result );
+	info->type = type;
+	info->hint = hint;
+	info->size = size;
+	info->glid = glid;
+	return result;
+}
+
+const buffer_info* nv::gl_device::get_buffer_info( buffer t )
+{
+	return m_buffers.get( t );
+}
Index: trunk/src/gl/gl_enum.cc
===================================================================
--- trunk/src/gl/gl_enum.cc	(revision 301)
+++ trunk/src/gl/gl_enum.cc	(revision 302)
@@ -144,4 +144,14 @@
 	case DYNAMIC_DRAW  : return GL_DYNAMIC_DRAW;
 	NV_RETURN_COVERED_DEFAULT( 0 );
+	}
+}
+
+unsigned int nv::buffer_type_to_enum( buffer_type type )
+{
+	switch( type )
+	{
+	case VERTEX_BUFFER : return GL_ARRAY_BUFFER;
+	case INDEX_BUFFER  : return GL_ELEMENT_ARRAY_BUFFER;
+		NV_RETURN_COVERED_DEFAULT( 0 );
 	}
 }
Index: trunk/src/gl/gl_vertex_buffer.cc
===================================================================
--- trunk/src/gl/gl_vertex_buffer.cc	(revision 301)
+++ 	(revision )
@@ -1,45 +1,0 @@
-// Copyright (C) 2012-2013 Kornel Kisielewicz
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-#include "nv/gl/gl_vertex_buffer.hh"
-
-#include "nv/lib/gl.hh"
-#include "nv/gl/gl_enum.hh"
-
-using namespace nv;
-
-gl_vertex_buffer::gl_vertex_buffer( buffer_hint hint, size_t size, const void* data ) 
-	: vertex_buffer( hint, size )
-{
-	glGenBuffers( 1, &glid );
-	glBindBuffer( GL_ARRAY_BUFFER, glid );
-	glBufferData( GL_ARRAY_BUFFER, (GLsizeiptr)m_size, data, buffer_hint_to_enum( m_hint ) );
-	glBindBuffer( GL_ARRAY_BUFFER, 0 );
-}
-
-nv::gl_vertex_buffer::~gl_vertex_buffer()
-{
-	if ( glid != 0 )
-	{
-		glDeleteBuffers( 1, &glid );
-	}
-}
-
-gl_index_buffer::gl_index_buffer( buffer_hint hint, size_t size, const void* data ) 
-	: index_buffer( hint, size )
-{
-	glGenBuffers( 1, &glid );
-
-	glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, glid );
-	glBufferData( GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)m_size, data, buffer_hint_to_enum( m_hint ) );
-	glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );
-}
-
-nv::gl_index_buffer::~gl_index_buffer()
-{
-	if ( glid != 0 )
-	{
-		glDeleteBuffers( 1, &glid );
-	}
-}
Index: trunk/src/gui/gui_renderer.cc
===================================================================
--- trunk/src/gui/gui_renderer.cc	(revision 301)
+++ trunk/src/gui/gui_renderer.cc	(revision 302)
@@ -21,36 +21,36 @@
 	{
 		set_color( color );
-		vtx[0].coord = coorda;
-		vtx[1].coord = nv::ivec2( coorda.x, coordb.y );
-		vtx[2].coord = coordb;
-		vtx[3].coord = coordb;
-		vtx[4].coord = nv::ivec2( coordb.x, coorda.y );
-		vtx[5].coord = coorda;
+		vtx[0].position = coorda;
+		vtx[1].position = nv::ivec2( coorda.x, coordb.y );
+		vtx[2].position = coordb;
+		vtx[3].position = coordb;
+		vtx[4].position = nv::ivec2( coordb.x, coorda.y );
+		vtx[5].position = coorda;
 	}
 	gui_quad( const nv::ivec2& coorda, const nv::ivec2& coordb, const nv::vec4& color, const nv::vec2& tcoorda, const nv::vec2& tcoordb )
 	{
 		set_color( color );
-		vtx[0].coord = coorda;
-		vtx[1].coord = nv::ivec2( coorda.x, coordb.y );
-		vtx[2].coord = coordb;
-		vtx[3].coord = coordb;
-		vtx[4].coord = nv::ivec2( coordb.x, coorda.y );
-		vtx[5].coord = coorda;
-		vtx[0].tcoord = tcoorda;
-		vtx[1].tcoord = nv::vec2( tcoorda.x, tcoordb.y );
-		vtx[2].tcoord = tcoordb;
-		vtx[3].tcoord = tcoordb;
-		vtx[4].tcoord = nv::vec2( tcoordb.x, tcoorda.y );
-		vtx[5].tcoord = tcoorda;
+		vtx[0].position = coorda;
+		vtx[1].position = nv::ivec2( coorda.x, coordb.y );
+		vtx[2].position = coordb;
+		vtx[3].position = coordb;
+		vtx[4].position = nv::ivec2( coordb.x, coorda.y );
+		vtx[5].position = coorda;
+		vtx[0].texcoord = tcoorda;
+		vtx[1].texcoord = nv::vec2( tcoorda.x, tcoordb.y );
+		vtx[2].texcoord = tcoordb;
+		vtx[3].texcoord = tcoordb;
+		vtx[4].texcoord = nv::vec2( tcoordb.x, tcoorda.y );
+		vtx[5].texcoord = tcoorda;
 	}
 	gui_quad( const nv::ivec2& coorda, const nv::ivec2& coordb, const nv::ivec2& coordc, const nv::ivec2& coordd, const nv::vec4& color )
 	{
 		set_color( color );
-		vtx[0].coord = coorda;
-		vtx[1].coord = coordb;
-		vtx[2].coord = coordc;
-		vtx[3].coord = coordc;
-		vtx[4].coord = coordd;
-		vtx[5].coord = coorda;
+		vtx[0].position = coorda;
+		vtx[1].position = coordb;
+		vtx[2].position = coordc;
+		vtx[3].position = coordc;
+		vtx[4].position = coordd;
+		vtx[5].position = coorda;
 	}
 	inline void set_color( const nv::vec4& color )
@@ -66,5 +66,5 @@
 public:
 	screen_render_data( context* actx, size_t initial_size )
-		: buffer( actx, nv::DYNAMIC_DRAW, initial_size ), varray( nullptr ), shader(nullptr)
+		: buffer( actx, VERTEX_BUFFER, DYNAMIC_DRAW, initial_size ), ctx( actx ), varray(), shader(nullptr)
 	{
 
@@ -73,10 +73,11 @@
 	{ 
 		delete shader; 
-		delete varray; 
+		ctx->get_device()->release( varray ); 
 	}
 
 	nv::sliced_buffer<gui_quad> buffer;
+	nv::context*      ctx;
 	nv::texture       tex;
-	nv::vertex_array* varray;
+	nv::vertex_array  varray;
 	nv::program*      shader;
 };
@@ -110,12 +111,10 @@
 	m_render_data = sr;
 	// ** EXTREMELY TEMPORARY!
-	sr->varray     = m_window->get_device()->create_vertex_array();
 	sr->shader     = m_window->get_device()->create_program( nv::slurp( shader_path + ".vert" ), nv::slurp( shader_path + ".frag" ) );
 	m_scene_state.get_camera().set_ortho( 0.0f, float( m_window->get_width() ), float( m_window->get_height() ), 0.0f );
 
-	vertex_buffer* vb = (vertex_buffer*)sr->buffer.get_buffer();
-	sr->varray->add_vertex_buffer( slot::POSITION, vb, nv::INT,   2, 0, sizeof( vertex ), false );
-	sr->varray->add_vertex_buffer( slot::TEXCOORD, vb, nv::FLOAT, 2, offset_of( &vertex::tcoord ), sizeof( vertex ), false );
-	sr->varray->add_vertex_buffer( slot::COLOR,    vb, nv::FLOAT, 4, offset_of( &vertex::color ), sizeof( vertex ), false );
+	sr->varray     = m_window->get_device()->create_vertex_array();
+	buffer vb      = sr->buffer.get_buffer();
+	m_window->get_device()->add_vertex_buffers< vertex >( sr->varray, vb );
 
 	nv::sampler sampler( nv::sampler::LINEAR, nv::sampler::CLAMP_TO_EDGE );
@@ -267,8 +266,6 @@
 	if ( sr->buffer.commit() )
 	{
-		nv::vertex_buffer* vb = (nv::vertex_buffer*)sr->buffer.get_buffer();
-		sr->varray->update_vertex_buffer( nv::slot::POSITION, vb, false );
-		sr->varray->update_vertex_buffer( nv::slot::TEXCOORD, vb, false );
-		sr->varray->update_vertex_buffer( nv::slot::COLOR,    vb, false );
+		buffer vb = sr->buffer.get_buffer();
+		m_context->get_device()->replace_vertex_buffer( sr->varray, vb, false );
 	}
 	m_context->bind( sr->tex, TEX_DIFFUSE );
@@ -284,5 +281,5 @@
 	if ( m_render_data )
 	{
-		m_context->get_device()->release_texture( ((screen_render_data*)m_render_data)->tex );
+		m_context->get_device()->release( ((screen_render_data*)m_render_data)->tex );
 		delete m_render_data;
 	}
