Changeset 326 for trunk/src/gl/gl_context.cc
- Timestamp:
- 08/26/14 18:39:10 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.