Index: trunk/src/gl/gl_context.cc
===================================================================
--- trunk/src/gl/gl_context.cc	(revision 487)
+++ trunk/src/gl/gl_context.cc	(revision 491)
@@ -14,12 +14,70 @@
 using namespace nv;
 
-nv::vertex_array nv::gl_context::create_vertex_array()
+nv::vertex_array nv::gl_context::create_vertex_array( const vertex_array_desc& desc )
 {
 	vertex_array result = m_vertex_arrays.create();
-	vertex_array_info* info = m_vertex_arrays.get( result );
-	info->count       = 0;
-	info->index       = buffer();
-	info->index_owner = false;
-	info->index_type  = USHORT;
+	gl_vertex_array_info* info = m_vertex_arrays.get( result );
+
+	glGenVertexArrays( 1, &info->glid );
+	info->count       = desc.count;
+	info->index       = desc.index;
+	info->index_owner = desc.index_owner;
+	info->index_type  = desc.index_type;
+
+	for ( uint32 i = 0; i < desc.count; ++i )
+		info->attr[i] = desc.attr[i];
+
+	glBindVertexArray( info->glid );
+
+	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 );
+		const gl_buffer_info* vinfo = static_cast<const gl_buffer_info*>( m_device->get_buffer_info( vba.vbuffer ) );
+		if ( vinfo && vinfo->type == VERTEX_BUFFER )
+			glBindBuffer( GL_ARRAY_BUFFER, vinfo->glid );
+		else
+		{
+			// TODO: report error
+		}
+
+		glVertexAttribPointer(
+			location,
+			static_cast<GLint>( vba.components ),
+			nv::datatype_to_gl_enum( vba.dtype ),
+			GL_FALSE,
+			static_cast<GLsizei>( vba.stride ),
+			reinterpret_cast<void*>( vba.offset )
+			);
+	}
+	glBindBuffer( GL_ARRAY_BUFFER, 0 );
+
+	if ( info->index.is_valid() )
+	{
+		const gl_buffer_info* iinfo = static_cast<const gl_buffer_info*>( m_device->get_buffer_info( info->index ) );
+		if ( iinfo && iinfo->type == INDEX_BUFFER )
+		{
+			glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, iinfo->glid );
+		}
+		else
+		{
+			// TODO: report error
+		}
+	}
+	glBindBuffer( GL_ARRAY_BUFFER, 0 );
+	glBindVertexArray( 0 );
+
+	if ( info->index.is_valid() )
+	{
+		glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );
+	}
+
+	for ( uint32 i = 0; i < info->count; ++i )
+	{
+		glDisableVertexAttribArray( static_cast<uint32>( info->attr[i].location ) );
+	}
+
+
 	return result;
 }
@@ -27,21 +85,17 @@
 nv::framebuffer nv::gl_context::create_framebuffer()
 {
-	if ( is_gl_extension_loaded( GL_EXT_FRAMEBUFFER_OBJECT ) && is_gl_extension_loaded( GL_EXT_FRAMEBUFFER_BLIT ) )
-	{
-		unsigned glid   = 0;
-		glGenFramebuffers( 1, &glid );
-		framebuffer result = m_framebuffers.create();
-		gl_framebuffer_info* info = m_framebuffers.get( result );
-		info->glid = glid;
-		info->depth_rb_glid = 0;
-		info->color_attachment_count = 0;
-		return result;
-	}
-	else return framebuffer();
+	unsigned glid   = 0;
+	glGenFramebuffers( 1, &glid );
+	framebuffer result = m_framebuffers.create();
+	gl_framebuffer_info* info = m_framebuffers.get( result );
+	info->glid = glid;
+	info->depth_rb_glid = 0;
+	info->color_attachment_count = 0;
+	return result;
 }
 
 void nv::gl_context::release( vertex_array va )
 {
-	vertex_array_info* info = m_vertex_arrays.get( va );
+	gl_vertex_array_info* info = m_vertex_arrays.get( va );
 	if ( info )
 	{
@@ -52,4 +106,5 @@
 		}
 		if ( info->index.is_valid() && info->index_owner) m_device->release( info->index );
+		glDeleteVertexArrays( 1, &info->glid );
 		m_vertex_arrays.destroy( va );
 	}
