- Timestamp:
- 07/12/16 20:22:23 (9 years ago)
- Location:
- trunk/src
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/io_event.cc
r487 r505 71 71 72 72 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 ); 79 80 80 81 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 ); 86 88 87 89 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 ); 94 97 95 98 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 ); 98 102 99 103 db->create_type<pad_button_event>() -
trunk/src/core/types.cc
r503 r505 3 3 #include "nv/interface/clear_state.hh" 4 4 #include "nv/interface/render_state.hh" 5 #include "nv/stl/string.hh" 5 6 6 7 using namespace nv; … … 26 27 db->create_type<ivec3>(); 27 28 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>(); 28 34 29 35 db->create_type<color_mask>() -
trunk/src/engine/image_manager.cc
r504 r505 12 12 using namespace nv; 13 13 14 void nv::image_manager::add_base_path( const string_view& path)14 bool image_manager::load_resource( const string_view& filename ) 15 15 { 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; 17 29 } 18 30 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 14 14 15 15 nv::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 ) 18 17 , m_image_manager( imgmgr ) 19 18 { … … 23 22 } 24 23 25 bool gpu_material_manager::load_resource( const string_view& id)24 nv::resource< nv::gpu_material > nv::gpu_material_manager::create_resource( resource< material > m ) 26 25 { 27 if ( auto mat = m_material_manager->get( id ).lock() ) 26 resource_id id = m.id(); 27 if ( auto mat = m.lock() ) 28 28 { 29 29 gpu_material* result = new gpu_material; … … 39 39 40 40 // 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 ); 47 46 } 48 return false;47 return resource< nv::gpu_material >(); 49 48 } 50 49 -
trunk/src/engine/mesh_manager.cc
r484 r505 6 6 7 7 #include "nv/engine/mesh_manager.hh" 8 #include "nv/formats/nmd_loader.hh" 9 #include "nv/io/c_file_system.hh" 8 10 9 11 using namespace nv; 10 12 11 resource< gpu_mesh > gpu_mesh_manager:: load_resource( resource< data_channel_set > mesh )13 resource< gpu_mesh > gpu_mesh_manager::create_resource( resource< data_channel_set > mesh ) 12 14 { 13 resource< gpu_mesh > result = get( mesh.id().value() );14 if ( result ) return result;15 15 if ( auto lmesh = mesh.lock() ) 16 16 { … … 24 24 } 25 25 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 40 26 void gpu_mesh_manager::release( gpu_mesh* m ) 41 27 { 42 28 m_context->release( m->va ); 43 29 } 30 31 nv::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 97 bool 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 45 45 } 46 46 47 nv::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 47 59 nv::string_buffer nv::program_manager::load_source( lua::table_guard& table, const string_view& append ) 48 60 { … … 51 63 if ( table.is_string( "files" ) ) 52 64 { 53 out.append( f s.slurp( table.get_string( "files" ) ) );65 out.append( file_to_string( table.get_string( "files" ) ) ); 54 66 } 55 67 else if ( table.is_table( "files" ) ) … … 61 73 const_string include( inctable.get<const_string,uint32>(i) ); 62 74 if ( i == count ) out.append( "#line 1\n" ); 63 out.append( f s.slurp( include ) );75 out.append( file_to_string( include ) ); 64 76 } 65 77 } … … 67 79 if ( table.is_string( "file" ) ) 68 80 { 69 const_string data = f s.slurp( table.get_string( "file" ) );81 const_string data = file_to_string( table.get_string( "file" ) ); 70 82 out.append( "#line 1\n" + data ); 71 83 } -
trunk/src/gfx/image.cc
r487 r505 98 98 const uint8* data = idata->get_data(); 99 99 size_t depth = idata->get_depth(); 100 size_t cdepth = m_depth > depth ? depth : m_depth; 100 101 uint32 dstride = rsizex * depth; 101 102 … … 106 107 { 107 108 uint32 xy = pos + x * m_depth; 108 for( size_t e = 0; e < depth; ++e )109 for( size_t e = 0; e < cdepth; ++e ) 109 110 { 110 111 m_data[ xy + e ] = data[ y*dstride + x * depth + e ]; -
trunk/src/gl/gl_context.cc
r503 r505 848 848 } 849 849 850 851 850 nv::gl_context::~gl_context() 852 851 { -
trunk/src/gl/gl_device.cc
r501 r505 145 145 { 146 146 unsigned glid = 0; 147 unsigned glenum = buffer_type_to_enum( type );148 147 glGenBuffers( 1, &glid ); 149 148 -
trunk/src/gl/gl_window.cc
r466 r505 9 9 #include "nv/core/logging.hh" 10 10 #include "nv/lib/gl.hh" 11 #include "nv/lib/sdl.hh" 11 12 12 13 using namespace nv; … … 31 32 delete m_context; 32 33 m_context = nullptr; 33 delete m_input;34 34 } 35 35 … … 41 41 42 42 m_handle = handle; 43 m_dc = dc; 43 44 44 45 // TODO: error checking … … 110 111 } 111 112 113 void 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 121 nv::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 201 201 } 202 202 203 shash64 nv::lua::table_guard::get_string( string_view element, string_table&table, uint64 defval /*= 0 */ )203 nv::shash64 nv::lua::table_guard::get_string( string_view element, string_table* table, uint64 defval /*= 0 */ ) 204 204 { 205 205 lua_getfield( m_state, -1, element.data() ); … … 210 210 { 211 211 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 219 shash64 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 235 nv::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 254 const_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 273 shash64 nv::lua::table_guard::get_string( int i, string_table* table, uint64 defval /*= 0 */ ) 274 { 275 lua_rawgeti( m_state, -1, i ); 221 276 size_t l = 0; 222 277 const char* str = nullptr; … … 302 357 } 303 358 359 char 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 367 int 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 375 unsigned 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 383 double 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 391 float 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 399 bool 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 304 407 float nv::lua::table_guard::get_float( string_view element, float defval /*= 0.0 */ ) 305 408 { … … 326 429 } 327 430 431 bool 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 439 bool 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 447 bool 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 455 bool 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 328 463 bool nv::lua::table_guard::is_number( string_view element ) 329 464 { … … 349 484 return result; 350 485 } 351 352 486 353 487 bool nv::lua::table_guard::read( const string_view& element, const type_entry* entry, void* object ) -
trunk/src/sdl/sdl_input.cc
r406 r505 20 20 static bool sdl_key_event_to_io_event( const SDL_KeyboardEvent& ke, io_event& kevent ) 21 21 { 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; 26 27 27 28 uint32 ucode = static_cast<uint32>( ke.keysym.sym ); … … 107 108 static bool sdl_mouse_button_to_io_event( const SDL_MouseButtonEvent& mb, io_event& mevent ) 108 109 { 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 ); 114 116 115 117 switch ( mb.button ) … … 126 128 static bool sdl_mouse_wheel_to_io_event( const SDL_MouseWheelEvent& mm, io_event& mevent ) 127 129 { 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 ); 131 134 return true; 132 135 } … … 134 137 static bool sdl_mouse_motion_to_io_event( const SDL_MouseMotionEvent& mm, io_event& mevent ) 135 138 { 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 ); 142 146 return true; 143 147 } … … 222 226 case SDL_VIDEOEXPOSE : return false; 223 227 */ 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; 224 230 case SDL_SYSWMEVENT : ioevent.type = EV_SYSTEM; return true; 225 231 case SDL_QUIT : ioevent.type = EV_QUIT; return true; -
trunk/src/sdl/sdl_window.cc
r492 r505 133 133 SDL_GL_SetSwapInterval( enabled ? 1 : 0 ); 134 134 } 135 136 void 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 142 nv::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 17 17 sdl::window_manager::window_manager() 18 18 { 19 primal_window = nullptr; 19 20 nv::load_sdl_library(); 20 21 … … 29 30 { 30 31 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; 32 35 } 33 36 … … 35 38 { 36 39 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; 38 48 } 39 49 -
trunk/src/wx/wx_canvas.cc
r470 r505 13 13 wxEND_EVENT_TABLE() 14 14 15 nv::wx_gl_canvas::wx_gl_canvas( wxWindow *parent )15 nv::wx_gl_canvas::wx_gl_canvas( wxWindow *parent, input* in ) 16 16 : wxWindow( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, 17 17 wxFULL_REPAINT_ON_RESIZE ) … … 19 19 nv::load_gl_no_context(); 20 20 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 30 nv::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 ); 21 35 m_render = true; 22 m_wm = new nv::sdl::window_manager;36 m_wm = sibling->m_wm; 23 37 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() ); 25 40 m_context = m_window->get_context(); 41 make_current(); 42 m_main = false; 43 26 44 } 27 45 28 46 nv::wx_gl_canvas::~wx_gl_canvas() 29 47 { 48 make_current(); 30 49 delete m_window; 31 50 delete m_device; … … 34 53 void nv::wx_gl_canvas::on_paint( wxPaintEvent& ) 35 54 { 55 make_current(); 36 56 const wxSize client_size = GetClientSize(); 37 57 m_context->set_viewport( nv::ivec4( nv::ivec2(), client_size.x, client_size.y ) ); … … 53 73 void nv::wx_gl_canvas::on_idle( wxIdleEvent& evt ) 54 74 { 55 nv::sleep( 1 0);75 nv::sleep( 1 ); 56 76 if ( m_render ) 57 77 { 78 make_current(); 58 79 on_update(); 59 80 evt.RequestMore(); // render continuously, not only once on idle 60 81 } 82 } 83 84 void nv::wx_gl_canvas::make_current() 85 { 86 m_window->make_current(); 61 87 } 62 88
Note: See TracChangeset
for help on using the changeset viewer.