Changeset 295


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
Files:
1 added
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/gfx/mesh_creator.hh

    r294 r295  
    2323                // TODO: this could generate normals too
    2424                void generate_tangents();
     25                void flip_normals();
     26                bool is_same_format( mesh_data* other );
     27                void merge( mesh_data* other );
    2528        private:
    2629                mesh_raw_channel* merge_channels( mesh_raw_channel* a, mesh_raw_channel* b );
     30                mesh_raw_channel* append_channels( mesh_raw_channel* a, mesh_raw_channel* b, uint32 frame_count = 1 );
    2731
    2832                mesh_data* m_data;
     
    4751                mesh_creator( mesh_data_pack* pack ) : m_pack( pack ) {}
    4852                // assumes that keys are equally spaced
    49                 void pre_transform_keys() { mesh_nodes_creator( m_pack->m_nodes ).pre_transform_keys(); }
     53                void pre_transform_keys()
     54                {
     55                        if ( m_pack->m_nodes )
     56                                mesh_nodes_creator( m_pack->m_nodes ).pre_transform_keys();
     57                }
    5058                void generate_tangents()
    5159                {
     
    5765                void merge_keys() { mesh_nodes_creator( m_pack->m_nodes ).merge_keys(); }
    5866                // assumes that position and normal is vec3, tangent is vec4
     67                void flip_normals()
     68                {
     69                        for ( size_t m = 0; m < m_pack->m_count; ++m )
     70                                mesh_data_creator( &(m_pack->m_meshes[m]) ).flip_normals();
     71                }
    5972                void transform( float scale, const mat3& r33 )
    6073                {
     
    6477                                mesh_nodes_creator( m_pack->m_nodes ).transform( scale, r33 );
    6578                }
     79                // assumes models have same format
     80                // currently only data merge
     81                bool merge( mesh_data_pack* other )
     82                {
     83                        for ( size_t m = 0; m < m_pack->m_count; ++m )
     84                        {
     85                                if (!mesh_data_creator( &(m_pack->m_meshes[m]) ).is_same_format( &(other->m_meshes[m]) ) )
     86                                        return false;
     87                        }
     88                        for ( size_t m = 0; m < m_pack->m_count; ++m )
     89                        {
     90                                mesh_data_creator(&(m_pack->m_meshes[m]) ).merge( &(other->m_meshes[m]) );
     91                        }
     92                        return true;
     93                }
    6694        private:
    6795                mesh_data_pack* m_pack;
  • trunk/nv/gl/gl_context.hh

    r245 r295  
    6464        public:
    6565                native_gl_context( device* a_device, void* a_native_win_handle );
     66                void* get_native_handle() { return m_handle; }
    6667                ~native_gl_context();
    6768        private:
  • trunk/nv/gl/gl_window.hh

    r245 r295  
    3232                virtual context* get_context() { return m_context; }
    3333                virtual device* get_device() { return m_device; }
    34 
    3534                virtual void swap_buffers();
    3635                virtual ~gl_window();
     
    4140                string      m_title;
    4241                void*       m_handle;
     42                void*       m_hwnd;
    4343                bool        m_adopted;
    4444                gl_context* m_context;
  • trunk/nv/handle.hh

    r287 r295  
    147147                        resize_indexes_to( h.index() );
    148148                        m_indexes[ h.index() ] = m_data.size();
     149                        m_handles.push_back( h );
    149150                        m_data.emplace_back();
    150151                        return &(m_data.back());
     
    170171                        if ( dead_eindex != (sint32)m_data.size()-1 )
    171172                        {
    172                                 m_data[ dead_eindex ]    = m_data.back();
    173                                 m_handles[ dead_eindex ] = m_handles.back();
    174                                 m_indexes[ h.index() ]   = m_indexes[ swap_handle.index() ];
     173                                m_data[ dead_eindex ]            = m_data.back();
     174                                m_handles[ dead_eindex ]         = swap_handle;
     175                                m_indexes[ swap_handle.index() ] = dead_eindex;
    175176                        }
    176177                        m_data.pop_back();
  • trunk/nv/interface/animated_mesh.hh

    r288 r295  
    3333                float get_end() const  { return m_end; }
    3434                bool is_looping() const { return m_looping; }
     35                void set_range( float a_start, float a_end )
     36                {
     37                        m_start = a_start;
     38                        m_end   = a_end;
     39                        m_duration = m_end - m_start;
     40                }
     41                void set_frame_rate( uint32 rate )
     42                {
     43                        m_frame_rate = rate;
     44                }
    3545                virtual ~animation_entry() {}
    3646        protected:
  • trunk/nv/interface/mesh_data.hh

    r294 r295  
    107107                        return nullptr;
    108108                }
     109
     110                const mesh_raw_channel* get_channel( slot s ) const
     111                {
     112                        for ( auto ch : m_channels )
     113                        {
     114                                for ( uint32 i = 0; i < ch->desc.count; ++i )
     115                                        if ( ch->desc.slots[i].vslot == s )
     116                                        {
     117                                                return ch;
     118                                        }
     119                        }
     120                        return nullptr;
     121                }
     122
     123                int get_channel_index( slot s ) const
     124                {
     125                        for ( uint32 c = 0; c < m_channels.size(); ++c )
     126                        {
     127                                const mesh_raw_channel* ch = m_channels[c];
     128                                for ( uint32 i = 0; i < ch->desc.count; ++i )
     129                                        if ( ch->desc.slots[i].vslot == s )
     130                                        {
     131                                                return c;
     132                                        }
     133                        }
     134                        return -1;
     135                }
     136
    109137
    110138                size_t get_count() const
  • trunk/nv/interface/vertex.hh

    r286 r295  
    261261                }
    262262
    263                 bool operator==( const vertex_descriptor& rhs )
     263                bool operator!=( const vertex_descriptor& rhs ) const
     264                {
     265                        return !( *this == rhs );
     266                }
     267
     268                bool operator==( const vertex_descriptor& rhs ) const
    264269                {
    265270                        if ( size  != rhs.size )  return false;
  • trunk/nv/lib/detail/gl_types.inc

    r244 r295  
     1#ifndef NV_LIB_GL_TYPES_HH
     2#define NV_LIB_GL_TYPES_HH
     3
    14typedef unsigned int GLenum;
    25typedef unsigned int GLbitfield;
     
    2124
    2225/* OpenGL 1.1 non-deprecated defines */
     26#define GL_NO_ERROR 0
    2327#define GL_DEPTH_BUFFER_BIT 0x00000100
    2428#define GL_STENCIL_BUFFER_BIT 0x00000400
     
    517521#define GL_RENDERBUFFER_DEPTH_SIZE 0x8D54
    518522#define GL_RENDERBUFFER_STENCIL_SIZE 0x8D55
     523
     524#endif // NV_LIB_GL_TYPES_HH
  • trunk/nv/logger.hh

    r256 r295  
    4141                const char* timestamp() const;
    4242                /**
     43         * Log level name (unpadded)
     44                 */
     45                const char* level_name( log_level level ) const;
     46                /**
     47         * Log level name (padded)
     48                 */
     49                const char* padded_level_name( log_level level ) const;
     50                /**
    4351                 * Enforcement of virtual destructor.
    4452                 */
  • 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.