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_context.cc

    r233 r245  
    362362
    363363
    364 gl_context::gl_context( device* a_device, void* a_win_handle )
    365         : context( a_device ), m_handle( nullptr )
     364gl_context::gl_context( device* a_device )
     365        : context( a_device )
     366{
     367}
     368
     369
     370nv::gl_context::~gl_context()
     371{
     372}
     373
     374
     375void gl_context::draw( primitive prim, const render_state& rs, program* p, vertex_array* va, size_t count )
     376{
     377        apply_render_state( rs );
     378        if ( count > 0 )
     379        {
     380                p->bind();
     381                va->bind();
     382                if ( va->has_index_buffer() )
     383                {
     384                        glDrawElements( primitive_to_enum(prim), static_cast<GLsizei>( count ), datatype_to_gl_enum( va->get_index_buffer_type() ), 0 );
     385                }
     386                else
     387                {
     388                        glDrawArrays( primitive_to_enum(prim), 0, static_cast<GLsizei>( count ) );
     389                }
     390                va->unbind();
     391                p->unbind();
     392        }
     393}
     394
     395nv::sdl_gl_context::sdl_gl_context( device* a_device, void* a_sdl_win_handle )
     396        : gl_context( a_device ), m_handle( nullptr )
    366397{
    367398#if NV_SDL_VERSION == NV_SDL_20
    368         m_handle = SDL_GL_CreateContext( static_cast<SDL_Window*>( a_win_handle ) );
     399        m_handle = SDL_GL_CreateContext( static_cast<SDL_Window*>( a_sdl_win_handle ) );
    369400
    370401        if ( m_handle == 0 )
     
    384415        NV_LOG( LOG_INFO, "OpenGL GLSL Version : " << glGetString(GL_SHADING_LANGUAGE_VERSION) );
    385416#if NV_SDL_VERSION == NV_SDL_20
    386 //      SDL_GL_SetSwapInterval(1);
     417        //      SDL_GL_SetSwapInterval(1);
    387418#endif
    388419
     
    393424}
    394425
    395 
    396 nv::gl_context::~gl_context()
     426nv::sdl_gl_context::~sdl_gl_context()
    397427{
    398428#if NV_SDL_VERSION == NV_SDL_20
     
    401431}
    402432
    403 
    404 void gl_context::draw( primitive prim, const render_state& rs, program* p, vertex_array* va, size_t count )
    405 {
    406         apply_render_state( rs );
    407         if ( count > 0 )
    408         {
    409                 p->bind();
    410                 va->bind();
    411                 if ( va->has_index_buffer() )
    412                 {
    413                         glDrawElements( primitive_to_enum(prim), static_cast<GLsizei>( count ), datatype_to_gl_enum( va->get_index_buffer_type() ), 0 );
    414                 }
    415                 else
    416                 {
    417                         glDrawArrays( primitive_to_enum(prim), 0, static_cast<GLsizei>( count ) );
    418                 }
    419                 va->unbind();
    420                 p->unbind();
    421         }
    422 }
     433nv::native_gl_context::native_gl_context( device* a_device, void* a_native_win_handle )
     434        : gl_context( a_device ), m_handle( nullptr )
     435{
     436#if NV_PLATFORM == NV_WINDOWS
     437
     438// TODO: error checking
     439        HDC hdc = (HDC)a_native_win_handle;
     440
     441        const int wgl_attrib_list[] =
     442        {
     443                WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
     444                WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
     445                WGL_ACCELERATION_ARB,   WGL_FULL_ACCELERATION_ARB,
     446                WGL_DOUBLE_BUFFER_ARB,  GL_TRUE,
     447                WGL_PIXEL_TYPE_ARB,     WGL_TYPE_RGBA_ARB,
     448                WGL_COLOR_BITS_ARB,     32,
     449                WGL_DEPTH_BITS_ARB,     24,
     450                WGL_STENCIL_BITS_ARB,   8,
     451                0, 0  //End
     452        };
     453
     454        unsigned int num_formats;
     455        int pixel_format;
     456        PIXELFORMATDESCRIPTOR pfd;
     457
     458        if ( FALSE == wglChoosePixelFormatARB(hdc, wgl_attrib_list, NULL, 1, &pixel_format, &num_formats) )
     459        {
     460                return;
     461        }
     462
     463        if ( FALSE == SetPixelFormat(hdc, pixel_format, &pfd) )
     464        {
     465                //int err = GetLastError();
     466                return;
     467        }
     468
     469        int attribs[] =
     470        {
     471                WGL_CONTEXT_MAJOR_VERSION_ARB,   2,
     472                WGL_CONTEXT_MINOR_VERSION_ARB,   1,
     473                WGL_CONTEXT_PROFILE_MASK_ARB,  WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
     474                //WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
     475                0, 0  //End
     476        };
     477
     478        HGLRC handle;
     479        if ( 0 == (handle = wglCreateContextAttribsARB(hdc, 0, attribs) ) )
     480        {
     481                return;
     482        }
     483
     484        if ( FALSE == dynwglMakeCurrent( hdc, handle ) )
     485        {
     486                return;
     487        }     
     488
     489        m_handle = (void*)handle;
     490#else
     491        NV_ASSERT( false, "Native GL context not implemented for this platform!" );
     492#endif
     493        force_apply_render_state( m_render_state );
     494}
     495
     496nv::native_gl_context::~native_gl_context()
     497{
     498#if NV_PLATFORM == NV_WINDOWS
     499        dynwglDeleteContext( (HGLRC)m_handle );
     500#endif
     501}
Note: See TracChangeset for help on using the changeset viewer.