- Timestamp:
- 08/07/14 10:10:24 (11 years ago)
- Location:
- trunk
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/gfx/keyframed_mesh.hh
r296 r299 19 19 { 20 20 public: 21 keyframed_mesh( device* a_device,const mesh_data* a_data, const mesh_nodes_data* a_tag_map );21 keyframed_mesh( const mesh_data* a_data, const mesh_nodes_data* a_tag_map ); 22 22 virtual size_t get_index_count() const { return m_index_count; } 23 23 virtual void run_animation( animation_entry* a_anim ); … … 67 67 { 68 68 public: 69 keyframed_mesh_gpu( device* a_device, const mesh_data* a_data, const mesh_nodes_data* a_tag_map );69 keyframed_mesh_gpu( context* a_context, const mesh_data* a_data, const mesh_nodes_data* a_tag_map ); 70 70 void update( uint32 ms ); 71 71 virtual void update( program* a_program ); … … 82 82 { 83 83 public: 84 keyframed_mesh_cpu( device* a_device, const mesh_data* a_data, const mesh_nodes_data* a_tag_map );84 keyframed_mesh_cpu( context* a_context, const mesh_data* a_data, const mesh_nodes_data* a_tag_map ); 85 85 void update( uint32 ms ); 86 86 ~keyframed_mesh_cpu(); 87 87 private: 88 context* m_context; 89 88 90 uint8* m_data; 89 91 vertex_buffer* m_vb; -
trunk/nv/gfx/skeletal_mesh.hh
r296 r299 41 41 { 42 42 public: 43 skeletal_mesh_cpu( device* a_device, const mesh_data* a_mesh_data, const mesh_nodes_data* bones );43 skeletal_mesh_cpu( context* a_context, const mesh_data* a_mesh_data, const mesh_nodes_data* bones ); 44 44 virtual size_t get_index_count() const { return m_indices; } 45 45 virtual void update_animation( animation_entry* a_anim, uint32 a_anim_time ); 46 46 virtual ~skeletal_mesh_cpu(); 47 47 protected: 48 context* m_context; 48 49 uint32 m_indices; 49 50 dynamic_array< md5_vtx_pnt > m_pntdata; … … 91 92 { 92 93 public: 93 skeletal_mesh_gpu( device* a_device, const mesh_data* a_mesh, const mesh_nodes_data* a_bone_data );94 skeletal_mesh_gpu( context* a_context, const mesh_data* a_mesh, const mesh_nodes_data* a_bone_data ); 94 95 virtual size_t get_index_count() const { return m_index_count; } 95 96 virtual void update( program* a_program ); -
trunk/nv/gfx/sliced_buffer.hh
r152 r299 93 93 static const size_t value_type_size = sizeof(T); 94 94 95 sliced_buffer( device* dev, buffer_hint hint, size_t initial_size, bool is_vertex = true )96 : m_ device( dev)95 sliced_buffer( context* ctx, buffer_hint hint, size_t initial_size, bool is_vertex = true ) 96 : m_context( ctx ) 97 97 , m_buffer( nullptr ) 98 98 , m_hint( hint ) … … 166 166 if ( m_max > 0 ) 167 167 { 168 m_buffer->bind();169 168 size_t offset = m_min * value_type_size; 170 169 size_t size = (m_max-m_min) * value_type_size; 171 m_buffer->update( m_data.data() + m_min, offset, size ); 172 m_buffer->unbind(); 170 if ( m_is_vertex ) 171 m_context->update( (vertex_buffer*)m_buffer, m_data.data() + m_min, offset, size ); 172 else 173 m_context->update( (index_buffer*)m_buffer, m_data.data() + m_min, offset, size ); 173 174 } 174 175 m_full_update = false; … … 202 203 delete m_buffer; 203 204 if ( m_is_vertex ) 204 m_buffer = m_ device->create_vertex_buffer( m_hint, size * value_type_size, nullptr );205 m_buffer = m_context->get_device()->create_vertex_buffer( m_hint, size * value_type_size, nullptr ); 205 206 else 206 m_buffer = m_ device->create_index_buffer( m_hint, size * value_type_size, nullptr );207 m_buffer = m_context->get_device()->create_index_buffer( m_hint, size * value_type_size, nullptr ); 207 208 } 208 209 private: 209 device* m_device;210 context* m_context; 210 211 buffer* m_buffer; 211 212 buffer_hint m_hint; -
trunk/nv/gl/gl_context.hh
r295 r299 23 23 public: 24 24 ~gl_context(); 25 virtual void bind( texture2d* texture, texture_slot slot ); 26 virtual void bind( program* p ); 27 virtual void bind( vertex_buffer* b ); 28 virtual void bind( index_buffer* b ); 29 virtual void bind( vertex_array* va ); 30 virtual void unbind( program* p ); 31 virtual void unbind( index_buffer* b ); 32 virtual void unbind( vertex_buffer* b ); 33 virtual void unbind( vertex_array* va ); 34 35 virtual void update( texture2d* texture, void* data ); 36 virtual void update( index_buffer* b, const void* data, size_t offset, size_t size ); 37 virtual void update( vertex_buffer* b, const void* data, size_t offset, size_t size ); 38 25 39 virtual void clear( const clear_state& cs ); 26 40 // temporary -
trunk/nv/gl/gl_program.hh
r121 r299 44 44 { 45 45 public: 46 friend class gl_context; 47 46 48 gl_program( const string& vertex_program, const string& fragment_program ); 47 49 bool compile( const string& vertex_program, const string& fragment_program ); 48 50 49 virtual void bind();50 virtual void unbind();51 51 virtual bool is_valid() const; 52 52 -
trunk/nv/gl/gl_texture2d.hh
r292 r299 22 22 { 23 23 public: 24 friend class gl_context; 25 24 26 gl_texture2d( ivec2 size, pixel_format aformat, datatype adatatype, sampler asampler, void* data = nullptr ); 25 virtual void assign( void* data );26 virtual void bind( size_t slot = 0 );27 virtual void unbind();28 virtual bool is_valid() const;29 27 protected: 30 28 gl_texture_name m_name; -
trunk/nv/gl/gl_vertex_buffer.hh
r153 r299 22 22 { 23 23 public: 24 friend class gl_context; 25 24 26 gl_vertex_buffer( buffer_hint hint, size_t size, const void* data = nullptr ); 25 virtual void update( const void* data, size_t offset, size_t size );26 virtual void bind();27 virtual void unbind();28 virtual bool is_valid() const;29 27 private: 30 28 gl_buffer_name m_name; … … 34 32 { 35 33 public: 34 friend class gl_context; 35 36 36 gl_index_buffer( buffer_hint hint, size_t size, const void* data = nullptr ); 37 virtual void update( const void* data, size_t offset, size_t size );38 virtual void bind();39 virtual void unbind();40 virtual bool is_valid() const;41 37 private: 42 38 gl_buffer_name m_name; 43 };44 45 class gl_vertex_array : public vertex_array46 {47 public:48 gl_vertex_array();49 virtual void bind();50 virtual void unbind();51 39 }; 52 40 -
trunk/nv/gui/gui_renderer.hh
r267 r299 59 59 typedef std::vector< vec4 > image_vector; 60 60 61 context* m_context; 61 62 window* m_window; 62 63 style m_style; -
trunk/nv/interface/context.hh
r296 r299 49 49 50 50 class device; 51 class texture2d; 51 52 class context 52 53 { … … 58 59 m_device = a_device; 59 60 } 61 virtual void bind( texture2d*, texture_slot ) = 0; 62 virtual void bind( vertex_buffer* ) = 0; 63 virtual void bind( index_buffer* ) = 0; 64 virtual void bind( program* ) = 0; 65 virtual void bind( vertex_array* ) = 0; 66 virtual void unbind( vertex_buffer* ) = 0; 67 virtual void unbind( index_buffer* ) = 0; 68 virtual void unbind( program* ) = 0; 69 virtual void unbind( vertex_array* ) = 0; 70 virtual void update( texture2d*, void* ) = 0; 71 virtual void update( index_buffer*, const void*, size_t /*offset*/, size_t /*size*/ ) = 0; 72 virtual void update( vertex_buffer*, const void*, size_t /*offset*/, size_t /*size*/ ) = 0; 73 60 74 virtual void clear( const clear_state& cs ) = 0; 61 75 // temporary -
trunk/nv/interface/program.hh
r287 r299 64 64 { 65 65 public: 66 virtual void bind() = 0;67 virtual void unbind() = 0;68 66 virtual bool is_valid() const = 0; 69 67 -
trunk/nv/interface/texture2d.hh
r292 r299 53 53 class texture2d 54 54 { 55 p ublic:55 protected: 56 56 texture2d( ivec2 size, pixel_format aformat, datatype adatatype, sampler asampler ) : 57 57 m_size( size ), m_format( aformat, adatatype ), m_sampler( asampler ) {} 58 virtual void assign( void* data ) = 0; 59 virtual void bind( size_t slot = 0 ) = 0; 60 virtual void unbind() = 0; 61 virtual bool is_valid() const = 0; 58 public: 62 59 const ivec2& get_size() const { return m_size; } 63 60 int get_width() const { return m_size.x; } -
trunk/nv/interface/vertex_buffer.hh
r281 r299 34 34 public: 35 35 buffer( buffer_hint hint, size_t size ) { m_size = size; m_hint = hint; } 36 virtual void update( const void* data, size_t offset, size_t size ) = 0;37 virtual void bind() = 0;38 virtual void unbind() = 0;39 virtual bool is_valid() const = 0;40 36 size_t get_size() const { return m_size; } 41 37 buffer_hint get_hint() const { return m_hint; } … … 94 90 { 95 91 public: 92 friend class context; 93 friend class gl_context; // TODO: HACK, remove 94 96 95 vertex_array() : m_map(), m_index( nullptr ), m_index_owner( false ), m_index_type(USHORT) {} 97 96 void add_vertex_buffer( int location, vertex_buffer* buffer, datatype datatype, size_t components, size_t offset = 0, size_t stride = 0, bool owner = true ) … … 162 161 bool has_index_buffer() const { return m_index != nullptr; } 163 162 datatype get_index_buffer_type() const { return m_index_type; } 164 virtual void bind() = 0;165 virtual void unbind() = 0;166 163 virtual ~vertex_array() { 167 164 for ( vertex_buffer_attribute_map::iterator i = m_map.begin(); i != m_map.end(); ++i ) -
trunk/src/gfx/keyframed_mesh.cc
r296 r299 15 15 using namespace nv; 16 16 17 nv::keyframed_mesh::keyframed_mesh( device* a_device,const mesh_data* a_data, const mesh_nodes_data* a_tag_map )17 nv::keyframed_mesh::keyframed_mesh( const mesh_data* a_data, const mesh_nodes_data* a_tag_map ) 18 18 : animated_mesh() 19 19 , m_mesh_data( a_data ) … … 24 24 , m_active( false ) 25 25 { 26 m_va = a_device->create_vertex_array();27 28 26 m_index_count = m_mesh_data->get_index_channel()->count; 29 27 m_vertex_count = m_mesh_data->get_channel<vertex_t>()->count; … … 123 121 } 124 122 125 nv::keyframed_mesh_gpu::keyframed_mesh_gpu( device* a_device, const mesh_data* a_data, const mesh_nodes_data* a_tag_map )126 : keyframed_mesh( a_d evice, a_data, a_tag_map )123 nv::keyframed_mesh_gpu::keyframed_mesh_gpu( context* a_context, const mesh_data* a_data, const mesh_nodes_data* a_tag_map ) 124 : keyframed_mesh( a_data, a_tag_map ) 127 125 , m_loc_next_position( -1 ) 128 126 , m_loc_next_normal( -1 ) … … 131 129 , m_gpu_next_frame( 0xFFFFFFFF ) 132 130 { 133 m_va = a_ device->create_vertex_array( a_data, STATIC_DRAW );131 m_va = a_context->get_device()->create_vertex_array( a_data, STATIC_DRAW ); 134 132 } 135 133 … … 177 175 } 178 176 179 nv::keyframed_mesh_cpu::keyframed_mesh_cpu( device* a_device, const mesh_data* a_data, const mesh_nodes_data* a_tag_map ) 180 : keyframed_mesh( a_device, a_data, a_tag_map ) 181 { 182 m_vb = a_device->create_vertex_buffer( nv::STATIC_DRAW, m_vertex_count * m_vsize, (void*)m_vchannel->data ); 177 nv::keyframed_mesh_cpu::keyframed_mesh_cpu( context* a_context, const mesh_data* a_data, const mesh_nodes_data* a_tag_map ) 178 : keyframed_mesh( a_data, a_tag_map ) 179 , m_context( a_context ) 180 { 181 m_va = m_context->get_device()->create_vertex_array(); 182 m_vb = m_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_vertex_count * m_vsize, (void*)m_vchannel->data ); 183 183 m_va->add_vertex_buffers( m_vb, m_vchannel ); 184 184 185 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 );185 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 ); 186 186 m_va->add_vertex_buffers( vb, m_mesh_data->get_channel<vertex_t>() ); 187 187 188 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 );188 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 ); 189 189 m_va->set_index_buffer( ib, m_mesh_data->get_index_channel()->desc.slots[0].etype, true ); 190 190 … … 224 224 } 225 225 226 m_vb->bind(); 227 m_vb->update( m_data, 0, m_vertex_count * m_vsize ); 228 m_vb->unbind(); 226 m_context->update( m_vb, m_data, 0, m_vertex_count * m_vsize ); 229 227 } 230 228 -
trunk/src/gfx/skeletal_mesh.cc
r296 r299 11 11 12 12 13 nv::skeletal_mesh_cpu::skeletal_mesh_cpu( device* a_device, const mesh_data* a_mesh_data, const mesh_nodes_data* bones )13 nv::skeletal_mesh_cpu::skeletal_mesh_cpu( context* a_context, const mesh_data* a_mesh_data, const mesh_nodes_data* bones ) 14 14 : skeletal_mesh() 15 , m_context( a_context ) 15 16 , m_data( a_mesh_data ) 16 17 { … … 26 27 m_vtx_data = a_mesh_data->get_channel_data<md5_vtx_pntiw>(); 27 28 m_indices = a_mesh_data->get_count(); 28 m_va = a_ device->create_vertex_array( a_mesh_data, nv::STREAM_DRAW );29 m_va = a_context->get_device()->create_vertex_array( a_mesh_data, nv::STREAM_DRAW ); 29 30 } 30 31 … … 63 64 64 65 vertex_buffer* vb = m_va->find_buffer( nv::slot::POSITION ); 65 vb->bind(); 66 vb->update( m_pntdata.data(), 0, m_pntdata.raw_size() ); 67 vb->unbind(); 66 m_context->update( vb, m_pntdata.data(), 0, m_pntdata.raw_size() ); 68 67 } 69 68 } … … 200 199 } 201 200 202 nv::skeletal_mesh_gpu::skeletal_mesh_gpu( device* a_device, const mesh_data* a_mesh, const mesh_nodes_data* a_bone_data )201 nv::skeletal_mesh_gpu::skeletal_mesh_gpu( context* a_context, const mesh_data* a_mesh, const mesh_nodes_data* a_bone_data ) 203 202 : skeletal_mesh(), m_bone_data( a_bone_data ), m_transform( nullptr ) 204 203 { 205 m_va = a_ device->create_vertex_array( a_mesh, nv::STATIC_DRAW );204 m_va = a_context->get_device()->create_vertex_array( a_mesh, nv::STATIC_DRAW ); 206 205 m_index_count = a_mesh->get_count(); 207 206 if ( m_bone_data ) -
trunk/src/gl/gl_context.cc
r245 r299 8 8 #include "nv/lib/gl.hh" 9 9 #include "nv/lib/sdl.hh" 10 #include "nv/gl/gl_texture2d.hh" 11 #include "nv/gl/gl_program.hh" 12 #include "nv/gl/gl_vertex_buffer.hh" 10 13 11 14 using namespace nv; 15 16 void gl_context::bind( texture2d* texture, texture_slot slot ) 17 { 18 GLuint id = static_cast< gl_texture2d* >( texture )->m_name.get_value(); 19 glActiveTexture( GL_TEXTURE0 + static_cast< GLenum >( slot ) ); 20 glBindTexture( GL_TEXTURE_2D, id ); 21 } 22 23 void nv::gl_context::bind( program* p ) 24 { 25 gl_program* glp = static_cast< gl_program* >( p ); 26 glUseProgram( glp->m_name.get_value() ); 27 glp->update_uniforms(); 28 } 29 30 void nv::gl_context::bind( vertex_buffer* b ) 31 { 32 GLuint id = static_cast< gl_vertex_buffer* >( b )->m_name.get_value(); 33 glBindBuffer( GL_ARRAY_BUFFER, id ); 34 } 35 36 void nv::gl_context::bind( index_buffer* b ) 37 { 38 GLuint id = static_cast< gl_index_buffer* >( b )->m_name.get_value(); 39 glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, id ); 40 } 41 42 void nv::gl_context::bind( vertex_array* va ) 43 { 44 for ( vertex_buffer_attribute_map::iterator i = va->m_map.begin(); i != va->m_map.end(); ++i ) 45 { 46 uint32 location = static_cast<uint32>( i->first ); 47 vertex_buffer_attribute* va = i->second; 48 vertex_buffer* vb = va->get_buffer(); 49 glEnableVertexAttribArray( location ); 50 bind( vb ); 51 glVertexAttribPointer( 52 location, 53 static_cast<GLint>( va->get_components() ), 54 nv::datatype_to_gl_enum( va->get_datatype() ), 55 GL_FALSE, 56 static_cast<GLsizei>( va->get_stride() ), 57 (void*)va->get_offset() 58 ); 59 unbind( vb ); 60 } 61 62 if ( va->m_index ) 63 { 64 bind( va->m_index ); 65 } 66 } 67 68 void nv::gl_context::unbind( program* ) 69 { 70 glUseProgram( 0 ); 71 } 72 73 void nv::gl_context::unbind( vertex_buffer* ) 74 { 75 glBindBuffer( GL_ARRAY_BUFFER, 0 ); 76 } 77 78 void nv::gl_context::unbind( index_buffer* ) 79 { 80 glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 ); 81 } 82 83 void nv::gl_context::unbind( vertex_array* va ) 84 { 85 if ( va->m_index ) 86 { 87 unbind( va->m_index ); 88 } 89 90 for ( vertex_buffer_attribute_map::iterator i = va->m_map.begin(); i != va->m_map.end(); ++i ) 91 { 92 glDisableVertexAttribArray( static_cast<uint32>( i->first ) ); 93 } 94 } 95 96 void gl_context::update( texture2d* texture, void* data ) 97 { 98 GLuint id = static_cast< gl_texture2d* >( texture )->m_name.get_value(); 99 image_format format = texture->get_format(); 100 ivec2 size = texture->get_size(); 101 102 glBindTexture( GL_TEXTURE_2D, id ); 103 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 ); 104 } 105 106 void gl_context::update( vertex_buffer* b, const void* data, size_t offset, size_t size ) 107 { 108 bind( b ); 109 glBufferSubData( GL_ARRAY_BUFFER, (GLintptr)offset, (GLsizeiptr)size, data ); 110 } 111 112 void gl_context::update( index_buffer* b, const void* data, size_t offset, size_t size ) 113 { 114 bind( b ); 115 glBufferSubData( GL_ELEMENT_ARRAY_BUFFER, (GLintptr)offset, (GLsizeiptr)size, data ); 116 } 12 117 13 118 void gl_context::clear( const clear_state& cs ) … … 372 477 } 373 478 374 375 479 void gl_context::draw( primitive prim, const render_state& rs, program* p, vertex_array* va, size_t count ) 376 480 { … … 378 482 if ( count > 0 ) 379 483 { 380 p->bind();381 va->bind();484 bind( p ); 485 bind( va ); 382 486 if ( va->has_index_buffer() ) 383 487 { … … 388 492 glDrawArrays( primitive_to_enum(prim), 0, static_cast<GLsizei>( count ) ); 389 493 } 390 va->unbind();391 p->unbind();494 unbind( va ); 495 //unbind( p ); 392 496 } 393 497 } -
trunk/src/gl/gl_device.cc
r292 r299 67 67 vertex_array* gl_device::create_vertex_array() 68 68 { 69 return new gl_vertex_array();69 return new vertex_array(); 70 70 } 71 71 -
trunk/src/gl/gl_program.cc
r237 r299 125 125 load_uniforms(); 126 126 return true; 127 }128 129 void gl_program::bind()130 {131 glUseProgram( m_name.get_value() );132 update_uniforms();133 }134 135 void gl_program::unbind()136 {137 glUseProgram( 0 );138 127 } 139 128 -
trunk/src/gl/gl_texture2d.cc
r292 r299 31 31 if (data) 32 32 { 33 assign(data); 33 glBindTexture( GL_TEXTURE_2D, m_name.get_value() ); 34 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 ); 35 glBindTexture( GL_TEXTURE_2D, 0 ); 34 36 } 35 37 } 36 38 37 void nv::gl_texture2d::assign( void* data )38 {39 glBindTexture( GL_TEXTURE_2D, m_name.get_value() );40 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 );41 glBindTexture( GL_TEXTURE_2D, 0 );42 }43 44 void nv::gl_texture2d::bind( size_t slot )45 {46 glActiveTexture( GL_TEXTURE0 + static_cast< GLenum >( slot ) );47 glBindTexture( GL_TEXTURE_2D, m_name.get_value() );48 }49 50 void nv::gl_texture2d::unbind()51 {52 glBindTexture( GL_TEXTURE_2D, 0 );53 }54 55 bool nv::gl_texture2d::is_valid() const56 {57 return m_name.is_valid();58 } -
trunk/src/gl/gl_vertex_buffer.cc
r191 r299 13 13 : vertex_buffer( hint, size ), m_name() 14 14 { 15 bind();15 glBindBuffer( GL_ARRAY_BUFFER, m_name.get_value() ); 16 16 glBufferData( GL_ARRAY_BUFFER, (GLsizeiptr)m_size, data, buffer_hint_to_enum( m_hint ) ); 17 unbind();18 }19 20 void gl_vertex_buffer::update( const void* data, size_t offset, size_t size )21 {22 // IMPORTANT - THIS DOES NOT BIND, SHOULD IT?23 glBufferSubData( GL_ARRAY_BUFFER, (GLintptr)offset, (GLsizeiptr)size, data );24 }25 26 27 void gl_vertex_buffer::bind()28 {29 glBindBuffer( GL_ARRAY_BUFFER, m_name.get_value() );30 }31 32 void gl_vertex_buffer::unbind()33 {34 17 glBindBuffer( GL_ARRAY_BUFFER, 0 ); 35 }36 37 bool gl_vertex_buffer::is_valid() const38 {39 return m_name.is_valid();40 18 } 41 19 … … 43 21 : index_buffer( hint, size ), m_name() 44 22 { 45 bind();23 glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, m_name.get_value() ); 46 24 glBufferData( GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)m_size, data, buffer_hint_to_enum( m_hint ) ); 47 unbind();48 }49 50 void gl_index_buffer::update( const void* data, size_t offset, size_t size )51 {52 glBufferSubData( GL_ELEMENT_ARRAY_BUFFER, (GLintptr)offset, (GLsizeiptr)size, data );53 }54 55 void gl_index_buffer::bind()56 {57 glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, m_name.get_value() );58 }59 60 void gl_index_buffer::unbind()61 {62 25 glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 ); 63 26 } 64 27 65 bool gl_index_buffer::is_valid() const66 {67 return m_name.is_valid();68 }69 70 gl_vertex_array::gl_vertex_array()71 {72 73 }74 75 void gl_vertex_array::bind()76 {77 for ( vertex_buffer_attribute_map::iterator i = m_map.begin(); i != m_map.end(); ++i )78 {79 uint32 location = static_cast<uint32>( i->first );80 vertex_buffer_attribute* va = i->second;81 vertex_buffer* vb = va->get_buffer();82 glEnableVertexAttribArray( location );83 vb->bind();84 glVertexAttribPointer(85 location,86 static_cast<GLint>( va->get_components() ),87 nv::datatype_to_gl_enum( va->get_datatype() ),88 GL_FALSE,89 static_cast<GLsizei>( va->get_stride() ),90 (void*)va->get_offset()91 );92 vb->unbind();93 }94 95 if ( m_index )96 {97 m_index->bind();98 }99 }100 101 void gl_vertex_array::unbind()102 {103 if ( m_index )104 {105 m_index->unbind();106 }107 108 for ( vertex_buffer_attribute_map::iterator i = m_map.begin(); i != m_map.end(); ++i )109 {110 glDisableVertexAttribArray( static_cast<uint32>( i->first ) );111 }112 } -
trunk/src/gui/gui_renderer.cc
r281 r299 65 65 { 66 66 public: 67 screen_render_data( device* dev, size_t initial_size )68 : buffer( dev, nv::DYNAMIC_DRAW, initial_size ), varray( nullptr ), shader(nullptr), texture(nullptr)67 screen_render_data( context* ctx, size_t initial_size ) 68 : buffer( ctx, nv::DYNAMIC_DRAW, initial_size ), varray( nullptr ), shader(nullptr), texture(nullptr) 69 69 { 70 70 … … 98 98 , m_reupload( true ) 99 99 { 100 m_context = w->get_context(); 100 101 m_area.dim( dimension( w->get_width(), w->get_height() ) ); 101 102 region white = m_atlas.get_region( ivec2(3,3) ); … … 107 108 delete[] wfill; 108 109 109 screen_render_data* sr = new screen_render_data( w->get_ device(), 1024 );110 screen_render_data* sr = new screen_render_data( w->get_context(), 1024 ); 110 111 m_render_data = sr; 111 112 // ** EXTREMELY TEMPORARY! … … 261 262 if ( m_reupload ) 262 263 { 263 sr->texture->assign((void*)m_atlas.get_data() );264 m_context->update( sr->texture, (void*)m_atlas.get_data() ); 264 265 m_reupload = false; 265 266 } … … 272 273 sr->varray->update_vertex_buffer( nv::slot::COLOR, vb, false ); 273 274 } 274 sr->texture->bind( nv::TEX_DIFFUSE );275 m_ window->get_context()->draw( TRIANGLES, m_render_state, m_scene_state, sr->shader, sr->varray, sr->buffer.get_size() * 6 );275 m_context->bind( sr->texture, TEX_DIFFUSE ); 276 m_context->draw( TRIANGLES, m_render_state, m_scene_state, sr->shader, sr->varray, sr->buffer.get_size() * 6 ); 276 277 } 277 278
Note: See TracChangeset
for help on using the changeset viewer.