Ignore:
Timestamp:
07/08/14 18:29:24 (11 years ago)
Author:
epyon
Message:
  • unified mesh_raw_channel and mesh_raw_index_channel
  • string_table cleaned up and implementation of creator split into a cc file
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/interface/mesh_data.hh

    r241 r280  
    2424                vertex_descriptor desc;
    2525                uint8*            data;
    26                 uint32            size;
    2726                uint32            count;
    2827
    29                 mesh_raw_channel() : data( nullptr ), size( 0 ) {}
     28                mesh_raw_channel() : data( nullptr ), count( 0 ) {}
    3029                ~mesh_raw_channel()
    3130                {
    3231                        if ( data != nullptr ) delete[] data;
    3332                }
     33
     34                bool is_index() const { return count > 0 && desc.slots[0].vslot == INDEX; }
     35
     36                uint32 size() const { return count * desc.size; }
    3437
    3538                template < typename VTX >
     
    3942                        result->desc.initialize<VTX>();
    4043                        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 );
    4345                        return result;
    4446                }
     
    4850                        result->desc  = vtxdesc;
    4951                        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 );
    5253                        return result;
    53                 }
    54         };
    55 
    56         struct mesh_raw_index_channel
    57         {
    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;
    6754                }
    6855
    6956                template < typename ITYPE >
    70                 static mesh_raw_index_channel* create( uint32 count = 0 )
     57                static mesh_raw_channel* create_index( uint32 count = 0 )
    7158                {
    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>();
    7461                        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 );
    7763                        return result;
    7864                }
    7965
    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 )
    8168                {
    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 );
    8471                        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 );
    8773                        return result;
    8874                }
     75
    8976        };
    9077
     
    9380        public:
    9481                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 )
    9783                {
    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                        }
    10091                }
    10192
    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; }
    10495
    10596                size_t get_count() const
     
    116107                }
    117108
     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
    118139                virtual ~mesh_data()
    119140                {
    120141                        for ( auto channel : m_channels ) delete channel;
    121                         if ( m_index_channel ) delete m_index_channel;
    122142                }
    123143        private:
    124144                std::vector< mesh_raw_channel* > m_channels;
    125                 mesh_raw_index_channel*          m_index_channel;
     145                mesh_raw_channel*                m_index_channel;
    126146        };
    127147
Note: See TracChangeset for help on using the changeset viewer.