Changeset 302 for trunk/src/gl/gl_context.cc
- Timestamp:
- 08/07/14 19:06:34 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gl/gl_context.cc
r301 r302 10 10 #include "nv/gl/gl_device.hh" 11 11 #include "nv/gl/gl_program.hh" 12 #include "nv/gl/gl_vertex_buffer.hh"13 12 14 13 using namespace nv; … … 31 30 } 32 31 33 void nv::gl_context::bind( vertex_buffer*b )34 { 35 GLuint id = static_cast< gl_vertex_buffer* >( b )->glid;36 glBindBuffer( GL_ARRAY_BUFFER, id );37 } 38 39 void nv::gl_context::bind( index_buffer* b ) 40 { 41 GLuint id = static_cast< gl_index_buffer* >( b )->glid; 42 glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, id ); 43 } 44 45 void nv::gl_context::bind( vertex_array* va)46 {47 for ( vertex_buffer_attribute_map::iterator i = va->m_map.begin(); i != va->m_map.end(); ++i )48 {49 uint32 location = static_cast<uint32>( i->first );50 vertex_buffer_attribute* va = i->second;51 vertex_buffer* vb = va->get_buffer();52 glEnableVertexAttribArray( location);53 bind( vb );54 glVertexAttribPointer(55 location,56 static_cast<GLint>( va->get_components() ),57 nv::datatype_to_gl_enum( va->get_datatype() ),58 GL_FALSE,59 static_cast<GLsizei>( va->get_stride() ),60 (void*)va->get_offset()61 );62 unbind( vb );63 } 64 65 if ( va->m_index )66 {67 bind( va->m_index );32 void nv::gl_context::bind( buffer b ) 33 { 34 const gl_buffer_info* info = static_cast< const gl_buffer_info* >( m_device->get_buffer_info( b ) ); 35 if ( info ) 36 { 37 glBindBuffer( buffer_type_to_enum( info->type ), info->glid ); 38 } 39 } 40 41 void nv::gl_context::bind( vertex_array va ) 42 { 43 vertex_array_info* info = get_vertex_array_info( va ); 44 if ( info ) 45 { 46 for ( uint32 i = 0; i < info->count; ++i ) 47 { 48 const vertex_buffer_attribute& vba = info->attr[i]; 49 uint32 location = static_cast<uint32>( vba.location ); 50 glEnableVertexAttribArray( location ); 51 bind( vba.vbuffer ); 52 glVertexAttribPointer( 53 location, 54 static_cast<GLint>( vba.components ), 55 nv::datatype_to_gl_enum( vba.dtype ), 56 GL_FALSE, 57 static_cast<GLsizei>( vba.stride ), 58 (void*)vba.offset 59 ); 60 unbind( vba.vbuffer ); 61 } 62 63 if ( info->index.is_valid() ) 64 { 65 bind( info->index ); 66 } 68 67 } 69 68 } … … 74 73 } 75 74 76 void nv::gl_context::unbind( vertex_buffer* ) 77 { 78 glBindBuffer( GL_ARRAY_BUFFER, 0 ); 79 } 80 81 void nv::gl_context::unbind( index_buffer* ) 82 { 83 glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 ); 84 } 85 86 void nv::gl_context::unbind( vertex_array* va ) 87 { 88 if ( va->m_index ) 89 { 90 unbind( va->m_index ); 91 } 92 93 for ( vertex_buffer_attribute_map::iterator i = va->m_map.begin(); i != va->m_map.end(); ++i ) 94 { 95 glDisableVertexAttribArray( static_cast<uint32>( i->first ) ); 75 void nv::gl_context::unbind( buffer b ) 76 { 77 const gl_buffer_info* info = static_cast< const gl_buffer_info* >( m_device->get_buffer_info( b ) ); 78 if ( info ) 79 { 80 glBindBuffer( buffer_type_to_enum( info->type ), 0 ); 81 } 82 } 83 84 void nv::gl_context::unbind( vertex_array va ) 85 { 86 vertex_array_info* info = get_vertex_array_info( va ); 87 if ( info ) 88 { 89 if ( info->index.is_valid() ) 90 { 91 unbind( info->index ); 92 } 93 94 for ( uint32 i = 0; i < info->count; ++i ) 95 { 96 glDisableVertexAttribArray( static_cast<uint32>( info->attr[i].location ) ); 97 } 96 98 } 97 99 } … … 110 112 } 111 113 112 void gl_context::update( vertex_buffer* b, const void* data, size_t offset, size_t size ) 113 { 114 bind( b ); 115 glBufferSubData( GL_ARRAY_BUFFER, (GLintptr)offset, (GLsizeiptr)size, data ); 116 } 117 118 void gl_context::update( index_buffer* b, const void* data, size_t offset, size_t size ) 119 { 120 bind( b ); 121 glBufferSubData( GL_ELEMENT_ARRAY_BUFFER, (GLintptr)offset, (GLsizeiptr)size, data ); 114 void gl_context::update( buffer b, const void* data, size_t offset, size_t size ) 115 { 116 const gl_buffer_info* info = static_cast< const gl_buffer_info* >( m_device->get_buffer_info( b ) ); 117 if ( info ) 118 { 119 bind( b ); 120 glBufferSubData( buffer_type_to_enum( info->type ), (GLintptr)offset, (GLsizeiptr)size, data ); 121 } 122 122 } 123 123 … … 483 483 } 484 484 485 void gl_context::draw( primitive prim, const render_state& rs, program* p, vertex_array *va, size_t count )485 void gl_context::draw( primitive prim, const render_state& rs, program* p, vertex_array va, size_t count ) 486 486 { 487 487 apply_render_state( rs ); 488 if ( count > 0 ) 488 vertex_array_info* info = get_vertex_array_info( va ); 489 if ( count > 0 && info ) 489 490 { 490 491 bind( p ); 491 492 bind( va ); 492 if ( va->has_index_buffer() )493 { 494 glDrawElements( primitive_to_enum(prim), static_cast<GLsizei>( count ), datatype_to_gl_enum( va->get_index_buffer_type()), 0 );493 if ( info->index.is_valid() ) 494 { 495 glDrawElements( primitive_to_enum(prim), static_cast<GLsizei>( count ), datatype_to_gl_enum( info->index_type ), 0 ); 495 496 } 496 497 else
Note: See TracChangeset
for help on using the changeset viewer.