Changeset 499
- Timestamp:
- 06/06/16 18:54:52 (9 years ago)
- Location:
- trunk
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/ecs/ecs.hh
r498 r499 77 77 return dead_eindex; 78 78 } 79 80 index_type remove_swap( index_type dead_eindex ) 81 { 82 if ( size_t( dead_eindex ) >= m_handles.size() ) return -1; 83 handle_type h = m_handles[ dead_eindex ]; 84 handle_type swap_handle = m_handles.back(); 85 if ( dead_eindex != static_cast<index_type>( m_handles.size() - 1 ) ) 86 { 87 m_handles[unsigned( dead_eindex )] = swap_handle; 88 m_indexes[swap_handle.index()] = dead_eindex; 89 } 90 m_handles.pop_back(); 91 m_indexes[ h.index() ] = -1; 92 return dead_eindex; 93 } 94 79 95 80 96 void clear() … … 265 281 } 266 282 283 virtual void remove( index_type i ) 284 { 285 index_type dead_eindex = m_index.remove_swap( i ); 286 if ( dead_eindex == -1 ) return; 287 if ( dead_eindex != static_cast<index_type>( m_data.size() - 1 ) ) 288 { 289 m_data[unsigned( dead_eindex )] = move( m_data.back() ); 290 } 291 m_data.pop_back(); 292 } 293 267 294 virtual bool handle_message( const message_type& ) 268 295 { -
trunk/nv/engine/particle_engine.hh
r439 r499 137 137 }; 138 138 139 struct particle_system_group_tag {}; 140 typedef handle< uint32, 16, 16, particle_system_group_tag > particle_system_group; 141 struct particle_system_tag {}; 142 typedef handle< uint32, 16, 16, particle_system_tag > particle_system; 139 143 140 144 struct particle_system_info 141 145 { 142 bool test;143 146 uint32 last_update; 144 147 particle* particles; 145 particle_quad* quads;146 148 particle_emmiter_info emmiters[MAX_PARTICLE_EMMITERS]; 147 149 148 150 uint32 count; 151 vec2 texcoords[4]; 152 particle_system_group group; 153 154 const particle_system_data* data; 155 }; 156 157 struct particle_system_group_info 158 { 159 uint32 count; 160 uint32 quota; 149 161 vertex_array vtx_array; 150 162 buffer vtx_buffer; 151 // bool own_va; 152 // uint32 offset; 153 154 const particle_system_data* data; 155 }; 156 157 struct particle_system_tag {}; 158 typedef handle< uint32, 16, 16, particle_system_tag > particle_system; 163 bool local; 164 particle_quad* quads; 165 }; 159 166 160 167 class particle_engine … … 164 171 void reset(); 165 172 void load( lua::table_guard& table ); 166 void draw( particle_system system, const render_state& rs, const scene_state& ss ); 167 particle_system create_system( const string_view& id ); 173 void draw( particle_system_group group, const render_state& rs, const scene_state& ss ); 174 void prepare( particle_system_group group ); 175 particle_system_group create_group( uint32 max_particles ); 176 particle_system create_system( const string_view& id, particle_system_group group ); 177 void release( particle_system_group group ); 168 178 void release( particle_system system ); 169 void update( particle_system system, const scene_state& s, uint32 ms ); 179 void update( const scene_state& s, uint32 ms ); 180 void update( particle_system system ); 170 181 void set_texcoords( particle_system system, vec2 a, vec2 b ); 171 182 void register_emmiter_type( const string_view& name, particle_emmiter_func func ); … … 193 204 vec3 m_camera_pos; 194 205 uint32 m_last_update; 195 196 handle_store< particle_system_info, particle_system > m_systems; 206 vec2 m_tc_a; 207 vec2 m_tc_b; 208 209 handle_store< particle_system_info, particle_system > m_systems; 210 handle_store< particle_system_group_info, particle_system_group > m_groups; 211 197 212 hash_store< shash64, uint32 > m_names; 198 213 vector< particle_system_data > m_data; -
trunk/nv/gl/gl_context.hh
r493 r499 60 60 virtual void update( texture t, const void* data ); 61 61 virtual void update( buffer b, const void* data, size_t offset, size_t size ); 62 virtual void* map_buffer( buffer, buffer_access, size_t /*offset*/, size_t /*length*/ ); 63 virtual void unmap_buffer( buffer ); 64 62 65 // virtual void update( buffer b, uint32 index, const void* data, size_t offset, size_t size ); 63 66 -
trunk/nv/gl/gl_enum.hh
r438 r499 43 43 unsigned int output_slot_to_enum( output_slot slot ); 44 44 45 unsigned int buffer_access_to_bitfield( buffer_access type ); 45 46 unsigned int datatype_to_gl_enum( datatype type ); 46 47 datatype gl_enum_to_datatype( unsigned int gl_enum ); -
trunk/nv/interface/context.hh
r492 r499 177 177 virtual void update( texture, const void* ) = 0; 178 178 virtual void update( buffer, const void*, size_t /*offset*/, size_t /*size*/ ) = 0; 179 virtual void* map_buffer( buffer, buffer_access, size_t /*offset*/, size_t /*length*/ ) = 0; 180 virtual void unmap_buffer( buffer ) = 0; 181 179 182 180 183 // virtual void update( buffer, uint32 /*index*/, const void* , size_t /*offset*/, size_t /*size*/ ) = 0; -
trunk/nv/interface/device.hh
r492 r499 152 152 }; 153 153 154 enum buffer_access 155 { 156 WRITE_UNSYNCHRONIZED, 157 }; 158 154 159 struct buffer_info 155 160 { -
trunk/src/engine/particle_engine.cc
r491 r499 470 470 } 471 471 472 nv::particle_system nv::particle_engine::create_system( const string_view& id )472 nv::particle_system nv::particle_engine::create_system( const string_view& id, particle_system_group group ) 473 473 { 474 474 auto it = m_names.find( id ); … … 480 480 particle_system result = m_systems.create(); 481 481 particle_system_info* info = m_systems.get( result ); 482 482 info->group = group; 483 483 info->data = data; 484 484 uint32 ecount = data->emmiter_count; … … 496 496 info->count = 0; 497 497 info->particles = new particle[ data->quota ]; 498 info->quads = new particle_quad[ data->quota ]; 499 498 info->last_update = m_last_update; 499 500 return result; 501 } 502 503 void nv::particle_engine::prepare( particle_system_group group ) 504 { 505 particle_system_group_info* info = m_groups.get( group ); 506 if ( info ) 507 { 508 info->count = 0; 509 } 510 } 511 512 void nv::particle_engine::draw( particle_system_group group, const render_state& rs, const scene_state& ss ) 513 { 514 particle_system_group_info* info = m_groups.get( group ); 515 if ( info ) 516 { 517 m_context->draw( nv::TRIANGLES, rs, ss, info->local ? m_program_local : m_program_world, info->vtx_array, info->count * 6, 0 ); 518 } 519 } 520 521 nv::particle_system_group nv::particle_engine::create_group( uint32 max_particles ) 522 { 523 particle_system_group result = m_groups.create(); 524 particle_system_group_info* info = m_groups.get( result ); 525 info->local = false; 526 info->count = 0; 527 info->quota = max_particles; 528 info->vtx_buffer = m_device->create_buffer( VERTEX_BUFFER, STREAM_DRAW, info->quota * sizeof( particle_quad )/*, info->quads_[0].data*/ ); 500 529 vertex_array_desc desc; 501 info->vtx_buffer = m_device->create_buffer( VERTEX_BUFFER, STREAM_DRAW, data->quota * 6 * sizeof( particle_vtx ), info->quads[0].data );502 530 desc.add_vertex_buffers< particle_vtx >( info->vtx_buffer, true ); 503 531 info->vtx_array = m_context->create_vertex_array( desc ); 504 info->last_update = m_last_update; 505 info->test = false; 506 // result->m_own_va = true; 507 // result->m_offset = 0; 508 532 info->quads = new particle_quad[info->quota]; 509 533 return result; 510 }511 512 void nv::particle_engine::draw( particle_system system, const render_state& rs, const scene_state& ss )513 {514 particle_system_info* info = m_systems.get( system );515 if ( info )516 {517 m_context->draw( nv::TRIANGLES, rs, ss, info->data->local ? m_program_local : m_program_world, info->vtx_array, info->count * 6 );518 }519 534 } 520 535 … … 537 552 while ( m_systems.size() > 0 ) 538 553 release( m_systems.get_handle( 0 ) ); 554 while ( m_groups.size() > 0 ) 555 release( m_groups.get_handle( 0 ) ); 539 556 m_emmiters.clear(); 540 557 m_affectors.clear(); … … 551 568 { 552 569 delete[] info->particles; 570 m_systems.destroy( system ); 571 } 572 } 573 574 void nv::particle_engine::release( particle_system_group group ) 575 { 576 particle_system_group_info* info = m_groups.get( group ); 577 if ( info ) 578 { 553 579 delete[] info->quads; 554 //if ( system->own_va )555 580 m_context->release( info->vtx_array ); 556 m_systems.destroy( system ); 557 } 558 } 559 560 void nv::particle_engine::update( particle_system system, const scene_state& s, uint32 ms ) 581 m_groups.destroy( group ); 582 } 583 } 584 585 void nv::particle_engine::update( const scene_state& s, uint32 ms ) 586 { 587 m_last_update += ms; 588 m_view_matrix = s.get_view(); 589 m_model_matrix = s.get_model(); 590 m_camera_pos = s.get_camera().get_position(); 591 m_inv_view_dir = math::normalize(-s.get_camera().get_direction()); 592 } 593 594 void nv::particle_engine::update( particle_system system ) 561 595 { 562 596 particle_system_info* info = m_systems.get( system ); 563 m_last_update += ms;564 597 if ( info ) 565 598 { 566 m_view_matrix = s.get_view();567 m_model_matrix = s.get_model();568 m_camera_pos = s.get_camera().get_position();569 m_inv_view_dir = math::normalize(-s.get_camera().get_direction());570 571 599 update_emmiters( info, m_last_update ); 572 600 destroy_particles( info, m_last_update ); … … 575 603 576 604 generate_data( info ); 577 m_context->update( info->vtx_buffer, info->quads, /*system->m_offset*sizeof(particle_quad)*/ 0, info->count*sizeof(particle_quad) );578 605 } 579 606 } … … 585 612 { 586 613 vec2 texcoords[4] = { a, vec2( b.x, a.y ), vec2( a.x, b.y ), b }; 587 588 for ( uint32 i = 0; i < info->data->quota; ++i ) 589 { 590 particle_quad& rdata = info->quads[i]; 591 rdata.data[0].texcoord = texcoords[0]; 592 rdata.data[1].texcoord = texcoords[1]; 593 rdata.data[2].texcoord = texcoords[2]; 594 rdata.data[3].texcoord = texcoords[3]; 595 rdata.data[4].texcoord = texcoords[2]; 596 rdata.data[5].texcoord = texcoords[1]; 597 } 614 for ( uint32 i = 0; i < 4; ++i ) 615 info->texcoords[i] = texcoords[i]; 598 616 } 599 617 } … … 601 619 void nv::particle_engine::generate_data( particle_system_info* info ) 602 620 { 621 // void* rawptr = m_context->map_buffer( info->vtx_buffer, nv::WRITE_UNSYNCHRONIZED, offset, info->count*sizeof( particle_quad ) ); 622 // particle_quad* quads = reinterpret_cast<particle_quad*>( rawptr ); 623 624 particle_system_group_info* group = m_groups.get( info->group ); 625 if ( !info ) 626 { 627 return; 628 } 629 603 630 vec2 lb = vec2( -0.5f, -0.5f ); 604 631 vec2 rt = vec2( 0.5f, 0.5f ); … … 634 661 vec3 pdir( 0.0f, 1.0f, 0.0f ); 635 662 663 vec2 texcoords[4] = 664 { 665 info->texcoords[0], 666 info->texcoords[1], 667 info->texcoords[2], 668 info->texcoords[3], 669 }; 670 636 671 for ( uint32 i = 0; i < info->count; ++i ) 637 672 { 638 673 const particle& pdata = info->particles[i]; 639 particle_quad& rdata = info->quads[i]; 674 // particle_quad& rdata = quads[i]; 675 particle_quad& rdata = group->quads[i + group->count]; 640 676 641 677 vec3 view_dir( m_inv_view_dir ); … … 676 712 rdata.data[0].position = pdata.position + s0; 677 713 rdata.data[0].color = pdata.color; 714 rdata.data[0].texcoord = texcoords[0]; 678 715 679 716 rdata.data[1].position = pdata.position + s1; 680 717 rdata.data[1].color = pdata.color; 718 rdata.data[1].texcoord = texcoords[1]; 681 719 682 720 rdata.data[2].position = pdata.position + s2; 683 721 rdata.data[2].color = pdata.color; 722 rdata.data[2].texcoord = texcoords[2]; 684 723 685 724 rdata.data[3].position = pdata.position + s3; 686 725 rdata.data[3].color = pdata.color; 726 rdata.data[3].texcoord = texcoords[3]; 687 727 688 728 rdata.data[4] = rdata.data[2]; 689 729 rdata.data[5] = rdata.data[1]; 690 730 } 731 // m_context->unmap_buffer( info->vtx_buffer ); 732 733 m_context->update( group->vtx_buffer, group->quads, group->count*sizeof(particle_quad), info->count*sizeof( particle_quad ) ); 734 group->count += info->count; 691 735 } 692 736 -
trunk/src/gfx/debug_draw.cc
r491 r499 45 45 if ( m_va.is_valid() ) m_context->release( m_va ); 46 46 m_buffer_size = nv::max( m_data.size(), 4096U, m_buffer_size ); 47 m_vb = m_context->get_device()->create_buffer( VERTEX_BUFFER, nv::STREAM_DRAW, m_buffer_size * sizeof( debug_vtx ) , m_data.data());47 m_vb = m_context->get_device()->create_buffer( VERTEX_BUFFER, nv::STREAM_DRAW, m_buffer_size * sizeof( debug_vtx ) ); 48 48 vertex_array_desc va_desc; 49 49 va_desc.add_vertex_buffers< debug_vtx >( m_vb, true ); 50 50 m_va = m_context->create_vertex_array( va_desc ); 51 51 } 52 else 53 { 54 m_context->update( m_vb, m_data.data(), 0, m_data.size()* sizeof( debug_vtx ) ); 55 } 52 m_context->update( m_vb, m_data.data(), 0, m_data.size()* sizeof( debug_vtx ) ); 56 53 } 57 54 -
trunk/src/gl/gl_context.cc
r493 r499 428 428 glTexImage2D( gl_type, 0, static_cast<GLint>( nv::image_format_to_internal_enum(format.format) ), size.x, size.y, 0, nv::image_format_to_enum(format.format), nv::datatype_to_gl_enum(format.type), data ); 429 429 } 430 } 431 432 void* nv::gl_context::map_buffer( buffer b, buffer_access ba, size_t offset, size_t length ) 433 { 434 const gl_buffer_info* info = static_cast<const gl_buffer_info*>( m_device->get_buffer_info( b ) ); 435 unsigned int glenum = buffer_type_to_enum( info->type ); 436 glBindBuffer( glenum, info->glid ); 437 void* result = glMapBufferRange( glenum, GLintptr( offset ), GLsizeiptr( length ), buffer_access_to_bitfield( ba ) ); 438 if ( result == nullptr ) 439 { 440 while ( GLenum err = glGetError() ) 441 switch ( err ) 442 { 443 case GL_INVALID_VALUE : NV_LOG_ERROR( "map_buffer failed : GL_INVALID_VALUE" ) break; 444 case GL_INVALID_OPERATION : NV_LOG_ERROR( "map_buffer failed : GL_INVALID_OPERATION " ) break; 445 case GL_OUT_OF_MEMORY : NV_LOG_ERROR( "map_buffer failed : GL_OUT_OF_MEMORY " ) break; 446 default: 447 break; 448 } 449 } 450 return result; 451 } 452 453 void nv::gl_context::unmap_buffer( buffer b ) 454 { 455 const gl_buffer_info* info = static_cast<const gl_buffer_info*>( m_device->get_buffer_info( b ) ); 456 glUnmapBuffer( buffer_type_to_enum( info->type ) ); 430 457 } 431 458 -
trunk/src/gl/gl_enum.cc
r492 r499 287 287 } 288 288 289 290 289 unsigned int nv::output_slot_to_enum( output_slot slot ) 291 290 { … … 307 306 } 308 307 308 309 unsigned int nv::buffer_access_to_bitfield( buffer_access type ) 310 { 311 switch ( type ) 312 { 313 case WRITE_UNSYNCHRONIZED : return GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT; 314 default: return 0; // TODO: throw! 315 } 316 } 309 317 310 318 unsigned int nv::datatype_to_gl_enum( datatype type )
Note: See TracChangeset
for help on using the changeset viewer.