Changeset 410 for trunk/src


Ignore:
Timestamp:
07/08/15 17:33:38 (10 years ago)
Author:
epyon
Message:
  • merge of vertex_descriptor and key_descriptor concepts - unified raw data description via data_descriptor
  • minor bugfixes
Location:
trunk/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/formats/assimp_loader.cc

    r406 r410  
    5050};
    5151
    52 struct assimp_key_p  { float time; vec3 position; };
     52struct assimp_key_p  { float time; vec3 translation; };
    5353struct assimp_key_r  { float time; quat rotation; };
    5454struct assimp_key_s  { float time; vec3 scale; };
     
    430430        for ( unsigned np = 0; np < node->mNumPositionKeys; ++np )
    431431        {
    432                 pchannel[np].time     = static_cast<float>( node->mPositionKeys[np].mTime );
    433                 pchannel[np].position = assimp_vec3_cast(node->mPositionKeys[np].mValue);
     432                pchannel[np].time        = static_cast<float>( node->mPositionKeys[np].mTime );
     433                pchannel[np].translation = assimp_vec3_cast(node->mPositionKeys[np].mValue);
    434434        }
    435435        for ( unsigned np = 0; np < node->mNumRotationKeys; ++np )
  • trunk/src/formats/nmd_loader.cc

    r406 r410  
    4444                source.read( &stream_header, sizeof( stream_header ), 1 );
    4545                mesh_raw_channel* channel = mesh_raw_channel::create( stream_header.format, stream_header.count );
    46                 source.read( channel->data, stream_header.format.size, stream_header.count );
     46                source.read( channel->data, stream_header.format.element_size(), stream_header.count );
    4747                mesh->add_channel( channel );
    4848        }
     
    126126                                source.read( &element_header, sizeof( element_header ), 1 );
    127127                                NV_ASSERT( element_header.type == nmd_type::KEY_CHANNEL, "CHANNEL expected!" );
    128                                 nv::nmd_key_channel_header cheader;
     128                                nv::nmd_stream_header cheader;
    129129                                source.read( &cheader, sizeof( cheader ), 1 );
    130130                                key_raw_channel* channel = key_raw_channel::create( cheader.format, cheader.count );
    131                                 source.read( channel->data, channel->desc.size, channel->count );
     131                                source.read( channel->data, channel->desc.element_size(), channel->count );
    132132                                kdata->add_channel( channel );
    133133                        }
     
    191191                sheader.count  = chan->count;
    192192                stream_out.write( &sheader, sizeof( sheader ), 1 );
    193                 stream_out.write( chan->data, chan->desc.size, chan->count );
     193                stream_out.write( chan->data, chan->desc.element_size(), chan->count );
    194194        }
    195195}
     
    205205                        for ( uint32 c = 0; c < node->data->get_channel_count(); ++c )
    206206                        {
    207                                 total += sizeof( nmd_element_header ) + sizeof( nmd_key_channel_header );
     207                                total += sizeof( nmd_element_header ) + sizeof( nmd_stream_header );
    208208                                total += node->data->get_channel(c)->size();
    209209                        }
     
    230230                for ( uint32 c = 0; c < chan_count; ++c )
    231231                {
    232                         chan_size += sizeof( nmd_element_header ) + sizeof( nv::nmd_key_channel_header );
     232                        chan_size += sizeof( nmd_element_header ) + sizeof( nv::nmd_stream_header );
    233233                        chan_size += node->data->get_channel(c)->size();
    234234                }
     
    252252                        eheader.type     = nmd_type::KEY_CHANNEL;
    253253                        eheader.children = 0;
    254                         eheader.size     = sizeof( nmd_key_channel_header ) + channel->size();
     254                        eheader.size     = sizeof( nmd_stream_header ) + channel->size();
    255255                        stream_out.write( &eheader, sizeof( eheader ), 1 );
    256256
    257                         nmd_key_channel_header cheader;
     257                        nmd_stream_header cheader;
    258258                        cheader.format    = channel->desc;
    259259                        cheader.count     = channel->count;
    260260                        stream_out.write( &cheader, sizeof( cheader ), 1 );
    261                         stream_out.write( channel->data, channel->desc.size, channel->count );
     261                        stream_out.write( channel->data, channel->desc.element_size(), channel->count );
    262262                }
    263263        }
  • trunk/src/gfx/keyframed_mesh.cc

    r406 r410  
    192192        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 );
    193193
    194         m_context->set_index_buffer( m_va, ib, m_mesh_data->get_index_channel()->desc.slots[0].etype, true );
     194        m_context->set_index_buffer( m_va, ib, m_mesh_data->get_index_channel()->desc[0].etype, true );
    195195
    196196        m_data = new uint8[ m_vertex_count * m_vsize ];
  • trunk/src/gfx/mesh_creator.cc

    r406 r410  
    5757                        size_t chan_count = old_keys->get_channel_count();
    5858                        if ( chan_count == 1
    59                                 && old_keys->get_channel(0)->desc.count == 1
    60                                 && old_keys->get_channel(0)->desc.slots[0].etype == TRANSFORM ) continue;
     59                                && old_keys->get_channel(0)->desc.slot_count() == 1
     60                                && old_keys->get_channel(0)->desc[0].etype == TRANSFORM ) continue;
    6161
    6262                        size_t max_keys = 0;
     
    7070                        new_keys->add_channel( raw_channel );
    7171                        nv_key_transform* channel = reinterpret_cast<nv_key_transform*>(raw_channel->data);
    72                         key_descriptor final_key = old_keys->get_final_key();
     72                        data_descriptor final_key = old_keys->get_final_key();
    7373
    7474                        for ( unsigned n = 0; n < max_keys; ++n )
     
    107107                        {
    108108                                const key_raw_channel* channel = kdata->get_channel(c);
    109                                 size_t key_size = channel->desc.size;
     109                                size_t key_size = channel->desc.element_size();
    110110                                for ( size_t n = 0; n < channel->count; ++n )
    111111                                {
     
    126126        {
    127127                const mesh_raw_channel* channel = m_data->get_channel(c);
    128                 const vertex_descriptor& desc   = channel->desc;
     128                const data_descriptor&  desc    = channel->desc;
    129129                uint8* raw_data = channel->data;
    130                 uint32 vtx_size = desc.size;
     130                uint32 vtx_size = desc.element_size();
    131131                int p_offset = -1;
    132132                int n_offset = -1;
    133133                int t_offset = -1;
    134                 for ( uint32 i = 0; i < desc.count; ++i )
    135                         switch ( desc.slots[i].vslot )
    136                         {
    137                                 case slot::POSITION : if ( desc.slots[i].etype == FLOAT_VECTOR_3 ) p_offset = int(desc.slots[i].offset); break;
    138                                 case slot::NORMAL   : if ( desc.slots[i].etype == FLOAT_VECTOR_3 ) n_offset = int(desc.slots[i].offset); break;
    139                                 case slot::TANGENT  : if ( desc.slots[i].etype == FLOAT_VECTOR_4 ) t_offset = int(desc.slots[i].offset); break;
     134                for ( const auto& cslot : desc )
     135                        switch ( cslot.vslot )
     136                        {
     137                                case slot::POSITION : if ( cslot.etype == FLOAT_VECTOR_3 ) p_offset = int( cslot.offset ); break;
     138                                case slot::NORMAL   : if ( cslot.etype == FLOAT_VECTOR_3 ) n_offset = int( cslot.offset ); break;
     139                                case slot::TANGENT  : if ( cslot.etype == FLOAT_VECTOR_4 ) t_offset = int( cslot.offset ); break;
    140140                                default             : break;
    141141                        }
     
    174174        if ( ch_n == -1 ) return;
    175175        mesh_raw_channel* channel = m_data->m_channels[ unsigned( ch_n ) ];
    176         for ( uint32 i = 0; i < channel->desc.count; ++i )
    177                 if ( channel->desc.slots[i].vslot == slot::NORMAL )
    178                 {
    179                         n_offset  = channel->desc.slots[i].offset;
     176        for ( const auto& cslot : channel->desc )
     177                if ( cslot.vslot == slot::NORMAL )
     178                {
     179                        n_offset  = cslot.offset;
    180180                }
    181181
    182182        for ( uint32 i = 0; i < channel->count; ++i )
    183183        {
    184                 vec3& normal = *reinterpret_cast<vec3*>( channel->data + channel->desc.size * i + n_offset );
     184                vec3& normal = *reinterpret_cast<vec3*>( channel->data + channel->desc.element_size() * i + n_offset );
    185185                normal = -normal;
    186186        }
     
    204204        {
    205205                const mesh_raw_channel* channel = m_data->get_channel(c);
    206                 const vertex_descriptor& desc   = channel->desc;
    207                 for ( uint32 i = 0; i < desc.count; ++i )
    208                         switch ( desc.slots[i].vslot )
     206
     207                for ( const auto& cslot : channel->desc )
     208                switch ( cslot.vslot )
    209209                {
    210210                        case slot::POSITION :
    211                                 if ( desc.slots[i].etype == FLOAT_VECTOR_3 )
    212                                 {
    213                                         p_offset  = int( desc.slots[i].offset );
     211                                if ( cslot.etype == FLOAT_VECTOR_3 )
     212                                {
     213                                        p_offset  = int( cslot.offset );
    214214                                        p_channel = channel;
    215215                                }
    216216                                break;
    217                         case slot::NORMAL   : if ( desc.slots[i].etype == FLOAT_VECTOR_3 )
    218                                 {
    219                                         n_offset  = int( desc.slots[i].offset );
     217                        case slot::NORMAL   :
     218                                if ( cslot.etype == FLOAT_VECTOR_3 )
     219                                {
     220                                        n_offset  = int( cslot.offset );
    220221                                        n_channel = m_data->m_channels[ c ];
    221222                                        n_channel_index = c;
    222223                                }
    223224                                break;
    224                         case slot::TEXCOORD : if ( desc.slots[i].etype == FLOAT_VECTOR_2 )
    225                                 {
    226                                         t_offset  = int( desc.slots[i].offset );
     225                        case slot::TEXCOORD :
     226                                if ( cslot.etype == FLOAT_VECTOR_2 )
     227                                {
     228                                        t_offset  = int( cslot.offset );
    227229                                        t_channel = channel;
    228230                                }
     
    230232                        case slot::INDEX    :
    231233                                {
    232                                         i_type    = desc.slots[i].etype;
     234                                        i_type    = cslot.etype;
    233235                                        i_channel = channel;
    234236                                }
     
    278280                }
    279281
    280                 const vec2& w1 = *reinterpret_cast<vec2*>(t_channel->data + t_channel->desc.size*ti0 + t_offset );
    281                 const vec2& w2 = *reinterpret_cast<vec2*>(t_channel->data + t_channel->desc.size*ti1 + t_offset );
    282                 const vec2& w3 = *reinterpret_cast<vec2*>(t_channel->data + t_channel->desc.size*ti2 + t_offset );
     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 );
    283285                vec2 st1 = w3 - w1;
    284286                vec2 st2 = w2 - w1;
     
    291293                        uint32 nti1 = t_channel->count * set + ti1;
    292294                        uint32 nti2 = t_channel->count * set + ti2;
    293                         vec3 v1 = *reinterpret_cast<vec3*>(p_channel->data + p_channel->desc.size*nti0 + p_offset );
    294                         vec3 v2 = *reinterpret_cast<vec3*>(p_channel->data + p_channel->desc.size*nti1 + p_offset );
    295                         vec3 v3 = *reinterpret_cast<vec3*>(p_channel->data + p_channel->desc.size*nti2 + p_offset );
     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 );
    296298                        vec3 xyz1 = v3 - v1;
    297299                        vec3 xyz2 = v2 - v1;
     
    317319        for ( unsigned int i = 0; i < vtx_count; ++i )
    318320        {
    319                 const vec3 n = *reinterpret_cast<vec3*>( n_channel->data + n_channel->desc.size*i + n_offset );
     321                const vec3 n = *reinterpret_cast<vec3*>( n_channel->data + n_channel->desc.element_size()*i + n_offset );
    320322                const vec3 t = vec3(tangents[i]);
    321323                if ( ! ( t.x == 0.0f && t.y == 0.0f && t.z == 0.0f ) )
     
    335337{
    336338        NV_ASSERT( a->count == b->count, "merge_channel - bad channels!" );
    337         vertex_descriptor adesc = a->desc;
    338         vertex_descriptor bdesc = b->desc;
    339         uint32            count = a->count;
    340 
    341         vertex_descriptor desc  = a->desc;
    342         for ( uint32 i = 0; i < bdesc.count; i++ )
    343         {
    344                 desc.slots[desc.count+i] = bdesc.slots[i];
    345                 desc.slots[desc.count+i].offset += desc.size;
    346         }
    347         desc.size  += bdesc.size;
    348         desc.count += bdesc.count;
    349         uint8* data = new uint8[ count * desc.size ];
     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() ];
    350349        for ( uint32 i = 0; i < count; ++i )
    351350        {
    352                 raw_copy_n( a->data + i * adesc.size, adesc.size, data + i*desc.size );
    353                 raw_copy_n( b->data + i * bdesc.size, bdesc.size, data + i*desc.size + adesc.size );
     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() );
    354353        }
    355354        mesh_raw_channel* result = new mesh_raw_channel;
     
    365364        if ( a->count % frame_count != 0 ) return nullptr;
    366365        if ( b->count % frame_count != 0 ) return nullptr;
    367         size_t vtx_size = a->desc.size;
     366        size_t vtx_size = a->desc.element_size();
    368367
    369368        uint8* data = new uint8[ ( a->count + b->count ) * vtx_size ];
     
    435434                if ( old->get_buffer_type() == INDEX_BUFFER )
    436435                {
    437                         switch ( old->desc.slots[0].etype )
     436                        switch ( old->desc[0].etype )
    438437                        {
    439438                        case USHORT :
  • trunk/src/gl/gl_window.cc

    r406 r410  
    104104        m_handle  = wm->adopt_window( handle );
    105105        m_hwnd    = ::GetDC( reinterpret_cast<HWND>( handle ) );
    106         m_context->set_viewport( nv::ivec4( 0, 0, m_width, m_height ) );
     106        m_context->set_viewport( nv::ivec4( 0, 0, 1, 1 ) );
    107107#else
    108108        NV_ASSERT( false, "Native GL context adoption not implemented for this platform!" );
  • trunk/src/stl/assert.cc

    r406 r410  
    55// For conditions of distribution and use, see copying.txt file in root folder.
    66
    7 #define NV_BASE_COMMON_HH
    8 #define NV_INTERNAL_INCLUDE
    9 #include "nv/base/assert.hh"
    10 #undef NV_BASE_COMMON_HH
     7#include "nv/base/common.hh"
    118#include "nv/core/logging.hh"
    129
    1310extern "C" {
    1411#if NV_COMPILER == NV_MSVC
    15         NV_NORETURN void __cdecl exit( _In_ int _Code );
     12        _ACRTIMP NV_NORETURN void __cdecl exit( _In_ int _Code );
    1613#else
    1714        void exit( int status_code ) NV_NORETURN;
  • trunk/src/wx/wx_canvas.cc

    r395 r410  
    6363}
    6464
    65 void nv::wx_log_text_ctrl_sink::log( nv::log_level level, const std::string& message )
     65void nv::wx_log_text_ctrl_sink::log( nv::log_level level, const nv::string_view& message )
    6666{
    6767        wxString str;
    68         str << timestamp() << " [" << padded_level_name( level ) << "] " << message << "\n";
     68        char stamp[16];
     69        size_t ssize = timestamp( stamp );
     70        str << stamp << " [" << padded_level_name( level ).data() << "] " << message.data() << "\n";
    6971        m_text_ctrl->AppendText( str );
    7072}
    7173
    7274nv::wx_app_base::wx_app_base()
     75        : m_logger( nv::LOG_TRACE )
    7376{
    74         static nv::logger log( nv::LOG_TRACE );
    75         log.add_sink( new nv::log_file_sink( "log.txt" ), nv::LOG_TRACE );
     77        nv::log_sink* sink = new nv::log_file_sink( "log.txt" );
     78        m_logger.add_sink( sink, nv::LOG_TRACE );
    7679        NV_LOG( nv::LOG_NOTICE, "Logging started" );
    7780}
Note: See TracChangeset for help on using the changeset viewer.