@@ -71,17 +126,7 @@
 }
 
-const vertex_array_info* nv::gl_context::get_vertex_array_info( vertex_array va ) const 
-{
-	return m_vertex_arrays.get( va );
-}
-
 const framebuffer_info* nv::gl_context::get_framebuffer_info( framebuffer f ) const
 {
 	return m_framebuffers.get( f );
-}
-
-vertex_array_info* nv::gl_context::get_vertex_array_info_mutable( vertex_array va ) 
-{
-	return m_vertex_arrays.get( va );
 }
 
@@ -170,23 +215,17 @@
  	glDrawBuffer( 0 );
  	glReadBuffer( 0 );
-	if ( is_gl_extension_loaded( GL_EXT_FRAMEBUFFER_OBJECT ) && is_gl_extension_loaded( GL_EXT_FRAMEBUFFER_BLIT ) )
-	{
-		unsigned result = glCheckFramebufferStatus( framebuffer_slot_to_enum(ft) );
-		if ( result == GL_FRAMEBUFFER_COMPLETE ) return true;
-		switch ( result )
-		{
-		case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT         : NV_LOG_ERROR( "gl_context::check : Framebuffer incomplete attachment!" ); break;
-		case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT : NV_LOG_ERROR( "gl_context::check : Framebuffer missing attachment!" ); break;
+
+	unsigned result = glCheckFramebufferStatus( framebuffer_slot_to_enum(ft) );
+	if ( result == GL_FRAMEBUFFER_COMPLETE ) return true;
+	switch ( result )
+	{
+	case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT         : NV_LOG_ERROR( "gl_context::check : Framebuffer incomplete attachment!" ); break;
+	case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT : NV_LOG_ERROR( "gl_context::check : Framebuffer missing attachment!" ); break;
 //		case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS         : NV_LOG_ERROR( "gl_context::check : Framebuffer incomplete dimensions!" ); break;
 //		case GL_FRAMEBUFFER_INCOMPLETE_FORMATS            : NV_LOG_ERROR( "gl_context::check : Framebuffer incomplete formats!" ); break;
-		case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER        : NV_LOG_ERROR( "gl_context::check : Framebuffer incomplete draw buffer!" ); break;
-		case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER        : NV_LOG_ERROR( "gl_context::check : Framebuffer incomplete read buffer!" ); break;
-		case GL_FRAMEBUFFER_UNSUPPORTED                   : NV_LOG_ERROR( "gl_context::check : Framebuffer format combination unsupported!" ); break;
-		default: NV_LOG_ERROR( "gl_context::check : Unknown Framebuffer error! (", result, ")" ); break;
-		}
-	}
-	else
-	{
-		NV_LOG_ERROR( "gl_context::check : Framebuffer extensions not loaded!" );
+	case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER        : NV_LOG_ERROR( "gl_context::check : Framebuffer incomplete draw buffer!" ); break;
+	case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER        : NV_LOG_ERROR( "gl_context::check : Framebuffer incomplete read buffer!" ); break;
+	case GL_FRAMEBUFFER_UNSUPPORTED                   : NV_LOG_ERROR( "gl_context::check : Framebuffer format combination unsupported!" ); break;
+	default: NV_LOG_ERROR( "gl_context::check : Unknown Framebuffer error! (", result, ")" ); break;
 	}
 	glDrawBuffer( GL_BACK );
@@ -205,4 +244,19 @@
 	{
 		glBindFramebuffer( framebuffer_slot_to_enum(ft), 0 );
+	}
+}
+
+void nv::gl_context::bind( buffer b, texture t )
+{
+	const gl_buffer_info*  binfo = static_cast< const gl_buffer_info* >( m_device->get_buffer_info( b ) );
+	const gl_texture_info* tinfo = static_cast< const gl_texture_info* >( m_device->get_texture_info( t ) );
+	NV_ASSERT( binfo && tinfo, "Bad buffer or texture passed to create_texture" );
+	if ( binfo && tinfo )
+	{
+		NV_ASSERT_ALWAYS( binfo->type == TEXTURE_BUFFER && tinfo->type == TEXTURE_1D_BUFFER, "bad texture or buffer type!" );
+		glActiveTexture( GL_TEXTURE0 );
+		glBindTexture( GL_TEXTURE_BUFFER, tinfo->glid );
+		glTexBuffer( GL_TEXTURE_BUFFER, image_format_to_internal_enum( tinfo->format.format ), binfo->glid );
+		glBindTexture( GL_TEXTURE_BUFFER, 0 );
 	}
 }
