- Timestamp:
- 07/10/15 20:34:11 (10 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/gfx/animation.hh
r417 r418 69 69 const data_descriptor& get_final_key() const { return m_final_key; } 70 70 71 static uint32 get_raw( const raw_data_channel *channel, uint32 index, float* result )72 { 73 if ( channel ->size() == 0 ) return 0;74 uint32 keyfsize = channel ->element_size() / 4;75 const float* fdata = reinterpret_cast<const float*>( channel ->raw_data() ) + keyfsize * index;71 static uint32 get_raw( const raw_data_channel& channel, uint32 index, float* result ) 72 { 73 if ( channel.size() == 0 ) return 0; 74 uint32 keyfsize = channel.element_size() / 4; 75 const float* fdata = reinterpret_cast<const float*>( channel.raw_data() ) + keyfsize * index; 76 76 uint32 mod = 0; 77 if ( channel ->descriptor()[0].vslot == slot::TIME ) mod = 1;77 if ( channel.descriptor()[0].vslot == slot::TIME ) mod = 1; 78 78 raw_copy_n( fdata + mod, keyfsize - mod, result ); 79 79 return keyfsize - mod; 80 80 } 81 81 82 static uint32 interpolate_raw( const raw_data_channel *channel, float time, float* result )83 { 84 if ( channel ->size() == 0 ) return 0;85 uint32 keyfsize = channel ->element_size() / 4;82 static uint32 interpolate_raw( const raw_data_channel& channel, float time, float* result ) 83 { 84 if ( channel.size() == 0 ) return 0; 85 uint32 keyfsize = channel.element_size() / 4; 86 86 uint32 keyfresult = keyfsize; 87 const float* fdata = reinterpret_cast<const float*>( channel ->raw_data() );87 const float* fdata = reinterpret_cast<const float*>( channel.raw_data() ); 88 88 89 89 uint32 slot = 0; … … 91 91 int index1 = -1; 92 92 float factor = 1.0f; 93 if ( channel ->descriptor()[0].vslot == slot::TIME )94 { 95 NV_ASSERT( channel ->descriptor()[0].offset == 0, "time offset not zero!" );93 if ( channel.descriptor()[0].vslot == slot::TIME ) 94 { 95 NV_ASSERT( channel.descriptor()[0].offset == 0, "time offset not zero!" ); 96 96 slot++; 97 97 keyfresult--; 98 if ( channel ->size() == 1 )98 if ( channel.size() == 1 ) 99 99 { 100 100 raw_copy_n( fdata + 1, keyfresult, result ); 101 101 return keyfresult; 102 102 } 103 for ( unsigned i = 1; i < channel ->size(); i++ )103 for ( unsigned i = 1; i < channel.size(); i++ ) 104 104 { 105 105 if ( time < fdata[i * keyfsize] ) … … 118 118 else 119 119 { 120 if ( channel ->size() == 1 )120 if ( channel.size() == 1 ) 121 121 { 122 122 raw_copy_n( fdata, keyfresult, result ); 123 123 return keyfresult; 124 124 } 125 index0 = glm::clamp<int>( int( time ), 0, int( channel ->size() ) - 2 );125 index0 = glm::clamp<int>( int( time ), 0, int( channel.size() ) - 2 ); 126 126 index1 = index0 + 1; 127 127 factor = glm::clamp<float>( time - index0, 0.0f, 1.0f ); 128 128 } 129 129 uint32 ret = 0; 130 for ( ; slot < channel ->descriptor().size(); ++slot )130 for ( ; slot < channel.descriptor().size(); ++slot ) 131 131 { 132 132 ret += nv::interpolate_raw( 133 channel ->descriptor()[slot], factor,134 fdata + index0 * static_cast<int>( keyfsize ) + channel ->descriptor()[slot].offset / 4,135 fdata + index1 * static_cast<int>( keyfsize ) + channel ->descriptor()[slot].offset / 4,133 channel.descriptor()[slot], factor, 134 fdata + index0 * static_cast<int>( keyfsize ) + channel.descriptor()[slot].offset / 4, 135 fdata + index1 * static_cast<int>( keyfsize ) + channel.descriptor()[slot].offset / 4, 136 136 result + ret ); 137 137 } -
trunk/nv/gfx/mesh_creator.hh
r416 r418 27 27 void merge( mesh_data* other ); 28 28 private: 29 raw_data_channel * merge_channels( const raw_data_channel* a, const raw_data_channel*b );30 raw_data_channel * append_channels( const raw_data_channel* a, const raw_data_channel*b, uint32 frame_count = 1 );29 raw_data_channel merge_channels( const raw_data_channel& a, const raw_data_channel& b ); 30 raw_data_channel append_channels( const raw_data_channel& a, const raw_data_channel& b, uint32 frame_count = 1 ); 31 31 32 32 mesh_data* m_data; -
trunk/nv/interface/context.hh
r417 r418 300 300 { 301 301 vertex_array va = create_vertex_array(); 302 for ( auto channel : *data )303 { 304 if ( channel ->size() > 0 )305 { 306 const data_descriptor& desc = channel ->descriptor();302 for ( auto& channel : *data ) 303 { 304 if ( channel.size() > 0 ) 305 { 306 const data_descriptor& desc = channel.descriptor(); 307 307 // TODO: no if switch 308 308 if ( desc[0].vslot == slot::INDEX ) 309 309 { 310 buffer b = m_device->create_buffer( INDEX_BUFFER, hint, channel ->raw_size(), channel->raw_data() );310 buffer b = m_device->create_buffer( INDEX_BUFFER, hint, channel.raw_size(), channel.raw_data() ); 311 311 set_index_buffer( va, b, desc[0].etype, true ); 312 312 } 313 313 else 314 314 { 315 buffer b = m_device->create_buffer( VERTEX_BUFFER, hint, channel ->raw_size(), channel->raw_data() );315 buffer b = m_device->create_buffer( VERTEX_BUFFER, hint, channel.raw_size(), channel.raw_data() ); 316 316 add_vertex_buffers( va, b, desc ); 317 317 } -
trunk/src/formats/nmd_loader.cc
r417 r418 164 164 { 165 165 uint32 size = sizeof( nmd_element_header ); 166 for ( auto chan : *mesh )166 for ( auto& chan : *mesh ) 167 167 { 168 168 size += sizeof( nmd_element_header ) + sizeof( nmd_stream_header ); 169 size += chan ->raw_size();169 size += chan.raw_size(); 170 170 } 171 171 … … 177 177 stream_out.write( &eheader, sizeof( eheader ), 1 ); 178 178 179 for ( auto chan : *mesh )179 for ( auto& chan : *mesh ) 180 180 { 181 181 nmd_element_header cheader; … … 183 183 cheader.type = nmd_type::STREAM; 184 184 cheader.children = 0; 185 cheader.size = chan ->raw_size() + sizeof( nmd_stream_header );185 cheader.size = chan.raw_size() + sizeof( nmd_stream_header ); 186 186 stream_out.write( &cheader, sizeof( cheader ), 1 ); 187 187 188 188 nmd_stream_header sheader; 189 sheader.format = chan ->descriptor();190 sheader.count = chan ->size();189 sheader.format = chan.descriptor(); 190 sheader.count = chan.size(); 191 191 stream_out.write( &sheader, sizeof( sheader ), 1 ); 192 stream_out.write( chan ->raw_data(), chan->element_size(), chan->size() );192 stream_out.write( chan.raw_data(), chan.element_size(), chan.size() ); 193 193 } 194 194 } -
trunk/src/gfx/mesh_creator.cc
r417 r418 82 82 for ( uint16 c = 0; c < chan_count; ++c ) 83 83 { 84 size_t idx = nv::min( old_keys->get_channel (c)->size() - 1, n );85 pkey += old_keys->get_raw( old_keys->get_channel(c), idx, pkey );84 size_t idx = nv::min( old_keys->get_channel_size(c) - 1, n ); 85 pkey += old_keys->get_raw( *old_keys->get_channel(c), idx, pkey ); 86 86 } 87 87 kt_channel.data()[n].tform = extract_transform_raw( final_key, key ); … … 252 252 } 253 253 254 raw_data_channel * g_channel= data_channel_creator::create< vertex_g >( p_channel->size() );255 vec4* tangents = &( data_channel_access< vertex_g >( g_channel ).data()[0].tangent );254 raw_data_channel g_channel = data_channel_creator::create< vertex_g >( p_channel->size() ); 255 vec4* tangents = &( data_channel_access< vertex_g >( &g_channel ).data()[0].tangent ); 256 256 vec3* tangents2 = new vec3[ p_channel->size() ]; 257 257 uint32 tri_count = i_channel ? i_channel->size() / 3 : t_channel->size() / 3; … … 334 334 delete tangents2; 335 335 336 data_channel_set_creator( m_data ).set_channel( n_channel_index, merge_channels( n_channel, g_channel ) ); 337 delete g_channel; 338 } 339 340 nv::raw_data_channel* nv::mesh_data_creator::merge_channels( const raw_data_channel* a, const raw_data_channel* b ) 341 { 342 NV_ASSERT( a->size() == b->size(), "merge_channel - bad channels!" ); 343 data_descriptor desc = a->descriptor(); 344 desc.append( b->descriptor() ); 345 346 raw_data_channel* result = data_channel_creator::create( desc, a->size() ); 347 for ( uint32 i = 0; i < a->size(); ++i ) 348 { 349 raw_copy_n( a->raw_data() + i * a->element_size(), a->element_size(), raw_data_channel_access( result ).raw_data() + i*desc.element_size() ); 350 raw_copy_n( b->raw_data() + i * b->element_size(), b->element_size(), raw_data_channel_access( result ).raw_data() + i*desc.element_size() + a->element_size() ); 336 data_channel_set_creator( m_data ).set_channel( n_channel_index, merge_channels( *n_channel, g_channel ) ); 337 } 338 339 nv::raw_data_channel nv::mesh_data_creator::merge_channels( const raw_data_channel& a, const raw_data_channel& b ) 340 { 341 NV_ASSERT( a.size() == b.size(), "merge_channel - bad channels!" ); 342 data_descriptor desc = a.descriptor(); 343 desc.append( b.descriptor() ); 344 345 raw_data_channel result = data_channel_creator::create( desc, a.size() ); 346 for ( uint32 i = 0; i < a.size(); ++i ) 347 { 348 raw_copy_n( a.raw_data() + i * a.element_size(), a.element_size(), raw_data_channel_access( &result ).raw_data() + i*desc.element_size() ); 349 raw_copy_n( b.raw_data() + i * b.element_size(), b.element_size(), raw_data_channel_access( &result ).raw_data() + i*desc.element_size() + a.element_size() ); 351 350 } 352 351 … … 354 353 } 355 354 356 nv::raw_data_channel * nv::mesh_data_creator::append_channels( const raw_data_channel* a, const raw_data_channel*b, uint32 frame_count )357 { 358 if ( a->descriptor() != b->descriptor() ) return nullptr;359 if ( a->size() % frame_count != 0 ) return nullptr;360 if ( b->size() % frame_count != 0 ) return nullptr;361 size_t vtx_size = a ->element_size();362 363 raw_data_channel * result = data_channel_creator::create( a->descriptor(), a->size() + b->size() );364 uint8* rdata = raw_data_channel_access( result ).raw_data();355 nv::raw_data_channel nv::mesh_data_creator::append_channels( const raw_data_channel& a, const raw_data_channel& b, uint32 frame_count ) 356 { 357 NV_ASSERT( a.descriptor() == b.descriptor(), "Merge - append not compatible format!" ); 358 NV_ASSERT( a.size() % frame_count == 0, "Merge - append first mesh empty!" ); 359 NV_ASSERT( b.size() % frame_count == 0, "Merge - append second mesh empty!" ); 360 size_t vtx_size = a.element_size(); 361 362 raw_data_channel result = data_channel_creator::create( a.descriptor(), a.size() + b.size() ); 363 uint8* rdata = raw_data_channel_access( &result ).raw_data(); 365 364 366 365 if ( frame_count == 1 ) 367 366 { 368 size_t a_size = vtx_size * a ->size();369 raw_copy_n( a ->raw_data(), a_size, rdata );370 raw_copy_n( b ->raw_data(), vtx_size * b->size(), rdata + a_size );367 size_t a_size = vtx_size * a.size(); 368 raw_copy_n( a.raw_data(), a_size, rdata ); 369 raw_copy_n( b.raw_data(), vtx_size * b.size(), rdata + a_size ); 371 370 } 372 371 else 373 372 { 374 size_t frame_size_a = ( a ->size() / frame_count ) * vtx_size;375 size_t frame_size_b = ( b ->size() / frame_count ) * vtx_size;373 size_t frame_size_a = ( a.size() / frame_count ) * vtx_size; 374 size_t frame_size_b = ( b.size() / frame_count ) * vtx_size; 376 375 size_t pos_a = 0; 377 376 size_t pos_b = 0; … … 379 378 for ( size_t i = 0; i < frame_count; ++i ) 380 379 { 381 raw_copy_n( a ->raw_data() + pos_a, frame_size_a, rdata + pos );382 raw_copy_n( b ->raw_data() + pos_b, frame_size_b, rdata + pos + frame_size_a ); pos_a += frame_size_a;380 raw_copy_n( a.raw_data() + pos_a, frame_size_a, rdata + pos ); 381 raw_copy_n( b.raw_data() + pos_b, frame_size_b, rdata + pos + frame_size_a ); pos_a += frame_size_a; 383 382 pos_b += frame_size_b; 384 383 pos += frame_size_a + frame_size_b; … … 422 421 { 423 422 const raw_data_channel* old = m_data->get_channel( c ); 424 bool old_is_index = old->size() > 0 && old->descriptor()[0].vslot == slot::INDEX; 425 size_t frame_count = ( old_is_index ? 1 : old->size() / size ); 426 data.set_channel( c, append_channels( old, other->get_channel(c), frame_count ) ); 427 NV_ASSERT( data[c], "Merge problem!" ); 423 uint32 old_size = old->size(); 424 data_descriptor old_desc = old->descriptor(); 425 bool old_is_index = old_size > 0 && old_desc[0].vslot == slot::INDEX; 426 size_t frame_count = ( old_is_index ? 1 : old_size / size ); 427 data.set_channel( c, append_channels( *old, *other->get_channel(c), frame_count ) ); 428 428 if ( old_is_index ) 429 429 { 430 switch ( old ->descriptor()[0].etype )430 switch ( old_desc[0].etype ) 431 431 { 432 432 case USHORT : … … 435 435 raw_data_channel_access ic( data[c] ); 436 436 uint16* indexes = reinterpret_cast<uint16*>( ic.raw_data() ); 437 for ( uint16 i = uint16( old ->size()); i < ic.size(); ++i )437 for ( uint16 i = uint16( old_size ); i < ic.size(); ++i ) 438 438 indexes[i] += uint16( size ); 439 439 … … 444 444 raw_data_channel_access ic( data[c] ); 445 445 uint32* indexes = reinterpret_cast<uint32*>( ic.raw_data() ); 446 for ( uint32 i = old ->size(); i < ic.size(); ++i )446 for ( uint32 i = old_size; i < ic.size(); ++i ) 447 447 indexes[i] += size; 448 448 } … … 451 451 } 452 452 } 453 delete old;454 453 } 455 454 } … … 459 458 if ( index < m_pack->get_count() ) 460 459 { 461 data_channel_set_creator( &m_pack->m_meshes[index] ).destroy();462 460 data_channel_set_creator( &m_pack->m_meshes[m_pack->m_count - 1] ).move_to( m_pack->m_meshes[index] ); 463 461 m_pack->m_count--; -
trunk/src/gfx/skeletal_mesh.cc
r417 r418 31 31 32 32 //array_view< raw_data_channel* > channels = a_mesh_data->get_raw_channels(); 33 for ( auto channel : *a_mesh_data )33 for ( auto& channel : *a_mesh_data ) 34 34 { 35 35 //const raw_data_channel* channel = channels[ch]; 36 if ( channel ->size() > 0 &&channel != pntiw_chan )37 { 38 const data_descriptor& desc = channel ->descriptor();36 if ( channel.size() > 0 && &channel != pntiw_chan ) 37 { 38 const data_descriptor& desc = channel.descriptor(); 39 39 if ( desc[0].vslot == slot::INDEX ) 40 40 { 41 buffer b = a_context->get_device()->create_buffer( INDEX_BUFFER, STREAM_DRAW, channel ->raw_size(), channel->raw_data() );41 buffer b = a_context->get_device()->create_buffer( INDEX_BUFFER, STREAM_DRAW, channel.raw_size(), channel.raw_data() ); 42 42 a_context->set_index_buffer( m_va, b, desc[0].etype, true ); 43 43 } 44 44 else 45 45 { 46 buffer b = a_context->get_device()->create_buffer( VERTEX_BUFFER, STREAM_DRAW, channel ->raw_size(), channel->raw_data() );46 buffer b = a_context->get_device()->create_buffer( VERTEX_BUFFER, STREAM_DRAW, channel.raw_size(), channel.raw_data() ); 47 47 a_context->add_vertex_buffers( m_va, b, desc ); 48 48 }
Note: See TracChangeset
for help on using the changeset viewer.