Changeset 326
- Timestamp:
- 08/26/14 18:39:10 (11 years ago)
- Location:
- trunk
- Files:
-
- 5 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/gl/gl_context.hh
r319 r326 24 24 class gl_context : public context 25 25 { 26 protected:27 gl_context( device* a_device );28 26 public: 29 ~gl_context(); 27 gl_context( device* a_device, void* a_handle ); 28 virtual ~gl_context(); 30 29 31 30 virtual vertex_array create_vertex_array(); … … 48 47 virtual void apply_render_state( const render_state& state ); 49 48 virtual void apply_engine_uniforms( program p, const scene_state& s ); 49 // TODO: remove 50 void* get_native_handle() { return m_handle; } 50 51 51 52 protected: … … 79 80 float m_clear_depth; 80 81 int m_clear_stencil; 82 void* m_handle; 81 83 82 84 entity_store< vertex_array_info, vertex_array > m_vertex_arrays; 83 85 entity_store< gl_framebuffer_info, framebuffer > m_framebuffers; 84 };85 86 class sdl_gl_context : public gl_context87 {88 public:89 sdl_gl_context( device* a_device, void* a_sdl_win_handle );90 ~sdl_gl_context();91 private:92 void* m_handle;93 };94 95 class native_gl_context : public gl_context96 {97 public:98 native_gl_context( device* a_device, void* a_native_win_handle );99 void* get_native_handle() { return m_handle; }100 ~native_gl_context();101 private:102 void* m_handle;103 86 }; 104 87 -
trunk/nv/gl/gl_device.hh
r319 r326 40 40 41 41 gl_device(); 42 virtual window* create_window( uint16 width, uint16 height, bool fullscreen );43 virtual window* adopt_window( void* sys_w_handle, void* sys_dc );44 42 virtual image_data* create_image_data( const std::string& filename ); // temporary 45 43 … … 47 45 virtual buffer create_buffer( buffer_type type, buffer_hint hint, size_t size, const void* source = nullptr ); 48 46 virtual texture create_texture( ivec2 size, image_format aformat, sampler asampler, void* data = nullptr ); 49 virtual uint32 get_ticks();50 virtual void delay( uint32 ms );51 47 52 48 virtual void release( buffer b ); … … 71 67 bool compile( uint32 sh_type, const std::string& shader_code, unsigned& glid ); 72 68 std::string m_shader_header; 73 const void* m_info;74 69 entity_store< gl_texture_info, texture > m_textures; 75 70 entity_store< gl_buffer_info, buffer > m_buffers; -
trunk/nv/gl/gl_window.hh
r319 r326 14 14 15 15 #include <nv/interface/window.hh> 16 #include <nv/interface/window_manager.hh> 17 #include <nv/interface/input.hh> 16 18 #include <nv/gl/gl_context.hh> 17 19 … … 22 24 { 23 25 public: 24 gl_window( device* dev, uint16 width, uint16 height, bool fullscreen = false);25 gl_window( device* dev, void* handle, void* dc );26 uint16 get_width() const;27 uint16 get_height() const;28 string get_title() const;29 v oid set_title( const string& title );30 virtual bool is_event_pending();31 virtual bool poll_event( io_event& event );32 virtual context* get_context() { return m_context; }33 virtual device* get_device() { return m_device; } 26 gl_window( device* dev, window_manager* wm, input* a_input, void* handle, void* dc ); 27 virtual void set_title( const string& ) {} 28 virtual context* get_context() { return m_context; } 29 virtual device* get_device() { return m_device; } 30 virtual uint16 get_width() const { return m_width; } 31 virtual uint16 get_height() const { return m_height; } 32 virtual string get_title() const { return std::string(); } 33 virtual bool is_event_pending() { return m_input->is_event_pending(); } 34 virtual bool poll_event( io_event& event ) { return m_input->poll_event( event ); } 35 34 36 virtual void swap_buffers(); 35 37 virtual ~gl_window(); 36 38 private: 39 input* m_input; 37 40 device* m_device; 38 41 uint16 m_width; 39 42 uint16 m_height; 40 string m_title;41 43 void* m_handle; 42 44 void* m_hwnd; 43 bool m_adopted;44 45 gl_context* m_context; 45 46 -
trunk/nv/interface/device.hh
r323 r326 130 130 initialize_engine_uniforms(); 131 131 } 132 virtual window* create_window( uint16 width, uint16 height, bool fullscreen ) = 0;133 virtual window* adopt_window( void* sys_w_handle, void* sys_dc ) = 0;134 132 virtual program create_program( const string& vs_source, const string& fs_source ) = 0; 135 133 virtual buffer create_buffer( buffer_type type, buffer_hint hint, size_t size, const void* source = nullptr ) = 0; 134 virtual texture create_texture( ivec2 size, image_format aformat, sampler asampler, void* data = nullptr ) = 0; 136 135 virtual image_data* create_image_data( const std::string& filename ) = 0; // temporary 137 virtual texture create_texture( ivec2 size, image_format aformat, sampler asampler, void* data = nullptr ) = 0;138 136 virtual void release( texture ) = 0; 139 137 virtual void release( buffer ) = 0; … … 141 139 virtual const texture_info* get_texture_info( texture ) const = 0; 142 140 virtual const buffer_info* get_buffer_info( buffer ) const = 0; 143 virtual uint32 get_ticks() = 0;144 virtual void delay( uint32 ms ) = 0;145 141 virtual const string& get_shader_header() const = 0; 146 142 -
trunk/nv/interface/window.hh
r319 r326 10 10 */ 11 11 12 #ifndef NV_ GUI_WINDOW_HH13 #define NV_ GUI_WINDOW_HH12 #ifndef NV_WINDOW_HH 13 #define NV_WINDOW_HH 14 14 15 15 #include <nv/core/common.hh> … … 21 21 class context; 22 22 class device; 23 23 24 class window 24 25 { … … 39 40 40 41 41 #endif // NV_ GUI_WINDOW_HH42 #endif // NV_WINDOW_HH -
trunk/nv/lib/detail/sdl_image_functions.inc
r325 r326 21 21 NV_SDL_FUN( SDL_Surface *, IMG_LoadTIF_RW, (SDL_RWops *src) ); 22 22 23 #if NV_SDL_VERSION == NV_SDL_2024 23 NV_SDL_FUN( int , IMG_SavePNG,(SDL_Surface *surface, const char *file) ); 25 24 NV_SDL_FUN( int , IMG_SavePNG_RW,(SDL_Surface *surface, SDL_RWops *dst, int freedst) ); … … 28 27 NV_SDL_FUN( SDL_Texture *, IMG_LoadTextureTyped_RW,(SDL_Renderer *renderer, SDL_RWops *src, int freesrc, const char *type) ); 29 28 NV_SDL_FUN( SDL_Surface *, IMG_LoadTyped_RW, (SDL_RWops *src, int freesrc, const char *etype) ); 30 #else31 NV_SDL_FUN( SDL_Surface *, IMG_LoadTyped_RW, (SDL_RWops *src, int freesrc, char *etype) );32 #endif -
trunk/nv/lib/wx.hh
r323 r326 22 22 #include <nv/lib/gl.hh> 23 23 #include <nv/gl/gl_device.hh> 24 #include <nv/gl/gl_window.hh> 25 #include <nv/sdl/sdl_input.hh> 26 #include <nv/sdl/sdl_window_manager.hh> 24 27 #include <nv/interface/context.hh> 25 28 #include <nv/interface/window.hh> … … 56 59 void OnPaint( wxPaintEvent& event ); 57 60 58 nv::device* m_device; 59 nv::context* m_context; 60 nv::window* m_window; 61 nv::window_manager* m_wm; 62 nv::device* m_device; 63 nv::context* m_context; 64 nv::window* m_window; 61 65 //wxTimer* m_update_timer; 62 bool m_render;66 bool m_render; 63 67 wxDECLARE_EVENT_TABLE(); 64 68 }; … … 84 88 nv::load_gl_no_context(); 85 89 wxClientDC dc(this); 90 m_wm = new nv::sdl::window_manager; 86 91 m_device = new nv::gl_device(); 87 m_window = m_device->adopt_window(GetHWND(), dc.GetHDC() );92 m_window = new nv::gl_window( m_device, m_wm, new nv::sdl::input(), GetHWND(), dc.GetHDC() ); 88 93 m_context = m_window->get_context(); 89 94 } -
trunk/src/gl/gl_context.cc
r319 r326 7 7 #include "nv/gl/gl_enum.hh" 8 8 #include "nv/lib/gl.hh" 9 #include "nv/lib/sdl.hh"10 9 #include "nv/gl/gl_device.hh" 11 10 … … 577 576 578 577 579 gl_context::gl_context( device* a_device ) 580 : context( a_device ) 581 { 578 gl_context::gl_context( device* a_device, void* a_handle ) 579 : context( a_device ), m_handle( a_handle ) 580 { 581 force_apply_render_state( m_render_state ); 582 582 } 583 583 … … 623 623 } 624 624 } 625 626 nv::sdl_gl_context::sdl_gl_context( device* a_device, void* a_sdl_win_handle )627 : gl_context( a_device ), m_handle( nullptr )628 {629 #if NV_SDL_VERSION == NV_SDL_20630 m_handle = SDL_GL_CreateContext( static_cast<SDL_Window*>( a_sdl_win_handle ) );631 632 if ( m_handle == 0 )633 {634 NV_LOG( LOG_CRITICAL, "GL Context creation failed: " << SDL_GetError( ) );635 return; // TODO: Error report636 }637 #else638 NV_UNUSED( a_win_handle );639 NV_UNUSED( m_handle );640 #endif641 642 nv::load_gl_library();643 NV_LOG( LOG_INFO, "OpenGL Vendor : " << glGetString(GL_VENDOR) );644 NV_LOG( LOG_INFO, "OpenGL Renderer : " << glGetString(GL_RENDERER) );645 NV_LOG( LOG_INFO, "OpenGL Version : " << glGetString(GL_VERSION) );646 NV_LOG( LOG_INFO, "OpenGL GLSL Version : " << glGetString(GL_SHADING_LANGUAGE_VERSION) );647 #if NV_SDL_VERSION == NV_SDL_20648 // SDL_GL_SetSwapInterval(1);649 #endif650 651 // TODO: do we really need this?652 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );653 654 force_apply_render_state( m_render_state );655 }656 657 nv::sdl_gl_context::~sdl_gl_context()658 {659 #if NV_SDL_VERSION == NV_SDL_20660 SDL_GL_DeleteContext(static_cast<SDL_GLContext>( m_handle ) );661 #endif662 }663 664 nv::native_gl_context::native_gl_context( device* a_device, void* a_native_win_handle )665 : gl_context( a_device ), m_handle( nullptr )666 {667 #if NV_PLATFORM == NV_WINDOWS668 669 // TODO: error checking670 HDC hdc = (HDC)a_native_win_handle;671 672 const int wgl_attrib_list[] =673 {674 WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,675 WGL_SUPPORT_OPENGL_ARB, GL_TRUE,676 WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,677 WGL_DOUBLE_BUFFER_ARB, GL_TRUE,678 WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,679 WGL_COLOR_BITS_ARB, 32,680 WGL_DEPTH_BITS_ARB, 24,681 WGL_STENCIL_BITS_ARB, 8,682 0, 0 //End683 };684 685 unsigned int num_formats;686 int pixel_format;687 PIXELFORMATDESCRIPTOR pfd;688 689 if ( FALSE == wglChoosePixelFormatARB(hdc, wgl_attrib_list, NULL, 1, &pixel_format, &num_formats) )690 {691 return;692 }693 694 if ( FALSE == SetPixelFormat(hdc, pixel_format, &pfd) )695 {696 //int err = GetLastError();697 return;698 }699 700 int attribs[] =701 {702 WGL_CONTEXT_MAJOR_VERSION_ARB, 2,703 WGL_CONTEXT_MINOR_VERSION_ARB, 1,704 WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,705 //WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,706 0, 0 //End707 };708 709 HGLRC handle;710 if ( 0 == (handle = wglCreateContextAttribsARB(hdc, 0, attribs) ) )711 {712 return;713 }714 715 if ( FALSE == dynwglMakeCurrent( hdc, handle ) )716 {717 return;718 }719 720 load_gl_library( NV_GL_PATH, true );721 load_wgl_library( NV_GL_PATH, true );722 m_handle = (void*)handle;723 #else724 NV_ASSERT( false, "Native GL context not implemented for this platform!" );725 #endif726 force_apply_render_state( m_render_state );727 }728 729 nv::native_gl_context::~native_gl_context()730 {731 #if NV_PLATFORM == NV_WINDOWS732 dynwglDeleteContext( (HGLRC)m_handle );733 #endif734 } -
trunk/src/gl/gl_device.cc
r323 r326 7 7 #include "nv/gl/gl_window.hh" 8 8 #include "nv/core/logging.hh" 9 #include "nv/lib/sdl.hh"10 9 #include "nv/lib/sdl_image.hh" 11 10 #include "nv/gl/gl_enum.hh" … … 14 13 using namespace nv; 15 14 16 window* gl_device::create_window( uint16 width, uint16 height, bool fullscreen )17 {18 return new gl_window( this, width, height, fullscreen );19 }20 21 window* nv::gl_device::adopt_window( void* sys_w_handle, void* sys_dc )22 {23 return new gl_window( this, sys_w_handle, sys_dc );24 }25 26 27 28 15 gl_device::gl_device() 29 16 { 30 nv::load_sdl_library();31 m_info = NULL;32 33 if ( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_JOYSTICK ) < 0 )34 {35 NV_LOG( LOG_CRITICAL, "Video initialization failed: " << SDL_GetError( ) );36 return; // TODO: Error report37 }38 39 #if NV_SDL_VERSION == NV_SDL_1240 m_info = SDL_GetVideoInfo( );41 42 if ( !m_info )43 {44 NV_LOG( LOG_CRITICAL, "Video query failed: " << SDL_GetError( ) );45 return; // TODO: Error report46 }47 #endif48 49 17 m_shader_header = "#version 120\n"; 50 18 for ( auto& i : get_uniform_factory() ) … … 67 35 // this is a temporary function that will be removed once we find a way to 68 36 // pass binary file data around 69 image_data* nv::gl_device::create_image_data( const std::string& filename )37 image_data* gl_device::create_image_data( const std::string& filename ) 70 38 { 71 39 load_sdl_image_library(); … … 83 51 } 84 52 85 uint32 gl_device::get_ticks()86 {87 return SDL_GetTicks();88 }89 90 void gl_device::delay( uint32 ms )91 {92 return SDL_Delay( ms );93 }94 53 95 54 gl_device::~gl_device() … … 101 60 while ( m_programs.size() > 0 ) 102 61 release( m_programs.get_handle(0) ); 103 SDL_Quit();104 62 } 105 63 -
trunk/src/gl/gl_window.cc
r323 r326 7 7 #include "nv/core/logging.hh" 8 8 #include "nv/lib/gl.hh" 9 #include "nv/lib/sdl.hh"10 9 11 10 using namespace nv; 12 11 13 static bool sdl_key_event_to_io_event( const SDL_KeyboardEvent& ke, io_event& kevent )14 {15 kevent.type = EV_KEY;16 kevent.key.pressed = ( ke.state != SDL_RELEASED );17 kevent.key.ascii = 0;18 kevent.key.code = KEY_NONE;19 20 #if NV_SDL_VERSION == NV_SDL_2021 uint32 ucode = (uint32)ke.keysym.sym;22 #else23 uint32 ucode = (uint32)ke.keysym.unicode;24 #endif25 26 // if result is a typable char place it into the structure27 if (ucode >= 32 && ucode < 128 )28 {29 kevent.key.ascii = static_cast<char8>( ucode );30 #if NV_SDL_VERSION == NV_SDL_2031 if (ucode >= 'a' && ucode <= 'z')32 {33 int shifted = !!(ke.keysym.mod & KMOD_SHIFT);34 int capslock = !!(ke.keysym.mod & KMOD_CAPS);35 if ((shifted ^ capslock) != 0) {36 kevent.key.ascii = (char8)SDL_toupper((int)ucode);37 }38 }39 #endif40 }41 42 // Get the Key value from the SDL Keyboard event43 int result = ke.keysym.sym;44 45 // Check the control and shift states46 kevent.key.alt = (ke.keysym.mod & KMOD_ALT ) != 0;47 kevent.key.control = (ke.keysym.mod & KMOD_CTRL ) != 0;48 kevent.key.shift = (ke.keysym.mod & KMOD_SHIFT ) != 0;49 50 // if result is a typable char from the directly transformable ranges51 if ( ( result >= KEY_A && result <= KEY_Z ) ||52 ( result >= KEY_0 && result <= KEY_9 ) ||53 result == ' ' )54 {55 kevent.key.code = static_cast<key_code>(result);56 }57 58 // if result is a typable char from the a..z range59 if ( result >= KEY_A + 32 && result <= KEY_Z + 32 )60 {61 kevent.key.code = static_cast<key_code>(result - 32);62 }63 64 if ( result >= SDLK_F1 && result <= SDLK_F12 )65 {66 kevent.key.code = static_cast<key_code>(result - SDLK_F1 + KEY_F1 );67 }68 69 // other recognized codes70 switch ( result )71 {72 case SDLK_BACKSPACE : kevent.key.code = KEY_BACK; break;73 case SDLK_TAB : kevent.key.code = KEY_TAB; break;74 case SDLK_RETURN : kevent.key.code = KEY_ENTER; break;75 case SDLK_PAGEUP : kevent.key.code = KEY_PGUP; break;76 case SDLK_PAGEDOWN : kevent.key.code = KEY_PGDOWN; break;77 case SDLK_END : kevent.key.code = KEY_END; break;78 case SDLK_HOME : kevent.key.code = KEY_HOME; break;79 case SDLK_LEFT : kevent.key.code = KEY_LEFT; break;80 case SDLK_UP : kevent.key.code = KEY_UP; break;81 case SDLK_RIGHT : kevent.key.code = KEY_RIGHT; break;82 case SDLK_DOWN : kevent.key.code = KEY_DOWN; break;83 case SDLK_DELETE : kevent.key.code = KEY_DELETE; break;84 case SDLK_INSERT : kevent.key.code = KEY_INSERT; break;85 //case SDLK_KP5 : kevent.key.code = KEY_CENTER; break;86 case SDLK_ESCAPE : kevent.key.code = KEY_ESCAPE; break;87 case SDLK_QUOTE : kevent.key.code = KEY_QUOTE; break;88 case SDLK_COMMA : kevent.key.code = KEY_COMMA; break;89 case SDLK_MINUS : kevent.key.code = KEY_MINUS; break;90 case SDLK_PERIOD : kevent.key.code = KEY_PERIOD; break;91 case SDLK_SLASH : kevent.key.code = KEY_SLASH; break;92 case SDLK_SEMICOLON : kevent.key.code = KEY_SCOLON; break;93 case SDLK_LEFTBRACKET : kevent.key.code = KEY_LBRACKET; break;94 case SDLK_BACKSLASH : kevent.key.code = KEY_BSLASH; break;95 case SDLK_RIGHTBRACKET : kevent.key.code = KEY_RBRACKET; break;96 case SDLK_BACKQUOTE : kevent.key.code = KEY_BQUOTE; break;97 default : break;98 }99 100 // If key was understood by nv, then it's valid, otherwise ignored101 return kevent.key.ascii != 0 || kevent.key.code != 0;102 }103 104 static bool sdl_mouse_button_to_io_event( const SDL_MouseButtonEvent& mb, io_event& mevent )105 {106 mevent.type = EV_MOUSE_BUTTON;107 mevent.mbutton.button = MOUSE_NONE;108 mevent.mbutton.pressed = (mb.state != SDL_RELEASED);109 mevent.mbutton.x = static_cast< uint16 >( mb.x );110 mevent.mbutton.y = static_cast< uint16 >( mb.y );111 112 switch ( mb.button )113 {114 case SDL_BUTTON_LEFT : mevent.mbutton.button = MOUSE_LEFT; break;115 case SDL_BUTTON_MIDDLE : mevent.mbutton.button = MOUSE_MIDDLE; break;116 case SDL_BUTTON_RIGHT : mevent.mbutton.button = MOUSE_RIGHT; break;117 #if NV_SDL_VERSION == NV_SDL_12118 case SDL_BUTTON_WHEELUP :119 mevent.type = EV_MOUSE_WHEEL;120 mevent.mwheel.x = 0;121 mevent.mwheel.y = 3;122 return true;123 case SDL_BUTTON_WHEELDOWN :124 mevent.type = EV_MOUSE_WHEEL;125 mevent.mwheel.x = 0;126 mevent.mwheel.y = -3;127 return true;128 #endif129 default : break;130 }131 132 return mevent.mbutton.button != MOUSE_NONE;133 }134 135 #if NV_SDL_VERSION == NV_SDL_20136 static bool sdl_mouse_wheel_to_io_event( const SDL_MouseWheelEvent& mm, io_event& mevent )137 {138 mevent.type = EV_MOUSE_WHEEL;139 mevent.mwheel.x = static_cast< sint32 >( mm.x );140 mevent.mwheel.y = static_cast< sint32 >( mm.y );141 return true;142 }143 #endif144 145 static bool sdl_mouse_motion_to_io_event( const SDL_MouseMotionEvent& mm, io_event& mevent )146 {147 mevent.type = EV_MOUSE_MOVE;148 mevent.mmove.pressed = (mm.state != SDL_RELEASED);149 mevent.mmove.x = static_cast< uint16 >( mm.x );150 mevent.mmove.y = static_cast< uint16 >( mm.y );151 mevent.mmove.rx = static_cast< sint16 >( mm.xrel );152 mevent.mmove.ry = static_cast< sint16 >( mm.yrel );153 return true;154 }155 156 static bool sdl_joy_button_event_to_io_event( const SDL_JoyButtonEvent& jb, io_event& jevent )157 {158 jevent.type = EV_JOY_BUTTON;159 jevent.jbutton.id = jb.which;160 jevent.jbutton.button = jb.button;161 jevent.jbutton.pressed = (jb.type == SDL_PRESSED);162 return true;163 }164 165 static bool sdl_joy_axis_event_to_io_event( const SDL_JoyAxisEvent& ja, io_event& jevent )166 {167 jevent.type = EV_JOY_AXIS;168 jevent.jaxis.id = ja.which;169 jevent.jaxis.axis = ja.axis;170 jevent.jaxis.value = ja.value;171 return true;172 }173 174 static bool sdl_joy_hat_event_to_io_event( const SDL_JoyHatEvent& jh, io_event& jevent )175 {176 jevent.type = EV_JOY_HAT;177 jevent.jhat.id = jh.which;178 jevent.jhat.hat = jh.hat;179 jevent.jhat.value = jh.value;180 return true;181 }182 183 static bool sdl_joy_ball_event_to_io_event( const SDL_JoyBallEvent& jb, io_event& jevent )184 {185 jevent.type = EV_JOY_HAT;186 jevent.jball.id = jb.which;187 jevent.jball.ball = jb.ball;188 jevent.jball.rx = jb.xrel;189 jevent.jball.ry = jb.yrel;190 return true;191 }192 193 static bool sdl_event_to_io_event( const SDL_Event& e, io_event& ioevent )194 {195 switch ( e.type )196 {197 case SDL_KEYDOWN : return sdl_key_event_to_io_event( e.key, ioevent );198 case SDL_KEYUP : return sdl_key_event_to_io_event( e.key, ioevent );199 case SDL_MOUSEMOTION : return sdl_mouse_motion_to_io_event( e.motion, ioevent );200 case SDL_MOUSEBUTTONDOWN : return sdl_mouse_button_to_io_event( e.button, ioevent );201 case SDL_MOUSEBUTTONUP : return sdl_mouse_button_to_io_event( e.button, ioevent );202 #if NV_SDL_VERSION == NV_SDL_20203 case SDL_MOUSEWHEEL : return sdl_mouse_wheel_to_io_event( e.wheel, ioevent );204 #endif205 /* // SDL 2.0 incompatible206 case SDL_ACTIVEEVENT :207 ioevent.type = EV_ACTIVE;208 ioevent.active.gain = (e.active.gain != 0);209 return e.active.state == SDL_APPINPUTFOCUS;210 case SDL_VIDEORESIZE :211 ioevent.type = EV_RESIZE;212 ioevent.resize.x = e.resize.w;213 ioevent.resize.y = e.resize.h;214 return true;215 case SDL_NOEVENT : return false;216 case SDL_VIDEOEXPOSE : return false;217 */218 case SDL_SYSWMEVENT : ioevent.type = EV_SYSTEM; return true;219 case SDL_QUIT : ioevent.type = EV_QUIT; return true;220 case SDL_JOYAXISMOTION : return sdl_joy_axis_event_to_io_event( e.jaxis, ioevent );221 case SDL_JOYBALLMOTION : return sdl_joy_ball_event_to_io_event( e.jball, ioevent );222 case SDL_JOYHATMOTION : return sdl_joy_hat_event_to_io_event( e.jhat, ioevent );223 case SDL_JOYBUTTONDOWN : return sdl_joy_button_event_to_io_event( e.jbutton, ioevent );224 case SDL_JOYBUTTONUP : return sdl_joy_button_event_to_io_event( e.jbutton, ioevent );225 default : return false;226 }227 }228 229 230 gl_window::gl_window( device* dev, uint16 width, uint16 height, bool fullscreen )231 : m_device( dev ), m_width( width ), m_height( height ), m_title("NV Engine"), m_handle( nullptr ), m_hwnd( 0 ), m_adopted( false )232 {233 // bpp = m_info->vfmt->BitsPerPixel;234 235 SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );236 SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );237 SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );238 SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 24 );239 SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );240 241 // SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 1 );242 // SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, 4 );243 244 #if NV_SDL_VERSION == NV_SDL_20245 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);246 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);247 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);248 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);249 #endif250 251 252 #if NV_SDL_VERSION == NV_SDL_12253 uint32 flags = SDL_OPENGL;254 if (fullscreen) flags |= SDL_FULLSCREEN;255 m_handle = SDL_SetVideoMode( width, height, 32, flags );256 #elif NV_SDL_VERSION == NV_SDL_20257 uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN;258 if (fullscreen) flags |= SDL_WINDOW_FULLSCREEN;259 m_handle = SDL_CreateWindow("Nova Engine", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,260 width, height, flags );261 #endif262 if ( m_handle == 0 )263 {264 NV_LOG( LOG_CRITICAL, "Video mode set failed: " << SDL_GetError( ) );265 return; // TODO: Error report266 }267 268 // NV_LOG( LOG_INFO, "Joystick count : " << SDL_NumJoysticks() );269 // SDL_Joystick* j = SDL_JoystickOpen(0);270 // if (j)271 // {272 // NV_LOG( LOG_INFO, "Joystick Name: " << SDL_JoystickNameForIndex(0) );273 // NV_LOG( LOG_INFO, "Joystick Number of Axes: " << SDL_JoystickNumAxes(j));274 // NV_LOG( LOG_INFO, "Joystick Number of Buttons: " << SDL_JoystickNumButtons(j));275 // NV_LOG( LOG_INFO, "Joystick Number of Balls: " << SDL_JoystickNumBalls(j));276 // }277 278 279 m_context = new sdl_gl_context( m_device, m_handle );280 m_context->set_viewport( nv::ivec4( 0, 0, m_width, m_height ) );281 }282 283 uint16 gl_window::get_width() const284 {285 return m_width;286 }287 288 uint16 gl_window::get_height() const289 {290 return m_height;291 }292 293 string gl_window::get_title() const294 {295 return m_title;296 }297 298 void gl_window::set_title( const string& title )299 {300 if ( m_adopted ) return;301 #if NV_SDL_VERSION == NV_SDL_20302 SDL_SetWindowTitle( static_cast<SDL_Window*>( m_handle ), title.c_str() );303 #else304 SDL_WM_SetCaption( title.c_str(), title.c_str() );305 #endif306 m_title = title;307 }308 309 bool gl_window::is_event_pending()310 {311 return SDL_PollEvent( nullptr ) != 0;312 }313 314 bool gl_window::poll_event( io_event& event )315 {316 SDL_Event sdl_event;317 if ( SDL_PollEvent( &sdl_event ) == 0 ) return false;318 return sdl_event_to_io_event( sdl_event, event );319 }320 321 12 void gl_window::swap_buffers() 322 13 { 323 if ( m_adopted )324 {325 14 #if NV_PLATFORM == NV_WINDOWS 326 15 ::SwapBuffers( (HDC)m_hwnd ); 327 16 #else 328 NV_ASSERT( false, "Native GL context only working with SDL 2.0!" ); 329 #endif 330 331 } 332 #if NV_SDL_VERSION == NV_SDL_20 333 SDL_GL_SwapWindow( static_cast<SDL_Window*>( m_handle ) ); 334 #else 335 SDL_GL_SwapBuffers(); 17 NV_ASSERT( false, "Native GL context currently only working on Windows!" ); 336 18 #endif 337 19 } … … 339 21 gl_window::~gl_window() 340 22 { 23 if ( m_context ) 24 { 25 #if NV_PLATFORM == NV_WINDOWS 26 dynwglDeleteContext( (HGLRC)m_context->get_native_handle() ); 27 #endif 28 } 341 29 delete m_context; 342 #if NV_SDL_VERSION == NV_SDL_20 343 if ( !m_adopted ) SDL_DestroyWindow( static_cast<SDL_Window*>( m_handle ) ); 344 #endif 30 m_context = nullptr; 31 delete m_input; 345 32 } 346 33 347 nv::gl_window::gl_window( device* dev, void* handle, void* dc )348 : m_device( dev ), m_width( 0 ), m_height( 0 ), m_ title(), m_handle( nullptr ), m_adopted( true)34 nv::gl_window::gl_window( device* dev, window_manager* wm, input* a_input, void* handle, void* dc ) 35 : m_device( dev ), m_width( 0 ), m_height( 0 ), m_handle( nullptr ) 349 36 { 350 37 #if NV_PLATFORM == NV_WINDOWS 351 #if NV_SDL_VERSION == NV_SDL_20 352 m_context = new native_gl_context( m_device, dc ); 353 SDL_Window* window = SDL_CreateWindowFrom( handle ); 38 m_input = a_input; 39 40 m_handle = (void*)handle; 41 42 // TODO: error checking 43 HDC hdc = (HDC)dc; 44 45 const int wgl_attrib_list[] = 46 { 47 WGL_DRAW_TO_WINDOW_ARB, GL_TRUE, 48 WGL_SUPPORT_OPENGL_ARB, GL_TRUE, 49 WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB, 50 WGL_DOUBLE_BUFFER_ARB, GL_TRUE, 51 WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB, 52 WGL_COLOR_BITS_ARB, 32, 53 WGL_DEPTH_BITS_ARB, 24, 54 WGL_STENCIL_BITS_ARB, 8, 55 0, 0 //End 56 }; 57 58 unsigned int num_formats; 59 int pixel_format; 60 PIXELFORMATDESCRIPTOR pfd; 61 62 if ( FALSE == wglChoosePixelFormatARB(hdc, wgl_attrib_list, NULL, 1, &pixel_format, &num_formats) ) 63 { 64 return; 65 } 66 67 if ( FALSE == SetPixelFormat(hdc, pixel_format, &pfd) ) 68 { 69 //int err = GetLastError(); 70 return; 71 } 72 73 int attribs[] = 74 { 75 WGL_CONTEXT_MAJOR_VERSION_ARB, 2, 76 WGL_CONTEXT_MINOR_VERSION_ARB, 1, 77 WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, 78 //WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, 79 0, 0 //End 80 }; 81 82 HGLRC ctx_handle; 83 if ( 0 == (ctx_handle = wglCreateContextAttribsARB(hdc, 0, attribs) ) ) 84 { 85 return; 86 } 87 88 if ( FALSE == dynwglMakeCurrent( hdc, ctx_handle ) ) 89 { 90 return; 91 } 92 93 load_gl_library( NV_GL_PATH, true ); 94 load_wgl_library( NV_GL_PATH, true ); 95 96 m_context = new gl_context( m_device, ctx_handle ); 354 97 // Doesn't work :/ 355 98 // RECT rect; … … 357 100 // m_width = (uint16)rect.right; 358 101 // m_height = (uint16)rect.bottom; 359 m_handle = w indow;102 m_handle = wm->adopt_window( handle ); 360 103 m_hwnd = ::GetDC( (HWND)handle ); 361 104 m_context->set_viewport( nv::ivec4( 0, 0, m_width, m_height ) ); 362 #else363 NV_ASSERT( false, "Native GL context only working with SDL 2.0!" );364 #endif365 105 #else 366 106 NV_ASSERT( false, "Native GL context adoption not implemented for this platform!" ); 367 107 #endif 368 108 } 109 -
trunk/src/lib/sdl.cc
r319 r326 13 13 #define NV_SDL_FUN( rtype, fname, fparams ) rtype (NV_SDL_APIENTRY *fname) fparams = nullptr; 14 14 #include <nv/lib/detail/sdl_functions.inc> 15 #if NV_SDL_VERSION == NV_SDL_1216 # include <nv/lib/detail/sdl_functions_12.inc>17 #elif NV_SDL_VERSION == NV_SDL_2018 # include <nv/lib/detail/sdl_functions_20.inc>19 #endif20 15 #undef NV_SDL_FUN 21 22 23 16 24 17 bool nv::load_sdl_library( const char* path ) … … 29 22 # define NV_SDL_FUN( rtype, fname, fparams ) *(void **) (&fname) = sdl_library.get(#fname); 30 23 # include <nv/lib/detail/sdl_functions.inc> 31 # if NV_SDL_VERSION == NV_SDL_1232 # include <nv/lib/detail/sdl_functions_12.inc>33 # elif NV_SDL_VERSION == NV_SDL_2034 # include <nv/lib/detail/sdl_functions_20.inc>35 # endif36 24 # undef NV_SDL_FUN 37 25 return true;
Note: See TracChangeset
for help on using the changeset viewer.