Changeset 411


Ignore:
Timestamp:
07/09/15 12:19:30 (10 years ago)
Author:
epyon
Message:
  • mesh_raw_channel and key_raw_channel merged into raw_data_channel
Location:
trunk
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/formats/md3_loader.hh

    r399 r411  
    4141        private:
    4242                void release_mesh_frame( mesh_data* data, sint32 frame, sint32 surface );
    43                 key_raw_channel* load_tags( const string_view& tag );
     43                raw_data_channel* load_tags( const string_view& tag );
    4444                bool m_merge_all;
    4545                void* m_md3;
  • trunk/nv/gfx/animation.hh

    r410 r411  
    2020{
    2121
    22         struct key_raw_channel
    23         {
    24                 data_descriptor desc;
    25                 uint8*          data;
    26                 uint32          count;
    27 
    28                 key_raw_channel() : data( nullptr ), count( 0 ) {}
    29                 ~key_raw_channel()
    30                 {
    31                         if ( data != nullptr ) delete[] data;
    32                 }
    33 
    34                 uint32 size() const { return count * desc.element_size(); }
    35 
    36                 template < typename KEY >
    37                 static key_raw_channel* create( uint32 count = 0 )
    38                 {
    39                         key_raw_channel* result = new key_raw_channel();
    40                         result->desc.initialize<KEY>();
    41                         result->count = count;
    42                         result->data  = (count > 0 ? ( new uint8[ result->size() ] ) : nullptr );
    43                         return result;
    44                 }
    45 
    46                 static key_raw_channel* create( const data_descriptor& keydesc, uint32 count = 0 )
    47                 {
    48                         key_raw_channel* result = new key_raw_channel();
    49                         result->desc  = keydesc;
    50                         result->count = count;
    51                         result->data  = (count > 0 ? ( new uint8[ result->size() ] ) : nullptr );
    52                         return result;
    53                 }
    54 
    55                 uint32 get_raw( uint32 index, float* result ) const
    56                 {
    57                         if ( count == 0 ) return 0;
    58                         uint32 keyfsize   = desc.element_size() / 4;
    59                         const float* fdata = reinterpret_cast<const float*>( data ) + keyfsize * index;
    60                         uint32 mod        = 0;
    61                         if ( desc[0].vslot == slot::TIME ) mod = 1;
     22        class key_data
     23        {
     24        public:
     25                key_data() {}
     26
     27                void add_channel( raw_data_channel* channel )
     28                {
     29                        NV_ASSERT( channel, "nullptr passed to add_channel!" );
     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 );
     34                }
     35
     36                mat4 get_raw_matrix( uint32 index ) const
     37                {
     38                        float key[ 16 ];
     39                        float* pkey = key;
     40                        for ( uint16 i = 0; i < m_channels.size(); ++i )
     41                        {
     42                                pkey += get_raw( m_channels[i], index, pkey );
     43                        }
     44                        return extract_matrix_raw( m_final_key, key );
     45                }
     46
     47                transform get_raw_transform( uint32 index ) const
     48                {
     49                        float key[ 16 ];
     50                        float* pkey = key;
     51                        for ( uint16 i = 0; i < m_channels.size(); ++i )
     52                        {
     53                                pkey += get_raw( m_channels[i], index, pkey );
     54                        }
     55                        return extract_transform_raw( m_final_key, key );
     56                }
     57
     58                mat4 get_matrix( float time ) const
     59                {
     60                        float key[ 16 ];
     61                        float* pkey = key;
     62                        for ( uint16 i = 0; i < m_channels.size(); ++i )
     63                        {
     64                                pkey += interpolate_raw( m_channels[i], time, pkey );
     65                        }
     66                        return extract_matrix_raw( m_final_key, key );
     67                }
     68
     69                transform get_transform( float time ) const
     70                {
     71                        float key[ 16 ];
     72                        float* pkey = key;
     73                        for ( uint16 i = 0; i < m_channels.size(); ++i )
     74                        {
     75                                pkey += interpolate_raw( m_channels[i], time, pkey );
     76                        }
     77                        return extract_transform_raw( m_final_key, key );
     78                }
     79
     80                size_t get_channel_count() const { return m_channels.size(); }
     81                const raw_data_channel* get_channel( size_t index ) const { return m_channels[ index ]; }
     82                const data_descriptor& get_final_key() const { return m_final_key; }
     83
     84                virtual ~key_data()
     85                {
     86                        for ( auto channel : m_channels ) delete channel;
     87                }
     88
     89                static uint32 get_raw( const raw_data_channel* channel, uint32 index, float* result )
     90                {
     91                        if ( channel->element_count() == 0 ) return 0;
     92                        uint32 keyfsize = channel->element_size() / 4;
     93                        const float* fdata = reinterpret_cast<const float*>( channel->data ) + keyfsize * index;
     94                        uint32 mod = 0;
     95                        if ( channel->descriptor()[0].vslot == slot::TIME ) mod = 1;
    6296                        raw_copy_n( fdata + mod, keyfsize - mod, result );
    6397                        return keyfsize - mod;
    6498                }
    6599
    66                 uint32 interpolate_raw( float time, float* result ) const
    67                 {
    68                         if ( count == 0 ) return 0;
    69                         uint32 keyfsize   = desc.element_size() / 4;
     100
     101                static uint32 interpolate_raw( const raw_data_channel* channel, float time, float* result )
     102                {
     103                        if ( channel->element_count() == 0 ) return 0;
     104                        uint32 keyfsize = channel->element_size() / 4;
    70105                        uint32 keyfresult = keyfsize;
    71                         const float* fdata = reinterpret_cast<const float*>( data );
     106                        const float* fdata = reinterpret_cast<const float*>( channel->data );
    72107
    73108                        uint32 slot = 0;
    74                         int index0  = -1;
    75                         int index1  = -1;
     109                        int index0 = -1;
     110                        int index1 = -1;
    76111                        float factor = 1.0f;
    77                         if ( desc[0].vslot == slot::TIME )
    78                         {
    79                                 NV_ASSERT( desc[0].offset == 0, "time offset not zero!" );
     112                        if ( channel->descriptor()[0].vslot == slot::TIME )
     113                        {
     114                                NV_ASSERT( channel->descriptor()[0].offset == 0, "time offset not zero!" );
    80115                                slot++;
    81116                                keyfresult--;
    82                                 if ( count == 1 )
     117                                if ( channel->element_count() == 1 )
    83118                                {
    84119                                        raw_copy_n( fdata + 1, keyfresult, result );
    85120                                        return keyfresult;
    86121                                }
    87                                 for ( unsigned i = 1 ; i < count ; i++ )
     122                                for ( unsigned i = 1; i < channel->element_count(); i++ )
    88123                                {
    89                                         if ( time < fdata[ i * keyfsize ] )
     124                                        if ( time < fdata[i * keyfsize] )
    90125                                        {
    91                                                 index0 = static_cast<int>(i) - 1;
     126                                                index0 = static_cast<int>( i ) - 1;
    92127                                                break;
    93128                                        }
    94129                                }
    95                                 NV_ASSERT( index0 >= 0, "animation time fail!");
     130                                NV_ASSERT( index0 >= 0, "animation time fail!" );
    96131                                index1 = index0 + 1;
    97                                 float time0  = fdata[ index0 * static_cast<int>( keyfsize ) ];
    98                                 float time1  = fdata[ index1 * static_cast<int>( keyfsize ) ];
    99                                 float delta  = time1 - time0;
    100                                 factor = glm::clamp( (time - time0) / delta, 0.0f, 1.0f );
     132                                float time0 = fdata[index0 * static_cast<int>( keyfsize )];
     133                                float time1 = fdata[index1 * static_cast<int>( keyfsize )];
     134                                float delta = time1 - time0;
     135                                factor = glm::clamp( ( time - time0 ) / delta, 0.0f, 1.0f );
    101136                        }
    102137                        else
    103138                        {
    104                                 if ( count == 1 )
     139                                if ( channel->element_count() == 1 )
    105140                                {
    106141                                        raw_copy_n( fdata, keyfresult, result );
    107142                                        return keyfresult;
    108143                                }
    109                                 index0 = glm::clamp<int>( int( time ), 0, int( count ) - 2 );
     144                                index0 = glm::clamp<int>( int( time ), 0, int( channel->element_count() ) - 2 );
    110145                                index1 = index0 + 1;
    111                                 factor = glm::clamp<float> ( time - index0, 0.0f, 1.0f );
     146                                factor = glm::clamp<float>( time - index0, 0.0f, 1.0f );
    112147                        }
    113148                        uint32 ret = 0;
    114                         for ( ; slot < desc.slot_count(); ++slot )
    115                         {
    116                                 ret += nv::interpolate_raw( 
    117                                         desc[slot], factor,
    118                                         fdata + index0 * static_cast<int>( keyfsize ) + desc[slot].offset / 4,
    119                                         fdata + index1 * static_cast<int>( keyfsize ) + desc[slot].offset / 4,
     149                        for ( ; slot < channel->descriptor().slot_count(); ++slot )
     150                        {
     151                                ret += nv::interpolate_raw(
     152                                        channel->descriptor()[slot], factor,
     153                                        fdata + index0 * static_cast<int>( keyfsize ) + channel->descriptor()[slot].offset / 4,
     154                                        fdata + index1 * static_cast<int>( keyfsize ) + channel->descriptor()[slot].offset / 4,
    120155                                        result + ret );
    121156                        }
    122157                        return ret;
    123158                }
    124         };
    125 
    126         class key_data
    127         {
    128         public:
    129                 key_data() {}
    130 
    131                 void add_channel( key_raw_channel* channel )
    132                 {
    133                         NV_ASSERT( channel, "nullptr passed to add_channel!" );
    134                         m_channels.push_back( channel );
    135                         for ( const auto& cslot : channel->desc )
    136                                 if ( cslot.vslot != slot::TIME )
    137                                         m_final_key.push_slot( cslot.etype, cslot.vslot );
    138                 }
    139 
    140                 mat4 get_raw_matrix( uint32 index ) const
    141                 {
    142                         float key[ 16 ];
    143                         float* pkey = key;
    144                         for ( uint16 i = 0; i < m_channels.size(); ++i )
    145                         {
    146                                 pkey += m_channels[i]->get_raw( index, pkey );
    147                         }
    148                         return extract_matrix_raw( m_final_key, key );
    149                 }
    150 
    151                 transform get_raw_transform( uint32 index ) const
    152                 {
    153                         float key[ 16 ];
    154                         float* pkey = key;
    155                         for ( uint16 i = 0; i < m_channels.size(); ++i )
    156                         {
    157                                 pkey += m_channels[i]->get_raw( index, pkey );
    158                         }
    159                         return extract_transform_raw( m_final_key, key );
    160                 }
    161 
    162                 mat4 get_matrix( float time ) const
    163                 {
    164                         float key[ 16 ];
    165                         float* pkey = key;
    166                         for ( uint16 i = 0; i < m_channels.size(); ++i )
    167                         {
    168                                 pkey += m_channels[i]->interpolate_raw( time, pkey );
    169                         }
    170                         return extract_matrix_raw( m_final_key, key );
    171                 }
    172 
    173                 transform get_transform( float time ) const
    174                 {
    175                         float key[ 16 ];
    176                         float* pkey = key;
    177                         for ( uint16 i = 0; i < m_channels.size(); ++i )
    178                         {
    179                                 pkey += m_channels[i]->interpolate_raw( time, pkey );
    180                         }
    181                         return extract_transform_raw( m_final_key, key );
    182                 }
    183 
    184                 size_t get_channel_count() const { return m_channels.size(); }
    185                 const key_raw_channel* get_channel( size_t index ) const { return m_channels[ index ]; }
    186                 const data_descriptor& get_final_key() const { return m_final_key; }
    187 
    188                 virtual ~key_data()
    189                 {
    190                         for ( auto channel : m_channels ) delete channel;
    191                 }
     159
    192160        private:
     161
    193162                data_descriptor m_final_key;
    194                 vector< key_raw_channel* > m_channels;
     163                vector< raw_data_channel* > m_channels;
    195164        };
    196165
     
    204173        public:
    205174                key_channel_interpolator() : m_data( nullptr ) {}
    206                 key_channel_interpolator( const key_raw_channel* data ) : m_data( nullptr ) { set_data( data ); }
    207                 key_channel_interpolator( const key_raw_channel* data, bool ) : m_data( data ) {}
    208                 void set_data( const key_raw_channel* data )
     175                key_channel_interpolator( const raw_data_channel* data ) : m_data( nullptr ) { set_data( data ); }
     176                key_channel_interpolator( const raw_data_channel* data, bool ) : m_data( data ) {}
     177                void set_data( const raw_data_channel* data )
    209178                {
    210179                        m_data = data;
     
    229198
    230199        private:
    231                 const key_raw_channel* m_data;
     200                const raw_data_channel* m_data;
    232201        };
    233202 
     
    237206        public:
    238207                key_channel_interpolator() : m_data( nullptr ) {}
    239                 key_channel_interpolator( const key_raw_channel* data ) : m_data( nullptr ) { set_data( data ); }
    240                 void set_data( const key_raw_channel* data )
     208                key_channel_interpolator( const raw_data_channel* data ) : m_data( nullptr ) { set_data( data ); }
     209                void set_data( const raw_data_channel* data )
    241210                {
    242211                        m_data = data;
     
    268237
    269238        private:
    270                 const key_raw_channel* m_data;
     239                const raw_data_channel* m_data;
    271240        };
    272241 
     
    295264                struct key_s { float time; vec3 scale; };
    296265        public:
    297                 explicit key_vectors_prs( const key_raw_channel* p, const key_raw_channel* r, const key_raw_channel* s )
     266                explicit key_vectors_prs( const raw_data_channel* p, const raw_data_channel* r, const raw_data_channel* s )
    298267                {
    299268                        m_pchannel = p;
     
    305274                }
    306275                size_t size() const { return 0; } // TODO: remove?
    307                 bool empty() const { return m_pchannel->count == 0 && m_rchannel->count == 0 && m_schannel->count == 0; }
     276                bool empty() const { return m_pchannel->element_count() == 0 && m_rchannel->count == 0 && m_schannel->count == 0; }
    308277                virtual mat4 get_matrix( float time ) const
    309278                {
     
    331300                {
    332301                        return 3 * sizeof( size_t )
    333                                 + m_pchannel->count * sizeof( key_p )
    334                                 + m_rchannel->count * sizeof( key_r )
    335                                 + m_schannel->count * sizeof( key_s );
     302                                + m_pchannel->element_count() * sizeof( key_p )
     303                                + m_rchannel->element_count() * sizeof( key_r )
     304                                + m_schannel->element_count() * sizeof( key_s );
    336305                }
    337306                ~key_vectors_prs()
     
    339308                }
    340309        protected:
    341                 const key_raw_channel* m_pchannel;
    342                 const key_raw_channel* m_rchannel;
    343                 const key_raw_channel* m_schannel;
     310                const raw_data_channel* m_pchannel;
     311                const raw_data_channel* m_rchannel;
     312                const raw_data_channel* m_schannel;
    344313                key_channel_interpolator< key_p, true > m_pinter;
    345314                key_channel_interpolator< key_r, true > m_rinter;
     
    354323                };
    355324        public:
    356                 explicit transform_vector( const key_raw_channel* channel )
     325                explicit transform_vector( const raw_data_channel* channel )
    357326                {
    358327                        data_descriptor kd;
     
    367336                        delete m_channel;
    368337                }
    369                 bool empty() const { return m_channel->count == 0; }
    370                 size_t size() const { return m_channel->count; }
     338                bool empty() const { return m_channel->element_count() == 0; }
     339                size_t size() const { return m_channel->element_count(); }
    371340                const transform& get( size_t index ) const { return reinterpret_cast<key*>(m_channel->data)[ index ].tform; }
    372341                const transform* data() const { return reinterpret_cast<const transform*>( m_channel->data ); }
     
    374343                virtual uint32 raw_size() const
    375344                {
    376                         return sizeof( size_t ) + m_channel->count * sizeof( key );
     345                        return sizeof( size_t ) + m_channel->element_count() * sizeof( key );
    377346                }
    378347
     
    389358        protected:
    390359                key_channel_interpolator< key, false > m_interpolator;
    391                 const key_raw_channel* m_channel;
     360                const raw_data_channel* m_channel;
    392361        };
    393362
  • trunk/nv/gfx/keyframed_mesh.hh

    r395 r411  
    5252                const mesh_data*        m_mesh_data;
    5353                const mesh_nodes_data*  m_tag_map;
    54                 const mesh_raw_channel* m_vchannel;
     54                const raw_data_channel* m_vchannel;
    5555
    5656                buffer       m_pbuffer;
  • trunk/nv/gfx/mesh_creator.hh

    r395 r411  
    2727                void merge( mesh_data* other );
    2828        private:
    29                 mesh_raw_channel* merge_channels( mesh_raw_channel* a, mesh_raw_channel* b );
    30                 mesh_raw_channel* append_channels( mesh_raw_channel* a, mesh_raw_channel* b, uint32 frame_count = 1 );
     29                raw_data_channel* merge_channels( raw_data_channel* a, raw_data_channel* b );
     30                raw_data_channel* append_channels( raw_data_channel* a, raw_data_channel* b, uint32 frame_count = 1 );
    3131
    3232                mesh_data* m_data;
  • trunk/nv/interface/context.hh

    r410 r411  
    155155                }
    156156
    157                 void add_vertex_buffers( vertex_array va, buffer buf, const mesh_raw_channel* channel )
     157                void add_vertex_buffers( vertex_array va, buffer buf, const raw_data_channel* channel )
    158158                {
    159159                        for ( const auto& cslot : channel->desc )
     
    300300                {
    301301                        vertex_array  va = create_vertex_array();
    302                         array_view< mesh_raw_channel* > channels = data->get_raw_channels();
     302                        array_view< raw_data_channel* > channels = data->get_raw_channels();
    303303                        for ( uint32 ch = 0; ch < channels.size(); ++ch )
    304304                        {
    305                                 const mesh_raw_channel* channel = channels[ch];
     305                                const raw_data_channel* channel = channels[ch];
    306306                                if ( channel->count > 0 )
    307307                                {
  • trunk/nv/interface/data_descriptor.hh

    r410 r411  
    1414namespace nv
    1515{
     16        // TODO: move somewhere else, or change to generic buffer_type
     17        enum buffer_type
     18        {
     19                VERTEX_BUFFER,
     20                INDEX_BUFFER,
     21        };
    1622
    1723        enum class slot : uint8
     
    232238                        }
    233239                        return true;
    234                 }
    235 
    236                 template < typename IndexType >
    237                 void initialize_index()
    238                 {
    239                         count = 1;
    240                         size = sizeof( IndexType );
    241                         slots[0].etype = type_to_enum< IndexType >::type;
    242                         slots[0].vslot = slot::INDEX;
    243                         slots[0].offset = 0;
    244                 }
    245 
    246                 void initialize_index( datatype itype )
    247                 {
    248                         count = 1;
    249                         size  = get_datatype_info( itype ).size;
    250                         slots[0].etype  = itype;
    251                         slots[0].vslot  = slot::INDEX;
    252                         slots[0].offset = 0;
    253240                }
    254241
     
    320307        };
    321308
     309        struct raw_data_channel
     310        {
     311                raw_data_channel() : data( nullptr ), count( 0 ) {}
     312                ~raw_data_channel()
     313                {
     314                        if ( data != nullptr ) delete[] data;
     315                }
     316
     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(); }
     331
     332                template < typename VTX >
     333                static raw_data_channel* create( uint32 count = 0 )
     334                {
     335                        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 );
     339                        return result;
     340                }
     341                static raw_data_channel* create( const data_descriptor& vtxdesc, uint32 count = 0 )
     342                {
     343                        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 );
     347                        return result;
     348                }
     349
     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 this
     361                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                friend class mesh_creator;
     371
     372                data_descriptor desc;
     373                uint8*          data;
     374                uint32          count;
     375
     376        };
     377
    322378}
    323379
  • trunk/nv/interface/mesh_data.hh

    r410 r411  
    1717{
    1818
    19         enum buffer_type
    20         {
    21                 VERTEX_BUFFER,
    22                 INDEX_BUFFER,
    23         };
    24 
    25 
    2619        // TODO: friend mesh_data_creator class?
    2720        // TODO: private const etc
    28 
    29 
    30         struct mesh_raw_channel
    31         {
    32                 friend class mesh_creator;
    33 
    34                 data_descriptor desc;
    35                 uint8*          data;
    36                 uint32          count;
    37 
    38                 mesh_raw_channel() : data( nullptr ), count( 0 ) {}
    39                 ~mesh_raw_channel()
    40                 {
    41                         if ( data != nullptr ) delete[] data;
    42                 }
    43 
    44                 // TODO: this could have more options if stored!
    45                 buffer_type get_buffer_type() const
    46                 {
    47                         if ( count > 0 && desc[0].vslot == slot::INDEX )
    48                         {
    49                                 return INDEX_BUFFER;
    50                         }
    51                         return VERTEX_BUFFER;
    52                 }
    53 
    54                 uint32 size() const { return count * desc.element_size(); }
    55 
    56                 template < typename VTX >
    57                 static mesh_raw_channel* create( uint32 count = 0 )
    58                 {
    59                         mesh_raw_channel* result = new mesh_raw_channel();
    60                         result->desc.initialize<VTX>();
    61                         result->count = count;
    62                         result->data  = (count > 0 ? ( new uint8[ result->size() ] ) : nullptr );
    63                         return result;
    64                 }
    65                 static mesh_raw_channel* create( const data_descriptor& vtxdesc, uint32 count = 0 )
    66                 {
    67                         mesh_raw_channel* result = new mesh_raw_channel();
    68                         result->desc  = vtxdesc;
    69                         result->count = count;
    70                         result->data  = (count > 0 ? ( new uint8[ result->size() ] ) : nullptr );
    71                         return result;
    72                 }
    73 
    74                 template < typename ITYPE >
    75                 static mesh_raw_channel* create_index( uint32 count = 0 )
    76                 {
    77                         mesh_raw_channel* result = new mesh_raw_channel();
    78                         result->desc.initialize_index<ITYPE>();
    79                         result->count = count;
    80                         result->data  = (count > 0 ? ( new uint8[ result->size() ] ) : nullptr );
    81                         return result;
    82                 }
    83 
    84                 // TODO: remove this
    85                 static mesh_raw_channel* create_index( datatype etype, uint32 count = 0 )
    86                 {
    87                         mesh_raw_channel* result = new mesh_raw_channel();
    88                         result->desc.initialize_index( etype );
    89                         result->count = count;
    90                         result->data  = (count > 0 ? ( new uint8[ result->size() ] ) : nullptr );
    91                         return result;
    92                 }
    93 
    94         };
    9521
    9622        class mesh_data
     
    10228                explicit mesh_data( const std::string& name ) : m_name(name), m_index_channel( nullptr ) {}
    10329
    104                 void add_channel( mesh_raw_channel* channel )
     30                void add_channel( raw_data_channel* channel )
    10531                {
    10632                        NV_ASSERT( channel, "nullptr passed to add_channel!" );
     
    11339                }
    11440
    115                 array_view< mesh_raw_channel* > get_raw_channels()  const { return m_channels; }
    116                 const mesh_raw_channel*         get_index_channel() const { return m_index_channel; }
     41                array_view< raw_data_channel* > get_raw_channels()  const { return m_channels; }
     42                const raw_data_channel*         get_index_channel() const { return m_index_channel; }
    11743                size_t get_channel_count() const { return m_channels.size(); }
    118                 const mesh_raw_channel* get_channel( size_t index ) const
     44                const raw_data_channel* get_channel( size_t index ) const
    11945                {
    12046                        if ( m_channels.size() > index ) return m_channels[index];
     
    12248                }
    12349
    124                 const mesh_raw_channel* get_channel( slot s ) const
     50                const raw_data_channel* get_channel( slot s ) const
    12551                {
    12652                        for ( auto ch : m_channels )
     
    15985
    16086                template < typename VTX >
    161                 const mesh_raw_channel* get_channel() const
     87                const raw_data_channel* get_channel() const
    16288                {
    16389                        data_descriptor compare;
     
    216142        private:
    217143                std::string                 m_name;
    218                 vector< mesh_raw_channel* > m_channels;
    219                 mesh_raw_channel*           m_index_channel;
     144                vector< raw_data_channel* > m_channels;
     145                raw_data_channel*           m_index_channel;
    220146        };
    221147
  • trunk/src/formats/assimp_loader.cc

    r410 r411  
    118118
    119119        bool skinned = mesh->mNumBones > 0;
    120         mesh_raw_channel* channel = nullptr;
     120        raw_data_channel* channel = nullptr;
    121121        if ( skinned )
    122                 channel = mesh_raw_channel::create< assimp_skinned_vtx >( mesh->mNumVertices );
     122                channel = raw_data_channel::create< assimp_skinned_vtx >( mesh->mNumVertices );
    123123        else
    124                 channel = mesh_raw_channel::create< assimp_plain_vtx >( mesh->mNumVertices );
     124                channel = raw_data_channel::create< assimp_plain_vtx >( mesh->mNumVertices );
    125125
    126126        data->add_channel( channel );
     
    169169        }
    170170
    171         mesh_raw_channel* ichannel = mesh_raw_channel::create_index( USHORT, mesh->mNumFaces * 3 );
     171        raw_data_channel* ichannel = raw_data_channel::create_index( USHORT, mesh->mNumFaces * 3 );
    172172        data->add_channel( ichannel );
    173173        uint16* indices = reinterpret_cast<uint16*>( ichannel->data );
     
    315315                        if ( m > 0 && bones.size() > 0 )
    316316                        {
    317                                 mesh_raw_channel* channel = meshes[m].get_raw_channels()[0];
     317                                raw_data_channel* channel = meshes[m].get_raw_channels()[0];
    318318                                assimp_skinned_vtx* va = reinterpret_cast< assimp_skinned_vtx* >( channel->data );
    319319                                for ( unsigned v = 0; v < channel->count; ++v )
     
    418418
    419419        data->data = new key_data;
    420         key_raw_channel* raw_pchannel = key_raw_channel::create<assimp_key_p>( node->mNumPositionKeys );
    421         key_raw_channel* raw_rchannel = key_raw_channel::create<assimp_key_r>( node->mNumRotationKeys );
    422         //key_raw_channel* raw_schannel = key_raw_channel::create<assimp_key_s>( node->mNumScalingKeys );
     420        raw_data_channel* raw_pchannel = raw_data_channel::create<assimp_key_p>( node->mNumPositionKeys );
     421        raw_data_channel* raw_rchannel = raw_data_channel::create<assimp_key_r>( node->mNumRotationKeys );
     422        //raw_data_channel* raw_schannel = raw_data_channel::create<assimp_key_s>( node->mNumScalingKeys );
    423423        data->data->add_channel( raw_pchannel );
    424424        data->data->add_channel( raw_rchannel );
  • trunk/src/formats/md2_loader.cc

    r406 r411  
    324324        size_t frame_count   = ( frame == -1 ? num_frames : 1 );
    325325
    326         mesh_raw_channel* mc_pn = mesh_raw_channel::create< vtx_md2_pn >( num_verts * frame_count );
     326        raw_data_channel* mc_pn = raw_data_channel::create< vtx_md2_pn >( num_verts * frame_count );
    327327        vtx_md2_pn* vtx_pn = reinterpret_cast< vtx_md2_pn* >( mc_pn->data );
    328328
     
    347347        }
    348348
    349         mesh_raw_channel* mc_t = mesh_raw_channel::create< vtx_md2_t >( num_verts );
     349        raw_data_channel* mc_t = raw_data_channel::create< vtx_md2_t >( num_verts );
    350350        vtx_md2_t* vtx_t = reinterpret_cast< vtx_md2_t* >( mc_t->data );
    351351
     
    357357        }
    358358
    359         mesh_raw_channel* ic = mesh_raw_channel::create_index< uint16 >( m_new_indexes.size() );
     359        raw_data_channel* ic = raw_data_channel::create_index< uint16 >( m_new_indexes.size() );
    360360        if ( m_new_indexes.size() > 0 )
    361361        {
  • trunk/src/formats/md3_loader.cc

    r406 r411  
    286286}
    287287
    288 nv::key_raw_channel* nv::md3_loader::load_tags( const string_view& tag )
     288nv::raw_data_channel* nv::md3_loader::load_tags( const string_view& tag )
    289289{
    290290        md3_t* md3 = reinterpret_cast< md3_t* >( m_md3 );
    291         key_raw_channel* result = key_raw_channel::create<md3_key>( uint32( md3->header.num_frames ) );
     291        raw_data_channel* result = raw_data_channel::create<md3_key>( uint32( md3->header.num_frames ) );
    292292        // TODO: is this brain damaged in efficiency (loop nest order) or what?
    293293        for ( sint32 f = 0; f < md3->header.num_frames; ++f )
     
    352352                }
    353353
    354         mesh_raw_channel* mc_pn = mesh_raw_channel::create< vtx_md3_pn >( uint32( num_verts * frame_count ) );
    355         mesh_raw_channel* mc_t  = mesh_raw_channel::create< vtx_md3_t >( uint32( num_verts ) );
    356         mesh_raw_channel* ic = mesh_raw_channel::create_index< uint16 >( uint32( index_count ) );
     354        raw_data_channel* mc_pn = raw_data_channel::create< vtx_md3_pn >( uint32( num_verts * frame_count ) );
     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 ) );
    357357        vtx_md3_pn* vtx_pn = reinterpret_cast< vtx_md3_pn* >( mc_pn->data );
    358358        vtx_md3_t*  vtx_t  = reinterpret_cast< vtx_md3_t* >( mc_t->data );
     
    435435                nodes[i].data      = new key_data;
    436436       
    437                 key_raw_channel* keys = load_tags( name );
     437                raw_data_channel* keys = load_tags( name );
    438438                nodes[i].data->add_channel( keys );
    439439        }
  • trunk/src/formats/md5_loader.cc

    r406 r411  
    159159                                        md5_vtx_t* tdata = nullptr;
    160160                                        {
    161                                                 mesh_raw_channel* ch_pnt = mesh_raw_channel::create<md5_vtx_pnt>( num_verts );
    162                                                 mesh_raw_channel* ch_t   = mesh_raw_channel::create<md5_vtx_t>( num_verts );
    163                                                 mesh_raw_channel* ch_pntiw = mesh_raw_channel::create<md5_vtx_pntiw>( num_verts );
     161                                                raw_data_channel* ch_pnt = raw_data_channel::create<md5_vtx_pnt>( num_verts );
     162                                                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 );
    164164                                                tdata = reinterpret_cast< md5_vtx_t* >( ch_t->data );
    165165                                                mesh->add_channel( ch_pnt );
     
    190190                                        sstream >> num_tris;
    191191
    192                                         mesh_raw_channel* ch_i = mesh_raw_channel::create_index<uint32>( num_tris * 3 );
     192                                        raw_data_channel* ch_i = raw_data_channel::create_index<uint32>( num_tris * 3 );
    193193                                        uint32* vtx_i                = reinterpret_cast< uint32* >( ch_i->data );
    194194                                        uint32 idx = 0;
     
    256256                                nodes[i].target_id = -1;
    257257                                nodes[i].data      = new key_data;
    258                                 nodes[i].data->add_channel( key_raw_channel::create< md5_key_t >( num_frames ) );
     258                                nodes[i].data->add_channel( raw_data_channel::create< md5_key_t >( num_frames ) );
    259259                                next_line( sstream );
    260260                        }
  • trunk/src/formats/nmd_loader.cc

    r410 r411  
    4343                nmd_stream_header stream_header;
    4444                source.read( &stream_header, sizeof( stream_header ), 1 );
    45                 mesh_raw_channel* channel = mesh_raw_channel::create( stream_header.format, stream_header.count );
     45                raw_data_channel* channel = raw_data_channel::create( stream_header.format, stream_header.count );
    4646                source.read( channel->data, stream_header.format.element_size(), stream_header.count );
    4747                mesh->add_channel( channel );
     
    128128                                nv::nmd_stream_header cheader;
    129129                                source.read( &cheader, sizeof( cheader ), 1 );
    130                                 key_raw_channel* channel = key_raw_channel::create( cheader.format, cheader.count );
     130                                raw_data_channel* channel = raw_data_channel::create( cheader.format, cheader.count );
    131131                                source.read( channel->data, channel->desc.element_size(), channel->count );
    132132                                kdata->add_channel( channel );
     
    162162static void nmd_dump_mesh( const mesh_data* mesh, stream& stream_out )
    163163{
    164         array_view< mesh_raw_channel* > data  = mesh->get_raw_channels();
     164        array_view< raw_data_channel* > data  = mesh->get_raw_channels();
    165165
    166166        uint32 size = sizeof( nmd_element_header );
     
    248248                for ( uint32 c = 0; c < chan_count; ++c )
    249249                {
    250                         const key_raw_channel* channel = node->data->get_channel(c);
     250                        const raw_data_channel* channel = node->data->get_channel(c);
    251251
    252252                        eheader.type     = nmd_type::KEY_CHANNEL;
  • trunk/src/formats/obj_loader.cc

    r406 r411  
    324324                }
    325325       
    326                 mesh_raw_channel* channel = new mesh_raw_channel();
     326                raw_data_channel* channel = new raw_data_channel();
    327327                nv::uint8* data = nullptr;
    328328
  • trunk/src/gfx/mesh_creator.cc

    r410 r411  
    1919                key_data* keys   = m_data->m_nodes[i].data;
    2020                key_data* pkeys  = ( parent_id != -1 ? m_data->m_nodes[parent_id].data : nullptr );
    21                 size_t count     = ( keys ? keys->get_channel(0)->count : 0 );
    22                 size_t pcount    = ( pkeys ? pkeys->get_channel(0)->count : 0 );
     21                size_t count     = ( keys ? keys->get_channel(0)->element_count() : 0 );
     22                size_t pcount    = ( pkeys ? pkeys->get_channel(0)->element_count() : 0 );
    2323                max_frames = nv::max<uint32>( count, max_frames );
    2424                if ( pkeys && pkeys->get_channel_count() > 0 && keys && keys->get_channel_count() > 0 )
     
    6666                        }
    6767
    68                         key_raw_channel* raw_channel = key_raw_channel::create<nv_key_transform>( max_keys );
     68                        raw_data_channel* raw_channel = raw_data_channel::create<nv_key_transform>( max_keys );
    6969                        key_data* new_keys = new key_data;
    7070                        new_keys->add_channel( raw_channel );
     
    8080                                {
    8181                                        size_t idx = nv::min( old_keys->get_channel(c)->count - 1, n );
    82                                         pkey += old_keys->get_channel(c)->get_raw( idx, pkey );
     82                                        pkey += old_keys->get_raw( old_keys->get_channel(c), idx, pkey );
    8383                                }
    8484                                channel[n].tform = extract_transform_raw( final_key, key );
     
    106106                        for ( size_t c = 0; c < kdata->get_channel_count(); ++c )
    107107                        {
    108                                 const key_raw_channel* channel = kdata->get_channel(c);
     108                                const raw_data_channel* channel = kdata->get_channel(c);
    109109                                size_t key_size = channel->desc.element_size();
    110110                                for ( size_t n = 0; n < channel->count; ++n )
     
    125125        for ( uint32 c = 0; c < m_data->get_channel_count(); ++c )
    126126        {
    127                 const mesh_raw_channel* channel = m_data->get_channel(c);
     127                const raw_data_channel* channel = m_data->get_channel(c);
    128128                const data_descriptor&  desc    = channel->desc;
    129129                uint8* raw_data = channel->data;
     
    173173        size_t n_offset = 0;
    174174        if ( ch_n == -1 ) return;
    175         mesh_raw_channel* channel = m_data->m_channels[ unsigned( ch_n ) ];
     175        raw_data_channel* channel = m_data->m_channels[ unsigned( ch_n ) ];
    176176        for ( const auto& cslot : channel->desc )
    177177                if ( cslot.vslot == slot::NORMAL )
     
    196196        uint32 n_channel_index = 0;
    197197
    198         const mesh_raw_channel* p_channel = nullptr;
    199               mesh_raw_channel* n_channel = nullptr;
    200         const mesh_raw_channel* t_channel = nullptr;
    201         const mesh_raw_channel* i_channel = nullptr;
     198        const raw_data_channel* p_channel = nullptr;
     199              raw_data_channel* n_channel = nullptr;
     200        const raw_data_channel* t_channel = nullptr;
     201        const raw_data_channel* i_channel = nullptr;
    202202
    203203        for ( uint32 c = 0; c < m_data->get_channel_count(); ++c )
    204204        {
    205                 const mesh_raw_channel* channel = m_data->get_channel(c);
     205                const raw_data_channel* channel = m_data->get_channel(c);
    206206
    207207                for ( const auto& cslot : channel->desc )
     
    247247        }
    248248
    249         mesh_raw_channel* g_channel = mesh_raw_channel::create<vertex_g>( p_channel->count );
     249        raw_data_channel* g_channel = raw_data_channel::create<vertex_g>( p_channel->count );
    250250        vec4* tangents              = reinterpret_cast<vec4*>( g_channel->data );
    251251        vec3* tangents2             = new vec3[ p_channel->count ];
     
    334334}
    335335
    336 nv::mesh_raw_channel* nv::mesh_data_creator::merge_channels( mesh_raw_channel* a, mesh_raw_channel* b )
     336nv::raw_data_channel* nv::mesh_data_creator::merge_channels( raw_data_channel* a, raw_data_channel* b )
    337337{
    338338        NV_ASSERT( a->count == b->count, "merge_channel - bad channels!" );
     
    352352                raw_copy_n( b->data + i * bdesc.element_size(), bdesc.element_size(), data + i*desc.element_size() + adesc.element_size() );
    353353        }
    354         mesh_raw_channel* result = new mesh_raw_channel;
     354        raw_data_channel* result = new raw_data_channel;
    355355        result->count = count;
    356356        result->desc  = desc;
     
    359359}
    360360
    361 nv::mesh_raw_channel* nv::mesh_data_creator::append_channels( mesh_raw_channel* a, mesh_raw_channel* b, uint32 frame_count )
     361nv::raw_data_channel* nv::mesh_data_creator::append_channels( raw_data_channel* a, raw_data_channel* b, uint32 frame_count )
    362362{
    363363        if ( a->desc != b->desc ) return nullptr;
     
    391391        }
    392392
    393         mesh_raw_channel* result = new mesh_raw_channel;
    394         result->count = a->count + b->count;
    395         result->desc  = a->desc;
     393        raw_data_channel* result = new raw_data_channel;
     394        result->count = a->element_count() + b->element_count();
     395        result->desc  = a->descriptor();
    396396        result->data  = data;
    397397        return result;
     
    405405        for ( uint32 c = 0; c < m_data->get_channel_count(); ++c )
    406406        {
    407                 if ( m_data->get_channel(c)->desc != other->get_channel(c)->desc )
     407                if ( m_data->get_channel(c)->descriptor() != other->get_channel(c)->descriptor() )
    408408                        return false;
    409409        }
     
    419419        int och_ti = other->get_channel_index( slot::TEXCOORD );
    420420        if ( ch_pi == -1 || ch_ti == -1 ) return;
    421         size_t size   = m_data->m_channels[ unsigned(ch_ti) ]->count;
    422         size_t osize  =  other->m_channels[ unsigned(och_ti) ]->count;
    423         size_t count  = m_data->m_channels[ unsigned(ch_pi) ]->count;
    424         size_t ocount =  other->m_channels[ unsigned(och_pi) ]->count;
     421        size_t size   = m_data->m_channels[ unsigned(ch_ti) ]->element_count();
     422        size_t osize  =  other->m_channels[ unsigned(och_ti) ]->element_count();
     423        size_t count  = m_data->m_channels[ unsigned(ch_pi) ]->element_count();
     424        size_t ocount =  other->m_channels[ unsigned(och_pi) ]->element_count();
    425425        if ( count % size != 0 || ocount % osize != 0 ) return;
    426426        if ( count / size != ocount / osize ) return;
     
    428428        for ( uint32 c = 0; c < m_data->get_channel_count(); ++c )
    429429        {
    430                 mesh_raw_channel* old = m_data->m_channels[c];
    431                 size_t frame_count = ( old->get_buffer_type() == INDEX_BUFFER ? 1 : old->count / size );
     430                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 );
    432432                m_data->m_channels[c] = append_channels( old, other->m_channels[c], frame_count );
    433433                NV_ASSERT( m_data->m_channels[c], "Merge problem!" );
     
    440440                                        NV_ASSERT( size + osize < uint16(-1), "Index out of range!" );
    441441                                        uint16* indexes = reinterpret_cast<uint16*>( m_data->m_channels[c]->data );
    442                                         for ( uint16 i = uint16( old->count ); i < m_data->m_channels[c]->count; ++i )
     442                                        for ( uint16 i = uint16( old->element_count() ); i < m_data->m_channels[c]->element_count(); ++i )
    443443                                                indexes[i] += uint16( size );
    444444
     
    448448                                {
    449449                                        uint32* indexes = reinterpret_cast<uint32*>( m_data->m_channels[c]->data );
    450                                         for ( uint32 i = old->count; i < m_data->m_channels[c]->count; ++i )
     450                                        for ( uint32 i = old->element_count(); i < m_data->m_channels[c]->element_count(); ++i )
    451451                                                indexes[i] += size;
    452452                                }
  • trunk/src/gfx/skeletal_mesh.cc

    r406 r411  
    1515        , m_data( a_mesh_data )
    1616{
    17         const mesh_raw_channel* pnt_chan = a_mesh_data->get_channel<md5_vtx_pnt>();
     17        const raw_data_channel* pnt_chan = a_mesh_data->get_channel<md5_vtx_pnt>();
    1818        m_pntdata.assign( reinterpret_cast<const md5_vtx_pnt*>( pnt_chan->data ), pnt_chan->count );
    1919        m_bone_offset.resize( bones->get_count() );
Note: See TracChangeset for help on using the changeset viewer.