- Timestamp:
- 07/08/14 18:29:24 (11 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/formats/assimp_loader.hh
r277 r280 9 9 10 10 #include <nv/common.hh> 11 #include <nv/io/string_table.hh> 11 12 #include <nv/interface/mesh_loader.hh> 12 13 #include <nv/interface/mesh_data.hh> … … 76 77 key_animation_data* create_direct_keys( const void* vnode ); 77 78 79 string_table_creator m_strings; 78 80 string m_ext; 79 81 mat4 m_rotate_transform; -
trunk/nv/gfx/keyframed_mesh.hh
r275 r280 53 53 vec3 normal; 54 54 }; 55 struct vertex_t 56 { 57 vec2 texcoord; 58 }; 55 59 56 60 mesh_data* m_mesh_data; -
trunk/nv/interface/device.hh
r277 r280 100 100 { 101 101 vertex_array* va = create_vertex_array(); 102 for ( uint32 ch = 0; ch < data->get_channel_data().size(); ++ch ) 102 const std::vector< mesh_raw_channel* >& channels = data->get_raw_channels(); 103 for ( uint32 ch = 0; ch < channels.size(); ++ch ) 103 104 { 104 const mesh_raw_channel* channel = data->get_channel_data()[ch]; 105 vertex_buffer* vb = create_vertex_buffer( hint, channel->size, channel->data ); 106 va->add_vertex_buffers( vb, channel ); 107 } 108 if ( data->get_index_channel() != nullptr ) 109 { 110 const mesh_raw_index_channel* index = data->get_index_channel(); 111 index_buffer* ib = create_index_buffer( hint, index->size, index->data ); 112 va->set_index_buffer( ib, index->etype, true ); 105 const mesh_raw_channel* channel = channels[ch]; 106 if ( channel->is_index() ) 107 { 108 index_buffer* ib = create_index_buffer( hint, channel->size(), channel->data ); 109 va->set_index_buffer( ib, channel->desc.slots[0].etype, true ); 110 } 111 else 112 { 113 vertex_buffer* vb = create_vertex_buffer( hint, channel->size(), channel->data ); 114 va->add_vertex_buffers( vb, channel ); 115 } 113 116 } 114 117 return va; -
trunk/nv/interface/mesh_data.hh
r241 r280 24 24 vertex_descriptor desc; 25 25 uint8* data; 26 uint32 size;27 26 uint32 count; 28 27 29 mesh_raw_channel() : data( nullptr ), size( 0 ) {}28 mesh_raw_channel() : data( nullptr ), count( 0 ) {} 30 29 ~mesh_raw_channel() 31 30 { 32 31 if ( data != nullptr ) delete[] data; 33 32 } 33 34 bool is_index() const { return count > 0 && desc.slots[0].vslot == INDEX; } 35 36 uint32 size() const { return count * desc.size; } 34 37 35 38 template < typename VTX > … … 39 42 result->desc.initialize<VTX>(); 40 43 result->count = count; 41 result->size = count * sizeof( VTX ); 42 result->data = (count > 0 ? ( new uint8[ result->size ] ) : nullptr ); 44 result->data = (count > 0 ? ( new uint8[ result->size() ] ) : nullptr ); 43 45 return result; 44 46 } … … 48 50 result->desc = vtxdesc; 49 51 result->count = count; 50 result->size = count * sizeof( vtxdesc.size ); 51 result->data = (count > 0 ? ( new uint8[ result->size ] ) : nullptr ); 52 result->data = (count > 0 ? ( new uint8[ result->size() ] ) : nullptr ); 52 53 return result; 53 }54 };55 56 struct mesh_raw_index_channel57 {58 datatype etype;59 uint8* data;60 uint32 size;61 uint32 count;62 63 mesh_raw_index_channel() : etype( NONE ), data( nullptr ), size( 0 ) {}64 ~mesh_raw_index_channel()65 {66 if ( data != nullptr ) delete[] data;67 54 } 68 55 69 56 template < typename ITYPE > 70 static mesh_raw_ index_channel* create( uint32 count = 0 )57 static mesh_raw_channel* create_index( uint32 count = 0 ) 71 58 { 72 mesh_raw_ index_channel* result = new mesh_raw_index_channel();73 result-> etype = type_to_enum< ITYPE >::type;59 mesh_raw_channel* result = new mesh_raw_channel(); 60 result->desc.initialize_index<ITYPE>(); 74 61 result->count = count; 75 result->size = count * sizeof( ITYPE ); 76 result->data = (count > 0 ? ( new uint8[ result->size ] ) : nullptr ); 62 result->data = (count > 0 ? ( new uint8[ result->size() ] ) : nullptr ); 77 63 return result; 78 64 } 79 65 80 static mesh_raw_index_channel* create( datatype etype, uint32 count = 0 ) 66 // TODO: remove this 67 static mesh_raw_channel* create_index( datatype etype, uint32 count = 0 ) 81 68 { 82 mesh_raw_ index_channel* result = new mesh_raw_index_channel();83 result-> etype = etype;69 mesh_raw_channel* result = new mesh_raw_channel(); 70 result->desc.initialize_index( etype ); 84 71 result->count = count; 85 result->size = count * get_datatype_info( etype ).size; 86 result->data = (count > 0 ? ( new uint8[ result->size ] ) : nullptr ); 72 result->data = (count > 0 ? ( new uint8[ result->size() ] ) : nullptr ); 87 73 return result; 88 74 } 75 89 76 }; 90 77 … … 93 80 public: 94 81 mesh_data() : m_index_channel( nullptr ) {} 95 void add_channel( mesh_raw_channel* channel ) { m_channels.push_back( channel ); } 96 void set_index_channel( mesh_raw_index_channel* channel ) 82 void add_channel( mesh_raw_channel* channel ) 97 83 { 98 if ( m_index_channel ) delete m_index_channel; 99 m_index_channel = channel; 84 NV_ASSERT( channel, "nullptr passed to add_channel!" ); 85 m_channels.push_back( channel ); 86 if ( channel->is_index() ) 87 { 88 NV_ASSERT( !m_index_channel, "second index channel!" ); 89 m_index_channel = channel; 90 } 100 91 } 101 92 102 const std::vector< mesh_raw_channel* >& get_ channel_data() const { return m_channels; }103 const mesh_raw_ index_channel* get_index_channel() const { return m_index_channel; }93 const std::vector< mesh_raw_channel* >& get_raw_channels() const { return m_channels; } 94 const mesh_raw_channel* get_index_channel() const { return m_index_channel; } 104 95 105 96 size_t get_count() const … … 116 107 } 117 108 109 template < typename VTX > 110 const mesh_raw_channel* get_channel() const 111 { 112 vertex_descriptor compare; 113 compare.initialize<VTX>(); 114 for ( auto ch : m_channels ) 115 { 116 if ( ch->desc == compare ) 117 { 118 return ch; 119 } 120 } 121 return nullptr; 122 } 123 124 template < typename VTX > 125 const VTX* get_channel_data() const 126 { 127 vertex_descriptor compare; 128 compare.initialize<VTX>(); 129 for ( auto ch : m_channels ) 130 { 131 if ( ch->desc == compare ) 132 { 133 return (VTX*)ch->data; 134 } 135 } 136 return nullptr; 137 } 138 118 139 virtual ~mesh_data() 119 140 { 120 141 for ( auto channel : m_channels ) delete channel; 121 if ( m_index_channel ) delete m_index_channel;122 142 } 123 143 private: 124 144 std::vector< mesh_raw_channel* > m_channels; 125 mesh_raw_ index_channel*m_index_channel;145 mesh_raw_channel* m_index_channel; 126 146 }; 127 147 -
trunk/nv/interface/vertex.hh
r238 r280 26 26 COLOR = 6, 27 27 28 SLOT_MAX = 6, 28 INDEX = 7, 29 SLOT_MAX = 7, 29 30 SLOT_MAX_STORE = 8, 30 31 }; … … 250 251 uint32 size; 251 252 253 template < typename IDX > 254 void initialize_index() 255 { 256 count = 1; 257 size = sizeof( IDX ); 258 slots[0].etype = type_to_enum< IDX >::type; 259 slots[0].vslot = slot::INDEX; 260 slots[0].offset = 0; 261 } 262 263 void initialize_index( datatype itype ) 264 { 265 count = 1; 266 size = get_datatype_info( itype ).size; 267 slots[0].etype = itype; 268 slots[0].vslot = slot::INDEX; 269 slots[0].offset = 0; 270 } 271 252 272 template < typename VTX > 253 273 void initialize() … … 263 283 size = sizeof( VTX ); 264 284 } 285 286 bool operator==( const vertex_descriptor& rhs ) 287 { 288 if ( size != rhs.size ) return false; 289 if ( count != rhs.count ) return false; 290 for ( uint32 i = 0; i < count; ++i ) 291 { 292 if ( slots[i].etype != rhs.slots[i].etype ) return false; 293 if ( slots[i].offset != rhs.slots[i].offset ) return false; 294 if ( slots[i].vslot != rhs.slots[i].vslot ) return false; 295 } 296 return true; 297 } 298 265 299 private: 266 300 template < typename VTX, slot SLOT > -
trunk/nv/io/string_table.hh
r279 r280 20 20 namespace nv 21 21 { 22 23 22 class string_table : noncopyable 24 23 { 25 24 public: 26 string_table( char* data, uint32 size, uint32* indices, uint32 count ) 27 : m_count( count ), m_size( size ), m_data( data ), m_indices( indices ) 25 typedef uint16 index; 26 typedef uint32 offset; 27 28 string_table( char* data, uint32 size, offset* offsets, index count ) 29 : m_count( count ), m_size( size ), m_data( data ), m_offsets( offsets ) 28 30 { 29 31 … … 34 36 } 35 37 36 const char* get( uint16 index )38 const char* get( index i ) const 37 39 { 38 return i ndex < m_count ? m_data + m_indices[index] : nullptr;40 return i < m_count ? m_data + m_offsets[i] : nullptr; 39 41 } 40 42 41 void dump( nv::stream* out ) 43 void dump( nv::stream* out ) const 42 44 { 43 45 out->write( &m_count, sizeof( m_count ), 1 ); 44 46 out->write( &m_size, sizeof( m_size ), 1 ); 45 out->write( m_ indices, sizeof( uint32), m_count );47 out->write( m_offsets, sizeof( offset ), m_count ); 46 48 out->write( m_data, sizeof( char ), m_size ); 47 49 } … … 50 52 { 51 53 delete[] m_data; 52 delete[] m_ indices;54 delete[] m_offsets; 53 55 } 54 56 private: … … 57 59 in->read( &m_count, sizeof( m_count ), 1 ); 58 60 in->read( &m_size, sizeof( m_size ), 1 ); 59 m_ indices = new uint32[ m_count ];61 m_offsets = new offset[ m_count ]; 60 62 m_data = new char[ m_count ]; 61 in->read( m_ indices, sizeof( uint32), m_count );63 in->read( m_offsets, sizeof( offset ), m_count ); 62 64 in->read( m_data, sizeof( char ), m_size ); 63 65 } 64 66 65 uint32 m_count;67 char* m_data; 66 68 uint32 m_size; 67 uint32* m_indices;68 char* m_data;69 offset* m_offsets; 70 index m_count; 69 71 }; 70 72 … … 72 74 { 73 75 public: 74 string_table_creator() {} 76 typedef string_table::index index; 77 typedef string_table::offset offset; 75 78 76 uint32 insert( const char* s ) 77 { 78 return insert( std::string(s) ); 79 } 80 81 uint32 insert( const std::string& s ) 82 { 83 auto i = m_map.find( s ); 84 if ( i != m_map.end() ) 85 { 86 return i->second; 87 } 88 const char* cs = s.c_str(); 89 uint32 cs_size = s.size() + 1; 90 uint32 result = m_indexes.size(); 91 uint32 index = m_data.size(); 92 m_indexes.push_back( index ); 93 std::copy( cs, cs + cs_size, std::back_inserter( m_data ) ); 94 m_map[ s ] = result; 95 return result; 96 } 97 98 string_table* create_table() const 99 { 100 uint32* indexes = new uint32[m_indexes.size()]; 101 char* data = new char [m_data.size()]; 102 std::copy( m_indexes.begin(), m_indexes.end(), indexes ); 103 std::copy( m_data.begin(), m_data.end(), data ); 104 return new string_table( data, m_data.size(), indexes, m_indexes.size() ); 105 } 106 107 void dump( nv::stream* out ) const 108 { 109 uint32 count = m_indexes.size(); 110 uint32 size = m_data.size(); 111 out->write( &count, sizeof( count ), 1 ); 112 out->write( &size, sizeof( size ), 1 ); 113 out->write( m_indexes.data(), sizeof( uint16 ), count ); 114 out->write( m_data.data(), sizeof( char ), size ); 115 } 79 string_table_creator(); 80 index insert( const std::string& s ); 81 string_table* create_table() const; 82 void dump( nv::stream* out ) const; 83 const char* get( index i ) const; 84 index get( const std::string& s ) const; 85 void clear(); 116 86 private: 117 std::unordered_map< std::string, uint32> m_map;118 std::vector< uint32 > m_indexes;87 std::unordered_map< std::string, index > m_map; 88 std::vector< offset > m_offsets; 119 89 std::vector< char > m_data; 120 90 }; -
trunk/src/formats/assimp_loader.cc
r279 r280 143 143 } 144 144 145 mesh_raw_ index_channel* ichannel = mesh_raw_index_channel::create( USHORT, mesh->mNumFaces * 3 );146 result-> set_index_channel( ichannel );145 mesh_raw_channel* ichannel = mesh_raw_channel::create_index( USHORT, mesh->mNumFaces * 3 ); 146 result->add_channel( ichannel ); 147 147 uint16* indices = (uint16*)ichannel->data; 148 148 for (unsigned int i=0; i<mesh->mNumFaces; i++) … … 294 294 { 295 295 mesh_data* mesh = model->meshes[m]; 296 mesh_raw_channel* channel = mesh->get_channel_data()[0]; 296 mesh_raw_channel* channel = mesh->get_raw_channels()[0]; 297 NV_ASSERT( !channel->is_index(), "index channel in release_merged!" ); 297 298 assimp_skinned_vtx* va = (assimp_skinned_vtx*)channel->data; 298 299 for ( unsigned v = 0; v < channel->count; ++v ) -
trunk/src/formats/md2_loader.cc
r240 r280 359 359 } 360 360 361 mesh_raw_ index_channel* ic = mesh_raw_index_channel::create< uint16 >( m_new_indexes.size() );361 mesh_raw_channel* ic = mesh_raw_channel::create_index< uint16 >( m_new_indexes.size() ); 362 362 if ( m_new_indexes.size() > 0 ) 363 363 { … … 369 369 result->add_channel( mc_pn ); 370 370 result->add_channel( mc_t ); 371 result-> set_index_channel( ic );371 result->add_channel( ic ); 372 372 return result; 373 373 } -
trunk/src/formats/md3_loader.cc
r241 r280 377 377 index = 0; 378 378 sint32 index_base = 0; 379 mesh_raw_ index_channel* ic = mesh_raw_index_channel::create< uint16 >( index_count );379 mesh_raw_channel* ic = mesh_raw_channel::create_index< uint16 >( index_count ); 380 380 uint16* icp = (uint16*)ic->data; 381 381 for ( sint32 i = 0; i < num_surfaces; ++i ) … … 396 396 result->add_channel( mc_pn ); 397 397 result->add_channel( mc_t ); 398 result-> set_index_channel( ic );398 result->add_channel( ic ); 399 399 return result; 400 400 } -
trunk/src/formats/md5_loader.cc
r261 r280 145 145 sstream >> num_tris; 146 146 147 mesh_raw_ index_channel* ch_i = mesh_raw_index_channel::create<uint32>( num_tris * 3 );147 mesh_raw_channel* ch_i = mesh_raw_channel::create_index<uint32>( num_tris * 3 ); 148 148 uint32* vtx_i = (uint32*)ch_i->data; 149 149 mesh->m_idata = vtx_i; 150 150 uint32 idx = 0; 151 mesh-> set_index_channel( ch_i );151 mesh->add_channel( ch_i ); 152 152 153 153 next_line( sstream ); -
trunk/src/formats/obj_loader.cc
r240 r280 334 334 channel->desc = m_descriptor; 335 335 channel->count = reader->size * 3; 336 channel->size = reader->raw_size();337 336 338 337 mesh_data* mesh = new mesh_data(); -
trunk/src/gfx/keyframed_mesh.cc
r275 r280 32 32 33 33 m_index_count = m_mesh_data->get_index_channel()->count; 34 m_vertex_count = m_mesh_data->get_channel _data()[1]->count;35 m_frame_count = m_mesh_data->get_channel _data()[0]->count / m_vertex_count;34 m_vertex_count = m_mesh_data->get_channel<vertex_t>()->count; 35 m_frame_count = m_mesh_data->get_channel<vertex_pn>()->count / m_vertex_count; 36 36 } 37 37 … … 167 167 : keyframed_mesh( a_device, a_data, a_tag_map ) 168 168 { 169 m_vb = a_device->create_vertex_buffer( nv::STATIC_DRAW, m_vertex_count * sizeof( vertex_pn ), (void*)m_mesh_data->get_channel _data()[0]->data );170 m_va->add_vertex_buffers( m_vb, m_mesh_data->get_channel _data()[0]);169 m_vb = a_device->create_vertex_buffer( nv::STATIC_DRAW, m_vertex_count * sizeof( vertex_pn ), (void*)m_mesh_data->get_channel<vertex_pn>()->data ); 170 m_va->add_vertex_buffers( m_vb, m_mesh_data->get_channel<vertex_pn>() ); 171 171 172 nv::vertex_buffer* vb = a_device->create_vertex_buffer( nv::STATIC_DRAW, m_vertex_count * sizeof( nv::vec2 ), (void*)m_mesh_data->get_channel _data()[1]->data );173 m_va->add_vertex_buffers( vb, m_mesh_data->get_channel _data()[1]);172 nv::vertex_buffer* vb = a_device->create_vertex_buffer( nv::STATIC_DRAW, m_vertex_count * sizeof( nv::vec2 ), (void*)m_mesh_data->get_channel<vertex_t>()->data ); 173 m_va->add_vertex_buffers( vb, m_mesh_data->get_channel<vertex_t>() ); 174 174 175 nv::index_buffer* ib = a_device->create_index_buffer( nv::STATIC_DRAW, m_mesh_data->get_index_channel()->size , (void*)m_mesh_data->get_index_channel()->data );176 m_va->set_index_buffer( ib, m_mesh_data->get_index_channel()-> etype, true );175 nv::index_buffer* ib = a_device->create_index_buffer( nv::STATIC_DRAW, m_mesh_data->get_index_channel()->size(), (void*)m_mesh_data->get_index_channel()->data ); 176 m_va->set_index_buffer( ib, m_mesh_data->get_index_channel()->desc.slots[0].etype, true ); 177 177 178 178 m_vertex.resize( m_vertex_count ); … … 183 183 keyframed_mesh::update( ms ); 184 184 185 const vertex_pn* data = (const vertex_pn*)(m_mesh_data->get_channel_data()[0]->data);185 const vertex_pn* data = m_mesh_data->get_channel_data<vertex_pn>(); 186 186 const vertex_pn* prev = data + m_vertex_count * m_last_frame; 187 187 const vertex_pn* next = data + m_vertex_count * m_next_frame;
Note: See TracChangeset
for help on using the changeset viewer.