Changeset 280 for trunk/nv/interface/mesh_data.hh
- Timestamp:
- 07/08/14 18:29:24 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.