Ignore:
Timestamp:
05/27/14 16:26:53 (11 years ago)
Author:
epyon
Message:
  • gl library wgl support
  • gl context and window adoption
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gl/gl_window.cc

    r243 r245  
    3434                        int capslock = !!(ke.keysym.mod & KMOD_CAPS);
    3535                        if ((shifted ^ capslock) != 0) {
    36                                 kevent.key.ascii = SDL_toupper(ucode);
     36                                kevent.key.ascii = (char8)SDL_toupper(ucode);
    3737                        }
    3838                }
     
    204204
    205205gl_window::gl_window( device* dev, uint16 width, uint16 height, bool fullscreen )
    206         : m_device( dev ), m_width( width ), m_height( height ), m_title("NV Engine"), m_handle( nullptr )
    207 {
     206        : m_device( dev ), m_width( width ), m_height( height ), m_title("NV Engine"), m_handle( nullptr ), m_adopted( false )
     207{
     208        //      bpp = m_info->vfmt->BitsPerPixel;
     209
     210        SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );
     211        SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );
     212        SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
     213        SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 24 );
     214        SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
     215
     216        //      SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 1 );
     217        //      SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, 4 );
     218
     219#if NV_SDL_VERSION == NV_SDL_20
     220        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
     221        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
     222        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
     223        SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
     224#endif
     225
     226
    208227#if NV_SDL_VERSION == NV_SDL_12
    209228        uint32 flags = SDL_OPENGL;
     
    233252
    234253
    235         m_context = new gl_context( m_device, m_handle );
     254        m_context = new sdl_gl_context( m_device, m_handle );
    236255        m_context->set_viewport( nv::ivec4( 0, 0, m_width, m_height ) );
    237256}
     
    254273void gl_window::set_title( const string& title )
    255274{
     275        if ( m_adopted ) return;
    256276#if NV_SDL_VERSION == NV_SDL_20
    257277        SDL_SetWindowTitle( static_cast<SDL_Window*>( m_handle ), title.c_str() );
     
    276296void gl_window::swap_buffers()
    277297{
     298        if ( m_adopted ) return; // NOT SURE
    278299#if NV_SDL_VERSION == NV_SDL_20
    279300        SDL_GL_SwapWindow( static_cast<SDL_Window*>( m_handle ) );
     
    287308        delete m_context;
    288309#if NV_SDL_VERSION == NV_SDL_20
    289         SDL_DestroyWindow( static_cast<SDL_Window*>( m_handle ) );
    290 #endif
    291 }
     310        if ( !m_adopted ) SDL_DestroyWindow( static_cast<SDL_Window*>( m_handle ) );
     311#endif
     312}
     313
     314nv::gl_window::gl_window( device* dev, void* handle, void* dc )
     315        : m_device( dev ), m_width( 0 ), m_height( 0 ), m_title(), m_handle( nullptr ), m_adopted( true )
     316{
     317#if NV_PLATFORM == NV_WINDOWS
     318#if NV_SDL_VERSION == NV_SDL_20
     319        nv::load_gl_no_context();
     320        m_context = new native_gl_context( m_device, dc );
     321        SDL_Window* window = SDL_CreateWindowFrom( handle );
     322        // Doesn't work :/
     323//      RECT rect;
     324//      GetClientRect( (HWND)handle, &rect );
     325//      m_width   = (uint16)rect.right;
     326//      m_height  = (uint16)rect.bottom;
     327        m_handle  = window;
     328        m_context->set_viewport( nv::ivec4( 0, 0, m_width, m_height ) );
     329#else
     330        NV_ASSERT( false, "Native GL context only working with SDL 2.0!" );
     331#endif
     332#else
     333        NV_ASSERT( false, "Native GL context adoption not implemented for this platform!" );
     334#endif
     335}
Note: See TracChangeset for help on using the changeset viewer.