Changeset 313
- Timestamp:
- 08/18/14 23:25:46 (11 years ago)
- Location:
- trunk
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/gfx/debug_draw.hh
r303 r313 26 26 { 27 27 public: 28 debug_data( device* a_device);28 debug_data( context* a_context ); 29 29 void update(); 30 30 void reset(); … … 37 37 ~debug_data(); 38 38 private: 39 device* m_device;39 context* m_context; 40 40 program m_program; 41 41 vertex_array m_va; -
trunk/nv/gfx/skeletal_mesh.hh
r303 r313 27 27 ~skeletal_mesh() 28 28 { 29 m_context-> get_device()->release( m_va );29 m_context->release( m_va ); 30 30 } 31 31 protected: -
trunk/nv/gl/gl_context.hh
r303 r313 17 17 namespace nv 18 18 { 19 struct gl_framebuffer_info : public framebuffer_info 20 { 21 unsigned glid; 22 }; 23 19 24 class gl_context : public context 20 25 { … … 23 28 public: 24 29 ~gl_context(); 30 31 virtual vertex_array create_vertex_array(); 32 virtual framebuffer create_framebuffer(); 33 virtual void release( vertex_array va ); 34 virtual void release( framebuffer f ); 35 virtual const vertex_array_info* get_vertex_array_info( vertex_array va ) const; 36 virtual const framebuffer_info* get_framebuffer_info( framebuffer f ) const; 37 25 38 virtual void bind( texture t, texture_slot slot ); 26 virtual void bind( program p );27 virtual void bind( buffer b );28 virtual void bind( vertex_array va );29 virtual void unbind( program p );30 virtual void unbind( buffer b );31 virtual void unbind( vertex_array va );32 39 33 40 virtual void update( texture t, void* data ); … … 43 50 44 51 protected: 52 void bind( program p ); 53 // void bind( buffer b ); 54 void bind( vertex_array va ); 55 void bind( framebuffer va ); 56 void unbind( program p ); 57 // void unbind( buffer b ); 58 void unbind( vertex_array va ); 59 void unbind( framebuffer va ); 60 45 61 void force_apply_render_state( const render_state& state ); 46 62 void force_apply_stencil_face( unsigned face, const stencil_test_face& stencil ); 63 // TODO: remove 64 virtual vertex_array_info* get_vertex_array_info_mutable( vertex_array ); 47 65 private: 48 66 void apply_stencil_test( const stencil_test& stencil ); … … 57 75 void apply_polygon_mode( const polygon_mode& mode ); 58 76 void enable( unsigned int what, bool value ); 59 60 77 private: 61 78 vec4 m_clear_color; 62 79 float m_clear_depth; 63 80 int m_clear_stencil; 81 82 entity_store< vertex_array_info, vertex_array > m_vertex_arrays; 83 entity_store< gl_framebuffer_info, framebuffer > m_framebuffers; 64 84 }; 65 85 -
trunk/nv/gl/gl_device.hh
r303 r313 45 45 46 46 virtual program create_program( const string& vs_source, const string& fs_source ); 47 virtual vertex_array create_vertex_array();48 47 virtual buffer create_buffer( buffer_type type, buffer_hint hint, size_t size, const void* source = nullptr ); 49 48 virtual texture create_texture( ivec2 size, image_format aformat, sampler asampler, void* data = nullptr ); … … 53 52 virtual void release( buffer b ); 54 53 virtual void release( texture t ); 55 virtual void release( vertex_array va );56 54 virtual void release( program p ); 57 55 virtual const texture_info* get_texture_info( texture t ) const; 58 56 virtual const buffer_info* get_buffer_info( buffer t ) const; 59 virtual const vertex_array_info* get_vertex_array_info( vertex_array va ) const;60 57 61 58 virtual int get_attribute_location( program p, const string& name, bool fatal = true ) const; … … 65 62 uniform_base* get_uniform( program p, const string& name, bool fatal = true ) const; 66 63 67 // TODO: remove68 virtual vertex_array_info* get_vertex_array_info_mutable( vertex_array );69 64 70 65 private: … … 75 70 bool compile( uint32 sh_type, const std::string& shader_code, unsigned& glid ); 76 71 77 78 79 72 const void* m_info; 80 entity_store< gl_texture_info, texture > m_textures; 81 entity_store< gl_buffer_info, buffer > m_buffers; 82 entity_store< vertex_array_info, vertex_array > m_vertex_arrays; 83 entity_store< gl_program_info, program > m_programs; 73 entity_store< gl_texture_info, texture > m_textures; 74 entity_store< gl_buffer_info, buffer > m_buffers; 75 entity_store< gl_program_info, program > m_programs; 84 76 }; 85 77 -
trunk/nv/interface/context.hh
r303 r313 22 22 namespace nv 23 23 { 24 struct vertex_array_tag {}; 25 struct framebuffer_tag {}; 26 typedef handle< uint32, 16, 16, vertex_array_tag > vertex_array; 27 typedef handle< uint32, 16, 16, framebuffer_tag > framebuffer; 28 24 29 enum primitive 25 30 { … … 45 50 }; 46 51 52 struct vertex_array_info 53 { 54 static const int MAX_ATTRIBUTES = 24; 55 56 uint32 count; 57 buffer index; 58 bool index_owner; 59 datatype index_type; 60 vertex_buffer_attribute attr[MAX_ATTRIBUTES]; 61 }; 62 63 struct framebuffer_info 64 { 65 texture color_attachments[8]; 66 uint32 color_attachment_count; 67 texture depth_attachment; 68 texture depth_stencil_attachment; 69 }; 70 47 71 class context 48 72 { … … 52 76 m_device = a_device; 53 77 } 78 79 virtual vertex_array create_vertex_array() = 0; 80 virtual framebuffer create_framebuffer() = 0; 81 virtual void release( vertex_array ) = 0; 82 virtual void release( framebuffer ) = 0; 83 84 virtual const vertex_array_info* get_vertex_array_info( vertex_array ) const = 0; 85 virtual const framebuffer_info* get_framebuffer_info( framebuffer ) const = 0; 86 54 87 virtual void bind( texture, texture_slot ) = 0; 55 virtual void bind( buffer ) = 0;56 virtual void bind( program ) = 0;57 virtual void bind( vertex_array ) = 0;58 virtual void unbind( buffer ) = 0;59 virtual void unbind( program ) = 0;60 88 virtual void update( texture, void* ) = 0; 61 89 virtual void update( buffer, const void*, size_t /*offset*/, size_t /*size*/ ) = 0; … … 88 116 { 89 117 } 118 119 template < typename VTX, slot SLOT > 120 void add_vertex_buffer_impl( vertex_array, buffer, const std::false_type& ) 121 { 122 } 123 124 template < typename VTX, slot SLOT > 125 void add_vertex_buffer_impl( vertex_array va, buffer vb, const std::true_type& ) 126 { 127 typedef vertex_slot_info< VTX, SLOT > vinfo; 128 typedef datatype_traits< typename vinfo::value_type > dt_traits; 129 add_vertex_buffer( va, SLOT, vb, type_to_enum< dt_traits::base_type >::type, dt_traits::size, vinfo::offset, sizeof( VTX ), false ); 130 } 131 132 template < typename VTX, slot SLOT > 133 void add_vertex_buffer( vertex_array va, buffer vb ) 134 { 135 add_vertex_buffer_impl< VTX, SLOT >( va, vb, std::integral_constant< bool, vertex_has_slot< VTX, SLOT >::value >() ); 136 } 137 138 template < typename VTX > 139 void add_vertex_buffers( vertex_array va, buffer vb ) 140 { 141 add_vertex_buffer< VTX, slot::POSITION > ( va, vb ); 142 add_vertex_buffer< VTX, slot::TEXCOORD > ( va, vb ); 143 add_vertex_buffer< VTX, slot::NORMAL > ( va, vb ); 144 add_vertex_buffer< VTX, slot::TANGENT > ( va, vb ); 145 add_vertex_buffer< VTX, slot::BONEINDEX > ( va, vb ); 146 add_vertex_buffer< VTX, slot::BONEWEIGHT >( va, vb ); 147 add_vertex_buffer< VTX, slot::COLOR > ( va, vb ); 148 } 149 150 void add_vertex_buffers( vertex_array va, buffer buf, const mesh_raw_channel* channel ) 151 { 152 for ( uint32 s = 0; s < channel->desc.count; ++s ) 153 { 154 const vertex_descriptor_slot& slot = channel->desc.slots[s]; 155 const datatype_info& info = get_datatype_info(slot.etype); 156 add_vertex_buffer( va, slot.vslot, buf, info.base , info.elements, slot.offset, channel->desc.size, false ); 157 } 158 } 159 160 template < typename VTX > 161 vertex_array create_vertex_array( const VTX* v, size_t count, buffer_hint hint ) 162 { 163 // TODO: vb will not be owned or freed! 164 vertex_array va = create_vertex_array(); 165 buffer vb = m_device->create_buffer( VERTEX_BUFFER, hint, count * sizeof( VTX ), v ); 166 add_vertex_buffers< VTX >( va, vb ); 167 return va; 168 } 169 170 template < typename VTX > 171 vertex_array create_vertex_array( const std::vector< VTX >& data, buffer_hint hint ) 172 { 173 return create_vertex_array( data.data(), data.size(), hint ); 174 } 175 176 template < typename VTX, typename IDX > 177 vertex_array create_vertex_array( const VTX* v, size_t vcount, const IDX* i, size_t icount, buffer_hint hint ) 178 { 179 vertex_array va = create_vertex_array( v, vcount, hint ); 180 buffer ib = create_buffer( INDEX_BUFFER, hint, icount * sizeof( IDX ), i ); 181 va->set_index_buffer( ib, type_to_enum< IDX >::type, true ); 182 return va; 183 } 184 185 template < typename VTX, typename IDX > 186 vertex_array create_vertex_array( const std::vector< VTX >& data, const std::vector< IDX >& idata, buffer_hint hint ) 187 { 188 return create_vertex_array( data.data(), data.size(), idata.data(), idata.size(), hint ); 189 } 190 191 void replace_vertex_buffer( vertex_array va, buffer vb, bool owner ) 192 { 193 vertex_array_info* info = get_vertex_array_info_mutable( va ); 194 if ( info ) 195 { 196 for ( uint32 i = 0; i < info->count; ++i ) 197 { 198 vertex_buffer_attribute& vba = info->attr[i]; 199 if ( vba.owner ) m_device->release( vba.vbuffer ); 200 vba.vbuffer = vb; 201 vba.owner = owner; 202 } 203 } 204 } 205 206 void replace_vertex_buffer( vertex_array va, buffer vb, slot location, bool owner ) 207 { 208 vertex_array_info* info = get_vertex_array_info_mutable( va ); 209 if ( info ) 210 { 211 for ( uint32 i = 0; i < info->count; ++i ) 212 { 213 if ( info->attr[i].location == location ) 214 { 215 vertex_buffer_attribute& vba = info->attr[i]; 216 if ( vba.owner ) m_device->release( vba.vbuffer ); 217 vba.vbuffer = vb; 218 vba.owner = owner; 219 } 220 } 221 } 222 } 223 224 void update_attribute_offset( vertex_array va, slot location, size_t offset ) 225 { 226 vertex_array_info* info = get_vertex_array_info_mutable( va ); 227 if ( info ) 228 { 229 for ( uint32 i = 0; i < info->count; ++i ) 230 { 231 if ( info->attr[i].location == location ) 232 { 233 info->attr[i].offset = offset; 234 } 235 } 236 } 237 } 238 239 void set_index_buffer( vertex_array va, buffer b, datatype datatype, bool owner ) 240 { 241 vertex_array_info* info = get_vertex_array_info_mutable( va ); 242 if ( info ) 243 { 244 if ( m_device->get_buffer_info( b )->type == INDEX_BUFFER ) 245 { 246 if (info->index.is_valid() && info->index_owner) m_device->release( info->index ); 247 248 info->index = b; 249 info->index_owner = owner; 250 info->index_type = datatype; 251 } 252 } 253 } 254 255 virtual void add_vertex_buffer( vertex_array va, slot location, buffer buf, datatype datatype, size_t components, size_t offset = 0, size_t stride = 0, bool owner = true ) 256 { 257 vertex_array_info* info = get_vertex_array_info_mutable( va ); 258 if ( info ) 259 { 260 NV_ASSERT( info->count < vertex_array_info::MAX_ATTRIBUTES, "MAX_ATTRIBUTES reached!" ); 261 vertex_buffer_attribute& p = info->attr[ info->count ]; 262 p.vbuffer = buf; 263 p.dtype = datatype; 264 p.components = components; 265 p.offset = offset; 266 p.stride = stride; 267 p.owner = owner; 268 p.location = location; 269 info->count++; 270 } 271 } 272 273 buffer find_buffer( vertex_array va, slot location ) 274 { 275 const vertex_array_info* info = get_vertex_array_info( va ); 276 if ( info ) 277 { 278 for ( uint32 i = 0; i < info->count; ++i ) 279 { 280 if ( info->attr[i].location == location ) 281 { 282 return info->attr[i].vbuffer; 283 } 284 } 285 } 286 return buffer(); 287 } 288 289 // TODO: HINTS ARE DIFFERENT! 290 vertex_array create_vertex_array( const mesh_data* data, buffer_hint hint ) 291 { 292 vertex_array va = create_vertex_array(); 293 const std::vector< mesh_raw_channel* >& channels = data->get_raw_channels(); 294 for ( uint32 ch = 0; ch < channels.size(); ++ch ) 295 { 296 const mesh_raw_channel* channel = channels[ch]; 297 if ( channel->count > 0 ) 298 { 299 buffer_type type = channel->get_buffer_type(); 300 buffer b = m_device->create_buffer( type, hint, channel->size(), channel->data ); 301 // TODO: no if switch 302 if ( type == INDEX_BUFFER ) 303 { 304 set_index_buffer( va, b, channel->desc.slots[0].etype, true ); 305 } 306 else 307 { 308 add_vertex_buffers( va, b, channel ); 309 } 310 } 311 } 312 return va; 313 } 314 90 315 protected: 316 // TODO: remove 317 virtual vertex_array_info* get_vertex_array_info_mutable( vertex_array ) = 0; 91 318 92 319 device* m_device; -
trunk/nv/interface/device.hh
r303 r313 52 52 53 53 struct texture_tag {}; 54 struct vertex_array_tag {};55 54 struct buffer_tag {}; 56 55 struct program_tag {}; 57 56 typedef handle< uint32, 16, 16, buffer_tag > buffer; 58 57 typedef handle< uint32, 16, 16, texture_tag > texture; 59 typedef handle< uint32, 16, 16, vertex_array_tag > vertex_array;60 58 typedef handle< uint32, 16, 16, program_tag > program; 61 59 … … 118 116 }; 119 117 120 struct vertex_array_info121 {122 static const int MAX_ATTRIBUTES = 24;123 124 uint32 count;125 buffer index;126 bool index_owner;127 datatype index_type;128 vertex_buffer_attribute attr[MAX_ATTRIBUTES];129 };130 131 118 struct program_info 132 119 { … … 150 137 virtual image_data* create_image_data( const std::string& filename ) = 0; // temporary 151 138 virtual texture create_texture( ivec2 size, image_format aformat, sampler asampler, void* data = nullptr ) = 0; 152 virtual vertex_array create_vertex_array() = 0;153 139 virtual void release( texture ) = 0; 154 140 virtual void release( buffer ) = 0; 155 virtual void release( vertex_array ) = 0;156 141 virtual void release( program ) = 0; 157 142 virtual const texture_info* get_texture_info( texture ) const = 0; 158 143 virtual const buffer_info* get_buffer_info( buffer ) const = 0; 159 virtual const vertex_array_info* get_vertex_array_info( vertex_array ) const = 0;160 144 virtual uint32 get_ticks() = 0; 161 145 virtual void delay( uint32 ms ) = 0; … … 164 148 { 165 149 return create_texture( data->get_size(), data->get_format(), asampler, (void*)data->get_data() ); 166 }167 168 template < typename VTX, slot SLOT >169 void add_vertex_buffer_impl( vertex_array, buffer, const std::false_type& )170 {171 }172 173 template < typename VTX, slot SLOT >174 void add_vertex_buffer_impl( vertex_array va, buffer vb, const std::true_type& )175 {176 typedef vertex_slot_info< VTX, SLOT > vinfo;177 typedef datatype_traits< typename vinfo::value_type > dt_traits;178 add_vertex_buffer( va, SLOT, vb, type_to_enum< dt_traits::base_type >::type, dt_traits::size, vinfo::offset, sizeof( VTX ), false );179 }180 181 template < typename VTX, slot SLOT >182 void add_vertex_buffer( vertex_array va, buffer vb )183 {184 add_vertex_buffer_impl< VTX, SLOT >( va, vb, std::integral_constant< bool, vertex_has_slot< VTX, SLOT >::value >() );185 }186 187 template < typename VTX >188 void add_vertex_buffers( vertex_array va, buffer vb )189 {190 add_vertex_buffer< VTX, slot::POSITION > ( va, vb );191 add_vertex_buffer< VTX, slot::TEXCOORD > ( va, vb );192 add_vertex_buffer< VTX, slot::NORMAL > ( va, vb );193 add_vertex_buffer< VTX, slot::TANGENT > ( va, vb );194 add_vertex_buffer< VTX, slot::BONEINDEX > ( va, vb );195 add_vertex_buffer< VTX, slot::BONEWEIGHT >( va, vb );196 add_vertex_buffer< VTX, slot::COLOR > ( va, vb );197 }198 199 void add_vertex_buffers( vertex_array va, buffer buf, const mesh_raw_channel* channel )200 {201 for ( uint32 s = 0; s < channel->desc.count; ++s )202 {203 const vertex_descriptor_slot& slot = channel->desc.slots[s];204 const datatype_info& info = get_datatype_info(slot.etype);205 add_vertex_buffer( va, slot.vslot, buf, info.base , info.elements, slot.offset, channel->desc.size, false );206 }207 }208 209 template < typename VTX >210 vertex_array create_vertex_array( const VTX* v, size_t count, buffer_hint hint )211 {212 // TODO: vb will not be owned or freed!213 vertex_array va = create_vertex_array();214 buffer vb = create_buffer( VERTEX_BUFFER, hint, count * sizeof( VTX ), v );215 add_vertex_buffers< VTX >( va, vb );216 return va;217 }218 219 template < typename VTX >220 vertex_array create_vertex_array( const std::vector< VTX >& data, buffer_hint hint )221 {222 return create_vertex_array( data.data(), data.size(), hint );223 }224 225 template < typename VTX, typename IDX >226 vertex_array create_vertex_array( const VTX* v, size_t vcount, const IDX* i, size_t icount, buffer_hint hint )227 {228 vertex_array va = create_vertex_array( v, vcount, hint );229 buffer ib = create_buffer( INDEX_BUFFER, hint, icount * sizeof( IDX ), i );230 va->set_index_buffer( ib, type_to_enum< IDX >::type, true );231 return va;232 }233 234 template < typename VTX, typename IDX >235 vertex_array create_vertex_array( const std::vector< VTX >& data, const std::vector< IDX >& idata, buffer_hint hint )236 {237 return create_vertex_array( data.data(), data.size(), idata.data(), idata.size(), hint );238 }239 240 void replace_vertex_buffer( vertex_array va, buffer vb, bool owner )241 {242 vertex_array_info* info = get_vertex_array_info_mutable( va );243 if ( info )244 {245 for ( uint32 i = 0; i < info->count; ++i )246 {247 vertex_buffer_attribute& vba = info->attr[i];248 if ( vba.owner ) release( vba.vbuffer );249 vba.vbuffer = vb;250 vba.owner = owner;251 }252 }253 }254 255 void replace_vertex_buffer( vertex_array va, buffer vb, slot location, bool owner )256 {257 vertex_array_info* info = get_vertex_array_info_mutable( va );258 if ( info )259 {260 for ( uint32 i = 0; i < info->count; ++i )261 {262 if ( info->attr[i].location == location )263 {264 vertex_buffer_attribute& vba = info->attr[i];265 if ( vba.owner ) release( vba.vbuffer );266 vba.vbuffer = vb;267 vba.owner = owner;268 }269 }270 }271 }272 273 void update_attribute_offset( vertex_array va, slot location, size_t offset )274 {275 vertex_array_info* info = get_vertex_array_info_mutable( va );276 if ( info )277 {278 for ( uint32 i = 0; i < info->count; ++i )279 {280 if ( info->attr[i].location == location )281 {282 info->attr[i].offset = offset;283 }284 }285 }286 }287 288 void set_index_buffer( vertex_array va, buffer b, datatype datatype, bool owner )289 {290 vertex_array_info* info = get_vertex_array_info_mutable( va );291 if ( info )292 {293 if ( get_buffer_info( b )->type == INDEX_BUFFER )294 {295 if (info->index.is_valid() && info->index_owner) release( info->index );296 297 info->index = b;298 info->index_owner = owner;299 info->index_type = datatype;300 }301 }302 }303 304 virtual void add_vertex_buffer( vertex_array va, slot location, buffer buf, datatype datatype, size_t components, size_t offset = 0, size_t stride = 0, bool owner = true )305 {306 vertex_array_info* info = get_vertex_array_info_mutable( va );307 if ( info )308 {309 NV_ASSERT( info->count < vertex_array_info::MAX_ATTRIBUTES, "MAX_ATTRIBUTES reached!" );310 vertex_buffer_attribute& p = info->attr[ info->count ];311 p.vbuffer = buf;312 p.dtype = datatype;313 p.components = components;314 p.offset = offset;315 p.stride = stride;316 p.owner = owner;317 p.location = location;318 info->count++;319 }320 }321 322 buffer find_buffer( vertex_array va, slot location )323 {324 const vertex_array_info* info = get_vertex_array_info( va );325 if ( info )326 {327 for ( uint32 i = 0; i < info->count; ++i )328 {329 if ( info->attr[i].location == location )330 {331 return info->attr[i].vbuffer;332 }333 }334 }335 return buffer();336 }337 338 // TODO: HINTS ARE DIFFERENT!339 vertex_array create_vertex_array( const mesh_data* data, buffer_hint hint )340 {341 vertex_array va = create_vertex_array();342 const std::vector< mesh_raw_channel* >& channels = data->get_raw_channels();343 for ( uint32 ch = 0; ch < channels.size(); ++ch )344 {345 const mesh_raw_channel* channel = channels[ch];346 if ( channel->count > 0 )347 {348 buffer_type type = channel->get_buffer_type();349 buffer b = create_buffer( type, hint, channel->size(), channel->data );350 // TODO: no if switch351 if ( type == INDEX_BUFFER )352 {353 set_index_buffer( va, b, channel->desc.slots[0].etype, true );354 }355 else356 {357 add_vertex_buffers( va, b, channel );358 }359 }360 }361 return va;362 150 } 363 151 … … 445 233 protected: 446 234 virtual uniform_base* get_uniform( program p, const string& name, bool fatal = true ) const = 0; 447 448 // TODO: remove449 virtual vertex_array_info* get_vertex_array_info_mutable( vertex_array ) = 0;450 235 451 236 void initialize_engine_uniforms() -
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.