Changeset 505 for trunk/src


Ignore:
Timestamp:
07/12/16 20:22:23 (9 years ago)
Author:
epyon
Message:
  • several STL updates
  • several minor fixes
Location:
trunk/src
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/io_event.cc

    r487 r505  
    7171
    7272        db->create_type<key_event>()
    73                 .field( "ascii",   &key_event::ascii )
    74                 .field( "code",    &key_event::code )
    75                 .field( "shift",   &key_event::shift )
    76                 .field( "control", &key_event::control )
    77                 .field( "alt",     &key_event::alt )
    78                 .field( "pressed", &key_event::pressed );
     73                .field( "window_id",&key_event::window_id )
     74                .field( "ascii",    &key_event::ascii )
     75                .field( "code",     &key_event::code )
     76                .field( "shift",    &key_event::shift )
     77                .field( "control",  &key_event::control )
     78                .field( "alt",      &key_event::alt )
     79                .field( "pressed",  &key_event::pressed );
    7980
    8081        db->create_type<mouse_button_event>()
    81                 .field( "x",       &mouse_button_event::x )
    82                 .field( "y",       &mouse_button_event::y )
    83                 .field( "button",  &mouse_button_event::button )
    84                 .field( "pressed", &mouse_button_event::pressed )
    85                 .field( "code",    &mouse_button_event::code );
     82                .field( "window_id",&mouse_button_event::window_id )
     83                .field( "x",        &mouse_button_event::x )
     84                .field( "y",        &mouse_button_event::y )
     85                .field( "button",   &mouse_button_event::button )
     86                .field( "pressed",  &mouse_button_event::pressed )
     87                .field( "code",     &mouse_button_event::code );
    8688
    8789        db->create_type<mouse_move_event>()
    88                 .field( "x",       &mouse_move_event::x )
    89                 .field( "y",       &mouse_move_event::y )
    90                 .field( "rx",      &mouse_move_event::rx )
    91                 .field( "ry",      &mouse_move_event::ry )
    92                 .field( "pressed", &mouse_move_event::pressed )
    93                 .field( "code",    &mouse_move_event::code );
     90                .field( "window_id",&mouse_move_event::window_id )
     91                .field( "x",        &mouse_move_event::x )
     92                .field( "y",        &mouse_move_event::y )
     93                .field( "rx",       &mouse_move_event::rx )
     94                .field( "ry",       &mouse_move_event::ry )
     95                .field( "pressed",  &mouse_move_event::pressed )
     96                .field( "code",     &mouse_move_event::code );
    9497
    9598        db->create_type<mouse_wheel_event>()
    96                 .field( "x",       &mouse_wheel_event::x )
    97                 .field( "y",       &mouse_wheel_event::y );
     99                .field( "window_id",&mouse_wheel_event::window_id )
     100                .field( "x",        &mouse_wheel_event::x )
     101                .field( "y",        &mouse_wheel_event::y );
    98102
    99103        db->create_type<pad_button_event>()
  • trunk/src/core/types.cc

    r503 r505  
    33#include "nv/interface/clear_state.hh"
    44#include "nv/interface/render_state.hh"
     5#include "nv/stl/string.hh"
    56
    67using namespace nv;
     
    2627        db->create_type<ivec3>();
    2728        db->create_type<ivec4>();
     29        db->create_type<quat>();
     30        db->create_type<string32>();
     31        db->create_type<string64>();
     32        db->create_type<string128>();
     33        db->create_type<string256>();
    2834
    2935        db->create_type<color_mask>()
  • trunk/src/engine/image_manager.cc

    r504 r505  
    1212using namespace nv;
    1313
    14 void nv::image_manager::add_base_path( const string_view& path )
     14bool image_manager::load_resource( const string_view& filename )
    1515{
    16         m_paths.emplace_back( path );
     16        c_file_system fs;
     17        if ( stream* file = open_stream( fs, filename ) )
     18        {
     19                png_loader loader;
     20                image_data* result = loader.load( *file );
     21                delete file;
     22                if ( result )
     23                {
     24                        add( filename, result );
     25                        return true;
     26                }
     27        }
     28        return false;
    1729}
    1830
    19 bool image_manager::load_resource( const string_view& filename )
    20 {
    21         png_loader loader;
    22         c_file_system fs;
    23         image_data* result = nullptr;
    24         if ( fs.exists( filename ) )
    25         {
    26                 stream* file = fs.open( filename );
    27                 result = loader.load( *file );
    28                 delete file;
    29         }
    30         else if ( m_paths.size() > 0 )
    31         {
    32                 for ( const auto& path : m_paths )
    33                 {
    34                         string128 fpath = path;
    35                         fpath.append( filename );
    36                         if ( fs.exists( fpath ) )
    37                         {
    38                                 stream* file = fs.open( fpath );
    39                                 result = loader.load( *file );
    40                                 delete file;
    41                                 break;
    42                         }
    43                 }
    44         }
    45         if ( result )
    46                 add( filename, result );
    47         return result != nullptr;
    48 }
    49 
  • trunk/src/engine/material_manager.cc

    r501 r505  
    1414
    1515nv::gpu_material_manager::gpu_material_manager( context* context, material_manager* matmgr, image_manager* imgmgr )
    16         : m_context( context )
    17         , m_material_manager( matmgr )
     16        : dependant_resource_manager( matmgr ), m_context( context )
    1817        , m_image_manager( imgmgr )
    1918{
     
    2322}
    2423
    25 bool gpu_material_manager::load_resource( const string_view& id )
     24nv::resource< nv::gpu_material > nv::gpu_material_manager::create_resource( resource< material > m )
    2625{
    27         if ( auto mat = m_material_manager->get( id ).lock() )
     26        resource_id id = m.id();
     27        if ( auto mat = m.lock() )
    2828        {
    2929                gpu_material* result = new gpu_material;
     
    3939
    4040                // HACK
    41                 for ( uint32 i = 0; i < 8; ++i )
    42                         if ( result->textures[i].is_nil() )
    43                                 result->textures[i] = m_default;
    44                        
    45                 add( id, result );
    46                 return true;
     41                for ( uint32 i = 0; i < 8; ++i )
     42                        if ( result->textures[i].is_nil() )
     43                                result->textures[i] = m_default;
     44
     45                return add( id, result );
    4746        }
    48         return false;
     47        return resource< nv::gpu_material >();
    4948}
    5049
  • trunk/src/engine/mesh_manager.cc

    r484 r505  
    66
    77#include "nv/engine/mesh_manager.hh"
     8#include "nv/formats/nmd_loader.hh"
     9#include "nv/io/c_file_system.hh"
    810
    911using namespace nv;
    1012
    11 resource< gpu_mesh > gpu_mesh_manager::load_resource( resource< data_channel_set > mesh )
     13resource< gpu_mesh > gpu_mesh_manager::create_resource( resource< data_channel_set > mesh )
    1214{
    13         resource< gpu_mesh > result = get( mesh.id().value() );
    14         if ( result ) return result;
    1515        if ( auto lmesh = mesh.lock() )
    1616        {
     
    2424}
    2525
    26 bool nv::gpu_mesh_manager::load_resource( const string_view& id )
    27 {
    28         if ( auto lmesh = m_mesh_manager->get( id ).lock() )
    29         {
    30                 gpu_mesh* gm = new gpu_mesh;
    31                 gm->va = m_context->create_vertex_array( &*lmesh, STATIC_DRAW );
    32                 gm->count = lmesh->get_channel_size( slot::INDEX );
    33                 gm->shader = lmesh->get_channel( slot::BONEINDEX ) != nullptr ? BONE : NORMAL;
    34                 add( id, gm );
    35                 return true;
    36         }
    37         return false;
    38 }
    39 
    4026void gpu_mesh_manager::release( gpu_mesh* m )
    4127{
    4228        m_context->release( m->va );
    4329}
     30
     31nv::resource< nv::data_channel_set > nv::mesh_data_manager::get_path( const string_view& path, resource< mesh_data > default /*= resource< mesh_data >()*/, data_node_info* info /*= nullptr */ )
     32{
     33        nv::resource< nv::mesh_data > mr = default;
     34
     35        nv::string_view sub_mesh_name;
     36        nv::string128 base_mesh_name( path );
     37        nv::size_t sub_mesh_pos = path.find( ":" );
     38        nv::size_t dot_pos = path.find( "." );
     39        if ( sub_mesh_pos != nv::string_view::npos )
     40        {
     41                sub_mesh_name = path.substr( sub_mesh_pos + 1 );
     42                base_mesh_name.assign( path.substr( 0, sub_mesh_pos ) );
     43                NV_LOG_INFO( "Requested submesh - [", sub_mesh_name, "] in [", base_mesh_name, "]" );
     44        }
     45
     46        if ( dot_pos != nv::string_view::npos )
     47        {
     48                mr = get( base_mesh_name );
     49        }
     50        else
     51        {
     52                sub_mesh_name = base_mesh_name;
     53        }
     54
     55        if ( !mr )
     56        {
     57                NV_LOG_ERROR( "MESH FILE NOT FOUND - ", path );
     58                NV_ASSERT( false, "MESH FILE NOT FOUND!" );
     59                return nv::resource< nv::data_channel_set >();
     60        }
     61
     62        if ( auto mdata = mr.lock() )
     63        {
     64                sint32 index = -1;
     65                if ( sub_mesh_name.empty() )
     66                {
     67                        index = 0;
     68                }
     69                else if ( sub_mesh_name[0] >= '0' && sub_mesh_name[0] <= '9' )
     70                {
     71                        index = nv::buffer_to_uint32( sub_mesh_name.data(), nullptr );
     72                }
     73                else
     74                {
     75                        auto itr = mdata->names.find( sub_mesh_name );
     76                        if ( itr != mdata->names.end() )
     77                                index = itr->second;
     78                }
     79                if ( index >= 0 )
     80                {
     81                        if ( info )
     82                                *info = mdata->infos[index];
     83                        return mdata->meshes[index];
     84                }
     85
     86                NV_LOG_ERROR( "Resource path fail! - ", path );
     87                NV_ASSERT( false, "Resource path fail!" );
     88        }
     89        else
     90        {
     91                NV_LOG_ERROR( "Resource lock fail! - ", path );
     92                NV_ASSERT( false, "Resource lock fail!" );
     93        }
     94        return nv::resource< nv::data_channel_set >();
     95}
     96
     97bool nv::mesh_data_manager::load_resource( const string_view& id )
     98{
     99        nmd_loader* loader = nullptr;
     100        c_file_system fs;
     101        stream* mesh_file = open_stream( fs, id );
     102        if ( !mesh_file ) return false;
     103
     104        loader = new nmd_loader( m_strings );
     105        loader->load( *mesh_file );
     106        delete mesh_file;
     107
     108        mesh_data* result = new mesh_data;
     109        result->node_data = loader->release_data_node_list();
     110        if ( result->node_data )
     111        {
     112                data_node_list* nd = result->node_data;
     113                for ( uint32 i = 0; i < nd->size(); ++i )
     114                        result->node_names[(*nd)[i].name] = i;
     115        }
     116        for ( uint32 i = 0; i < loader->get_mesh_count(); ++i )
     117        {
     118                data_node_info info;
     119                data_channel_set* data = loader->release_mesh_data( i, info );
     120                result->infos.push_back( info );
     121                result->names[ info.name ] = i;
     122                auto mesh = m_mesh_manager->add( shash64( id.get_hash() + i ), data );
     123                result->meshes.push_back( mesh );
     124        }
     125        delete loader;
     126        if ( result )
     127                add( id, result );
     128        return result != nullptr;
     129}
  • trunk/src/engine/program_manager.cc

    r501 r505  
    4545}
    4646
     47nv::const_string nv::program_manager::file_to_string( const string_view& path )
     48{
     49        c_file_system fs;
     50        stream* fstream = open_stream( fs, path );
     51        if ( !fstream ) return const_string();
     52        uint32 size = fstream->size();
     53        const_string result( nullptr, size );
     54        fstream->read( const_cast<char*>( result.data() ), size, 1 );
     55        delete fstream;
     56        return result;
     57}
     58
    4759nv::string_buffer nv::program_manager::load_source( lua::table_guard& table, const string_view& append )
    4860{
     
    5163        if ( table.is_string( "files" ) )
    5264        {
    53                 out.append( fs.slurp( table.get_string( "files" ) ) );
     65                out.append( file_to_string( table.get_string( "files" ) ) );
    5466        }
    5567        else if ( table.is_table( "files" ) )
     
    6173                        const_string include( inctable.get<const_string,uint32>(i) );
    6274                        if ( i == count ) out.append( "#line 1\n" );
    63                         out.append( fs.slurp( include ) );
     75                        out.append( file_to_string( include ) );
    6476                }
    6577        }
     
    6779        if ( table.is_string( "file" ) )
    6880        {
    69                 const_string data = fs.slurp( table.get_string( "file" ) );
     81                const_string data = file_to_string( table.get_string( "file" ) );
    7082                out.append( "#line 1\n" + data );
    7183        }
  • trunk/src/gfx/image.cc

    r487 r505  
    9898        const uint8* data = idata->get_data();
    9999        size_t depth      = idata->get_depth();
     100        size_t cdepth     = m_depth > depth ? depth : m_depth;
    100101        uint32 dstride    = rsizex * depth;
    101102
     
    106107                {
    107108                        uint32 xy = pos + x * m_depth;
    108                         for( size_t e = 0; e < depth; ++e )
     109                        for( size_t e = 0; e < cdepth; ++e )
    109110                        {
    110111                                m_data[ xy + e ] = data[ y*dstride + x * depth + e ];
  • trunk/src/gl/gl_context.cc

    r503 r505  
    848848}
    849849
    850 
    851850nv::gl_context::~gl_context()
    852851{
  • trunk/src/gl/gl_device.cc

    r501 r505  
    145145{
    146146        unsigned glid = 0;
    147         unsigned glenum = buffer_type_to_enum( type );
    148147        glGenBuffers( 1, &glid );
    149148
  • trunk/src/gl/gl_window.cc

    r466 r505  
    99#include "nv/core/logging.hh"
    1010#include "nv/lib/gl.hh"
     11#include "nv/lib/sdl.hh"
    1112
    1213using namespace nv;
     
    3132        delete m_context;
    3233        m_context = nullptr;
    33         delete m_input;
    3434}
    3535
     
    4141
    4242        m_handle = handle;
     43        m_dc     = dc;
    4344
    4445        // TODO: error checking
     
    110111}
    111112
     113void nv::gl_window::make_current()
     114{
     115#if NV_PLATFORM == NV_WINDOWS
     116        HDC hdc = reinterpret_cast<HDC>( m_hwnd );
     117        dynwglMakeCurrent( hdc, reinterpret_cast<HGLRC>( m_context->get_native_handle() ) );
     118#endif
     119}
     120
     121nv::uint32 nv::gl_window::window_id()
     122{
     123        return SDL_GetWindowID( static_cast<SDL_Window*>( m_handle ) );
     124}
     125
  • trunk/src/lua/lua_state.cc

    r503 r505  
    201201}
    202202
    203 shash64 nv::lua::table_guard::get_string( string_view element, string_table& table, uint64 defval /*= 0 */ )
     203nv::shash64 nv::lua::table_guard::get_string( string_view element, string_table* table, uint64 defval /*= 0 */ )
    204204{
    205205        lua_getfield( m_state, -1, element.data() );
     
    210210        {
    211211                str = lua_tolstring( m_state, -1, &l );
    212                 result = table.insert( string_view( str, l ) );
    213         }
    214         lua_pop( m_state, 1 );
    215         return result;
    216 }
    217 
    218 nv::shash64 nv::lua::table_guard::get_string( string_view element, string_table* table, uint64 defval /*= 0 */ )
    219 {
    220         lua_getfield( m_state, -1, element.data() );
     212                string_view sv( str, l );
     213                result = table ? table->insert( sv ) : shash64( sv );
     214        }
     215        lua_pop( m_state, 1 );
     216        return result;
     217}
     218
     219shash64 nv::lua::table_guard::get_string_hash_64( int i, uint64 defval /*= 0 */ )
     220{
     221        lua_rawgeti( m_state, -1, i );
     222        size_t l = 0;
     223        const char* str = nullptr;
     224        uint64 result = defval;
     225        if ( lua_type( m_state, -1 ) == LUA_TSTRING )
     226        {
     227                str = lua_tolstring( m_state, -1, &l );
     228                result = hash_string< uint64 >( str, l );
     229                //NV_LOG_DEBUG( str );
     230        }
     231        lua_pop( m_state, 1 );
     232        return shash64( result );
     233}
     234
     235nv::string128 nv::lua::table_guard::get_string128( int i, string_view defval /*= string_view() */ )
     236{
     237        lua_rawgeti( m_state, -1, i );
     238        size_t l = 0;
     239        const char* str = nullptr;
     240        if ( lua_type( m_state, -1 ) == LUA_TSTRING )
     241        {
     242                str = lua_tolstring( m_state, -1, &l );
     243        }
     244        else
     245        {
     246                l = defval.size();
     247                str = defval.data();
     248        }
     249        string128 result( str, l );
     250        lua_pop( m_state, 1 );
     251        return result;
     252}
     253
     254const_string nv::lua::table_guard::get_string( int i, string_view defval /*= string_view() */ )
     255{
     256        lua_rawgeti( m_state, -1, i );
     257        size_t l = 0;
     258        const char* str = nullptr;
     259        if ( lua_type( m_state, -1 ) == LUA_TSTRING )
     260        {
     261                str = lua_tolstring( m_state, -1, &l );
     262        }
     263        else
     264        {
     265                l = defval.size();
     266                str = defval.data();
     267        }
     268        const_string result( str, l );
     269        lua_pop( m_state, 1 );
     270        return result;
     271}
     272
     273shash64 nv::lua::table_guard::get_string( int i, string_table* table, uint64 defval /*= 0 */ )
     274{
     275        lua_rawgeti( m_state, -1, i );
    221276        size_t l = 0;
    222277        const char* str = nullptr;
     
    302357}
    303358
     359char nv::lua::table_guard::get_char( int i, char defval /*= ' ' */ )
     360{
     361        lua_rawgeti( m_state, -1, i );
     362        char result = ( lua_type( m_state, -1 ) == LUA_TSTRING && nlua_rawlen( m_state, -1 ) > 0 ) ? lua_tostring( m_state, -1 )[0] : defval;
     363        lua_pop( m_state, 1 );
     364        return result;
     365}
     366
     367int nv::lua::table_guard::get_integer( int i, int defval /*= 0 */ )
     368{
     369        lua_rawgeti( m_state, -1, i );
     370        lua_Integer result = lua_type( m_state, -1 ) == LUA_TNUMBER ? lua_tointeger( m_state, -1 ) : defval;
     371        lua_pop( m_state, 1 );
     372        return static_cast<int>( result );
     373}
     374
     375unsigned nv::lua::table_guard::get_unsigned( int i, unsigned defval /*= 0 */ )
     376{
     377        lua_rawgeti( m_state, -1, i );
     378        unsigned result = lua_type( m_state, -1 ) == LUA_TNUMBER ? nlua_tounsigned( m_state, -1 ) : defval;
     379        lua_pop( m_state, 1 );
     380        return result;
     381}
     382
     383double nv::lua::table_guard::get_double( int i, double defval /*= 0.0 */ )
     384{
     385        lua_rawgeti( m_state, -1, i );
     386        double result = lua_type( m_state, -1 ) == LUA_TNUMBER ? lua_tonumber( m_state, -1 ) : defval;
     387        lua_pop( m_state, 1 );
     388        return result;
     389}
     390
     391float nv::lua::table_guard::get_float( int i, float defval /*= 0.0 */ )
     392{
     393        lua_rawgeti( m_state, -1, i );
     394        float result = lua_type( m_state, -1 ) == LUA_TNUMBER ? static_cast<float>( lua_tonumber( m_state, -1 ) ) : defval;
     395        lua_pop( m_state, 1 );
     396        return result;
     397}
     398
     399bool nv::lua::table_guard::get_boolean( int i, bool defval /*= false */ )
     400{
     401        lua_rawgeti( m_state, -1, i );
     402        bool result = lua_type( m_state, -1 ) == LUA_TBOOLEAN ? lua_toboolean( m_state, -1 ) != 0 : defval;
     403        lua_pop( m_state, 1 );
     404        return result;
     405}
     406
    304407float nv::lua::table_guard::get_float( string_view element, float defval /*= 0.0 */ )
    305408{
     
    326429}
    327430
     431bool nv::lua::table_guard::is_table( int i )
     432{
     433        lua_rawgeti( m_state, -1, i );
     434        bool result = lua_type( m_state, -1 ) == LUA_TTABLE;
     435        lua_pop( m_state, 1 );
     436        return result;
     437}
     438
     439bool nv::lua::table_guard::is_number( int i )
     440{
     441        lua_rawgeti( m_state, -1, i );
     442        bool result = lua_type( m_state, -1 ) == LUA_TNUMBER;
     443        lua_pop( m_state, 1 );
     444        return result;
     445}
     446
     447bool nv::lua::table_guard::is_boolean( int i )
     448{
     449        lua_rawgeti( m_state, -1, i );
     450        bool result = lua_type( m_state, -1 ) == LUA_TBOOLEAN;
     451        lua_pop( m_state, 1 );
     452        return result;
     453}
     454
     455bool nv::lua::table_guard::is_string( int i )
     456{
     457        lua_rawgeti( m_state, -1, i );
     458        bool result = lua_type( m_state, -1 ) == LUA_TSTRING;
     459        lua_pop( m_state, 1 );
     460        return result;
     461}
     462
    328463bool nv::lua::table_guard::is_number( string_view element )
    329464{
     
    349484        return result;
    350485}
    351 
    352486
    353487bool nv::lua::table_guard::read( const string_view& element, const type_entry* entry, void* object )
  • trunk/src/sdl/sdl_input.cc

    r406 r505  
    2020static bool sdl_key_event_to_io_event( const SDL_KeyboardEvent& ke, io_event& kevent )
    2121{
    22         kevent.type        = EV_KEY;
    23         kevent.key.pressed = ( ke.state != SDL_RELEASED );
    24         kevent.key.ascii   = 0;
    25         kevent.key.code    = KEY_NONE;
     22        kevent.type          = EV_KEY;
     23        kevent.key.window_id = ke.windowID;
     24        kevent.key.pressed   = ( ke.state != SDL_RELEASED );
     25        kevent.key.ascii     = 0;
     26        kevent.key.code      = KEY_NONE;
    2627
    2728        uint32 ucode = static_cast<uint32>( ke.keysym.sym );
     
    107108static bool sdl_mouse_button_to_io_event( const SDL_MouseButtonEvent& mb, io_event& mevent )
    108109{
    109         mevent.type            = EV_MOUSE_BUTTON;
    110         mevent.mbutton.button  = MOUSE_NONE;
    111         mevent.mbutton.pressed = (mb.state != SDL_RELEASED);
    112         mevent.mbutton.x       = static_cast< uint16 >( mb.x );
    113         mevent.mbutton.y       = static_cast< uint16 >( mb.y );
     110        mevent.type              = EV_MOUSE_BUTTON;
     111        mevent.mbutton.window_id = mb.windowID;
     112        mevent.mbutton.button    = MOUSE_NONE;
     113        mevent.mbutton.pressed   = (mb.state != SDL_RELEASED);
     114        mevent.mbutton.x         = static_cast< uint16 >( mb.x );
     115        mevent.mbutton.y         = static_cast< uint16 >( mb.y );
    114116
    115117        switch ( mb.button )
     
    126128static bool sdl_mouse_wheel_to_io_event( const SDL_MouseWheelEvent& mm, io_event& mevent )
    127129{
    128         mevent.type          = EV_MOUSE_WHEEL;
    129         mevent.mwheel.x      = static_cast< sint32 >( mm.x );
    130         mevent.mwheel.y      = static_cast< sint32 >( mm.y );
     130        mevent.type             = EV_MOUSE_WHEEL;
     131        mevent.mwheel.window_id = mm.windowID;
     132        mevent.mwheel.x         = static_cast< sint32 >( mm.x );
     133        mevent.mwheel.y         = static_cast< sint32 >( mm.y );
    131134        return true;
    132135}
     
    134137static bool sdl_mouse_motion_to_io_event( const SDL_MouseMotionEvent& mm, io_event& mevent )
    135138{
    136         mevent.type          = EV_MOUSE_MOVE;
    137         mevent.mmove.pressed = (mm.state != SDL_RELEASED);
    138         mevent.mmove.x       = static_cast< uint16 >( mm.x );
    139         mevent.mmove.y       = static_cast< uint16 >( mm.y );
    140         mevent.mmove.rx      = static_cast< sint16 >( mm.xrel );
    141         mevent.mmove.ry      = static_cast< sint16 >( mm.yrel );
     139        mevent.type            = EV_MOUSE_MOVE;
     140        mevent.mmove.window_id = mm.windowID;
     141        mevent.mmove.pressed   = (mm.state != SDL_RELEASED);
     142        mevent.mmove.x         = static_cast< uint16 >( mm.x );
     143        mevent.mmove.y         = static_cast< uint16 >( mm.y );
     144        mevent.mmove.rx        = static_cast< sint16 >( mm.xrel );
     145        mevent.mmove.ry        = static_cast< sint16 >( mm.yrel );
    142146        return true;
    143147}
     
    222226        case SDL_VIDEOEXPOSE     : return false;
    223227*/
     228        case SDL_WINDOWEVENT_ENTER: ioevent.type = EV_SYSTEM; ioevent.system.param1 = 1; ioevent.system.param1 = e.window.windowID; return true;
     229        case SDL_WINDOWEVENT_LEAVE: ioevent.type = EV_SYSTEM; ioevent.system.param1 = 0; ioevent.system.param1 = e.window.windowID; return true;
    224230        case SDL_SYSWMEVENT      : ioevent.type = EV_SYSTEM; return true;
    225231        case SDL_QUIT            : ioevent.type = EV_QUIT;   return true;
  • trunk/src/sdl/sdl_window.cc

    r492 r505  
    133133        SDL_GL_SetSwapInterval( enabled ? 1 : 0 );
    134134}
     135
     136void nv::sdl::window::make_current()
     137{
     138        SDL_GLContext native = static_cast<SDL_GLContext>( m_context->get_native_handle() );
     139        SDL_GL_MakeCurrent( static_cast<SDL_Window*>( m_handle ), native );
     140}
     141
     142nv::uint32 nv::sdl::window::window_id()
     143{
     144        return SDL_GetWindowID( static_cast<SDL_Window*>( m_handle ) );
     145}
  • trunk/src/sdl/sdl_window_manager.cc

    r395 r505  
    1717sdl::window_manager::window_manager()
    1818{
     19        primal_window = nullptr;
    1920        nv::load_sdl_library();
    2021
     
    2930{
    3031        if ( ! SDL_WasInit( SDL_INIT_VIDEO ) ) SDL_InitSubSystem( SDL_INIT_VIDEO );
    31         return new sdl::window( dev, width, height, fullscreen );
     32        sdl::window* result = new sdl::window( dev, width, height, fullscreen );
     33        primal_window = result->get_handle();
     34        return result;
    3235}
    3336
     
    3538{
    3639        if ( ! SDL_WasInit( SDL_INIT_VIDEO ) ) SDL_InitSubSystem( SDL_INIT_VIDEO );
    37         return SDL_CreateWindowFrom( sys_w_handle );
     40        if ( primal_window )
     41        {
     42                char buffer[128];
     43                sprintf( buffer, "%p", primal_window );
     44                NV_ASSERT( SDL_SetHint( "SDL_VIDEO_WINDOW_SHARE_PIXEL_FORMAT", buffer ) == SDL_TRUE );
     45        }
     46        primal_window = SDL_CreateWindowFrom( sys_w_handle );
     47        return primal_window;
    3848}
    3949
  • trunk/src/wx/wx_canvas.cc

    r470 r505  
    1313wxEND_EVENT_TABLE()
    1414
    15 nv::wx_gl_canvas::wx_gl_canvas( wxWindow *parent )
     15nv::wx_gl_canvas::wx_gl_canvas( wxWindow *parent, input* in )
    1616        : wxWindow( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
    1717        wxFULL_REPAINT_ON_RESIZE )
     
    1919        nv::load_gl_no_context();
    2020        wxClientDC dc( this );
     21        m_render  = true;
     22        m_wm      = new nv::sdl::window_manager;
     23        m_device  = new nv::gl_device();
     24        if ( !in ) in = new nv::sdl::input;
     25        m_window = new nv::gl_window( m_device, m_wm, in, GetHWND(), dc.GetHDC() );
     26        m_context = m_window->get_context();
     27        m_main    = true;
     28}
     29
     30nv::wx_gl_canvas::wx_gl_canvas( wxWindow *parent, wx_gl_canvas *sibling, input* in )
     31        : wxWindow( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
     32                wxFULL_REPAINT_ON_RESIZE )
     33{
     34        wxClientDC dc( this );
    2135        m_render = true;
    22         m_wm = new nv::sdl::window_manager;
     36        m_wm = sibling->m_wm;
    2337        m_device = new nv::gl_device();
    24         m_window = new nv::gl_window( m_device, m_wm, new nv::sdl::input(), GetHWND(), dc.GetHDC() );
     38        if ( !in ) in = new nv::sdl::input;
     39        m_window = new nv::gl_window( m_device, m_wm, in, GetHWND(), dc.GetHDC() );
    2540        m_context = m_window->get_context();
     41        make_current();
     42        m_main = false;
     43
    2644}
    2745
    2846nv::wx_gl_canvas::~wx_gl_canvas()
    2947{
     48        make_current();
    3049        delete m_window;
    3150        delete m_device;
     
    3453void nv::wx_gl_canvas::on_paint( wxPaintEvent& )
    3554{
     55        make_current();
    3656        const wxSize client_size = GetClientSize();
    3757        m_context->set_viewport( nv::ivec4( nv::ivec2(), client_size.x, client_size.y ) );
     
    5373void nv::wx_gl_canvas::on_idle( wxIdleEvent& evt )
    5474{
    55         nv::sleep( 10 );
     75        nv::sleep( 1 );
    5676        if ( m_render )
    5777        {
     78                make_current();
    5879                on_update();
    5980                evt.RequestMore(); // render continuously, not only once on idle
    6081        }
     82}
     83
     84void nv::wx_gl_canvas::make_current()
     85{
     86        m_window->make_current();
    6187}
    6288
Note: See TracChangeset for help on using the changeset viewer.