- Timestamp:
- 07/09/15 14:40:36 (10 years ago)
- Location:
- trunk
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/formats/md5_loader.hh
r399 r412 84 84 void reset(); 85 85 void build_frame_skeleton( mesh_node_data* nodes, uint32 index, const array_view<md5_joint_info>& joint_info, const array_view<transform>& base_frames, const array_view<float>& frame_data ); 86 bool prepare_mesh( m esh_node_data* nodes, uint32 vtx_count, mesh_data* mdata, md5_weight* weights, md5_weight_info* weight_info );86 bool prepare_mesh( md5_vtx_pntiw* vtx_data, mesh_node_data* nodes, uint32 vtx_count, mesh_data* mdata, md5_weight* weights, md5_weight_info* weight_info ); 87 87 protected: 88 88 file_type m_type; -
trunk/nv/gfx/animation.hh
r411 r412 29 29 NV_ASSERT( channel, "nullptr passed to add_channel!" ); 30 30 m_channels.push_back( channel ); 31 for ( const auto& cslot : channel->descriptor() ) 32 if ( cslot.vslot != slot::TIME ) 33 m_final_key.push_slot( cslot.etype, cslot.vslot ); 31 m_final_key.append( channel->descriptor() ); 34 32 } 35 33 … … 180 178 data_descriptor desc; 181 179 desc.initialize<KEY>(); 182 NV_ASSERT( data->desc == desc, "Bad channel passed!" );180 NV_ASSERT( data->descriptor() == desc, "Bad channel passed!" ); 183 181 } 184 182 void get_interpolated( KEY& result, float frame ) const 185 183 { 186 184 NV_ASSERT( m_data, "Data is null!" ); 187 if ( m_data->count == 0 ) return; 188 if ( m_data->count == 1 ) 185 uint32 count = m_data->element_count(); 186 if ( count == 0 ) return; 187 if ( count == 1 ) 189 188 { 190 189 result = reinterpret_cast<KEY*>(m_data->data)[0]; 191 190 return; 192 191 } 193 size_t index = glm::clamp<size_t>( size_t( frame ), 0, m_data->count - 2 );192 size_t index = glm::clamp<size_t>( size_t( frame ), 0, count - 2 ); 194 193 float factor = glm::clamp<float> ( frame - index, 0.0f, 1.0f ); 195 194 KEY* keys = reinterpret_cast<KEY*>( m_data->data ); … … 212 211 data_descriptor desc; 213 212 desc.initialize<KEY>(); 214 NV_ASSERT( data->desc == desc, "Bad channel passed!" );213 NV_ASSERT( data->descriptor() == desc, "Bad channel passed!" ); 215 214 } 216 215 void get_interpolated( KEY& result, float time ) const 217 216 { 218 217 // TODO: this probably could be optimized 219 const KEY* keys = reinterpret_cast<const KEY*>(m_data->data);220 218 NV_ASSERT( m_data, "Data is null!" ); 221 if ( m_data->count == 0 ) return; 222 if ( m_data->count == 1 ) 219 const KEY* keys = reinterpret_cast<const KEY*>( m_data->data ); 220 uint32 count = m_data->element_count(); 221 if ( count == 0 ) return; 222 if ( count == 1 ) 223 223 { 224 224 result = keys[0]; … … 226 226 } 227 227 int index = -1; 228 for ( int i = 0 ; i < int( m_data->count ) - 1 ; i++ )228 for ( int i = 0 ; i < int( count ) - 1 ; i++ ) 229 229 { 230 230 if ( time < keys[i + 1].time ) { index = i; break; } … … 274 274 } 275 275 size_t size() const { return 0; } // TODO: remove? 276 bool empty() const { return m_pchannel->element_count() == 0 && m_rchannel->count == 0 && m_schannel->count == 0; } 276 bool empty() const { 277 return m_pchannel->element_count() == 0 278 && m_rchannel->element_count() == 0 279 && m_schannel->element_count() == 0; } 277 280 virtual mat4 get_matrix( float time ) const 278 281 { … … 327 330 data_descriptor kd; 328 331 kd.initialize<key>(); 329 NV_ASSERT( kd == channel->desc , "bad channel!" );332 NV_ASSERT( kd == channel->descriptor(), "bad channel!" ); 330 333 m_channel = channel; 331 334 m_interpolator.set_data( m_channel ); -
trunk/nv/gfx/skeletal_mesh.hh
r410 r412 59 59 dynamic_array< transform > m_bone_offset; 60 60 61 const mesh_data* m_data;62 61 const md5_vtx_pntiw* m_vtx_data; 63 62 dynamic_array< transform > m_transform; -
trunk/nv/interface/context.hh
r411 r412 157 157 void add_vertex_buffers( vertex_array va, buffer buf, const raw_data_channel* channel ) 158 158 { 159 for ( const auto& cslot : channel->desc )159 for ( const auto& cslot : channel->descriptor() ) 160 160 { 161 161 const datatype_info& info = get_datatype_info( cslot.etype ); 162 add_vertex_buffer( va, cslot.vslot, buf, info.base, info.elements, cslot.offset, channel->desc .element_size(), false );162 add_vertex_buffer( va, cslot.vslot, buf, info.base, info.elements, cslot.offset, channel->descriptor().element_size(), false ); 163 163 } 164 164 } … … 304 304 { 305 305 const raw_data_channel* channel = channels[ch]; 306 if ( channel->count > 0 ) 307 { 308 buffer_type type = channel->get_buffer_type(); 309 buffer b = m_device->create_buffer( type, hint, channel->size(), channel->data ); 306 if ( channel->element_count() > 0 ) 307 { 308 const data_descriptor& desc = channel->descriptor(); 310 309 // TODO: no if switch 311 if ( type == INDEX_BUFFER ) 312 { 313 set_index_buffer( va, b, channel->desc[0].etype, true ); 310 if ( desc[0].vslot == slot::INDEX ) 311 { 312 buffer b = m_device->create_buffer( INDEX_BUFFER, hint, channel->raw_size(), channel->raw_data() ); 313 set_index_buffer( va, b, desc[0].etype, true ); 314 314 } 315 315 else 316 316 { 317 buffer b = m_device->create_buffer( VERTEX_BUFFER, hint, channel->raw_size(), channel->raw_data() ); 317 318 add_vertex_buffers( va, b, channel ); 318 319 } -
trunk/nv/interface/data_descriptor.hh
r411 r412 14 14 namespace nv 15 15 { 16 // TODO: move somewhere else, or change to generic buffer_type17 enum buffer_type18 {19 VERTEX_BUFFER,20 INDEX_BUFFER,21 };22 16 23 17 enum class slot : uint8 … … 228 222 bool operator==( const data_descriptor& rhs ) const 229 223 { 230 // if ( flags != rhs.flags ) return false; 231 if ( size != rhs.size ) return false; 232 if ( count != rhs.count ) return false; 233 for ( uint32 i = 0; i < count; ++i ) 224 if ( m_size != rhs.m_size ) return false; 225 if ( m_count != rhs.m_count ) return false; 226 for ( uint32 i = 0; i < m_count; ++i ) 234 227 { 235 if ( slots[i].etype != rhs.slots[i].etype ) return false;236 if ( slots[i].offset != rhs.slots[i].offset ) return false;237 if ( slots[i].vslot != rhs.slots[i].vslot ) return false;228 if ( m_slots[i].etype != rhs.m_slots[i].etype ) return false; 229 if ( m_slots[i].offset != rhs.m_slots[i].offset ) return false; 230 if ( m_slots[i].vslot != rhs.m_slots[i].vslot ) return false; 238 231 } 239 232 return true; … … 243 236 void initialize() 244 237 { 245 count = 0;238 m_count = 0; 246 239 initialize_slot< Struct, slot::POSITION >(); 247 240 initialize_slot< Struct, slot::TEXCOORD >(); … … 251 244 initialize_slot< Struct, slot::BONEWEIGHT >(); 252 245 initialize_slot< Struct, slot::COLOR >(); 246 initialize_slot< Struct, slot::INDEX >(); 253 247 initialize_slot< Struct, slot::TIME >(); 254 248 initialize_slot< Struct, slot::TRANSLATION >(); … … 256 250 initialize_slot< Struct, slot::SCALE >(); 257 251 initialize_slot< Struct, slot::TFORM >(); 258 size = sizeof( Struct ); 259 } 260 261 uint32 element_size() const { return size; } 262 uint32 slot_count() const { return count; } 263 264 const_iterator begin() const { return &slots[0]; } 265 const_iterator end() const { return &slots[count]; } 252 m_size = sizeof( Struct ); 253 } 254 255 uint32 element_size() const { return m_size; } 256 uint32 slot_count() const { return m_count; } 257 258 bool has_slot( slot vslot ) const 259 { 260 for ( const auto& dslot : *this ) 261 if ( dslot.vslot == vslot ) return true; 262 return false; 263 } 264 265 const_iterator begin() const { return &m_slots[0]; } 266 const_iterator end() const { return &m_slots[m_count]; } 266 267 267 268 const data_descriptor_slot& operator []( uint32 i ) const 268 269 { 269 NV_ASSERT( i < count, "data_descriptor indexing failure!" ); 270 return slots[i]; 271 } 272 273 void push_slot( datatype etype, slot vslot ) 274 { 275 slots[count].etype = etype; 276 slots[count].offset = size; 277 slots[count].vslot = vslot; 278 size += get_datatype_info( etype ).size; 279 count++; 270 NV_ASSERT( i < m_count, "data_descriptor indexing failure!" ); 271 return m_slots[i]; 272 } 273 274 void append( const data_descriptor& desc ) 275 { 276 for ( const auto& dslot : desc ) 277 { 278 m_slots[m_count].etype = dslot.etype; 279 m_slots[m_count].offset = m_size; 280 m_slots[m_count].vslot = dslot.vslot; 281 m_size += get_datatype_info( dslot.etype ).size; 282 m_count++; 283 } 280 284 } 281 285 282 286 protected: 283 // enum flag_type : uint32 284 // { 285 // NONE = 0b0000, 286 // VERTEX = 0b0001, 287 // INDEX = 0b0010, 288 // KEY = 0b0100 289 // }; 290 data_descriptor_slot slots[uint16( slot::MAX_STORE )]; 291 uint32 count = 0; 292 uint32 size = 0; 293 // flag_type flags = NONE; 287 288 data_descriptor_slot m_slots[uint16( slot::MAX_STORE )]; 289 uint32 m_count = 0; 290 uint32 m_size = 0; 294 291 295 292 template < typename Struct, slot Slot > … … 297 294 { 298 295 typedef slot_info< Struct, Slot > sinfo; 299 slots[count].etype = sinfo::etype;300 if ( slots[count].etype != datatype::NONE )296 m_slots[m_count].etype = sinfo::etype; 297 if ( m_slots[m_count].etype != datatype::NONE ) 301 298 { 302 slots[count].vslot = Slot;303 slots[count].offset = sinfo::offset;304 count++;299 m_slots[m_count].vslot = Slot; 300 m_slots[m_count].offset = sinfo::offset; 301 m_count++; 305 302 } 306 303 } … … 309 306 struct raw_data_channel 310 307 { 311 raw_data_channel() : data( nullptr ), count( 0 ) {}308 raw_data_channel() : data( nullptr ), m_count( 0 ) {} 312 309 ~raw_data_channel() 313 310 { … … 315 312 } 316 313 317 // TODO: this could have more options if stored! 318 buffer_type get_buffer_type() const 319 { 320 if ( count > 0 && desc[0].vslot == slot::INDEX ) 321 { 322 return INDEX_BUFFER; 323 } 324 return VERTEX_BUFFER; 325 } 326 327 const data_descriptor& descriptor() const { return desc; } 328 uint32 element_size() const { return desc.element_size(); } 329 uint32 element_count() const { return count; } 330 uint32 size() const { return count * desc.element_size(); } 314 const data_descriptor& descriptor() const { return m_desc; } 315 uint32 element_size() const { return m_desc.element_size(); } 316 uint32 element_count() const { return m_count; } 317 uint32 raw_size() const { return m_count * m_desc.element_size(); } 318 const uint8* raw_data() const { return data; } 319 320 bool has_slot( slot vslot ) const { return m_desc.has_slot( vslot ); } 331 321 332 322 template < typename VTX > … … 334 324 { 335 325 raw_data_channel* result = new raw_data_channel(); 336 result-> desc.initialize<VTX>();337 result-> count = count;338 result->data = ( count > 0 ? ( new uint8[result-> size()] ) : nullptr );326 result->m_desc.initialize<VTX>(); 327 result->m_count = count; 328 result->data = ( count > 0 ? ( new uint8[result->raw_size()] ) : nullptr ); 339 329 return result; 340 330 } 341 static raw_data_channel* create( const data_descriptor& vtxdesc, uint32 count = 0 )331 static raw_data_channel* create( const data_descriptor& desc, uint32 count = 0 ) 342 332 { 343 333 raw_data_channel* result = new raw_data_channel(); 344 result-> desc = vtxdesc;345 result-> count = count;346 result->data = ( count > 0 ? ( new uint8[result-> size()] ) : nullptr );334 result->m_desc = desc; 335 result->m_count = count; 336 result->data = ( count > 0 ? ( new uint8[result->raw_size()] ) : nullptr ); 347 337 return result; 348 338 } 349 339 350 template < typename IndexType >351 static raw_data_channel* create_index( uint32 count = 0 )352 {353 raw_data_channel* result = new raw_data_channel();354 result->desc.push_slot( type_to_enum< IndexType >::type, slot::INDEX );355 result->count = count;356 result->data = ( count > 0 ? ( new uint8[result->size()] ) : nullptr );357 return result;358 }359 360 // TODO: remove this361 static raw_data_channel* create_index( datatype etype, uint32 count = 0, slot s = slot::INDEX )362 {363 raw_data_channel* result = new raw_data_channel();364 result->desc.push_slot( etype, s );365 result->count = count;366 result->data = ( count > 0 ? ( new uint8[result->size()] ) : nullptr );367 return result;368 }369 370 340 friend class mesh_creator; 371 372 data_descriptor desc; 341 friend class mesh_data_creator; 342 373 343 uint8* data; 374 uint32 count; 344 protected: 345 data_descriptor m_desc; 346 uint32 m_count; 375 347 376 348 }; -
trunk/nv/interface/device.hh
r410 r412 120 120 STREAM_DRAW, 121 121 DYNAMIC_DRAW 122 }; 123 124 enum buffer_type 125 { 126 VERTEX_BUFFER, 127 INDEX_BUFFER, 122 128 }; 123 129 -
trunk/nv/interface/mesh_data.hh
r411 r412 17 17 { 18 18 19 struct index_u16 { uint16 index; }; 20 struct index_u32 { uint32 index; }; 21 19 22 // TODO: friend mesh_data_creator class? 20 23 // TODO: private const etc … … 32 35 NV_ASSERT( channel, "nullptr passed to add_channel!" ); 33 36 m_channels.push_back( channel ); 34 if ( channel-> get_buffer_type() == INDEX_BUFFER)37 if ( channel->element_count() > 0 && channel->descriptor()[0].vslot == slot::INDEX ) 35 38 { 36 39 NV_ASSERT( !m_index_channel, "second index channel!" ); … … 51 54 { 52 55 for ( auto ch : m_channels ) 53 { 54 for ( auto slot : ch->desc ) 55 if ( slot.vslot == s ) 56 return ch; 57 } 56 if ( ch->has_slot( s ) ) 57 return ch; 58 58 return nullptr; 59 59 } … … 62 62 { 63 63 for ( uint32 c = 0; c < m_channels.size(); ++c ) 64 { 65 for ( auto slot : m_channels[c]->desc ) 66 if ( slot.vslot == s ) 67 return int( c ); 68 } 64 if ( m_channels[c]->has_slot( s ) ) 65 return int( c ); 69 66 return -1; 70 67 } … … 73 70 size_t get_count() const 74 71 { 75 if ( m_index_channel ) return m_index_channel-> count;76 if ( m_channels.size() > 0 ) return m_channels[0]-> count;72 if ( m_index_channel ) return m_index_channel->element_count(); 73 if ( m_channels.size() > 0 ) return m_channels[0]->element_count(); 77 74 return 0; 78 75 } … … 80 77 size_t get_count( size_t channel ) const 81 78 { 82 if ( m_channels.size() > channel ) return m_channels[channel]-> count;79 if ( m_channels.size() > channel ) return m_channels[channel]->element_count(); 83 80 return 0; 84 81 } … … 91 88 for ( auto ch : m_channels ) 92 89 { 93 if ( ch->desc == compare )90 if ( ch->descriptor() == compare ) 94 91 { 95 92 return ch; … … 106 103 for ( auto ch : m_channels ) 107 104 { 108 if ( ch->desc == compare )105 if ( ch->descriptor() == compare ) 109 106 { 110 107 return reinterpret_cast<VTX*>( ch->data ); -
trunk/src/formats/assimp_loader.cc
r411 r412 169 169 } 170 170 171 raw_data_channel* ichannel = raw_data_channel::create _index( USHORT,mesh->mNumFaces * 3 );171 raw_data_channel* ichannel = raw_data_channel::create< index_u16 >( mesh->mNumFaces * 3 ); 172 172 data->add_channel( ichannel ); 173 173 uint16* indices = reinterpret_cast<uint16*>( ichannel->data ); … … 317 317 raw_data_channel* channel = meshes[m].get_raw_channels()[0]; 318 318 assimp_skinned_vtx* va = reinterpret_cast< assimp_skinned_vtx* >( channel->data ); 319 for ( unsigned v = 0; v < channel-> count; ++v )319 for ( unsigned v = 0; v < channel->element_count(); ++v ) 320 320 { 321 321 assimp_skinned_vtx& vertex = va[v]; -
trunk/src/formats/md2_loader.cc
r411 r412 357 357 } 358 358 359 raw_data_channel* ic = raw_data_channel::create _index< uint16 >( m_new_indexes.size() );359 raw_data_channel* ic = raw_data_channel::create< index_u16 >( m_new_indexes.size() ); 360 360 if ( m_new_indexes.size() > 0 ) 361 361 { -
trunk/src/formats/md3_loader.cc
r411 r412 354 354 raw_data_channel* mc_pn = raw_data_channel::create< vtx_md3_pn >( uint32( num_verts * frame_count ) ); 355 355 raw_data_channel* mc_t = raw_data_channel::create< vtx_md3_t >( uint32( num_verts ) ); 356 raw_data_channel* ic = raw_data_channel::create _index< uint16 >( uint32( index_count ) );356 raw_data_channel* ic = raw_data_channel::create< index_u16 >( uint32( index_count ) ); 357 357 vtx_md3_pn* vtx_pn = reinterpret_cast< vtx_md3_pn* >( mc_pn->data ); 358 358 vtx_md3_t* vtx_t = reinterpret_cast< vtx_md3_t* >( mc_t->data ); -
trunk/src/formats/md5_loader.cc
r411 r412 137 137 assert( m_type == MESH ); 138 138 mesh_data* mesh = new mesh_data("md5_mesh"); 139 raw_data_channel* ch_pntiw = nullptr; 139 140 140 141 uint32 num_verts = 0; … … 161 162 raw_data_channel* ch_pnt = raw_data_channel::create<md5_vtx_pnt>( num_verts ); 162 163 raw_data_channel* ch_t = raw_data_channel::create<md5_vtx_t>( num_verts ); 163 raw_data_channel*ch_pntiw = raw_data_channel::create<md5_vtx_pntiw>( num_verts );164 ch_pntiw = raw_data_channel::create<md5_vtx_pntiw>( num_verts ); 164 165 tdata = reinterpret_cast< md5_vtx_t* >( ch_t->data ); 165 166 mesh->add_channel( ch_pnt ); 166 167 mesh->add_channel( ch_t ); 167 168 // TODO: hack to prevent rendering 168 ch_pntiw->count = 0;169 //ch_pntiw->m_count = 0; 169 170 mesh->add_channel( ch_pntiw ); 170 171 } … … 190 191 sstream >> num_tris; 191 192 192 raw_data_channel* ch_i = raw_data_channel::create _index<uint32>( num_tris * 3 );193 raw_data_channel* ch_i = raw_data_channel::create<index_u32>( num_tris * 3 ); 193 194 uint32* vtx_i = reinterpret_cast< uint32* >( ch_i->data ); 194 195 uint32 idx = 0; … … 234 235 } 235 236 236 prepare_mesh( nodes, weight_info.size(), mesh, weights.data(), weight_info.data() );237 prepare_mesh( reinterpret_cast< md5_vtx_pntiw* >( ch_pntiw->data ), nodes, weight_info.size(), mesh, weights.data(), weight_info.data() ); 237 238 238 239 m_meshes[ num_meshes ] = mesh; … … 333 334 } 334 335 335 bool md5_loader::prepare_mesh( m esh_node_data* nodes, uint32 vtx_count, mesh_data* mdata, md5_weight* weights, md5_weight_info* weight_info )336 bool md5_loader::prepare_mesh( md5_vtx_pntiw* vtx_data, mesh_node_data* nodes, uint32 vtx_count, mesh_data* mdata, md5_weight* weights, md5_weight_info* weight_info ) 336 337 { 337 338 assert( m_type == MESH ); 338 339 md5_vtx_pnt* vtcs = reinterpret_cast< md5_vtx_pnt* >( mdata->get_channel< md5_vtx_pnt >()->data ); 339 md5_vtx_pntiw* vtx_data = reinterpret_cast< md5_vtx_pntiw* >( mdata->get_channel< md5_vtx_pntiw >()->data );340 340 341 341 for ( uint32 i = 0; i < vtx_count; ++i ) … … 486 486 const transform* ptv = reinterpret_cast< const transform* >( pjoint.data->get_channel(0)->data ); 487 487 transform ptr; 488 if ( pjoint.data->get_channel(0)-> count> index ) ptr = ptv[ index ];488 if ( pjoint.data->get_channel(0)->element_count() > index ) ptr = ptv[ index ]; 489 489 vec3 rot_pos = ptr.get_orientation() * pos; 490 490 -
trunk/src/formats/nmd_loader.cc
r411 r412 129 129 source.read( &cheader, sizeof( cheader ), 1 ); 130 130 raw_data_channel* channel = raw_data_channel::create( cheader.format, cheader.count ); 131 source.read( channel->data, channel-> desc.element_size(), channel->count);131 source.read( channel->data, channel->element_size(), channel->element_count() ); 132 132 kdata->add_channel( channel ); 133 133 } … … 168 168 { 169 169 size += sizeof( nmd_element_header ) + sizeof( nmd_stream_header ); 170 size += chan-> size();170 size += chan->raw_size(); 171 171 } 172 172 … … 184 184 cheader.type = nmd_type::STREAM; 185 185 cheader.children = 0; 186 cheader.size = chan-> size() + sizeof( nmd_stream_header );186 cheader.size = chan->raw_size() + sizeof( nmd_stream_header ); 187 187 stream_out.write( &cheader, sizeof( cheader ), 1 ); 188 188 189 189 nmd_stream_header sheader; 190 sheader.format = chan->desc ;191 sheader.count = chan-> count;190 sheader.format = chan->descriptor(); 191 sheader.count = chan->element_count(); 192 192 stream_out.write( &sheader, sizeof( sheader ), 1 ); 193 stream_out.write( chan-> data, chan->desc.element_size(), chan->count);193 stream_out.write( chan->raw_data(), chan->element_size(), chan->element_count() ); 194 194 } 195 195 } … … 206 206 { 207 207 total += sizeof( nmd_element_header ) + sizeof( nmd_stream_header ); 208 total += node->data->get_channel(c)-> size();208 total += node->data->get_channel(c)->raw_size(); 209 209 } 210 210 } … … 231 231 { 232 232 chan_size += sizeof( nmd_element_header ) + sizeof( nv::nmd_stream_header ); 233 chan_size += node->data->get_channel(c)-> size();233 chan_size += node->data->get_channel(c)->raw_size(); 234 234 } 235 235 … … 252 252 eheader.type = nmd_type::KEY_CHANNEL; 253 253 eheader.children = 0; 254 eheader.size = sizeof( nmd_stream_header ) + channel-> size();254 eheader.size = sizeof( nmd_stream_header ) + channel->raw_size(); 255 255 stream_out.write( &eheader, sizeof( eheader ), 1 ); 256 256 257 257 nmd_stream_header cheader; 258 cheader.format = channel->desc ;259 cheader.count = channel-> count;258 cheader.format = channel->descriptor(); 259 cheader.count = channel->element_count(); 260 260 stream_out.write( &cheader, sizeof( cheader ), 1 ); 261 stream_out.write( channel-> data, channel->desc.element_size(), channel->count);261 stream_out.write( channel->raw_data(), channel->element_size(), channel->element_count() ); 262 262 } 263 263 } -
trunk/src/formats/obj_loader.cc
r411 r412 324 324 } 325 325 326 raw_data_channel* channel = new raw_data_channel(); 327 nv::uint8* data = nullptr; 328 329 if ( reader->raw_size() > 0 ) 330 { 331 data = new uint8[ reader->raw_size() ]; 332 raw_copy_n( reader->raw_pointer(), reader->raw_size(), data ); 333 } 334 channel->data = data; 335 channel->desc = m_descriptor; 336 channel->count = reader->size * 3; 326 raw_data_channel* channel = raw_data_channel::create( m_descriptor, reader->size * 3 ); 327 if ( reader->raw_size() > 0 ) 328 { 329 raw_copy_n( reader->raw_pointer(), reader->raw_size(), channel->data ); 330 } 337 331 338 332 mesh_data* mesh = new mesh_data(reader->name); -
trunk/src/gfx/keyframed_mesh.cc
r410 r412 23 23 , m_active( false ) 24 24 { 25 m_index_count = m_mesh_data->get_index_channel()-> count;26 m_vertex_count = m_mesh_data->get_channel<vertex_t>()-> count;25 m_index_count = m_mesh_data->get_index_channel()->element_count(); 26 m_vertex_count = m_mesh_data->get_channel<vertex_t>()->element_count(); 27 27 m_vchannel = m_mesh_data->get_channel<vertex_pnt>(); 28 28 m_vsize = sizeof( vertex_pnt ); … … 34 34 m_vsize = sizeof( vertex_pn ); 35 35 } 36 m_frame_count = m_vchannel-> count/ m_vertex_count;36 m_frame_count = m_vchannel->element_count() / m_vertex_count; 37 37 m_pbuffer = buffer(); 38 38 } … … 190 190 m_context->add_vertex_buffers( m_va, vb, m_mesh_data->get_channel<vertex_t>() ); 191 191 192 buffer ib = m_context->get_device()->create_buffer( INDEX_BUFFER, STATIC_DRAW, m_mesh_data->get_index_channel()->size(), m_mesh_data->get_index_channel()->data ); 193 194 m_context->set_index_buffer( m_va, ib, m_mesh_data->get_index_channel()->desc[0].etype, true ); 192 const raw_data_channel* index_channel = m_mesh_data->get_index_channel(); 193 buffer ib = m_context->get_device()->create_buffer( INDEX_BUFFER, STATIC_DRAW, index_channel->raw_size(), index_channel->raw_data() ); 194 195 m_context->set_index_buffer( m_va, ib, m_mesh_data->get_index_channel()->descriptor()[0].etype, true ); 195 196 196 197 m_data = new uint8[ m_vertex_count * m_vsize ]; -
trunk/src/gfx/mesh_creator.cc
r411 r412 57 57 size_t chan_count = old_keys->get_channel_count(); 58 58 if ( chan_count == 1 59 && old_keys->get_channel(0)->desc .slot_count() == 160 && old_keys->get_channel(0)->desc [0].etype == TRANSFORM ) continue;59 && old_keys->get_channel(0)->descriptor().slot_count() == 1 60 && old_keys->get_channel(0)->descriptor()[0].etype == TRANSFORM ) continue; 61 61 62 62 size_t max_keys = 0; 63 63 for ( size_t c = 0; c < chan_count; ++c ) 64 64 { 65 max_keys = nv::max( max_keys, old_keys->get_channel(c)-> count);65 max_keys = nv::max( max_keys, old_keys->get_channel(c)->element_count() ); 66 66 } 67 67 … … 79 79 for ( uint16 c = 0; c < chan_count; ++c ) 80 80 { 81 size_t idx = nv::min( old_keys->get_channel(c)-> count- 1, n );81 size_t idx = nv::min( old_keys->get_channel(c)->element_count() - 1, n ); 82 82 pkey += old_keys->get_raw( old_keys->get_channel(c), idx, pkey ); 83 83 } … … 107 107 { 108 108 const raw_data_channel* channel = kdata->get_channel(c); 109 size_t key_size = channel-> desc.element_size();110 for ( size_t n = 0; n < channel-> count; ++n )111 { 112 transform_key_raw( channel->desc , channel->data + n * key_size, scale, r33, ri33 );109 size_t key_size = channel->element_size(); 110 for ( size_t n = 0; n < channel->element_count(); ++n ) 111 { 112 transform_key_raw( channel->descriptor(), channel->data + n * key_size, scale, r33, ri33 ); 113 113 } 114 114 } … … 126 126 { 127 127 const raw_data_channel* channel = m_data->get_channel(c); 128 const data_descriptor& desc = channel->desc ;128 const data_descriptor& desc = channel->descriptor(); 129 129 uint8* raw_data = channel->data; 130 130 uint32 vtx_size = desc.element_size(); … … 142 142 143 143 if ( p_offset != -1 ) 144 for ( uint32 i = 0; i < channel-> count; i++)144 for ( uint32 i = 0; i < channel->element_count(); i++) 145 145 { 146 146 vec3& p = *reinterpret_cast<vec3*>( raw_data + vtx_size*i + p_offset ); … … 149 149 150 150 if ( n_offset != -1 ) 151 for ( uint32 i = 0; i < channel-> count; i++)151 for ( uint32 i = 0; i < channel->element_count(); i++) 152 152 { 153 153 vec3& n = *reinterpret_cast<vec3*>( raw_data + vtx_size*i + n_offset ); … … 155 155 } 156 156 if ( t_offset != -1 ) 157 for ( uint32 i = 0; i < channel-> count; i++)157 for ( uint32 i = 0; i < channel->element_count(); i++) 158 158 { 159 159 vec4& t = *reinterpret_cast<vec4*>(raw_data + vtx_size*i + t_offset ); … … 174 174 if ( ch_n == -1 ) return; 175 175 raw_data_channel* channel = m_data->m_channels[ unsigned( ch_n ) ]; 176 for ( const auto& cslot : channel->desc )176 for ( const auto& cslot : channel->descriptor() ) 177 177 if ( cslot.vslot == slot::NORMAL ) 178 178 { … … 180 180 } 181 181 182 for ( uint32 i = 0; i < channel-> count; ++i )183 { 184 vec3& normal = *reinterpret_cast<vec3*>( channel->data + channel-> desc.element_size() * i + n_offset );182 for ( uint32 i = 0; i < channel->element_count(); ++i ) 183 { 184 vec3& normal = *reinterpret_cast<vec3*>( channel->data + channel->element_size() * i + n_offset ); 185 185 normal = -normal; 186 186 } … … 205 205 const raw_data_channel* channel = m_data->get_channel(c); 206 206 207 for ( const auto& cslot : channel->desc )207 for ( const auto& cslot : channel->descriptor() ) 208 208 switch ( cslot.vslot ) 209 209 { … … 242 242 if ( !p_channel || !n_channel || !t_channel ) return; 243 243 244 if ( p_channel->count != n_channel->count || p_channel->count % t_channel->count != 0 || ( i_type != UINT && i_type != USHORT && i_type != NONE ) ) 244 if ( p_channel->element_count() != n_channel->element_count() 245 || p_channel->element_count() % t_channel->element_count() != 0 246 || ( i_type != UINT && i_type != USHORT && i_type != NONE ) ) 245 247 { 246 248 return; 247 249 } 248 250 249 raw_data_channel* g_channel = raw_data_channel::create<vertex_g>( p_channel-> count);251 raw_data_channel* g_channel = raw_data_channel::create<vertex_g>( p_channel->element_count() ); 250 252 vec4* tangents = reinterpret_cast<vec4*>( g_channel->data ); 251 vec3* tangents2 = new vec3[ p_channel-> count];252 uint32 tri_count = i_channel ? i_channel-> count / 3 : t_channel->count/ 3;253 uint32 vtx_count = p_channel-> count;254 uint32 sets = p_channel-> count / t_channel->count;253 vec3* tangents2 = new vec3[ p_channel->element_count() ]; 254 uint32 tri_count = i_channel ? i_channel->element_count() / 3 : t_channel->element_count() / 3; 255 uint32 vtx_count = p_channel->element_count(); 256 uint32 sets = p_channel->element_count() / t_channel->element_count(); 255 257 256 258 for ( unsigned int i = 0; i < tri_count; ++i ) … … 280 282 } 281 283 282 const vec2& w1 = *reinterpret_cast<vec2*>(t_channel->data + t_channel-> desc.element_size()*ti0 + t_offset );283 const vec2& w2 = *reinterpret_cast<vec2*>(t_channel->data + t_channel-> desc.element_size()*ti1 + t_offset );284 const vec2& w3 = *reinterpret_cast<vec2*>(t_channel->data + t_channel-> desc.element_size()*ti2 + t_offset );284 const vec2& w1 = *reinterpret_cast<vec2*>(t_channel->data + t_channel->element_size()*ti0 + t_offset ); 285 const vec2& w2 = *reinterpret_cast<vec2*>(t_channel->data + t_channel->element_size()*ti1 + t_offset ); 286 const vec2& w3 = *reinterpret_cast<vec2*>(t_channel->data + t_channel->element_size()*ti2 + t_offset ); 285 287 vec2 st1 = w3 - w1; 286 288 vec2 st2 = w2 - w1; … … 290 292 for ( uint32 set = 0; set < sets; ++set ) 291 293 { 292 uint32 nti0 = t_channel-> count* set + ti0;293 uint32 nti1 = t_channel-> count* set + ti1;294 uint32 nti2 = t_channel-> count* set + ti2;295 vec3 v1 = *reinterpret_cast<vec3*>(p_channel->data + p_channel-> desc.element_size()*nti0 + p_offset );296 vec3 v2 = *reinterpret_cast<vec3*>(p_channel->data + p_channel-> desc.element_size()*nti1 + p_offset );297 vec3 v3 = *reinterpret_cast<vec3*>(p_channel->data + p_channel-> desc.element_size()*nti2 + p_offset );294 uint32 nti0 = t_channel->element_count() * set + ti0; 295 uint32 nti1 = t_channel->element_count() * set + ti1; 296 uint32 nti2 = t_channel->element_count() * set + ti2; 297 vec3 v1 = *reinterpret_cast<vec3*>(p_channel->data + p_channel->element_size()*nti0 + p_offset ); 298 vec3 v2 = *reinterpret_cast<vec3*>(p_channel->data + p_channel->element_size()*nti1 + p_offset ); 299 vec3 v3 = *reinterpret_cast<vec3*>(p_channel->data + p_channel->element_size()*nti2 + p_offset ); 298 300 vec3 xyz1 = v3 - v1; 299 301 vec3 xyz2 = v2 - v1; … … 319 321 for ( unsigned int i = 0; i < vtx_count; ++i ) 320 322 { 321 const vec3 n = *reinterpret_cast<vec3*>( n_channel->data + n_channel-> desc.element_size()*i + n_offset );323 const vec3 n = *reinterpret_cast<vec3*>( n_channel->data + n_channel->element_size()*i + n_offset ); 322 324 const vec3 t = vec3(tangents[i]); 323 325 if ( ! ( t.x == 0.0f && t.y == 0.0f && t.z == 0.0f ) ) … … 336 338 nv::raw_data_channel* nv::mesh_data_creator::merge_channels( raw_data_channel* a, raw_data_channel* b ) 337 339 { 338 NV_ASSERT( a->count == b->count, "merge_channel - bad channels!" ); 339 data_descriptor adesc = a->desc; 340 data_descriptor bdesc = b->desc; 341 uint32 count = a->count; 342 343 data_descriptor desc = a->desc; 344 for ( auto bslot : bdesc ) 345 { 346 desc.push_slot( bslot.etype, bslot.vslot ); 347 } 348 uint8* data = new uint8[ count * desc.element_size() ]; 349 for ( uint32 i = 0; i < count; ++i ) 350 { 351 raw_copy_n( a->data + i * adesc.element_size(), adesc.element_size(), data + i*desc.element_size() ); 352 raw_copy_n( b->data + i * bdesc.element_size(), bdesc.element_size(), data + i*desc.element_size() + adesc.element_size() ); 353 } 340 NV_ASSERT( a->element_count() == b->element_count(), "merge_channel - bad channels!" ); 341 data_descriptor desc = a->descriptor(); 342 desc.append( b->descriptor() ); 343 344 uint8* data = new uint8[a->element_count() * desc.element_size() ]; 345 for ( uint32 i = 0; i < a->element_count(); ++i ) 346 { 347 raw_copy_n( a->data + i * a->element_size(), a->element_size(), data + i*desc.element_size() ); 348 raw_copy_n( b->data + i * b->element_size(), b->element_size(), data + i*desc.element_size() + a->element_size() ); 349 } 350 354 351 raw_data_channel* result = new raw_data_channel; 355 result-> count = count;356 result-> desc = desc;352 result->m_count = a->element_count(); 353 result->m_desc = desc; 357 354 result->data = data; 358 355 return result; … … 361 358 nv::raw_data_channel* nv::mesh_data_creator::append_channels( raw_data_channel* a, raw_data_channel* b, uint32 frame_count ) 362 359 { 363 if ( a->desc != b->desc) return nullptr;364 if ( a-> count% frame_count != 0 ) return nullptr;365 if ( b-> count% frame_count != 0 ) return nullptr;366 size_t vtx_size = a-> desc.element_size();367 368 uint8* data = new uint8[ ( a-> count + b->count) * vtx_size ];360 if ( a->descriptor() != b->descriptor() ) return nullptr; 361 if ( a->element_count() % frame_count != 0 ) return nullptr; 362 if ( b->element_count() % frame_count != 0 ) return nullptr; 363 size_t vtx_size = a->element_size(); 364 365 uint8* data = new uint8[ ( a->element_count() + b->element_count() ) * vtx_size ]; 369 366 370 367 371 368 if ( frame_count == 1 ) 372 369 { 373 size_t a_size = vtx_size * a-> count;370 size_t a_size = vtx_size * a->element_count(); 374 371 raw_copy_n( a->data, a_size, data ); 375 raw_copy_n( b->data, vtx_size * b-> count, data + a_size );372 raw_copy_n( b->data, vtx_size * b->element_count(), data + a_size ); 376 373 } 377 374 else 378 375 { 379 size_t frame_size_a = ( a-> count/ frame_count ) * vtx_size;380 size_t frame_size_b = ( b-> count/ frame_count ) * vtx_size;376 size_t frame_size_a = ( a->element_count() / frame_count ) * vtx_size; 377 size_t frame_size_b = ( b->element_count() / frame_count ) * vtx_size; 381 378 size_t pos_a = 0; 382 379 size_t pos_b = 0; … … 392 389 393 390 raw_data_channel* result = new raw_data_channel; 394 result-> count = a->element_count() + b->element_count();395 result-> desc = a->descriptor();391 result->m_count = a->element_count() + b->element_count(); 392 result->m_desc = a->descriptor(); 396 393 result->data = data; 397 394 return result; … … 429 426 { 430 427 raw_data_channel* old = m_data->m_channels[c]; 431 size_t frame_count = ( old->get_buffer_type() == INDEX_BUFFER ? 1 : old->element_count() / size ); 428 bool old_is_index = old->element_count() > 0 && old->descriptor()[0].vslot == slot::INDEX; 429 size_t frame_count = ( old_is_index ? 1 : old->element_count() / size ); 432 430 m_data->m_channels[c] = append_channels( old, other->m_channels[c], frame_count ); 433 431 NV_ASSERT( m_data->m_channels[c], "Merge problem!" ); 434 if ( old ->get_buffer_type() == INDEX_BUFFER)435 { 436 switch ( old->desc [0].etype )432 if ( old_is_index ) 433 { 434 switch ( old->descriptor()[0].etype ) 437 435 { 438 436 case USHORT : -
trunk/src/gfx/skeletal_mesh.cc
r411 r412 13 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( a_context ) 15 , m_data( a_mesh_data ) 16 { 17 const raw_data_channel* pnt_chan = a_mesh_data->get_channel<md5_vtx_pnt>(); 18 m_pntdata.assign( reinterpret_cast<const md5_vtx_pnt*>( pnt_chan->data ), pnt_chan->count ); 15 { 16 const raw_data_channel* pnt_chan = a_mesh_data->get_channel<md5_vtx_pnt>(); 17 const raw_data_channel* pntiw_chan = a_mesh_data->get_channel<md5_vtx_pntiw>(); 18 19 m_pntdata.assign( reinterpret_cast<const md5_vtx_pnt*>( pnt_chan->data ), pnt_chan->element_count() ); 19 20 m_bone_offset.resize( bones->get_count() ); 20 21 m_transform.resize( bones->get_count() ); … … 24 25 m_bone_offset[i] = transform( bones->get_node(i)->transform ); 25 26 } 27 26 28 m_vtx_data = a_mesh_data->get_channel_data<md5_vtx_pntiw>(); 27 29 m_indices = a_mesh_data->get_count(); 28 m_va = a_context->create_vertex_array( a_mesh_data, 29 STREAM_DRAW ); 30 m_va = a_context->create_vertex_array(); 31 32 array_view< raw_data_channel* > channels = a_mesh_data->get_raw_channels(); 33 for ( uint32 ch = 0; ch < channels.size(); ++ch ) 34 { 35 const raw_data_channel* channel = channels[ch]; 36 if ( channel->element_count() > 0 && channel != pntiw_chan ) 37 { 38 const data_descriptor& desc = channel->descriptor(); 39 if ( desc[0].vslot == slot::INDEX ) 40 { 41 buffer b = a_context->get_device()->create_buffer( INDEX_BUFFER, STREAM_DRAW, channel->raw_size(), channel->raw_data() ); 42 a_context->set_index_buffer( m_va, b, desc[0].etype, true ); 43 } 44 else 45 { 46 buffer b = a_context->get_device()->create_buffer( VERTEX_BUFFER, STREAM_DRAW, channel->raw_size(), channel->raw_data() ); 47 a_context->add_vertex_buffers( m_va, b, channel ); 48 } 49 } 50 } 51 30 52 m_pbuffer = a_context->find_buffer( m_va, slot::POSITION ); 31 53 }
Note: See TracChangeset
for help on using the changeset viewer.