Changeset 295 for trunk/src


Ignore:
Timestamp:
07/31/14 02:32:59 (11 years ago)
Author:
epyon
Message:
  • gl_context - support for integration with wxWindows
  • wx.hh - simple wxWindows integration
  • mesh_creator - flip normals and merge operations added
  • fix in packed_indexed_array
  • various minor fixes
Location:
trunk/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gfx/mesh_creator.cc

    r294 r295  
    168168};
    169169
     170void nv::mesh_data_creator::flip_normals()
     171{
     172        int ch_n  = m_data->get_channel_index( slot::NORMAL );
     173        size_t n_offset = 0;
     174        if ( ch_n == -1 ) return;
     175        mesh_raw_channel* channel = m_data->m_channels[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;
     180                }
     181
     182        for ( uint32 i = 0; i < channel->count; ++i )
     183        {
     184                vec3& normal = *(vec3*)(channel->data + channel->desc.size * i + n_offset);
     185                normal = -normal;
     186        }
     187}
     188
     189
    170190void nv::mesh_data_creator::generate_tangents()
    171191{
     
    339359        return result;
    340360}
     361
     362nv::mesh_raw_channel* nv::mesh_data_creator::append_channels( mesh_raw_channel* a, mesh_raw_channel* b, uint32 frame_count )
     363{
     364        if ( a->desc != b->desc ) return nullptr;
     365        if ( a->count % frame_count != 0 ) return nullptr;
     366        if ( b->count % frame_count != 0 ) return nullptr;
     367        size_t vtx_size = a->desc.size;
     368
     369        uint8* data = new uint8[ ( a->count + b->count ) * vtx_size ];
     370       
     371
     372        if ( frame_count == 1 )
     373        {
     374                size_t a_size = vtx_size * a->count;
     375                std::copy_n( a->data, a_size, data );
     376                std::copy_n( b->data, vtx_size * b->count, data + a_size );             
     377        }
     378        else
     379        {
     380                size_t frame_size_a = ( a->count / frame_count ) * vtx_size;
     381                size_t frame_size_b = ( b->count / frame_count ) * vtx_size;
     382                size_t pos_a = 0;
     383                size_t pos_b = 0;
     384                size_t pos   = 0;
     385                for ( size_t i = 0; i < frame_count; ++i )
     386                {
     387                        std::copy_n( a->data + pos_a, frame_size_a, data + pos );
     388                        std::copy_n( b->data + pos_b, frame_size_b, data + pos + frame_size_a );                                pos_a += frame_size_a;
     389                        pos_b += frame_size_b;
     390                        pos   += frame_size_a + frame_size_b;
     391                }
     392        }
     393
     394        mesh_raw_channel* result = new mesh_raw_channel;
     395        result->count = a->count + b->count;
     396        result->desc  = a->desc;
     397        result->data  = data;
     398        return result;
     399}
     400
     401
     402
     403bool nv::mesh_data_creator::is_same_format( mesh_data* other )
     404{
     405        if ( m_data->get_channel_count() != other->get_channel_count() ) return false;
     406        for ( uint32 c = 0; c < m_data->get_channel_count(); ++c )
     407        {
     408                if ( m_data->get_channel(c)->desc != other->get_channel(c)->desc )
     409                        return false;
     410        }
     411        return true;
     412}
     413
     414void nv::mesh_data_creator::merge( mesh_data* other )
     415{
     416        if ( !is_same_format( other ) ) return;
     417        int ch_pi  = m_data->get_channel_index( slot::POSITION );
     418        int ch_ti  = m_data->get_channel_index( slot::TEXCOORD );
     419        int och_pi = other->get_channel_index( slot::POSITION );
     420        int och_ti = other->get_channel_index( slot::TEXCOORD );
     421        if ( ch_pi == -1 || ch_ti == -1 ) return;
     422        size_t size   = m_data->m_channels[ ch_ti ]->count;
     423        size_t osize  =  other->m_channels[ och_ti ]->count;
     424        size_t count  = m_data->m_channels[ ch_pi ]->count;
     425        size_t ocount =  other->m_channels[ och_pi ]->count;
     426        if ( count % size != 0 || ocount % osize != 0 ) return;
     427        if ( count / size != ocount / osize ) return;
     428       
     429        for ( uint32 c = 0; c < m_data->get_channel_count(); ++c )
     430        {
     431                mesh_raw_channel* old = m_data->m_channels[c];
     432                size_t frame_count = ( old->is_index() ? 1 : old->count / size );
     433                m_data->m_channels[c] = append_channels( old, other->m_channels[c], frame_count );
     434                NV_ASSERT( m_data->m_channels[c], "Merge problem!" );
     435                if ( old->is_index() )
     436                {
     437                        switch ( old->desc.slots[0].etype )
     438                        {
     439                        case USHORT :
     440                                {
     441                                        NV_ASSERT( size + osize < uint16(-1), "Index out of range!" );
     442                                        uint16* indexes = (uint16*)m_data->m_channels[c]->data;
     443                                        for ( uint16 i = (uint16)old->count; i < m_data->m_channels[c]->count; ++i )
     444                                                indexes[i] += (uint16)size;
     445
     446                                }
     447                                break;
     448                        case UINT   :
     449                                {
     450                                        uint32* indexes = (uint32*)m_data->m_channels[c]->data;
     451                                        for ( uint32 i = old->count; i < m_data->m_channels[c]->count; ++i )
     452                                                indexes[i] += size;
     453                                }
     454                                break;
     455                        default : NV_ASSERT( false, "Unsupported index type!" ); break;
     456                        }
     457                        m_data->m_index_channel = m_data->m_channels[c];
     458                }
     459                delete old;
     460        }
     461}
  • trunk/src/gfx/skeletal_mesh.cc

    r290 r295  
    225225                skeletal_animation_entry_gpu * anim = (skeletal_animation_entry_gpu*)(a_anim);
    226226                anim->prepare( m_bone_data );
    227                 update_animation( a_anim, uint32( anim->get_start() * 1000.f * anim->get_frame_rate() * 1000 ) );
     227                update_animation( a_anim, 0 );
    228228        }
    229229}
  • trunk/src/gl/gl_window.cc

    r246 r295  
    206206
    207207gl_window::gl_window( device* dev, uint16 width, uint16 height, bool fullscreen )
    208         : m_device( dev ), m_width( width ), m_height( height ), m_title("NV Engine"), m_handle( nullptr ), m_adopted( false )
     208        : m_device( dev ), m_width( width ), m_height( height ), m_title("NV Engine"), m_handle( nullptr ), m_hwnd( 0 ), m_adopted( false )
    209209{
    210210        //      bpp = m_info->vfmt->BitsPerPixel;
     
    298298void gl_window::swap_buffers()
    299299{
    300         if ( m_adopted ) return; // NOT SURE
     300        if ( m_adopted )
     301        {
     302#if NV_PLATFORM == NV_WINDOWS
     303                ::SwapBuffers( (HDC)m_hwnd );
     304#else
     305        NV_ASSERT( false, "Native GL context only working with SDL 2.0!" );
     306#endif
     307
     308        }
    301309#if NV_SDL_VERSION == NV_SDL_20
    302310        SDL_GL_SwapWindow( static_cast<SDL_Window*>( m_handle ) );
     
    328336//      m_height  = (uint16)rect.bottom;
    329337        m_handle  = window;
     338        m_hwnd    = ::GetDC( (HWND)handle );
    330339        m_context->set_viewport( nv::ivec4( 0, 0, m_width, m_height ) );
    331340#else
  • trunk/src/library.cc

    r256 r295  
    120120    }
    121121    m_handle = NULL;
    122     NV_LOG( LOG_NOTICE, "library : '" + m_name + "' closed." );
    123122}
    124123
  • trunk/src/logger.cc

    r204 r295  
    251251        return buffer;
    252252}
     253
     254const char* nv::log_sink::level_name( log_level level ) const
     255{
     256        return NV_LOG_LEVEL_NAME( level );
     257}
     258
     259const char* nv::log_sink::padded_level_name( log_level level ) const
     260{
     261        return NV_LOG_LEVEL_NAME_PAD( level );
     262}
Note: See TracChangeset for help on using the changeset viewer.