- Timestamp:
- 08/18/14 23:25:46 (11 years ago)
- Location:
- trunk/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gfx/debug_draw.cc
r303 r313 28 28 "}\n"; 29 29 30 nv::debug_data::debug_data( device* a_device)31 : m_ device( a_device), m_program(), m_va()30 nv::debug_data::debug_data( context* a_context ) 31 : m_context( a_context ), m_program(), m_va() 32 32 { 33 m_program = m_ device->create_program( nv_debug_draw_vertex_shader, nv_debug_draw_fragment_shader );33 m_program = m_context->get_device()->create_program( nv_debug_draw_vertex_shader, nv_debug_draw_fragment_shader ); 34 34 } 35 35 36 36 void nv::debug_data::update() 37 37 { 38 m_ device->release( m_va );39 m_va = m_ device->create_vertex_array( m_data, nv::STATIC_DRAW );38 m_context->release( m_va ); 39 m_va = m_context->create_vertex_array( m_data, nv::STATIC_DRAW ); 40 40 } 41 41 … … 75 75 nv::debug_data::~debug_data() 76 76 { 77 m_ device->release( m_va );78 m_ device->release( m_program );77 m_context->release( m_va ); 78 m_context->get_device()->release( m_program ); 79 79 } -
trunk/src/gfx/keyframed_mesh.cc
r304 r313 105 105 nv::keyframed_mesh::~keyframed_mesh() 106 106 { 107 m_context-> get_device()->release( m_va );107 m_context->release( m_va ); 108 108 } 109 109 … … 131 131 , m_gpu_next_frame( 0xFFFFFFFF ) 132 132 { 133 m_va = a_context-> get_device()->create_vertex_array( a_data, STATIC_DRAW );134 m_pbuffer = a_context-> get_device()->find_buffer( m_va, slot::POSITION );133 m_va = a_context->create_vertex_array( a_data, STATIC_DRAW ); 134 m_pbuffer = a_context->find_buffer( m_va, slot::POSITION ); 135 135 } 136 136 … … 140 140 if ( m_loc_next_position == -1 ) return; 141 141 animated_mesh::update( ms ); 142 device* dev = m_context->get_device();143 142 if ( m_gpu_last_frame != m_last_frame ) 144 143 { 145 144 uint32 base_offset = m_last_frame * m_vertex_count * m_vsize; 146 dev->update_attribute_offset( m_va, slot::POSITION, base_offset );147 dev->update_attribute_offset( m_va, slot::NORMAL, base_offset + sizeof( vec3 ) );145 m_context->update_attribute_offset( m_va, slot::POSITION, base_offset ); 146 m_context->update_attribute_offset( m_va, slot::NORMAL, base_offset + sizeof( vec3 ) ); 148 147 if ( m_has_tangent && m_loc_next_tangent != -1 ) 149 148 { 150 dev->update_attribute_offset( m_va, slot::TANGENT, base_offset + 2*sizeof( vec3 ) );149 m_context->update_attribute_offset( m_va, slot::TANGENT, base_offset + 2*sizeof( vec3 ) ); 151 150 } 152 151 m_gpu_last_frame = m_last_frame; … … 155 154 { 156 155 uint32 base_offset = m_next_frame * m_vertex_count * m_vsize; 157 dev->update_attribute_offset( m_va, (slot)m_loc_next_position, base_offset );158 dev->update_attribute_offset( m_va, (slot)m_loc_next_normal, base_offset + sizeof( vec3 ) );156 m_context->update_attribute_offset( m_va, (slot)m_loc_next_position, base_offset ); 157 m_context->update_attribute_offset( m_va, (slot)m_loc_next_normal, base_offset + sizeof( vec3 ) ); 159 158 if ( m_has_tangent && m_loc_next_tangent != -1 ) 160 159 { 161 dev->update_attribute_offset( m_va, (slot)m_loc_next_tangent, base_offset + 2*sizeof( vec3 ) );160 m_context->update_attribute_offset( m_va, (slot)m_loc_next_tangent, base_offset + 2*sizeof( vec3 ) ); 162 161 } 163 162 m_gpu_next_frame = m_next_frame; … … 175 174 m_loc_next_tangent = dev->get_attribute_location( a_program, "nv_next_tangent" ); 176 175 177 dev->add_vertex_buffer( m_va, (slot)m_loc_next_position, m_pbuffer, FLOAT, 3, 0, m_vsize, false );178 dev->add_vertex_buffer( m_va, (slot)m_loc_next_normal, m_pbuffer, FLOAT, 3, sizeof( vec3 ), m_vsize, false );176 m_context->add_vertex_buffer( m_va, (slot)m_loc_next_position, m_pbuffer, FLOAT, 3, 0, m_vsize, false ); 177 m_context->add_vertex_buffer( m_va, (slot)m_loc_next_normal, m_pbuffer, FLOAT, 3, sizeof( vec3 ), m_vsize, false ); 179 178 if ( m_has_tangent ) 180 dev->add_vertex_buffer( m_va, (slot)m_loc_next_tangent, m_pbuffer, FLOAT, 4, 2*sizeof( vec3 ), m_vsize, false );179 m_context->add_vertex_buffer( m_va, (slot)m_loc_next_tangent, m_pbuffer, FLOAT, 4, 2*sizeof( vec3 ), m_vsize, false ); 181 180 } 182 181 keyframed_mesh::update( a_program ); … … 186 185 : keyframed_mesh( a_context, a_data, a_tag_map ) 187 186 { 188 m_va = m_context-> get_device()->create_vertex_array();187 m_va = m_context->create_vertex_array(); 189 188 m_pbuffer = m_context->get_device()->create_buffer( VERTEX_BUFFER, STATIC_DRAW, m_vertex_count * m_vsize, (void*)m_vchannel->data ); 190 m_context-> get_device()->add_vertex_buffers( m_va, m_pbuffer, m_vchannel );189 m_context->add_vertex_buffers( m_va, m_pbuffer, m_vchannel ); 191 190 192 191 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 ); 193 m_context-> get_device()->add_vertex_buffers( m_va, vb, m_mesh_data->get_channel<vertex_t>() );192 m_context->add_vertex_buffers( m_va, vb, m_mesh_data->get_channel<vertex_t>() ); 194 193 195 194 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 ); 196 195 197 m_context-> get_device()->set_index_buffer( m_va, ib, m_mesh_data->get_index_channel()->desc.slots[0].etype, true );196 m_context->set_index_buffer( m_va, ib, m_mesh_data->get_index_channel()->desc.slots[0].etype, true ); 198 197 199 198 m_data = new uint8[ m_vertex_count * m_vsize ]; -
trunk/src/gfx/particle_engine.cc
r312 r313 485 485 info->particles = new particle[ data->quota ]; 486 486 info->quads = new particle_quad[ data->quota ]; 487 info->vtx_array = m_ device->create_vertex_array<particle_vtx>(487 info->vtx_array = m_context->create_vertex_array<particle_vtx>( 488 488 (particle_vtx*)info->quads, data->quota*6, STREAM_DRAW ); 489 info->vtx_buffer = m_ device->find_buffer( info->vtx_array, slot::POSITION );489 info->vtx_buffer = m_context->find_buffer( info->vtx_array, slot::POSITION ); 490 490 info->last_update = 0; 491 491 info->test = false; … … 519 519 delete[] info->quads; 520 520 //if ( system->own_va ) 521 m_ device->release( info->vtx_array );521 m_context->release( info->vtx_array ); 522 522 m_systems.destroy( system ); 523 523 } -
trunk/src/gfx/skeletal_mesh.cc
r303 r313 26 26 m_vtx_data = a_mesh_data->get_channel_data<md5_vtx_pntiw>(); 27 27 m_indices = a_mesh_data->get_count(); 28 m_va = a_context-> get_device()->create_vertex_array( a_mesh_data,28 m_va = a_context->create_vertex_array( a_mesh_data, 29 29 STREAM_DRAW ); 30 m_pbuffer = a_context-> get_device()->find_buffer( m_va, slot::POSITION );30 m_pbuffer = a_context->find_buffer( m_va, slot::POSITION ); 31 31 } 32 32 … … 195 195 : skeletal_mesh( a_context ), m_bone_data( a_bone_data ), m_transform( nullptr ) 196 196 { 197 m_va = a_context-> get_device()->create_vertex_array( a_mesh, nv::STATIC_DRAW );197 m_va = a_context->create_vertex_array( a_mesh, nv::STATIC_DRAW ); 198 198 m_index_count = a_mesh->get_count(); 199 199 if ( m_bone_data ) -
trunk/src/gl/gl_context.cc
r311 r313 12 12 using namespace nv; 13 13 14 nv::vertex_array nv::gl_context::create_vertex_array() 15 { 16 vertex_array result = m_vertex_arrays.create(); 17 vertex_array_info* info = m_vertex_arrays.get( result ); 18 info->count = 0; 19 info->index = buffer(); 20 info->index_owner = false; 21 info->index_type = USHORT; 22 return result; 23 } 24 25 nv::framebuffer nv::gl_context::create_framebuffer() 26 { 27 if ( is_gl_extension_loaded( GL_EXT_FRAMEBUFFER_OBJECT ) ) 28 { 29 unsigned glid = 0; 30 glGenFramebuffers( 1, &glid ); 31 framebuffer result = m_framebuffers.create(); 32 gl_framebuffer_info* info = m_framebuffers.get( result ); 33 info->glid = glid; 34 info->color_attachment_count = 0; 35 return result; 36 } 37 else return framebuffer(); 38 } 39 40 void nv::gl_context::release( vertex_array va ) 41 { 42 vertex_array_info* info = m_vertex_arrays.get( va ); 43 if ( info ) 44 { 45 for ( uint32 i = 0; i < info->count; ++i ) 46 { 47 if ( info->attr[i].owner ) m_device->release( info->attr[i].vbuffer ); 48 } 49 if ( info->index.is_valid() && info->index_owner) m_device->release( info->index ); 50 m_vertex_arrays.destroy( va ); 51 } 52 } 53 54 void nv::gl_context::release( framebuffer f ) 55 { 56 gl_framebuffer_info* info = m_framebuffers.get( f ); 57 if ( info ) 58 { 59 // TODO: release textures? 60 glBindFramebuffer(GL_FRAMEBUFFER, 0); 61 glDeleteFramebuffers(1, &info->glid); 62 } 63 } 64 65 const vertex_array_info* nv::gl_context::get_vertex_array_info( vertex_array va ) const 66 { 67 return m_vertex_arrays.get( va ); 68 } 69 70 const framebuffer_info* nv::gl_context::get_framebuffer_info( framebuffer f ) const 71 { 72 return m_framebuffers.get( f ); 73 } 74 75 vertex_array_info* nv::gl_context::get_vertex_array_info_mutable( vertex_array va ) 76 { 77 return m_vertex_arrays.get( va ); 78 } 79 80 14 81 void gl_context::bind( texture t, texture_slot slot ) 15 82 { … … 32 99 } 33 100 34 void nv::gl_context::bind( buffer b )35 {36 const gl_buffer_info* info = static_cast< const gl_buffer_info* >( m_device->get_buffer_info( b ) );37 if ( info )38 {39 glBindBuffer( buffer_type_to_enum( info->type ), info->glid );40 }41 }101 // void nv::gl_context::bind( buffer b ) 102 // { 103 // const gl_buffer_info* info = static_cast< const gl_buffer_info* >( m_device->get_buffer_info( b ) ); 104 // if ( info ) 105 // { 106 // glBindBuffer( buffer_type_to_enum( info->type ), info->glid ); 107 // } 108 // } 42 109 43 110 void nv::gl_context::bind( vertex_array va ) 44 111 { 45 const vertex_array_info* info = m_ device->get_vertex_array_info( va );112 const vertex_array_info* info = m_vertex_arrays.get( va ); 46 113 if ( info ) 47 114 { … … 51 118 uint32 location = static_cast<uint32>( vba.location ); 52 119 glEnableVertexAttribArray( location ); 53 bind( vba.vbuffer ); 120 const gl_buffer_info* vinfo = static_cast< const gl_buffer_info* >( m_device->get_buffer_info( vba.vbuffer ) ); 121 if ( vinfo && vinfo->type == VERTEX_BUFFER ) 122 glBindBuffer( GL_ARRAY_BUFFER, vinfo->glid ); 123 else 124 { 125 // TODO: report error 126 } 127 54 128 glVertexAttribPointer( 55 129 location, … … 60 134 (void*)vba.offset 61 135 ); 62 unbind( vba.vbuffer );63 }136 } 137 glBindBuffer( GL_ARRAY_BUFFER, 0 ); 64 138 65 139 if ( info->index.is_valid() ) 66 140 { 67 bind( info->index ); 68 } 141 const gl_buffer_info* iinfo = static_cast< const gl_buffer_info* >( m_device->get_buffer_info( info->index ) ); 142 if ( iinfo && iinfo->type == INDEX_BUFFER ) 143 { 144 glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, iinfo->glid ); 145 } 146 else 147 { 148 // TODO: report error 149 } 150 } 151 } 152 } 153 154 void nv::gl_context::bind( framebuffer f ) 155 { 156 const gl_framebuffer_info* info = m_framebuffers.get( f ); 157 if ( info ) 158 { 159 glBindFramebuffer( GL_FRAMEBUFFER, info->glid ); 69 160 } 70 161 } … … 75 166 } 76 167 77 void nv::gl_context::unbind( buffer b )78 {79 const gl_buffer_info* info = static_cast< const gl_buffer_info* >( m_device->get_buffer_info( b ) );80 if ( info )81 {82 glBindBuffer( buffer_type_to_enum( info->type ), 0 );83 }84 }168 // void nv::gl_context::unbind( buffer b ) 169 // { 170 // const gl_buffer_info* info = static_cast< const gl_buffer_info* >( m_device->get_buffer_info( b ) ); 171 // if ( info ) 172 // { 173 // glBindBuffer( buffer_type_to_enum( info->type ), 0 ); 174 // } 175 // } 85 176 86 177 void nv::gl_context::unbind( vertex_array va ) 87 178 { 88 const vertex_array_info* info = m_ device->get_vertex_array_info( va );179 const vertex_array_info* info = m_vertex_arrays.get( va ); 89 180 if ( info ) 90 181 { 91 182 if ( info->index.is_valid() ) 92 183 { 93 unbind( info->index);184 glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 ); 94 185 } 95 186 … … 98 189 glDisableVertexAttribArray( static_cast<uint32>( info->attr[i].location ) ); 99 190 } 191 } 192 } 193 194 void nv::gl_context::unbind( framebuffer f ) 195 { 196 // this way we are sure that the extension is loaded 197 const gl_framebuffer_info* info = m_framebuffers.get( f ); 198 if ( info ) 199 { 200 glBindFramebuffer( GL_FRAMEBUFFER, 0 ); 100 201 } 101 202 } … … 119 220 if ( info ) 120 221 { 121 bind( b ); 122 glBufferSubData( buffer_type_to_enum( info->type ), (GLintptr)offset, (GLsizeiptr)size, data ); 222 GLenum glenum = buffer_type_to_enum( info->type ); 223 glBindBuffer( glenum, info->glid ); 224 glBufferSubData( glenum, (GLintptr)offset, (GLsizeiptr)size, data ); 123 225 } 124 226 } … … 483 585 nv::gl_context::~gl_context() 484 586 { 587 while ( m_framebuffers.size() > 0 ) 588 release( m_framebuffers.get_handle(0) ); 589 while ( m_vertex_arrays.size() > 0 ) 590 release( m_vertex_arrays.get_handle(0) ); 485 591 } 486 592 … … 500 606 { 501 607 apply_render_state( rs ); 502 const vertex_array_info* info = m_ device->get_vertex_array_info( va );608 const vertex_array_info* info = m_vertex_arrays.get( va ); 503 609 if ( count > 0 && info ) 504 610 { -
trunk/src/gl/gl_device.cc
r303 r313 90 90 gl_device::~gl_device() 91 91 { 92 while ( m_vertex_arrays.size() > 0 )93 release( m_vertex_arrays.get_handle(0) );94 92 while ( m_textures.size() > 0 ) 95 93 release( m_textures.get_handle(0) ); … … 98 96 while ( m_programs.size() > 0 ) 99 97 release( m_programs.get_handle(0) ); 100 101 98 SDL_Quit(); 102 99 } … … 192 189 } 193 190 194 nv::vertex_array nv::gl_device::create_vertex_array()195 {196 vertex_array result = m_vertex_arrays.create();197 vertex_array_info* info = m_vertex_arrays.get( result );198 info->count = 0;199 info->index = buffer();200 info->index_owner = false;201 info->index_type = USHORT;202 return result;203 }204 205 void nv::gl_device::release( vertex_array va )206 {207 vertex_array_info* info = m_vertex_arrays.get( va );208 if ( info )209 {210 for ( uint32 i = 0; i < info->count; ++i )211 {212 if ( info->attr[i].owner ) release( info->attr[i].vbuffer );213 }214 if ( info->index.is_valid() && info->index_owner) release( info->index );215 m_vertex_arrays.destroy( va );216 }217 }218 219 191 void nv::gl_device::release( program p ) 220 192 { … … 233 205 m_programs.destroy( p ); 234 206 } 235 }236 237 const vertex_array_info* nv::gl_device::get_vertex_array_info( vertex_array va ) const238 {239 return m_vertex_arrays.get( va );240 }241 242 vertex_array_info* nv::gl_device::get_vertex_array_info_mutable( vertex_array va )243 {244 return m_vertex_arrays.get( va );245 207 } 246 208 … … 485 447 } 486 448 487 -
trunk/src/gui/gui_renderer.cc
r303 r313 73 73 { 74 74 ctx->get_device()->release( shader ); 75 ctx-> get_device()->release( varray );75 ctx->release( varray ); 76 76 } 77 77 … … 114 114 m_scene_state.get_camera().set_ortho( 0.0f, float( m_window->get_width() ), float( m_window->get_height() ), 0.0f ); 115 115 116 sr->varray = m_window->get_ device()->create_vertex_array();116 sr->varray = m_window->get_context()->create_vertex_array(); 117 117 buffer vb = sr->buffer.get_buffer(); 118 m_window->get_ device()->add_vertex_buffers< vertex >( sr->varray, vb );118 m_window->get_context()->add_vertex_buffers< vertex >( sr->varray, vb ); 119 119 120 120 nv::sampler sampler( nv::sampler::LINEAR, nv::sampler::CLAMP_TO_EDGE ); … … 267 267 { 268 268 buffer vb = sr->buffer.get_buffer(); 269 m_context-> get_device()->replace_vertex_buffer( sr->varray, vb, false );269 m_context->replace_vertex_buffer( sr->varray, vb, false ); 270 270 } 271 271 m_context->bind( sr->tex, TEX_DIFFUSE );
Note: See TracChangeset
for help on using the changeset viewer.