@@ -252,43 +306,8 @@
 void nv::gl_context::bind( vertex_array va )
 {
-	const vertex_array_info* info = m_vertex_arrays.get( 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 );
-			const gl_buffer_info* vinfo = static_cast< const gl_buffer_info* >( m_device->get_buffer_info( vba.vbuffer ) );
-			if ( vinfo && vinfo->type == VERTEX_BUFFER )
-				glBindBuffer( GL_ARRAY_BUFFER, vinfo->glid );
-			else
-			{
-				// TODO: report error
-			}
-
-			glVertexAttribPointer(
-				location,
-				static_cast<GLint>( vba.components ),
-				nv::datatype_to_gl_enum( vba.dtype ),
-				GL_FALSE,
-				static_cast<GLsizei>( vba.stride ),
-				reinterpret_cast<void*>( vba.offset )
-				);
-		}
-		glBindBuffer( GL_ARRAY_BUFFER, 0 );
-
-		if ( info->index.is_valid() )
-		{
-			const gl_buffer_info* iinfo = static_cast< const gl_buffer_info* >( m_device->get_buffer_info( info->index ) );
-			if ( iinfo && iinfo->type == INDEX_BUFFER )
-			{
-				glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, iinfo->glid );
-			}
-			else
-			{
-				// TODO: report error
-			}
-		}
+	gl_vertex_array_info* info = m_vertex_arrays.get( va );
+	if ( info )
+	{
+		glBindVertexArray( info->glid );
 	}
 }
@@ -313,13 +332,5 @@
 	if ( info )
 	{
-		if ( info->index.is_valid() )
-		{
-			glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );
-		}
-
-		for ( uint32 i = 0; i < info->count; ++i ) 
-		{
-			glDisableVertexAttribArray( static_cast<uint32>( info->attr[i].location ) );
-		}
+		glBindVertexArray( 0 );
 	}
 }
@@ -340,4 +351,5 @@
 {
 	const gl_texture_info* info = static_cast< const gl_texture_info* >( m_device->get_texture_info( t ) );
+	NV_ASSERT_ALWAYS( info->type != TEXTURE_1D_BUFFER, "Buffer texture passed to update!" );
 	if ( info )
 	{
@@ -347,4 +359,5 @@
 
 		glBindTexture( gl_type, info->glid );
+		int this_should_be_subTexImage;
 		if ( info->type == TEXTURE_3D || info->type == TEXTURE_2D_ARRAY )
 			glTexImage3D( gl_type, 0, static_cast<GLint>( nv::image_format_to_internal_enum( format.format ) ), size.x, size.y, size.z, 0, nv::image_format_to_enum( format.format ), nv::datatype_to_gl_enum( format.type ), data );
@@ -722,7 +735,6 @@
 {
 	// TODO: configurable:
-	load_gl_extensions( GL_EXT_FRAMEBUFFER_BLIT | GL_EXT_FRAMEBUFFER_OBJECT | GL_EXT_TEXTURE_ARRAY );
+//	load_gl_extensions( GL_EXT_FRAMEBUFFER_BLIT | GL_EXT_FRAMEBUFFER_OBJECT | GL_EXT_TEXTURE_ARRAY );
 	force_apply_render_state( m_render_state );
-
 }
 
