Changeset 416


Ignore:
Timestamp:
07/10/15 14:16:42 (10 years ago)
Author:
epyon
Message:
  • mesh_data and key_data are data_channel_set (WIP)
  • massive cleanup of privacy in data_channels
Location:
trunk
Files:
21 edited

Legend:

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

    r395 r416  
    2222                explicit assimp_loader( const std::string& a_ext, uint32 a_assimp_flags = 0 );
    2323                virtual bool load( stream& source );
    24                 virtual mesh_data* release_mesh_data( size_t index = 0 );
     24                virtual data_channel_set* release_mesh_data( size_t index = 0 );
    2525                virtual size_t get_mesh_count() const { return m_mesh_count; }
    2626                virtual ~assimp_loader();
     
    3030                void scene_report() const;
    3131        private:
    32                 mesh_nodes_data* release_merged_bones( mesh_data* meshes );
     32                mesh_nodes_data* release_merged_bones( data_channel_set* meshes );
    3333                bool load_bones( size_t index, array_ref< mesh_node_data > bones );
    34                 void load_mesh_data( mesh_data* data, size_t index );
     34                void load_mesh_data( data_channel_set* data, size_t index );
    3535                sint16 load_node( uint32 anim_id, mesh_node_data* nodes, const void* vnode, sint16 this_id, sint16 parent_id );
    3636                uint32 count_nodes( const void* node ) const;
  • trunk/nv/formats/md2_loader.hh

    r395 r416  
    2727                virtual ~md2_loader();
    2828                virtual bool load( stream& source );
    29                 virtual mesh_data* release_mesh_data( size_t index = 0 );
     29                virtual data_channel_set* release_mesh_data( size_t index = 0 );
    3030                virtual mesh_data_pack* release_mesh_data_pack();
    3131                virtual size_t get_mesh_count() const { return 1; }
    3232        private:
    33                 void release_mesh_frame( mesh_data* data, sint32 frame );
     33                void release_mesh_frame( data_channel_set* data, sint32 frame );
    3434                size_t get_max_frames() const;
    3535                void reindex();
  • trunk/nv/formats/md3_loader.hh

    r411 r416  
    3333                virtual ~md3_loader();
    3434                virtual bool load( stream& source );
    35                 virtual mesh_data* release_mesh_data( size_t index = 0 );
     35                virtual data_channel_set* release_mesh_data( size_t index = 0 );
    3636                virtual mesh_data_pack* release_mesh_data_pack();
    3737                virtual size_t get_mesh_count() const { return 1; }
     
    4040                virtual mesh_nodes_data* release_mesh_nodes_data( size_t = 0 );
    4141        private:
    42                 void release_mesh_frame( mesh_data* data, sint32 frame, sint32 surface );
     42                void release_mesh_frame( data_channel_set* data, sint32 frame, sint32 surface );
    4343                raw_data_channel* load_tags( const string_view& tag );
    4444                bool m_merge_all;
  • trunk/nv/formats/md5_loader.hh

    r415 r416  
    5555                virtual ~md5_loader();
    5656                virtual bool load( stream& source );
    57                 virtual mesh_data* release_mesh_data( size_t index = 0 );
     57                virtual data_channel_set* release_mesh_data( size_t index = 0 );
    5858                virtual size_t get_nodes_data_count() const { return 1; }
    5959                virtual mesh_nodes_data* release_mesh_nodes_data( size_t = 0 );
     
    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( mesh_node_data* nodes, uint32 vtx_count, data_channel_set* mdata, md5_weight* weights, md5_weight_info* weight_info );
    8787        protected:
    8888                file_type m_type;
    8989                uint32 m_md5_version;
    9090                mesh_nodes_data* m_nodes;
    91                 dynamic_array<mesh_data*> m_meshes;
     91                dynamic_array<data_channel_set*> m_meshes;
    9292        };
    9393
  • trunk/nv/formats/nmd_loader.hh

    r410 r416  
    6666                nmd_loader() : m_node_data( nullptr ), m_node_array( nullptr ), m_strings( nullptr ) {}
    6767                virtual bool load( stream& source );
    68                 virtual mesh_data* release_mesh_data( size_t index = 0 );
     68                virtual data_channel_set* release_mesh_data( size_t index = 0 );
    6969                virtual size_t get_nodes_data_count() const { return 1; }
    7070                virtual mesh_nodes_data* release_mesh_nodes_data( size_t = 0 );
     
    7878                bool load_animation( stream& source, const nmd_element_header& e );
    7979
    80                 mesh_nodes_data*          m_node_data;
    81                 mesh_node_data*           m_node_array;
    82                 string_table*             m_strings;
    83                 vector< uint16 >          m_mesh_names;
    84                 vector< uint16 >          m_node_names;
    85                 vector< mesh_data* >      m_meshes;
     80                mesh_nodes_data*            m_node_data;
     81                mesh_node_data*             m_node_array;
     82                string_table*               m_strings;
     83                vector< uint16 >            m_mesh_names;
     84                vector< uint16 >            m_node_names;
     85                vector< data_channel_set* > m_meshes;
    8686        };
    8787
  • trunk/nv/formats/obj_loader.hh

    r410 r416  
    2727                obj_loader( bool normals = true, bool tangents = false );
    2828                virtual bool load( stream& source );
    29                 virtual mesh_data* release_mesh_data( size_t index = 0 );
     29                virtual data_channel_set* release_mesh_data( size_t index = 0 );
    3030                virtual mesh_data_pack* release_mesh_data_pack();
    3131                virtual size_t get_mesh_count() const { return m_meshes.size(); }
    3232                ~obj_loader();
    3333        private:
    34                 data_descriptor      m_descriptor;
    35                 bool                 m_normals;
    36                 bool                 m_tangents;
    37                 vector< mesh_data* > m_meshes;
     34                data_descriptor             m_descriptor;
     35                bool                        m_normals;
     36                bool                        m_tangents;
     37                vector< data_channel_set* > m_meshes;
    3838        };
    3939
  • trunk/nv/gfx/animation.hh

    r415 r416  
    1212#include <nv/interface/stream.hh>
    1313#include <nv/stl/math.hh>
    14 #include <nv/interface/data_descriptor.hh>
     14#include <nv/interface/data_channel.hh>
    1515#include <nv/interface/interpolation_raw.hh>
    1616#include <nv/interface/interpolation_template.hh>
     
    2020{
    2121
    22         class key_data
     22        class key_data : public data_channel_set
    2323        {
    2424        public:
    2525                key_data() {}
    2626
    27                 void add_channel( raw_data_channel* channel )
     27                void add_key_channel( raw_data_channel* channel )
    2828                {
    2929                        NV_ASSERT( channel, "nullptr passed to add_channel!" );
    30                         m_channels.push_back( channel );
     30                        add_channel( channel );
    3131                        for ( const auto& cslot : channel->descriptor() )
    3232                                if ( cslot.vslot != slot::TIME )
    3333                                        m_final_key.push_slot( cslot.etype, cslot.vslot );
    34                         //m_final_key.append( channel->descriptor() );
    3534                }
    3635
     
    3938                        float key[ 16 ];
    4039                        float* pkey = key;
    41                         for ( uint16 i = 0; i < m_channels.size(); ++i )
     40                        for ( uint16 i = 0; i < size(); ++i )
    4241                        {
    4342                                pkey += get_raw( m_channels[i], index, pkey );
     
    5049                        float key[ 16 ];
    5150                        float* pkey = key;
    52                         for ( uint16 i = 0; i < m_channels.size(); ++i )
     51                        for ( uint16 i = 0; i < size(); ++i )
    5352                        {
    5453                                pkey += get_raw( m_channels[i], index, pkey );
     
    6160                        float key[ 16 ];
    6261                        float* pkey = key;
    63                         for ( uint16 i = 0; i < m_channels.size(); ++i )
     62                        for ( uint16 i = 0; i < size(); ++i )
    6463                        {
    6564                                pkey += interpolate_raw( m_channels[i], time, pkey );
     
    7271                        float key[ 16 ];
    7372                        float* pkey = key;
    74                         for ( uint16 i = 0; i < m_channels.size(); ++i )
     73                        for ( uint16 i = 0; i < size(); ++i )
    7574                        {
    7675                                pkey += interpolate_raw( m_channels[i], time, pkey );
     
    7978                }
    8079
    81                 size_t get_channel_count() const { return m_channels.size(); }
    82                 const raw_data_channel* get_channel( size_t index ) const { return m_channels[ index ]; }
    8380                const data_descriptor& get_final_key() const { return m_final_key; }
    84 
    85                 virtual ~key_data()
    86                 {
    87                         for ( auto channel : m_channels ) delete channel;
    88                 }
    8981
    9082                static uint32 get_raw( const raw_data_channel* channel, uint32 index, float* result )
     
    9890                        return keyfsize - mod;
    9991                }
    100 
    10192
    10293                static uint32 interpolate_raw( const raw_data_channel* channel, float time, float* result )
     
    160151
    161152        private:
    162 
    163153                data_descriptor m_final_key;
    164                 vector< raw_data_channel* > m_channels;
    165154        };
    166155
  • trunk/nv/gfx/mesh_creator.hh

    r411 r416  
    2727                void merge( mesh_data* other );
    2828        private:
    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 );
     29                raw_data_channel* merge_channels( const raw_data_channel* a, const raw_data_channel* b );
     30                raw_data_channel* append_channels( const raw_data_channel* a, const raw_data_channel* b, uint32 frame_count = 1 );
    3131
    3232                mesh_data* m_data;
     
    5050        public:
    5151                mesh_creator( mesh_data_pack* pack ) : m_pack( pack ) {}
    52                 void delete_mesh( uint32 index )
    53                 {
    54                         if ( index < m_pack->get_count() )
    55                         {
    56                                 m_pack->m_meshes[ index ].destroy();
    57                                 m_pack->m_meshes[ m_pack->m_count-1 ].move_to( m_pack->m_meshes[ index ] );
    58                                 m_pack->m_count--;
    59                         }
    60                 }
     52                void delete_mesh( uint32 index );
    6153                // assumes that keys are equally spaced
    6254                void pre_transform_keys()
  • trunk/nv/interface/context.hh

    r415 r416  
    300300                {
    301301                        vertex_array  va = create_vertex_array();
    302                         array_view< raw_data_channel* > channels = data->get_raw_channels();
    303                         for ( uint32 ch = 0; ch < channels.size(); ++ch )
    304                         {
    305                                 const raw_data_channel* channel = channels[ch];
     302                        //array_view< raw_data_channel* > channels = data->get_raw_channels();
     303                        //for ( uint32 ch = 0; ch < channels.size(); ++ch )
     304                        for ( auto channel : *data )
     305                        {
     306//                              const raw_data_channel* channel = channels[ch];
    306307                                if ( channel->size() > 0 )
    307308                                {
  • trunk/nv/interface/data_descriptor.hh

    r415 r416  
    1717        enum class slot : uint8
    1818        {
    19                 POSITION    = 0,
    20                 TEXCOORD    = 1,
    21                 NORMAL      = 2,
    22                 TANGENT     = 3,
    23                 BONEINDEX   = 4,
    24                 BONEWEIGHT  = 5,
    25                 COLOR       = 6,
    26 
    27                 INDEX       = 7,
    28 
    29                 TIME        = 8,
     19                POSITION = 0,
     20                TEXCOORD = 1,
     21                NORMAL = 2,
     22                TANGENT = 3,
     23                BONEINDEX = 4,
     24                BONEWEIGHT = 5,
     25                COLOR = 6,
     26
     27                INDEX = 7,
     28
     29                TIME = 8,
    3030                TRANSLATION = 9,
    31                 ROTATION    = 10,
    32                 SCALE       = 11,
    33                 TFORM       = 12,
    34 
    35                 MAX_STORE   = 8,
     31                ROTATION = 10,
     32                SCALE = 11,
     33                TFORM = 12,
     34
     35                MAX_STORE = 8,
    3636        };
    3737
    3838        struct data_descriptor_slot
    3939        {
    40                 datatype etype  = NONE;
     40                datatype etype = NONE;
    4141                uint32   offset = 0;
    42                 slot     vslot  = slot::POSITION;
     42                slot     vslot = slot::POSITION;
    4343        };
    4444
     
    4646        struct has_slot : false_type {};
    4747
    48         template < typename Struct >
    49         struct has_slot< Struct, slot::POSITION, void_t< NV_VOID_DECLTYPE( Struct::position ) > > : true_type {};
    50        
     48        template < typename Struct >
     49        struct has_slot< Struct, slot::POSITION, void_t< NV_VOID_DECLTYPE( Struct::position ) > > : true_type{};
     50
    5151        template < typename Struct >
    5252        struct has_slot < Struct, slot::TEXCOORD, void_t< NV_VOID_DECLTYPE( Struct::texcoord ) > > : true_type{};
     
    9797                {
    9898                        typedef empty_type value_type;
    99                         static const datatype etype  = datatype::NONE;
     99                        static const datatype etype = datatype::NONE;
    100100                        static const int      offset = 0;
    101101                };
     
    105105                {
    106106                        typedef decltype( Struct::position ) value_type;
    107                         static const datatype etype  = type_to_enum< decltype( Struct::position ) >::type;
     107                        static const datatype etype = type_to_enum< decltype( Struct::position ) >::type;
    108108                        static const int      offset = NV_OFFSET_OF( Struct, position );
    109109                };
     
    113113                {
    114114                        typedef decltype( Struct::texcoord ) value_type;
    115                         static const datatype etype  = type_to_enum< decltype( Struct::texcoord ) >::type;
     115                        static const datatype etype = type_to_enum< decltype( Struct::texcoord ) >::type;
    116116                        static const int      offset = NV_OFFSET_OF( Struct, texcoord );
    117117                };
     
    121121                {
    122122                        typedef decltype( Struct::normal ) value_type;
    123                         static const datatype etype  = type_to_enum< decltype( Struct::normal ) >::type;
     123                        static const datatype etype = type_to_enum< decltype( Struct::normal ) >::type;
    124124                        static const int      offset = NV_OFFSET_OF( Struct, normal );
    125125                };
     
    129129                {
    130130                        typedef decltype( Struct::tangent ) value_type;
    131                         static const datatype etype  = type_to_enum< decltype( Struct::tangent ) >::type;
     131                        static const datatype etype = type_to_enum< decltype( Struct::tangent ) >::type;
    132132                        static const int      offset = NV_OFFSET_OF( Struct, tangent );
    133133                };
     
    137137                {
    138138                        typedef decltype( Struct::boneindex ) value_type;
    139                         static const datatype etype  = type_to_enum< decltype( Struct::boneindex ) >::type;
     139                        static const datatype etype = type_to_enum< decltype( Struct::boneindex ) >::type;
    140140                        static const int      offset = NV_OFFSET_OF( Struct, boneindex );
    141141                };
     
    145145                {
    146146                        typedef decltype( Struct::boneweight ) value_type;
    147                         static const datatype etype  = type_to_enum< decltype( Struct::boneweight ) >::type;
     147                        static const datatype etype = type_to_enum< decltype( Struct::boneweight ) >::type;
    148148                        static const int      offset = NV_OFFSET_OF( Struct, boneweight );
    149149                };
     
    153153                {
    154154                        typedef decltype( Struct::color ) value_type;
    155                         static const datatype etype  = type_to_enum< decltype( Struct::color ) >::type;
     155                        static const datatype etype = type_to_enum< decltype( Struct::color ) >::type;
    156156                        static const int      offset = NV_OFFSET_OF( Struct, color );
    157157                };
     
    161161                {
    162162                        typedef decltype( Struct::index ) value_type;
    163                         static const datatype etype  = type_to_enum< decltype( Struct::index ) >::type;
     163                        static const datatype etype = type_to_enum< decltype( Struct::index ) >::type;
    164164                        static const int      offset = NV_OFFSET_OF( Struct, index );
    165165                };
     
    226226                        for ( uint32 i = 0; i < m_size; ++i )
    227227                        {
    228                                 if ( m_slots[i].etype  != rhs.m_slots[i].etype )  return false;
     228                                if ( m_slots[i].etype != rhs.m_slots[i].etype )  return false;
    229229                                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;
     230                                if ( m_slots[i].vslot != rhs.m_slots[i].vslot )  return false;
    231231                        }
    232232                        return true;
     
    274274                void push_slot( datatype etype, slot vslot )
    275275                {
    276                         m_slots[m_size].etype  = etype;
     276                        m_slots[m_size].etype = etype;
    277277                        m_slots[m_size].offset = m_element_size;
    278                         m_slots[m_size].vslot  = vslot;
     278                        m_slots[m_size].vslot = vslot;
    279279                        m_element_size += get_datatype_info( etype ).size;
    280280                        m_size++;
     
    285285                        for ( const auto& dslot : desc )
    286286                        {
    287                                 m_slots[m_size].etype  = dslot.etype;
     287                                m_slots[m_size].etype = dslot.etype;
    288288                                m_slots[m_size].offset = m_element_size;
    289                                 m_slots[m_size].vslot  = dslot.vslot;
     289                                m_slots[m_size].vslot = dslot.vslot;
    290290                                m_element_size += get_datatype_info( dslot.etype ).size;
    291291                                m_size++;
     
    314314                        if ( m_slots[m_size].etype != datatype::NONE )
    315315                        {
    316                                 m_slots[m_size].vslot  = Slot;
     316                                m_slots[m_size].vslot = Slot;
    317317                                m_slots[m_size].offset = sinfo::offset;
    318318                                m_size++;
     
    321321        };
    322322
    323         struct raw_data_channel
    324         {
    325                 raw_data_channel() : m_data( nullptr ), m_size( 0 ) {}
    326                 ~raw_data_channel()
    327                 {
    328                         if ( m_data != nullptr ) delete[] m_data;
    329                 }
    330 
    331                 const data_descriptor& descriptor() const { return m_desc;  }
    332                 uint32 element_size() const { return m_desc.element_size(); }
    333                 uint32 size() const { return m_size; }
    334                 uint32 raw_size() const { return m_size * m_desc.element_size(); }
    335                 const uint8* raw_data() const { return m_data; }
    336 
    337                 // TODO: constexpr compile-time cast check?
    338                 template < typename Struct >
    339                 const Struct* data_cast() const
    340                 {
    341                         return reinterpret_cast<const Struct*>( m_data );
    342                 }
    343 
    344                 bool has_slot( slot vslot ) const { return m_desc.has_slot( vslot ); }
    345 
    346                 template < typename Struct >
    347                 friend class data_channel_creator;
    348                 friend class raw_data_channel_creator;
    349 
    350         protected:
    351                 uint8*          m_data;
    352                 data_descriptor m_desc;
    353                 uint32          m_size;
    354 
    355         };
    356 
    357         class raw_data_channel_creator
    358         {
    359         public:
    360                 raw_data_channel_creator( const data_descriptor& desc, uint32 size )
    361                 {
    362                         m_channel = new raw_data_channel();
    363                         m_channel->m_desc = desc;
    364                         m_channel->m_size = size;
    365                         m_channel->m_data = ( size > 0 ? ( new uint8[m_channel->raw_size()] ) : nullptr );
    366                         m_owned   = true;
    367                 }
    368                 explicit raw_data_channel_creator( raw_data_channel* channel )
    369                 {
    370                         m_channel = channel;
    371                         m_owned   = false;
    372                 }
    373 
    374                 uint32 element_size() const { return m_channel->element_size(); }
    375                 uint32 size() const { return m_channel->size(); }
    376                 uint32 raw_size() const { return m_channel->size() * m_channel->element_size(); }
    377                 uint8* raw_data() { return m_channel->m_data; }
    378                 const uint8* raw_data() const { return m_channel->m_data; }
    379                 raw_data_channel* channel() { return m_channel; }
    380 
    381                 data_descriptor& descriptor() { return m_channel->m_desc; }
    382                 const data_descriptor& descriptor() const { return m_channel->m_desc; }
    383 
    384                 raw_data_channel* release()
    385                 {
    386                         raw_data_channel* result = m_channel;
    387                         m_channel = nullptr;
    388                         return result;
    389                 }
    390 
    391                 ~raw_data_channel_creator()
    392                 {
    393                         if ( m_owned && m_channel ) delete m_channel;
    394                 }
    395         protected:
    396                 raw_data_channel* m_channel;
    397                 bool              m_owned;
    398         };
    399 
    400         template < typename Struct >
    401         class data_channel_creator : public raw_data_channel_creator
    402         {
    403         public:
    404                 explicit data_channel_creator( uint32 size )
    405                         : raw_data_channel_creator( data_descriptor::create< Struct >(), size ) {}
    406                 // TODO - descriptor check
    407                 explicit data_channel_creator( raw_data_channel* channel )
    408                         : raw_data_channel_creator( channel ) {}
    409                
    410                 Struct* data() { return reinterpret_cast< Struct* >( m_channel->m_data ); }
    411                 const Struct* data() const { return reinterpret_cast< const Struct* >( m_channel->m_data ); }
    412 
    413                 const Struct& operator []( uint32 i ) const
    414                 {
    415                         NV_ASSERT( i < m_channel->m_size, "data_channel_creator indexing failure!" );
    416                         return reinterpret_cast< const Struct* >( m_channel->m_data )[i];
    417                 }
    418 
    419                 Struct& operator []( uint32 i )
    420                 {
    421                         NV_ASSERT( i < m_channel->m_size, "data_channel_creator indexing failure!" );
    422                         return reinterpret_cast<Struct*>( m_channel->m_data )[i];
    423                 }
    424         };
    425323}
    426324
  • trunk/nv/interface/mesh_data.hh

    r415 r416  
    1111#include <nv/stl/math.hh>
    1212#include <nv/stl/string.hh>
    13 #include <nv/interface/data_descriptor.hh>
     13#include <nv/interface/data_channel.hh>
    1414#include <nv/gfx/animation.hh>
    1515
     
    2020        struct index_u32 { uint32 index; };
    2121
    22         // TODO: friend mesh_data_creator class?
    23         // TODO: private const etc
    24 
    25         class mesh_data
    26         {
    27                 friend class mesh_creator;
    28                 friend class mesh_data_creator;
    29         public:
    30                 explicit mesh_data() : m_index_channel( nullptr ) {}
    31                 explicit mesh_data( const std::string& name ) : m_name(name), m_index_channel( nullptr ) {}
    32 
    33                 void add_channel( raw_data_channel* channel )
    34                 {
    35                         NV_ASSERT( channel, "nullptr passed to add_channel!" );
    36                         m_channels.push_back( channel );
    37                         if ( channel->size() > 0 && channel->descriptor()[0].vslot == slot::INDEX )
    38                         {
    39                                 NV_ASSERT( !m_index_channel, "second index channel!" );
    40                                 m_index_channel = channel;
    41                         }
    42                 }
    43 
    44                 array_view< raw_data_channel* > get_raw_channels()  const { return m_channels; }
    45                 const raw_data_channel*         get_index_channel() const { return m_index_channel; }
    46                 size_t get_channel_count() const { return m_channels.size(); }
    47                 const raw_data_channel* get_channel( size_t index ) const
    48                 {
    49                         if ( m_channels.size() > index ) return m_channels[index];
    50                         return nullptr;
    51                 }
    52 
    53                 const raw_data_channel* get_channel( slot s ) const
    54                 {
    55                         for ( auto ch : m_channels )
    56                                 if ( ch->has_slot( s ) )
    57                                         return ch;
    58                         return nullptr;
    59                 }
    60 
    61                 int get_channel_index( slot s ) const
    62                 {
    63                         for ( uint32 c = 0; c < m_channels.size(); ++c )
    64                                 if ( m_channels[c]->has_slot( s ) )
    65                                         return int( c );
    66                         return -1;
    67                 }
    68 
    69 
    70                 // TODO: this should be "size"
    71                 size_t get_count() const
    72                 {
    73                         if ( m_index_channel ) return m_index_channel->size();
    74                         if ( m_channels.size() > 0 ) return m_channels[0]->size();
    75                         return 0;
    76                 }
    77 
    78                 size_t get_count( size_t channel ) const
    79                 {
    80                         if ( m_channels.size() > channel ) return m_channels[channel]->size();
    81                         return 0;
    82                 }
    83 
    84                 template < typename VTX >
    85                 const raw_data_channel* get_channel() const
    86                 {
    87                         data_descriptor compare;
    88                         compare.initialize<VTX>();
    89                         for ( auto ch : m_channels )
    90                         {
    91                                 if ( ch->descriptor() == compare )
    92                                 {
    93                                         return ch;
    94                                 }
    95                         }
    96                         return nullptr;
    97                 }
    98 
    99                 template < typename VTX >
    100                 const VTX* get_channel_data() const
    101                 {
    102                         data_descriptor compare;
    103                         compare.initialize<VTX>();
    104                         for ( auto ch : m_channels )
    105                         {
    106                                 if ( ch->descriptor() == compare )
    107                                 {
    108                                         return ch->data_cast< VTX >();
    109                                 }
    110                         }
    111                         return nullptr;
    112                 }
    113 
    114                 void set_name( const std::string& name ) { m_name = name; }
    115                 const std::string& get_name() const { return m_name; }
    116 
    117                 void move_to( mesh_data& other )
    118                 {
    119                         other.m_name          = m_name;
    120                         other.m_index_channel = m_index_channel;
    121                         for ( auto c : m_channels )
    122                         {
    123                                 other.m_channels.push_back( c );
    124                         }
    125                         m_channels.clear();
    126                         m_index_channel = nullptr;
    127                 }
    128 
    129                 void destroy()
    130                 {
    131                         for ( auto channel : m_channels ) delete channel;
    132                         m_channels.clear();
    133                         m_index_channel = nullptr;
    134                 }
    135 
    136                 virtual ~mesh_data()
    137                 {
    138                         destroy();
    139                 }
    140         private:
    141                 std::string                 m_name;
    142                 vector< raw_data_channel* > m_channels;
    143                 raw_data_channel*           m_index_channel;
    144         };
     22        using mesh_data = data_channel_set;
    14523
    14624        struct mesh_node_data
     
    241119                        return &m_meshes[ index ];
    242120                }
    243                 const mesh_data* get_mesh( const std::string& name ) const
    244                 {
    245                         for ( uint32 i = 0; i < m_count; ++i )
    246                         {
    247                                 if ( m_meshes[ i ].get_name() == name )
    248                                         return &m_meshes[ i ];
    249                         }
    250                         return nullptr;
    251                 }
     121//              const mesh_data* get_mesh( const std::string& name ) const
     122//              {
     123//                      for ( uint32 i = 0; i < m_count; ++i )
     124//                      {
     125//                              if ( m_meshes[ i ].get_name() == name )
     126//                                      return &m_meshes[ i ];
     127//                      }
     128//                      return nullptr;
     129//              }
    252130                uint32 get_count() const { return m_count; }
    253131                const mesh_nodes_data* get_nodes() const { return m_nodes; }
  • trunk/nv/interface/mesh_loader.hh

    r395 r416  
    3030                virtual ~mesh_loader() {}
    3131                virtual bool load( stream& source ) = 0;
    32                 virtual mesh_data* release_mesh_data( size_t index = 0 ) = 0;
     32                virtual data_channel_set* release_mesh_data( size_t index = 0 ) = 0;
    3333                virtual mesh_data_pack* release_mesh_data_pack() = 0;
    3434                virtual size_t get_mesh_count() const = 0;
  • trunk/src/formats/assimp_loader.cc

    r415 r416  
    66
    77#include "nv/formats/assimp_loader.hh"
     8
     9#include "nv/interface/data_channel_access.hh"
    810#include "nv/stl/unordered_map.hh"
    911#include "nv/lib/assimp.hh"
     
    103105}
    104106
    105 mesh_data* nv::assimp_loader::release_mesh_data( size_t index /*= 0 */ )
     107data_channel_set* nv::assimp_loader::release_mesh_data( size_t index /*= 0 */ )
    106108{
    107109        if ( index >= m_mesh_count ) return nullptr;
    108         mesh_data* result = new mesh_data;
     110        data_channel_set* result = data_channel_set_creator::create( 2 );
    109111        load_mesh_data( result, index );
    110112        return result;
    111113}
    112 void nv::assimp_loader::load_mesh_data( mesh_data* data, size_t index )
     114void nv::assimp_loader::load_mesh_data( data_channel_set* data, size_t index )
    113115{
    114116        const aiScene* scene = reinterpret_cast<const aiScene*>( m_scene );
    115117        const aiMesh*  mesh  = scene->mMeshes[ index ];
    116         data->set_name( mesh->mName.data );
    117118
    118119        bool skinned = mesh->mNumBones > 0;
     
    180181                }
    181182        }
    182         data->add_channel( channel.release() );
    183         data->add_channel( ichannel.release() );
     183
     184        data_channel_set_creator maccess( data );
     185        maccess.set_name( mesh->mName.data );
     186        maccess.add_channel( channel.release() );
     187        maccess.add_channel( ichannel.release() );
    184188}
    185189
     
    283287}
    284288
    285 mesh_nodes_data* nv::assimp_loader::release_merged_bones( mesh_data* meshes )
     289mesh_nodes_data* nv::assimp_loader::release_merged_bones( data_channel_set* meshes )
    286290{
    287291        const aiScene* scene = reinterpret_cast<const aiScene*>( m_scene );
     
    317321                        if ( m > 0 && bones.size() > 0 )
    318322                        {
    319                                 data_channel_creator< assimp_skinned_vtx > channel( meshes[m].get_raw_channels()[0] );
     323                                data_channel_creator< assimp_skinned_vtx > channel( const_cast< raw_data_channel* >( meshes[m].get_channel(0) ) );
    320324                                for ( unsigned v = 0; v < channel.size(); ++v )
    321325                                {
     
    456460//              }
    457461//      }
    458         data->data->add_channel( pchannel_creator.release() );
    459         data->data->add_channel( rchannel_creator.release() );
    460 //      data->data->add_channel( schannel_creator.release() );
     462        data->data->add_key_channel( pchannel_creator.release() );
     463        data->data->add_key_channel( rchannel_creator.release() );
     464//      data->data->add_key_channel( schannel_creator.release() );
    461465}
    462466
     
    466470        const aiScene* scene = reinterpret_cast<const aiScene*>( m_scene );
    467471        bool has_bones = false;
    468         mesh_data* meshes = new mesh_data[ m_mesh_count ];
     472        data_channel_set* meshes = data_channel_set_creator::create_array( m_mesh_count, 2 );
    469473        for ( size_t m = 0; m < m_mesh_count; ++m )
    470474        {
    471475                const aiMesh* mesh = scene->mMeshes[ m ];
    472                 meshes[m].set_name( mesh->mName.data );
     476                data_channel_set_creator( &meshes[m] ).set_name( mesh->mName.data );
    473477                if ( mesh->mNumBones > 0 ) has_bones = true;
    474478                load_mesh_data(&meshes[m],m);
  • trunk/src/formats/md2_loader.cc

    r413 r416  
    88
    99#include "nv/core/logging.hh"
     10#include "nv/interface/data_channel_access.hh"
     11
    1012#include <cstring>
    1113
     
    309311
    310312
    311 mesh_data* nv::md2_loader::release_mesh_data( size_t )
    312 {
    313         mesh_data* data = new mesh_data( "md2_mesh" );
     313data_channel_set* nv::md2_loader::release_mesh_data( size_t )
     314{
     315        data_channel_set* data = data_channel_set_creator::create( 3 );
    314316        release_mesh_frame( data, -1 );
    315317        return data;
    316318}
    317319
    318 void nv::md2_loader::release_mesh_frame( mesh_data* data, sint32 frame )
     320void nv::md2_loader::release_mesh_frame( data_channel_set* data, sint32 frame )
    319321{
    320322        md2_t* md2 = reinterpret_cast< md2_t* >( m_md2 );
     
    364366        }
    365367
    366         data->add_channel( mc_pn.release() );
    367         data->add_channel( mc_t.release() );
    368         data->add_channel( ic.release() );
     368        data_channel_set_creator maccess( data );
     369
     370        maccess.add_channel( mc_pn.release() );
     371        maccess.add_channel( mc_t.release() );
     372        maccess.add_channel( ic.release() );
    369373}
    370374
    371375mesh_data_pack* nv::md2_loader::release_mesh_data_pack()
    372376{
    373         mesh_data* data = new mesh_data[1];
     377        data_channel_set* data = data_channel_set_creator::create_array( 1, 3 );
    374378        release_mesh_frame( &data[0], -1 );
    375379        return new mesh_data_pack( 1, data );
  • trunk/src/formats/md3_loader.cc

    r413 r416  
    88
    99#include "nv/core/logging.hh"
     10#include "nv/interface/data_channel_access.hh"
    1011
    1112using namespace nv;
     
    322323};
    323324
    324 mesh_data* nv::md3_loader::release_mesh_data( nv::size_t index )
    325 {
    326         mesh_data* data = new mesh_data;
     325data_channel_set* nv::md3_loader::release_mesh_data( nv::size_t index )
     326{
     327        data_channel_set* data = data_channel_set_creator::create(3);
    327328        release_mesh_frame( data, -1, static_cast< sint32 >( index ) );
    328329        return data;
    329330}
    330331
    331 void nv::md3_loader::release_mesh_frame( mesh_data* data, sint32 frame, sint32 surface )
     332void nv::md3_loader::release_mesh_frame( data_channel_set* data, sint32 frame, sint32 surface )
    332333{
    333334        md3_t* md3 = reinterpret_cast< md3_t* >( m_md3 );
     
    412413        }
    413414
    414         data->set_name( reinterpret_cast< char* >( md3->header.name ) );
    415         data->add_channel( mc_pn.release() );
    416         data->add_channel( mc_t.release() );
    417         data->add_channel( ic.release() );
     415        data_channel_set_creator maccess( data );
     416        maccess.set_name( reinterpret_cast<char*>( md3->header.name ) );
     417        maccess.add_channel( mc_pn.release() );
     418        maccess.add_channel( mc_t.release() );
     419        maccess.add_channel( ic.release() );
    418420}
    419421
     
    436438       
    437439                raw_data_channel* keys = load_tags( name );
    438                 nodes[i].data->add_channel( keys );
     440                nodes[i].data->add_key_channel( keys );
    439441        }
    440442        return new mesh_nodes_data( "tags", node_count, nodes );
     
    445447        md3_t* md3 = reinterpret_cast<md3_t*>( m_md3 );
    446448        int count = 1;
    447         mesh_data* data = nullptr;
     449        data_channel_set* data = nullptr;
    448450        if ( m_merge_all )
    449451        {
    450                 data = new mesh_data[1];
     452                data = data_channel_set_creator::create_array(1,3);
    451453                release_mesh_frame( &data[0], -1, -1 );
    452                 data[0].set_name( reinterpret_cast< char* >( md3->header.name ) );
     454                data_channel_set_creator( &data[0] ).set_name( reinterpret_cast< char* >( md3->header.name ) );
    453455        }
    454456        else
    455457        {
    456458                count = md3->header.num_surfaces;
    457                 data = new mesh_data[ count ];
     459                data = data_channel_set_creator::create_array( count, 3 );
    458460                for ( int i = 0; i < count; ++i )
    459461                {
    460462                        release_mesh_frame( &data[i], -1, i );
    461                         data[i].set_name( reinterpret_cast< char* >( md3->surfaces[i].header.name ) );
     463                        data_channel_set_creator( &data[i] ).set_name( reinterpret_cast< char* >( md3->surfaces[i].header.name ) );
    462464                }
    463465        }
  • trunk/src/formats/md5_loader.cc

    r415 r416  
    1010#include "nv/stl/vector.hh"
    1111#include "nv/io/std_stream.hh"
     12#include "nv/interface/data_channel_access.hh"
    1213
    1314#include <stdio.h>  // sscanf
     
    136137                {
    137138                        assert( m_type == MESH );
    138                         mesh_data* mesh = new mesh_data("md5_mesh");
     139                        data_channel_set_creator mesh;
    139140
    140141                        uint32 num_verts   = 0;
     
    163164                                                data_channel_creator<md5_vtx_pntiw> ch_pntiw( num_verts );
    164165                                                tdata = ch_t.data();
    165                                                 mesh->add_channel( ch_pnt.release() );
    166                                                 mesh->add_channel( ch_t.release() );
     166                                                mesh.add_channel( ch_pnt.release() );
     167                                                mesh.add_channel( ch_t.release() );
    167168                                                // TODO: hack to prevent rendering
    168169                                                //ch_pntiw->m_count = 0;
    169                                                 mesh->add_channel( ch_pntiw.release() );
     170                                                mesh.add_channel( ch_pntiw.release() );
    170171                                        }
    171172                                        weight_info.resize( num_verts );
     
    210211                                        }             
    211212
    212                                         mesh->add_channel( ch_i.release() );
     213                                        mesh.add_channel( ch_i.release() );
    213214                                }
    214215                                else if ( command == "numweights" )
     
    235236                        }
    236237
    237                         prepare_mesh( nodes, weight_info.size(), mesh, weights.data(), weight_info.data() );
    238 
    239                         m_meshes[ num_meshes ] = mesh;
     238                        data_channel_set* mdata = mesh.release();
     239                        prepare_mesh( nodes, weight_info.size(), mdata, weights.data(), weight_info.data() );
     240
     241                        m_meshes[ num_meshes ] = mdata;
    240242                        num_meshes++;
    241243                } // mesh
     
    258260                                nodes[i].data      = new key_data;
    259261                                data_channel_creator< md5_key_t > fc( num_frames );
    260                                 nodes[i].data->add_channel( fc.release() );
     262                                nodes[i].data->add_key_channel( fc.release() );
    261263                                next_line( sstream );
    262264                        }
     
    335337}
    336338
    337 bool md5_loader::prepare_mesh( mesh_node_data* nodes, uint32 vtx_count, mesh_data* mdata, md5_weight* weights, md5_weight_info* weight_info )
     339bool md5_loader::prepare_mesh( mesh_node_data* nodes, uint32 vtx_count, data_channel_set* mdata, md5_weight* weights, md5_weight_info* weight_info )
    338340{
    339341        assert( m_type == MESH );
     
    400402        }
    401403
    402         const uint32*    idata = reinterpret_cast< uint32* >( const_cast< uint8* >( mdata->get_index_channel()->raw_data() ) );
     404        const uint32*    idata = reinterpret_cast< uint32* >( const_cast< uint8* >( mdata->get_channel( slot::INDEX )->raw_data() ) );
    403405        const md5_vtx_t* tdata = mdata->get_channel_data<md5_vtx_t>();
    404406
    405407        // Prepare normals
    406         uint32 tri_count = mdata->get_count() / 3;
     408        uint32 tri_count = mdata->get_channel_size( slot::INDEX ) / 3;
    407409        for ( unsigned int i = 0; i < tri_count; ++i )
    408410        {
     
    503505}
    504506
    505 mesh_data* nv::md5_loader::release_mesh_data( size_t index )
    506 {
    507         mesh_data* result = m_meshes[ index ];
     507data_channel_set* nv::md5_loader::release_mesh_data( size_t index )
     508{
     509        data_channel_set* result = m_meshes[ index ];
    508510        m_meshes[ index ] = nullptr;
    509511        return result;
     
    520522{
    521523        uint32 size = m_meshes.size();
    522         mesh_data* meshes = new mesh_data[ size ];
     524        data_channel_set* meshes = data_channel_set_creator::create_array( size, 4 );
    523525        for ( uint32 i = 0; i < size; ++i )
    524526        {
    525                 m_meshes[i]->move_to( meshes[i] );
     527                data_channel_set_creator( m_meshes[i] ).move_to( meshes[i] );
    526528                delete m_meshes[i];
    527529                m_meshes[i] = nullptr;
  • trunk/src/formats/nmd_loader.cc

    r415 r416  
    88#include "nv/io/std_stream.hh"
    99#include "nv/stl/string.hh"
     10#include "nv/interface/data_channel_access.hh"
    1011
    1112using namespace nv;
     
    3435bool nv::nmd_loader::load_mesh( stream& source, const nmd_element_header& e )
    3536{
    36         mesh_data* mesh = new mesh_data();
     37        data_channel_set_creator mesh;
    3738        for ( uint32 s = 0; s < e.children; ++s )
    3839        {
     
    4546                raw_data_channel_creator channel_creator( stream_header.format, stream_header.count );
    4647                source.read( channel_creator.raw_data(), channel_creator.element_size(), channel_creator.size() );
    47                 mesh->add_channel( channel_creator.release() );
     48                mesh.add_channel( channel_creator.release() );
    4849        }
    4950        m_mesh_names.push_back( e.name );
    50         m_meshes.push_back( mesh );
    51         return true;
    52 }
    53 
    54 mesh_data* nv::nmd_loader::release_mesh_data( size_t index )
    55 {
    56         mesh_data* result = m_meshes[ index ];
    57         if ( m_strings ) result->set_name( m_strings->get( m_mesh_names[ index ] ) );
     51        m_meshes.push_back( mesh.release() );
     52        return true;
     53}
     54
     55data_channel_set* nv::nmd_loader::release_mesh_data( size_t index )
     56{
     57        data_channel_set* result = m_meshes[ index ];
     58        if ( m_strings ) data_channel_set_creator( result ).set_name( m_strings->get( m_mesh_names[ index ] ) );
    5859        m_meshes[ index ] = nullptr;
    5960        return result;
     
    6364{
    6465        uint32 size = m_meshes.size();
    65         mesh_data* meshes = new mesh_data[ size ];
     66        data_channel_set* meshes = data_channel_set_creator::create_array( size, 0 );
    6667        for ( uint32 i = 0; i < size; ++i )
    6768        {
    68                 m_meshes[i]->move_to( meshes[i] );
     69                data_channel_set_creator( m_meshes[i] ).move_to( meshes[i] );
    6970                delete m_meshes[i];
    7071        }
     
    130131                                raw_data_channel_creator channel_creator( cheader.format, cheader.count );
    131132                                source.read( channel_creator.raw_data(), channel_creator.element_size(), channel_creator.size() );
    132                                 kdata->add_channel( channel_creator.release() );
     133                                kdata->add_key_channel( channel_creator.release() );
    133134                        }
    134135                }
     
    160161// nmd format dump
    161162// HACK : TEMPORARY - will go to it's own file, probably nmd_io
    162 static void nmd_dump_mesh( const mesh_data* mesh, stream& stream_out )
    163 {
    164         array_view< raw_data_channel* > data  = mesh->get_raw_channels();
    165 
     163static void nmd_dump_mesh( const data_channel_set* mesh, stream& stream_out )
     164{
    166165        uint32 size = sizeof( nmd_element_header );
    167         for ( auto chan : data )
     166        for ( auto chan : *mesh )
    168167        {
    169168                size += sizeof( nmd_element_header ) + sizeof( nmd_stream_header );
     
    174173        eheader.type     = nmd_type::MESH;
    175174        eheader.name     = 0;
    176         eheader.children = static_cast< uint16 >( data.size() );
     175        eheader.children = static_cast< uint16 >( mesh->size() );
    177176        eheader.size     = size;
    178177        stream_out.write( &eheader, sizeof( eheader ), 1 );
    179178
    180         for ( auto chan : data )
     179        for ( auto chan : *mesh )
    181180        {
    182181                nmd_element_header cheader;
     
    203202                total += sizeof( nmd_element_header ) + sizeof( nmd_node_header );
    204203                if ( node->data )
    205                         for ( uint32 c = 0; c < node->data->get_channel_count(); ++c )
     204                        for ( uint32 c = 0; c < node->data->size(); ++c )
    206205                        {
    207206                                total += sizeof( nmd_element_header ) + sizeof( nmd_stream_header );
     
    227226                const mesh_node_data* node = nodes->get_node(i);
    228227                uint32 chan_size  = 0;
    229                 uint32 chan_count = ( node->data ? node->data->get_channel_count() : 0 );
     228                uint32 chan_count = ( node->data ? node->data->size() : 0 );
    230229                for ( uint32 c = 0; c < chan_count; ++c )
    231230                {
     
    280279        for ( uint32 i = 0; i < model->get_count(); ++i )
    281280        {
    282                 const mesh_data* mesh = model->get_mesh(i);
     281                const data_channel_set* mesh = model->get_mesh(i);
    283282                nmd_dump_mesh( mesh, stream_out );
    284283        }
  • trunk/src/formats/obj_loader.cc

    r413 r416  
    77#include "nv/formats/obj_loader.hh"
    88#include "nv/io/std_stream.hh"
     9#include "nv/interface/data_channel_access.hh"
     10
    911#include <sstream>
    1012
     
    330332                }
    331333
    332                 mesh_data* mesh = new mesh_data(reader->name);
    333                 mesh->add_channel( channel.release() );
    334                 m_meshes.push_back( mesh );
     334                data_channel_set_creator result;// ( reader->name );
     335                result.add_channel( channel.release() );
     336                m_meshes.push_back( result.release() );
    335337
    336338                reader->reset();
     
    341343}
    342344
    343 mesh_data* nv::obj_loader::release_mesh_data( size_t index )
    344 {
    345         mesh_data* result = m_meshes[ index ];
     345data_channel_set* nv::obj_loader::release_mesh_data( size_t index )
     346{
     347        data_channel_set* result = m_meshes[ index ];
    346348        m_meshes[ index ] = nullptr;
    347349        return result;
     
    356358{
    357359        uint32 size = m_meshes.size();
    358         mesh_data* meshes = new mesh_data[ size ];
     360        data_channel_set* meshes = data_channel_set_creator::create_array( size, 1 );
    359361        for ( uint32 i = 0; i < size; ++i )
    360362        {
    361                 m_meshes[i]->move_to( meshes[i] );
     363                data_channel_set_creator( m_meshes[i] ).move_to( meshes[i] );
    362364                delete m_meshes[i];
    363365        }
  • trunk/src/gfx/keyframed_mesh.cc

    r415 r416  
    2323        , m_active( false )
    2424{
    25         m_index_count  = m_mesh_data->get_index_channel()->size();
     25        m_index_count  = m_mesh_data->get_channel( slot::INDEX )->size();
    2626        m_vertex_count = m_mesh_data->get_channel<vertex_t>()->size();
    2727        m_vchannel     = m_mesh_data->get_channel<vertex_pnt>();
     
    190190        m_context->add_vertex_buffers( m_va, vb, m_mesh_data->get_channel<vertex_t>() );
    191191
    192         const raw_data_channel* index_channel = m_mesh_data->get_index_channel();
     192        const raw_data_channel* index_channel = m_mesh_data->get_channel( slot::INDEX );
    193193        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 );
     194        m_context->set_index_buffer( m_va, ib, index_channel->descriptor()[0].etype, true );
    196195
    197196        m_data = new uint8[ m_vertex_count * m_vsize ];
  • trunk/src/gfx/mesh_creator.cc

    r415 r416  
    66
    77#include "nv/gfx/mesh_creator.hh"
     8
     9#include "nv/interface/data_channel_access.hh"
    810
    911struct nv_key_transform { nv::transform tform; };
     
    2224                size_t pcount    = ( pkeys ? pkeys->get_channel(0)->size() : 0 );
    2325                max_frames = nv::max<uint32>( count, max_frames );
    24                 if ( pkeys && pkeys->get_channel_count() > 0 && keys && keys->get_channel_count() > 0 )
     26                if ( pkeys && pkeys->size() > 0 && keys && keys->size() > 0 )
    2527                {
    2628                        data_channel_creator< nv_key_transform > channel_creator( const_cast< raw_data_channel* >( keys->get_channel( 0 ) ) );
     
    5456        {
    5557                key_data* old_keys = m_data->m_nodes[i].data;
    56                 if ( old_keys && old_keys->get_channel_count() > 0 )
    57                 {
    58                         size_t chan_count = old_keys->get_channel_count();
     58                if ( old_keys && old_keys->size() > 0 )
     59                {
     60                        size_t chan_count = old_keys->size();
    5961                        if ( chan_count == 1
    6062                                && old_keys->get_channel(0)->descriptor().size() == 1
     
    8587
    8688                        delete old_keys;
    87                         new_keys->add_channel( kt_channel.release() );
     89                        new_keys->add_key_channel( kt_channel.release() );
    8890                        m_data->m_nodes[i].data = new_keys;
    8991                }
     
    104106                {
    105107                        key_data* kdata  = node.data;
    106                         for ( size_t c = 0; c < kdata->get_channel_count(); ++c )
     108                        for ( size_t c = 0; c < kdata->size(); ++c )
    107109                        {
    108110                                raw_data_channel_creator channel( const_cast< raw_data_channel* >( kdata->get_channel( c ) ) );
     
    123125        mat3 normal_transform  = r33;
    124126
    125         for ( uint32 c = 0; c < m_data->get_channel_count(); ++c )
    126         {
    127                 raw_data_channel_creator channel( m_data->m_channels[ c ] );
     127        for ( uint32 c = 0; c < m_data->size(); ++c )
     128        {
     129                raw_data_channel_creator channel( m_data, c );
    128130                const data_descriptor&  desc    = channel.descriptor();
    129131                uint8* raw_data = channel.raw_data();
     
    173175        size_t n_offset = 0;
    174176        if ( ch_n == -1 ) return;
    175         raw_data_channel_creator channel( m_data->m_channels[ unsigned( ch_n ) ] );
     177        raw_data_channel_creator channel( m_data, unsigned( ch_n ) );
    176178        for ( const auto& cslot : channel.descriptor() )
    177179                if ( cslot.vslot == slot::NORMAL )
     
    201203        const raw_data_channel* i_channel = nullptr;
    202204
    203         for ( uint32 c = 0; c < m_data->get_channel_count(); ++c )
     205        for ( uint32 c = 0; c < m_data->size(); ++c )
    204206        {
    205207                const raw_data_channel* channel = m_data->get_channel(c);
     
    219221                                {
    220222                                        n_offset  = int( cslot.offset );
    221                                         n_channel = m_data->m_channels[ c ];
     223                                        n_channel = data_channel_set_creator( m_data )[ c ];
    222224                                        n_channel_index = c;
    223225                                }
     
    331333        delete tangents2;
    332334
    333         m_data->m_channels[ n_channel_index ] = merge_channels( n_channel, g_channel.channel() );
     335        ( data_channel_set_creator( m_data ))[ n_channel_index ] = merge_channels( n_channel, g_channel.channel() );
    334336        delete n_channel;
    335337}
    336338
    337 nv::raw_data_channel* nv::mesh_data_creator::merge_channels( raw_data_channel* a, raw_data_channel* b )
     339nv::raw_data_channel* nv::mesh_data_creator::merge_channels( const raw_data_channel* a, const raw_data_channel* b )
    338340{
    339341        NV_ASSERT( a->size() == b->size(), "merge_channel - bad channels!" );
     
    351353}
    352354
    353 nv::raw_data_channel* nv::mesh_data_creator::append_channels( raw_data_channel* a, raw_data_channel* b, uint32 frame_count )
     355nv::raw_data_channel* nv::mesh_data_creator::append_channels( const raw_data_channel* a, const raw_data_channel* b, uint32 frame_count )
    354356{
    355357        if ( a->descriptor() != b->descriptor() ) return nullptr;
     
    389391bool nv::mesh_data_creator::is_same_format( mesh_data* other )
    390392{
    391         if ( m_data->get_channel_count() != other->get_channel_count() ) return false;
    392         for ( uint32 c = 0; c < m_data->get_channel_count(); ++c )
     393        if ( m_data->size() != other->size() ) return false;
     394        for ( uint32 c = 0; c < m_data->size(); ++c )
    393395        {
    394396                if ( m_data->get_channel(c)->descriptor() != other->get_channel(c)->descriptor() )
     
    406408        int och_ti = other->get_channel_index( slot::TEXCOORD );
    407409        if ( ch_pi == -1 || ch_ti == -1 ) return;
    408         size_t size   = m_data->m_channels[ unsigned(ch_ti) ]->size();
    409         size_t osize  =  other->m_channels[ unsigned(och_ti) ]->size();
    410         size_t count  = m_data->m_channels[ unsigned(ch_pi) ]->size();
    411         size_t ocount =  other->m_channels[ unsigned(och_pi) ]->size();
     410        size_t size   = m_data->get_channel_size( unsigned(ch_ti) );
     411        size_t osize  =  other->get_channel_size( unsigned(och_ti) );
     412        size_t count  = m_data->get_channel_size( unsigned(ch_pi) );
     413        size_t ocount =  other->get_channel_size( unsigned(och_pi) );
    412414        if ( count % size != 0 || ocount % osize != 0 ) return;
    413415        if ( count / size != ocount / osize ) return;
    414416       
    415         for ( uint32 c = 0; c < m_data->get_channel_count(); ++c )
    416         {
    417                 raw_data_channel* old = m_data->m_channels[c];
     417        data_channel_set_creator data( m_data );
     418
     419        for ( uint32 c = 0; c < m_data->size(); ++c )
     420        {
     421                const raw_data_channel* old = m_data->get_channel( c );
    418422                bool old_is_index = old->size() > 0 && old->descriptor()[0].vslot == slot::INDEX;
    419423                size_t frame_count = ( old_is_index ? 1 : old->size() / size );
    420                 m_data->m_channels[c] = append_channels( old, other->m_channels[c], frame_count );
    421                 NV_ASSERT( m_data->m_channels[c], "Merge problem!" );
     424                data[c] = append_channels( old, other->get_channel(c), frame_count );
     425                NV_ASSERT( data[c], "Merge problem!" );
    422426                if ( old_is_index )
    423427                {
     
    427431                                {
    428432                                        NV_ASSERT( size + osize < uint16(-1), "Index out of range!" );
    429                                         raw_data_channel_creator ic( m_data->m_channels[c] );
     433                                        raw_data_channel_creator ic( data[c] );
    430434                                        uint16* indexes = reinterpret_cast<uint16*>( ic.raw_data() );
    431435                                        for ( uint16 i = uint16( old->size() ); i < ic.size(); ++i )
     
    436440                        case UINT   :
    437441                                {
    438                                         raw_data_channel_creator ic( m_data->m_channels[c] );
     442                                        raw_data_channel_creator ic( data[c] );
    439443                                        uint32* indexes = reinterpret_cast<uint32*>( ic.raw_data() );
    440444                                        for ( uint32 i = old->size(); i < ic.size(); ++i )
     
    444448                        default : NV_ASSERT( false, "Unsupported index type!" ); break;
    445449                        }
    446                         m_data->m_index_channel = m_data->m_channels[c];
    447450                }
    448451                delete old;
    449452        }
    450453}
     454
     455void nv::mesh_creator::delete_mesh( uint32 index )
     456{
     457        if ( index < m_pack->get_count() )
     458        {
     459                data_channel_set_creator( &m_pack->m_meshes[index] ).destroy();
     460                data_channel_set_creator( &m_pack->m_meshes[m_pack->m_count - 1] ).move_to( m_pack->m_meshes[index] );
     461                m_pack->m_count--;
     462        }
     463}
  • trunk/src/gfx/skeletal_mesh.cc

    r415 r416  
    2727
    2828        m_vtx_data  = a_mesh_data->get_channel_data<md5_vtx_pntiw>();
    29         m_indices   = a_mesh_data->get_count();
     29        m_indices   = a_mesh_data->get_channel_size( slot::INDEX );
    3030        m_va        = a_context->create_vertex_array();
    3131
    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];
     32        //array_view< raw_data_channel* > channels = a_mesh_data->get_raw_channels();
     33        for ( auto channel : *a_mesh_data )
     34        {
     35                //const raw_data_channel* channel = channels[ch];
    3636                if ( channel->size() > 0 && channel != pntiw_chan )
    3737                {
     
    218218{
    219219        m_va          = a_context->create_vertex_array( a_mesh, nv::STATIC_DRAW );
    220         m_index_count = a_mesh->get_count();
     220        m_index_count = a_mesh->get_channel_size( slot::INDEX );
    221221        if ( m_bone_data )
    222222        {
Note: See TracChangeset for help on using the changeset viewer.