Changeset 412


Ignore:
Timestamp:
07/09/15 14:40:36 (10 years ago)
Author:
epyon
Message:
  • refactoring of raw_data_channel and data_descriptor access
Location:
trunk
Files:
16 edited

Legend:

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

    r399 r412  
    8484                void reset();
    8585                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( mesh_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 );
    8787        protected:
    8888                file_type m_type;
  • trunk/nv/gfx/animation.hh

    r411 r412  
    2929                        NV_ASSERT( channel, "nullptr passed to add_channel!" );
    3030                        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() );
    3432                }
    3533
     
    180178                        data_descriptor desc;
    181179                        desc.initialize<KEY>();
    182                         NV_ASSERT( data->desc == desc, "Bad channel passed!" );
     180                        NV_ASSERT( data->descriptor() == desc, "Bad channel passed!" );
    183181                }
    184182                void get_interpolated( KEY& result, float frame ) const
    185183                {
    186184                        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 )
    189188                        {
    190189                                result = reinterpret_cast<KEY*>(m_data->data)[0];
    191190                                return;
    192191                        }
    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 );
    194193                        float factor = glm::clamp<float> ( frame - index, 0.0f, 1.0f );
    195194                        KEY* keys = reinterpret_cast<KEY*>( m_data->data );
     
    212211                        data_descriptor desc;
    213212                        desc.initialize<KEY>();
    214                         NV_ASSERT( data->desc == desc, "Bad channel passed!" );
     213                        NV_ASSERT( data->descriptor() == desc, "Bad channel passed!" );
    215214                }
    216215                void get_interpolated( KEY& result, float time ) const
    217216                {
    218217                        // TODO: this probably could be optimized
    219                         const KEY* keys = reinterpret_cast<const KEY*>(m_data->data);
    220218                        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 )
    223223                        {
    224224                                result = keys[0];
     
    226226                        }
    227227                        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++ )
    229229                        {
    230230                                if ( time < keys[i + 1].time ) { index = i; break; }
     
    274274                }
    275275                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; }
    277280                virtual mat4 get_matrix( float time ) const
    278281                {
     
    327330                        data_descriptor kd;
    328331                        kd.initialize<key>();
    329                         NV_ASSERT( kd == channel->desc, "bad channel!" );
     332                        NV_ASSERT( kd == channel->descriptor(), "bad channel!" );
    330333                        m_channel = channel;
    331334                        m_interpolator.set_data( m_channel );
  • trunk/nv/gfx/skeletal_mesh.hh

    r410 r412  
    5959                dynamic_array< transform >   m_bone_offset;
    6060
    61                 const mesh_data*             m_data;
    6261                const md5_vtx_pntiw*         m_vtx_data;
    6362                dynamic_array< transform >   m_transform;
  • trunk/nv/interface/context.hh

    r411 r412  
    157157                void add_vertex_buffers( vertex_array va, buffer buf, const raw_data_channel* channel )
    158158                {
    159                         for ( const auto& cslot : channel->desc )
     159                        for ( const auto& cslot : channel->descriptor() )
    160160                        {
    161161                                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 );
    163163                        }
    164164                }
     
    304304                        {
    305305                                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();
    310309                                        // 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 );
    314314                                        }
    315315                                        else
    316316                                        {
     317                                                buffer b = m_device->create_buffer( VERTEX_BUFFER, hint, channel->raw_size(), channel->raw_data() );
    317318                                                add_vertex_buffers( va, b, channel );
    318319                                        }
  • trunk/nv/interface/data_descriptor.hh

    r411 r412  
    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         };
    2216
    2317        enum class slot : uint8
     
    228222                bool operator==( const data_descriptor& rhs ) const
    229223                {
    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 )
    234227                        {
    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;
    238231                        }
    239232                        return true;
     
    243236                void initialize()
    244237                {
    245                         count = 0;
     238                        m_count = 0;
    246239                        initialize_slot< Struct, slot::POSITION >();
    247240                        initialize_slot< Struct, slot::TEXCOORD >();
     
    251244                        initialize_slot< Struct, slot::BONEWEIGHT >();
    252245                        initialize_slot< Struct, slot::COLOR >();
     246                        initialize_slot< Struct, slot::INDEX >();
    253247                        initialize_slot< Struct, slot::TIME >();
    254248                        initialize_slot< Struct, slot::TRANSLATION >();
     
    256250                        initialize_slot< Struct, slot::SCALE >();
    257251                        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]; }
    266267
    267268                const data_descriptor_slot& operator []( uint32 i ) const
    268269                {
    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                        }
    280284                }
    281285
    282286        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;
    294291
    295292                template < typename Struct, slot Slot >
     
    297294                {
    298295                        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 )
    301298                        {
    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++;
    305302                        }
    306303                }
     
    309306        struct raw_data_channel
    310307        {
    311                 raw_data_channel() : data( nullptr ), count( 0 ) {}
     308                raw_data_channel() : data( nullptr ), m_count( 0 ) {}
    312309                ~raw_data_channel()
    313310                {
     
    315312                }
    316313
    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 ); }
    331321
    332322                template < typename VTX >
     
    334324                {
    335325                        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 );
    339329                        return result;
    340330                }
    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 )
    342332                {
    343333                        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 );
    347337                        return result;
    348338                }
    349339
    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 
    370340                friend class mesh_creator;
    371 
    372                 data_descriptor desc;
     341                friend class mesh_data_creator;
     342
    373343                uint8*          data;
    374                 uint32          count;
     344        protected:
     345                data_descriptor m_desc;
     346                uint32          m_count;
    375347
    376348        };
  • trunk/nv/interface/device.hh

    r410 r412  
    120120                STREAM_DRAW,
    121121                DYNAMIC_DRAW
     122        };
     123
     124        enum buffer_type
     125        {
     126                VERTEX_BUFFER,
     127                INDEX_BUFFER,
    122128        };
    123129
  • trunk/nv/interface/mesh_data.hh

    r411 r412  
    1717{
    1818
     19        struct index_u16 { uint16 index; };
     20        struct index_u32 { uint32 index; };
     21
    1922        // TODO: friend mesh_data_creator class?
    2023        // TODO: private const etc
     
    3235                        NV_ASSERT( channel, "nullptr passed to add_channel!" );
    3336                        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 )
    3538                        {
    3639                                NV_ASSERT( !m_index_channel, "second index channel!" );
     
    5154                {
    5255                        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;
    5858                        return nullptr;
    5959                }
     
    6262                {
    6363                        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 );
    6966                        return -1;
    7067                }
     
    7370                size_t get_count() const
    7471                {
    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();
    7774                        return 0;
    7875                }
     
    8077                size_t get_count( size_t channel ) const
    8178                {
    82                         if ( m_channels.size() > channel ) return m_channels[channel]->count;
     79                        if ( m_channels.size() > channel ) return m_channels[channel]->element_count();
    8380                        return 0;
    8481                }
     
    9188                        for ( auto ch : m_channels )
    9289                        {
    93                                 if ( ch->desc == compare )
     90                                if ( ch->descriptor() == compare )
    9491                                {
    9592                                        return ch;
     
    106103                        for ( auto ch : m_channels )
    107104                        {
    108                                 if ( ch->desc == compare )
     105                                if ( ch->descriptor() == compare )
    109106                                {
    110107                                        return reinterpret_cast<VTX*>( ch->data );
  • trunk/src/formats/assimp_loader.cc

    r411 r412  
    169169        }
    170170
    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 );
    172172        data->add_channel( ichannel );
    173173        uint16* indices = reinterpret_cast<uint16*>( ichannel->data );
     
    317317                                raw_data_channel* channel = meshes[m].get_raw_channels()[0];
    318318                                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 )
    320320                                {
    321321                                        assimp_skinned_vtx& vertex = va[v];
  • trunk/src/formats/md2_loader.cc

    r411 r412  
    357357        }
    358358
    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() );
    360360        if ( m_new_indexes.size() > 0 )
    361361        {
  • trunk/src/formats/md3_loader.cc

    r411 r412  
    354354        raw_data_channel* mc_pn = raw_data_channel::create< vtx_md3_pn >( uint32( num_verts * frame_count ) );
    355355        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 ) );
    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 );
  • trunk/src/formats/md5_loader.cc

    r411 r412  
    137137                        assert( m_type == MESH );
    138138                        mesh_data* mesh = new mesh_data("md5_mesh");
     139                        raw_data_channel* ch_pntiw = nullptr;
    139140
    140141                        uint32 num_verts   = 0;
     
    161162                                                raw_data_channel* ch_pnt = raw_data_channel::create<md5_vtx_pnt>( num_verts );
    162163                                                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 );
    164165                                                tdata = reinterpret_cast< md5_vtx_t* >( ch_t->data );
    165166                                                mesh->add_channel( ch_pnt );
    166167                                                mesh->add_channel( ch_t );
    167168                                                // TODO: hack to prevent rendering
    168                                                 ch_pntiw->count = 0;
     169                                                //ch_pntiw->m_count = 0;
    169170                                                mesh->add_channel( ch_pntiw );
    170171                                        }
     
    190191                                        sstream >> num_tris;
    191192
    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 );
    193194                                        uint32* vtx_i                = reinterpret_cast< uint32* >( ch_i->data );
    194195                                        uint32 idx = 0;
     
    234235                        }
    235236
    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() );
    237238
    238239                        m_meshes[ num_meshes ] = mesh;
     
    333334}
    334335
    335 bool md5_loader::prepare_mesh( mesh_node_data* nodes, uint32 vtx_count, mesh_data* mdata, md5_weight* weights, md5_weight_info* weight_info )
     336bool 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 )
    336337{
    337338        assert( m_type == MESH );
    338339        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 );
    340340
    341341        for ( uint32 i = 0; i < vtx_count; ++i )
     
    486486                        const transform* ptv = reinterpret_cast< const transform* >( pjoint.data->get_channel(0)->data );
    487487                        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 ];
    489489                        vec3 rot_pos = ptr.get_orientation() * pos;
    490490
  • trunk/src/formats/nmd_loader.cc

    r411 r412  
    129129                                source.read( &cheader, sizeof( cheader ), 1 );
    130130                                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() );
    132132                                kdata->add_channel( channel );
    133133                        }
     
    168168        {
    169169                size += sizeof( nmd_element_header ) + sizeof( nmd_stream_header );
    170                 size += chan->size();
     170                size += chan->raw_size();
    171171        }
    172172
     
    184184                cheader.type     = nmd_type::STREAM;
    185185                cheader.children = 0;
    186                 cheader.size     = chan->size() + sizeof( nmd_stream_header );
     186                cheader.size     = chan->raw_size() + sizeof( nmd_stream_header );
    187187                stream_out.write( &cheader, sizeof( cheader ), 1 );
    188188
    189189                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();
    192192                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() );
    194194        }
    195195}
     
    206206                        {
    207207                                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();
    209209                        }
    210210        }
     
    231231                {
    232232                        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();
    234234                }
    235235
     
    252252                        eheader.type     = nmd_type::KEY_CHANNEL;
    253253                        eheader.children = 0;
    254                         eheader.size     = sizeof( nmd_stream_header ) + channel->size();
     254                        eheader.size     = sizeof( nmd_stream_header ) + channel->raw_size();
    255255                        stream_out.write( &eheader, sizeof( eheader ), 1 );
    256256
    257257                        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();
    260260                        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() );
    262262                }
    263263        }
  • trunk/src/formats/obj_loader.cc

    r411 r412  
    324324                }
    325325       
    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                }
    337331
    338332                mesh_data* mesh = new mesh_data(reader->name);
  • trunk/src/gfx/keyframed_mesh.cc

    r410 r412  
    2323        , m_active( false )
    2424{
    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();
    2727        m_vchannel     = m_mesh_data->get_channel<vertex_pnt>();
    2828        m_vsize        = sizeof( vertex_pnt );
     
    3434                m_vsize        = sizeof( vertex_pn );
    3535        }
    36         m_frame_count  = m_vchannel->count / m_vertex_count;
     36        m_frame_count  = m_vchannel->element_count() / m_vertex_count;
    3737        m_pbuffer      = buffer();
    3838}
     
    190190        m_context->add_vertex_buffers( m_va, vb, m_mesh_data->get_channel<vertex_t>() );
    191191
    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 );
    195196
    196197        m_data = new uint8[ m_vertex_count * m_vsize ];
  • trunk/src/gfx/mesh_creator.cc

    r411 r412  
    5757                        size_t chan_count = old_keys->get_channel_count();
    5858                        if ( chan_count == 1
    59                                 && old_keys->get_channel(0)->desc.slot_count() == 1
    60                                 && 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;
    6161
    6262                        size_t max_keys = 0;
    6363                        for ( size_t c = 0; c < chan_count; ++c )
    6464                        {
    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() );
    6666                        }
    6767
     
    7979                                for ( uint16 c = 0; c < chan_count; ++c )
    8080                                {
    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 );
    8282                                        pkey += old_keys->get_raw( old_keys->get_channel(c), idx, pkey );
    8383                                }
     
    107107                        {
    108108                                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 );
    113113                                }
    114114                        }
     
    126126        {
    127127                const raw_data_channel* channel = m_data->get_channel(c);
    128                 const data_descriptor&  desc    = channel->desc;
     128                const data_descriptor&  desc    = channel->descriptor();
    129129                uint8* raw_data = channel->data;
    130130                uint32 vtx_size = desc.element_size();
     
    142142
    143143                if ( p_offset != -1 )
    144                         for ( uint32 i = 0; i < channel->count; i++)
     144                        for ( uint32 i = 0; i < channel->element_count(); i++)
    145145                        {
    146146                                vec3& p = *reinterpret_cast<vec3*>( raw_data + vtx_size*i + p_offset );
     
    149149
    150150                if ( n_offset != -1 )
    151                         for ( uint32 i = 0; i < channel->count; i++)
     151                        for ( uint32 i = 0; i < channel->element_count(); i++)
    152152                        {
    153153                                vec3& n = *reinterpret_cast<vec3*>( raw_data + vtx_size*i + n_offset );
     
    155155                        }
    156156                if ( t_offset != -1 )
    157                         for ( uint32 i = 0; i < channel->count; i++)
     157                        for ( uint32 i = 0; i < channel->element_count(); i++)
    158158                        {
    159159                                vec4& t = *reinterpret_cast<vec4*>(raw_data + vtx_size*i + t_offset );
     
    174174        if ( ch_n == -1 ) return;
    175175        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() )
    177177                if ( cslot.vslot == slot::NORMAL )
    178178                {
     
    180180                }
    181181
    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 );
    185185                normal = -normal;
    186186        }
     
    205205                const raw_data_channel* channel = m_data->get_channel(c);
    206206
    207                 for ( const auto& cslot : channel->desc )
     207                for ( const auto& cslot : channel->descriptor() )
    208208                switch ( cslot.vslot )
    209209                {
     
    242242        if ( !p_channel || !n_channel || !t_channel ) return;
    243243
    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 ) )
    245247        {
    246248                return;
    247249        }
    248250
    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() );
    250252        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();
    255257
    256258        for ( unsigned int i = 0; i < tri_count; ++i )
     
    280282                }
    281283
    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 );
    285287                vec2 st1 = w3 - w1;
    286288                vec2 st2 = w2 - w1;
     
    290292                for ( uint32 set = 0; set < sets; ++set )
    291293                {
    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 );
    298300                        vec3 xyz1 = v3 - v1;
    299301                        vec3 xyz2 = v2 - v1;
     
    319321        for ( unsigned int i = 0; i < vtx_count; ++i )
    320322        {
    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 );
    322324                const vec3 t = vec3(tangents[i]);
    323325                if ( ! ( t.x == 0.0f && t.y == 0.0f && t.z == 0.0f ) )
     
    336338nv::raw_data_channel* nv::mesh_data_creator::merge_channels( raw_data_channel* a, raw_data_channel* b )
    337339{
    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
    354351        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;
    357354        result->data  = data;
    358355        return result;
     
    361358nv::raw_data_channel* nv::mesh_data_creator::append_channels( raw_data_channel* a, raw_data_channel* b, uint32 frame_count )
    362359{
    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 ];
    369366       
    370367
    371368        if ( frame_count == 1 )
    372369        {
    373                 size_t a_size = vtx_size * a->count;
     370                size_t a_size = vtx_size * a->element_count();
    374371                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 );
    376373        }
    377374        else
    378375        {
    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;
    381378                size_t pos_a = 0;
    382379                size_t pos_b = 0;
     
    392389
    393390        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();
    396393        result->data  = data;
    397394        return result;
     
    429426        {
    430427                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 );
    432430                m_data->m_channels[c] = append_channels( old, other->m_channels[c], frame_count );
    433431                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 )
    437435                        {
    438436                        case USHORT :
  • trunk/src/gfx/skeletal_mesh.cc

    r411 r412  
    1313nv::skeletal_mesh_cpu::skeletal_mesh_cpu( context* a_context, const mesh_data* a_mesh_data, const mesh_nodes_data* bones )
    1414        : 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() );
    1920        m_bone_offset.resize( bones->get_count() );
    2021        m_transform.resize( bones->get_count() );
     
    2425                m_bone_offset[i] = transform( bones->get_node(i)->transform );
    2526        }
     27
    2628        m_vtx_data  = a_mesh_data->get_channel_data<md5_vtx_pntiw>();
    2729        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
    3052        m_pbuffer   = a_context->find_buffer( m_va, slot::POSITION );
    3153}
Note: See TracChangeset for help on using the changeset viewer.