Changeset View
Changeset View
Standalone View
Standalone View
intern/ghost/intern/GHOST_ContextWGL.cpp
| Show First 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | |||||
| GHOST_TSuccess GHOST_ContextWGL::swapBuffers() | GHOST_TSuccess GHOST_ContextWGL::swapBuffers() | ||||
| { | { | ||||
| return WIN32_CHK(::SwapBuffers(m_hDC)) ? GHOST_kSuccess : GHOST_kFailure; | return WIN32_CHK(::SwapBuffers(m_hDC)) ? GHOST_kSuccess : GHOST_kFailure; | ||||
| } | } | ||||
| GHOST_TSuccess GHOST_ContextWGL::setSwapInterval(int interval) | GHOST_TSuccess GHOST_ContextWGL::setSwapInterval(int interval) | ||||
| { | { | ||||
| if (WGLEW_EXT_swap_control) | if (epoxy_has_wgl_extension(m_hDC, "WGL_EXT_swap_control")) | ||||
| return WIN32_CHK(::wglSwapIntervalEXT(interval)) == TRUE ? GHOST_kSuccess : GHOST_kFailure; | return WIN32_CHK(::wglSwapIntervalEXT(interval)) == TRUE ? GHOST_kSuccess : GHOST_kFailure; | ||||
| else | else | ||||
| return GHOST_kFailure; | return GHOST_kFailure; | ||||
| } | } | ||||
| GHOST_TSuccess GHOST_ContextWGL::getSwapInterval(int &intervalOut) | GHOST_TSuccess GHOST_ContextWGL::getSwapInterval(int &intervalOut) | ||||
| { | { | ||||
| if (WGLEW_EXT_swap_control) { | if (epoxy_has_wgl_extension(m_hDC, "WGL_EXT_swap_control")) { | ||||
| intervalOut = ::wglGetSwapIntervalEXT(); | intervalOut = ::wglGetSwapIntervalEXT(); | ||||
| return GHOST_kSuccess; | return GHOST_kSuccess; | ||||
| } | } | ||||
| else { | else { | ||||
| return GHOST_kFailure; | return GHOST_kFailure; | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 154 Lines • ▼ Show 20 Lines | HWND hwndCloned = CreateWindowExW(dwExStyle, | ||||
| hInstance, | hInstance, | ||||
| lpParam); | lpParam); | ||||
| WIN32_CHK(hwndCloned != NULL); | WIN32_CHK(hwndCloned != NULL); | ||||
| return hwndCloned; | return hwndCloned; | ||||
| } | } | ||||
| void GHOST_ContextWGL::initContextWGLEW(PIXELFORMATDESCRIPTOR &preferredPFD) | static void makeAttribList(std::vector<int> &out, bool stereoVisual, bool needAlpha) | ||||
| { | { | ||||
| out.clear(); | |||||
| out.reserve(30); | |||||
| out.push_back(WGL_SUPPORT_OPENGL_ARB); | |||||
| out.push_back(GL_TRUE); | |||||
| out.push_back(WGL_DRAW_TO_WINDOW_ARB); | |||||
| out.push_back(GL_TRUE); | |||||
| out.push_back(WGL_DOUBLE_BUFFER_ARB); | |||||
| out.push_back(GL_TRUE); | |||||
| out.push_back(WGL_ACCELERATION_ARB); | |||||
| out.push_back(WGL_FULL_ACCELERATION_ARB); | |||||
| if (stereoVisual) { | |||||
| out.push_back(WGL_STEREO_ARB); | |||||
| out.push_back(GL_TRUE); | |||||
| } | |||||
| out.push_back(WGL_PIXEL_TYPE_ARB); | |||||
| out.push_back(WGL_TYPE_RGBA_ARB); | |||||
| out.push_back(WGL_COLOR_BITS_ARB); | |||||
| out.push_back(24); | |||||
| if (needAlpha) { | |||||
| out.push_back(WGL_ALPHA_BITS_ARB); | |||||
| out.push_back(8); | |||||
| } | |||||
| out.push_back(0); | |||||
| } | |||||
| /* Temporary context used to create the actual context. We need ARB pixel format | |||||
| * and context extensions, which are only available within a context. */ | |||||
| struct DummyContextWGL { | |||||
| HWND dummyHWND = NULL; | HWND dummyHWND = NULL; | ||||
| HDC dummyHDC = NULL; | HDC dummyHDC = NULL; | ||||
| HGLRC dummyHGLRC = NULL; | HGLRC dummyHGLRC = NULL; | ||||
| HDC prevHDC; | HDC prevHDC = NULL; | ||||
| HGLRC prevHGLRC; | HGLRC prevHGLRC = NULL; | ||||
| int iPixelFormat; | int dummyPixelFormat = 0; | ||||
| PIXELFORMATDESCRIPTOR preferredPFD; | |||||
| bool has_WGL_ARB_pixel_format = false; | |||||
| bool has_WGL_ARB_create_context = false; | |||||
| bool has_WGL_ARB_create_context_profile = false; | |||||
| bool has_WGL_ARB_create_context_robustness = false; | |||||
| DummyContextWGL(HDC hDC, HWND hWnd, bool stereoVisual, bool needAlpha) | |||||
| { | |||||
| preferredPFD = { | |||||
| sizeof(PIXELFORMATDESCRIPTOR), /* size */ | |||||
| 1, /* version */ | |||||
| (DWORD)(PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | | |||||
| PFD_DOUBLEBUFFER | /* support double-buffering */ | |||||
| (stereoVisual ? PFD_STEREO : 0) | /* support stereo */ | |||||
| ( | |||||
| #ifdef WIN32_COMPOSITING | |||||
| /* Support composition for transparent background. */ | |||||
| needAlpha ? PFD_SUPPORT_COMPOSITION : | |||||
| #endif | |||||
| 0)), | |||||
| PFD_TYPE_RGBA, /* color type */ | |||||
| (BYTE)(needAlpha ? 32 : 24), /* preferred color depth */ | |||||
| 0, | |||||
| 0, | |||||
| 0, | |||||
| 0, | |||||
| 0, | |||||
| 0, /* color bits (ignored) */ | |||||
| (BYTE)(needAlpha ? 8 : 0), /* alpha buffer */ | |||||
| 0, /* alpha shift (ignored) */ | |||||
| 0, /* no accumulation buffer */ | |||||
| 0, | |||||
| 0, | |||||
| 0, | |||||
| 0, /* accum bits (ignored) */ | |||||
| 0, /* depth buffer */ | |||||
| 0, /* stencil buffer */ | |||||
| 0, /* no auxiliary buffers */ | |||||
| PFD_MAIN_PLANE, /* main layer */ | |||||
| 0, /* reserved */ | |||||
| 0, | |||||
| 0, | |||||
| 0 /* layer, visible, and damage masks (ignored) */ | |||||
| }; | |||||
| SetLastError(NO_ERROR); | SetLastError(NO_ERROR); | ||||
| prevHDC = ::wglGetCurrentDC(); | prevHDC = ::wglGetCurrentDC(); | ||||
| WIN32_CHK(GetLastError() == NO_ERROR); | WIN32_CHK(GetLastError() == NO_ERROR); | ||||
| prevHGLRC = ::wglGetCurrentContext(); | prevHGLRC = ::wglGetCurrentContext(); | ||||
| WIN32_CHK(GetLastError() == NO_ERROR); | WIN32_CHK(GetLastError() == NO_ERROR); | ||||
| iPixelFormat = choose_pixel_format_legacy(m_hDC, preferredPFD); | dummyPixelFormat = choose_pixel_format_legacy(hDC, preferredPFD); | ||||
| if (iPixelFormat == 0) | if (dummyPixelFormat == 0) | ||||
| goto finalize; | return; | ||||
| PIXELFORMATDESCRIPTOR chosenPFD; | PIXELFORMATDESCRIPTOR chosenPFD; | ||||
| if (!WIN32_CHK( | if (!WIN32_CHK(::DescribePixelFormat( | ||||
| ::DescribePixelFormat(m_hDC, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &chosenPFD))) | hDC, dummyPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &chosenPFD))) | ||||
| goto finalize; | return; | ||||
| if (m_hWnd) { | if (hWnd) { | ||||
| dummyHWND = clone_window(m_hWnd, NULL); | dummyHWND = clone_window(hWnd, NULL); | ||||
| if (dummyHWND == NULL) | if (dummyHWND == NULL) | ||||
| goto finalize; | return; | ||||
| dummyHDC = GetDC(dummyHWND); | dummyHDC = GetDC(dummyHWND); | ||||
| } | } | ||||
| if (!WIN32_CHK(dummyHDC != NULL)) | if (!WIN32_CHK(dummyHDC != NULL)) | ||||
| goto finalize; | return; | ||||
| if (!WIN32_CHK(::SetPixelFormat(dummyHDC, iPixelFormat, &chosenPFD))) | if (!WIN32_CHK(::SetPixelFormat(dummyHDC, dummyPixelFormat, &chosenPFD))) | ||||
| goto finalize; | return; | ||||
| dummyHGLRC = ::wglCreateContext(dummyHDC); | dummyHGLRC = ::wglCreateContext(dummyHDC); | ||||
| if (!WIN32_CHK(dummyHGLRC != NULL)) | if (!WIN32_CHK(dummyHGLRC != NULL)) | ||||
| goto finalize; | return; | ||||
| if (!WIN32_CHK(::wglMakeCurrent(dummyHDC, dummyHGLRC))) | if (!WIN32_CHK(::wglMakeCurrent(dummyHDC, dummyHGLRC))) | ||||
| goto finalize; | return; | ||||
| if (GLEW_CHK(glewInit()) != GLEW_OK) { | has_WGL_ARB_pixel_format = epoxy_has_wgl_extension(hDC, "WGL_ARB_pixel_format"); | ||||
| fprintf(stderr, "Warning! Dummy GLEW/WGLEW failed to initialize properly.\n"); | has_WGL_ARB_create_context = epoxy_has_wgl_extension(hDC, "WGL_ARB_create_context"); | ||||
| has_WGL_ARB_create_context_profile = epoxy_has_wgl_extension(hDC, | |||||
| "WGL_ARB_create_context_profile"); | |||||
| has_WGL_ARB_create_context_robustness = epoxy_has_wgl_extension( | |||||
| hDC, "WGL_ARB_create_context_robustness"); | |||||
| } | } | ||||
| /* The following are not technically WGLEW, but they also require a context to work. */ | ~DummyContextWGL() | ||||
| { | |||||
| #ifndef NDEBUG | |||||
| free((void *)m_dummyRenderer); | |||||
| free((void *)m_dummyVendor); | |||||
| free((void *)m_dummyVersion); | |||||
| m_dummyRenderer = _strdup(reinterpret_cast<const char *>(glGetString(GL_RENDERER))); | |||||
| m_dummyVendor = _strdup(reinterpret_cast<const char *>(glGetString(GL_VENDOR))); | |||||
| m_dummyVersion = _strdup(reinterpret_cast<const char *>(glGetString(GL_VERSION))); | |||||
| #endif | |||||
| finalize: | |||||
| WIN32_CHK(::wglMakeCurrent(prevHDC, prevHGLRC)); | WIN32_CHK(::wglMakeCurrent(prevHDC, prevHGLRC)); | ||||
| if (dummyHGLRC != NULL) | if (dummyHGLRC != NULL) | ||||
| WIN32_CHK(::wglDeleteContext(dummyHGLRC)); | WIN32_CHK(::wglDeleteContext(dummyHGLRC)); | ||||
| if (dummyHWND != NULL) { | if (dummyHWND != NULL) { | ||||
| if (dummyHDC != NULL) | if (dummyHDC != NULL) | ||||
| WIN32_CHK(::ReleaseDC(dummyHWND, dummyHDC)); | WIN32_CHK(::ReleaseDC(dummyHWND, dummyHDC)); | ||||
| WIN32_CHK(::DestroyWindow(dummyHWND)); | WIN32_CHK(::DestroyWindow(dummyHWND)); | ||||
| } | } | ||||
| } | } | ||||
| }; | |||||
| static void makeAttribList(std::vector<int> &out, bool stereoVisual, bool needAlpha) | |||||
| { | |||||
| out.clear(); | |||||
| out.reserve(30); | |||||
| out.push_back(WGL_SUPPORT_OPENGL_ARB); | |||||
| out.push_back(GL_TRUE); | |||||
| out.push_back(WGL_DRAW_TO_WINDOW_ARB); | |||||
| out.push_back(GL_TRUE); | |||||
| out.push_back(WGL_DOUBLE_BUFFER_ARB); | |||||
| out.push_back(GL_TRUE); | |||||
| out.push_back(WGL_ACCELERATION_ARB); | |||||
| out.push_back(WGL_FULL_ACCELERATION_ARB); | |||||
| if (stereoVisual) { | |||||
| out.push_back(WGL_STEREO_ARB); | |||||
| out.push_back(GL_TRUE); | |||||
| } | |||||
| out.push_back(WGL_PIXEL_TYPE_ARB); | |||||
| out.push_back(WGL_TYPE_RGBA_ARB); | |||||
| out.push_back(WGL_COLOR_BITS_ARB); | |||||
| out.push_back(24); | |||||
| if (needAlpha) { | |||||
| out.push_back(WGL_ALPHA_BITS_ARB); | |||||
| out.push_back(8); | |||||
| } | |||||
| out.push_back(0); | |||||
| } | |||||
| int GHOST_ContextWGL::_choose_pixel_format_arb_1(bool stereoVisual, bool needAlpha) | int GHOST_ContextWGL::_choose_pixel_format_arb_1(bool stereoVisual, bool needAlpha) | ||||
| { | { | ||||
| std::vector<int> iAttributes; | std::vector<int> iAttributes; | ||||
| #define _MAX_PIXEL_FORMATS 32 | #define _MAX_PIXEL_FORMATS 32 | ||||
| int iPixelFormat = 0; | int iPixelFormat = 0; | ||||
| ▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | if (iPixelFormat == 0 && stereoVisual) { | ||||
| iPixelFormat = _choose_pixel_format_arb_1(false, needAlpha); | iPixelFormat = _choose_pixel_format_arb_1(false, needAlpha); | ||||
| m_stereoVisual = false; // set context property to actual value | m_stereoVisual = false; // set context property to actual value | ||||
| } | } | ||||
| return iPixelFormat; | return iPixelFormat; | ||||
| } | } | ||||
| int GHOST_ContextWGL::choose_pixel_format(bool stereoVisual, bool needAlpha) | |||||
| { | |||||
| PIXELFORMATDESCRIPTOR preferredPFD = { | |||||
| sizeof(PIXELFORMATDESCRIPTOR), /* size */ | |||||
| 1, /* version */ | |||||
| (DWORD)(PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | | |||||
| PFD_DOUBLEBUFFER | /* support double-buffering */ | |||||
| (stereoVisual ? PFD_STEREO : 0) | /* support stereo */ | |||||
| ( | |||||
| #ifdef WIN32_COMPOSITING | |||||
| /* Support composition for transparent background. */ | |||||
| needAlpha ? PFD_SUPPORT_COMPOSITION : | |||||
| #endif | |||||
| 0)), | |||||
| PFD_TYPE_RGBA, /* color type */ | |||||
| (BYTE)(needAlpha ? 32 : 24), /* preferred color depth */ | |||||
| 0, | |||||
| 0, | |||||
| 0, | |||||
| 0, | |||||
| 0, | |||||
| 0, /* color bits (ignored) */ | |||||
| (BYTE)(needAlpha ? 8 : 0), /* alpha buffer */ | |||||
| 0, /* alpha shift (ignored) */ | |||||
| 0, /* no accumulation buffer */ | |||||
| 0, | |||||
| 0, | |||||
| 0, | |||||
| 0, /* accum bits (ignored) */ | |||||
| 0, /* depth buffer */ | |||||
| 0, /* stencil buffer */ | |||||
| 0, /* no auxiliary buffers */ | |||||
| PFD_MAIN_PLANE, /* main layer */ | |||||
| 0, /* reserved */ | |||||
| 0, | |||||
| 0, | |||||
| 0 /* layer, visible, and damage masks (ignored) */ | |||||
| }; | |||||
| initContextWGLEW(preferredPFD); | |||||
| int iPixelFormat = 0; | |||||
| if (WGLEW_ARB_pixel_format) | |||||
| iPixelFormat = choose_pixel_format_arb(stereoVisual, needAlpha); | |||||
| if (iPixelFormat == 0) | |||||
| iPixelFormat = choose_pixel_format_legacy(m_hDC, preferredPFD); | |||||
| return iPixelFormat; | |||||
| } | |||||
| #ifndef NDEBUG | #ifndef NDEBUG | ||||
| static void reportContextString(const char *name, const char *dummy, const char *context) | static void reportContextString(const char *name, const char *dummy, const char *context) | ||||
| { | { | ||||
| fprintf(stderr, "%s: %s\n", name, context); | fprintf(stderr, "%s: %s\n", name, context); | ||||
| if (dummy && strcmp(dummy, context) != 0) | if (dummy && strcmp(dummy, context) != 0) | ||||
| fprintf(stderr, "Warning! Dummy %s: %s\n", name, dummy); | fprintf(stderr, "Warning! Dummy %s: %s\n", name, dummy); | ||||
| } | } | ||||
| #endif | #endif | ||||
| GHOST_TSuccess GHOST_ContextWGL::initializeDrawingContext() | GHOST_TSuccess GHOST_ContextWGL::initializeDrawingContext() | ||||
| { | { | ||||
| SetLastError(NO_ERROR); | SetLastError(NO_ERROR); | ||||
| HGLRC prevHGLRC = ::wglGetCurrentContext(); | HGLRC prevHGLRC = ::wglGetCurrentContext(); | ||||
| WIN32_CHK(GetLastError() == NO_ERROR); | WIN32_CHK(GetLastError() == NO_ERROR); | ||||
| HDC prevHDC = ::wglGetCurrentDC(); | HDC prevHDC = ::wglGetCurrentDC(); | ||||
| WIN32_CHK(GetLastError() == NO_ERROR); | WIN32_CHK(GetLastError() == NO_ERROR); | ||||
| if (!WGLEW_ARB_create_context || ::GetPixelFormat(m_hDC) == 0) { | { | ||||
| const bool needAlpha = m_alphaBackground; | const bool needAlpha = m_alphaBackground; | ||||
| int iPixelFormat; | DummyContextWGL dummy(m_hDC, m_hWnd, m_stereoVisual, needAlpha); | ||||
| int lastPFD; | |||||
| PIXELFORMATDESCRIPTOR chosenPFD; | if (!dummy.has_WGL_ARB_create_context || ::GetPixelFormat(m_hDC) == 0) { | ||||
| int iPixelFormat = 0; | |||||
| iPixelFormat = choose_pixel_format(m_stereoVisual, needAlpha); | if (dummy.has_WGL_ARB_pixel_format) | ||||
| iPixelFormat = choose_pixel_format_arb(m_stereoVisual, needAlpha); | |||||
| if (iPixelFormat == 0) | |||||
| iPixelFormat = choose_pixel_format_legacy(m_hDC, dummy.preferredPFD); | |||||
| if (iPixelFormat == 0) { | if (iPixelFormat == 0) { | ||||
| goto error; | goto error; | ||||
| } | } | ||||
| lastPFD = ::DescribePixelFormat( | PIXELFORMATDESCRIPTOR chosenPFD; | ||||
| int lastPFD = ::DescribePixelFormat( | |||||
| m_hDC, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &chosenPFD); | m_hDC, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &chosenPFD); | ||||
| if (!WIN32_CHK(lastPFD != 0)) { | if (!WIN32_CHK(lastPFD != 0)) { | ||||
| goto error; | goto error; | ||||
| } | } | ||||
| if (needAlpha && chosenPFD.cAlphaBits == 0) | if (needAlpha && chosenPFD.cAlphaBits == 0) | ||||
| fprintf(stderr, "Warning! Unable to find a pixel format with an alpha channel.\n"); | fprintf(stderr, "Warning! Unable to find a pixel format with an alpha channel.\n"); | ||||
| if (!WIN32_CHK(::SetPixelFormat(m_hDC, iPixelFormat, &chosenPFD))) { | if (!WIN32_CHK(::SetPixelFormat(m_hDC, iPixelFormat, &chosenPFD))) { | ||||
| goto error; | goto error; | ||||
| } | } | ||||
| } | } | ||||
| if (WGLEW_ARB_create_context) { | if (dummy.has_WGL_ARB_create_context) { | ||||
| int profileBitCore = m_contextProfileMask & WGL_CONTEXT_CORE_PROFILE_BIT_ARB; | int profileBitCore = m_contextProfileMask & WGL_CONTEXT_CORE_PROFILE_BIT_ARB; | ||||
| int profileBitCompat = m_contextProfileMask & WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; | int profileBitCompat = m_contextProfileMask & WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; | ||||
| #ifdef WITH_GLEW_ES | if (!dummy.has_WGL_ARB_create_context_profile && profileBitCore) | ||||
| int profileBitES = m_contextProfileMask & WGL_CONTEXT_ES_PROFILE_BIT_EXT; | |||||
| #endif | |||||
| if (!WGLEW_ARB_create_context_profile && profileBitCore) | |||||
| fprintf(stderr, "Warning! OpenGL core profile not available.\n"); | fprintf(stderr, "Warning! OpenGL core profile not available.\n"); | ||||
| if (!WGLEW_ARB_create_context_profile && profileBitCompat) | if (!dummy.has_WGL_ARB_create_context_profile && profileBitCompat) | ||||
| fprintf(stderr, "Warning! OpenGL compatibility profile not available.\n"); | fprintf(stderr, "Warning! OpenGL compatibility profile not available.\n"); | ||||
| #ifdef WITH_GLEW_ES | |||||
| if (!WGLEW_EXT_create_context_es_profile && profileBitES && m_contextMajorVersion == 1) | |||||
| fprintf(stderr, "Warning! OpenGL ES profile not available.\n"); | |||||
| if (!WGLEW_EXT_create_context_es2_profile && profileBitES && m_contextMajorVersion == 2) | |||||
| fprintf(stderr, "Warning! OpenGL ES2 profile not available.\n"); | |||||
| #endif | |||||
| int profileMask = 0; | int profileMask = 0; | ||||
| if (WGLEW_ARB_create_context_profile && profileBitCore) | if (dummy.has_WGL_ARB_create_context_profile && profileBitCore) | ||||
| profileMask |= profileBitCore; | profileMask |= profileBitCore; | ||||
| if (WGLEW_ARB_create_context_profile && profileBitCompat) | if (dummy.has_WGL_ARB_create_context_profile && profileBitCompat) | ||||
| profileMask |= profileBitCompat; | profileMask |= profileBitCompat; | ||||
| #ifdef WITH_GLEW_ES | |||||
| if (WGLEW_EXT_create_context_es_profile && profileBitES) | |||||
| profileMask |= profileBitES; | |||||
| #endif | |||||
| if (profileMask != m_contextProfileMask) | if (profileMask != m_contextProfileMask) | ||||
| fprintf(stderr, "Warning! Ignoring untested OpenGL context profile mask bits."); | fprintf(stderr, "Warning! Ignoring untested OpenGL context profile mask bits."); | ||||
| std::vector<int> iAttributes; | std::vector<int> iAttributes; | ||||
| if (profileMask) { | if (profileMask) { | ||||
| iAttributes.push_back(WGL_CONTEXT_PROFILE_MASK_ARB); | iAttributes.push_back(WGL_CONTEXT_PROFILE_MASK_ARB); | ||||
| iAttributes.push_back(profileMask); | iAttributes.push_back(profileMask); | ||||
| } | } | ||||
| if (m_contextMajorVersion != 0) { | if (m_contextMajorVersion != 0) { | ||||
| iAttributes.push_back(WGL_CONTEXT_MAJOR_VERSION_ARB); | iAttributes.push_back(WGL_CONTEXT_MAJOR_VERSION_ARB); | ||||
| iAttributes.push_back(m_contextMajorVersion); | iAttributes.push_back(m_contextMajorVersion); | ||||
| } | } | ||||
| if (m_contextMinorVersion != 0) { | if (m_contextMinorVersion != 0) { | ||||
| iAttributes.push_back(WGL_CONTEXT_MINOR_VERSION_ARB); | iAttributes.push_back(WGL_CONTEXT_MINOR_VERSION_ARB); | ||||
| iAttributes.push_back(m_contextMinorVersion); | iAttributes.push_back(m_contextMinorVersion); | ||||
| } | } | ||||
| if (m_contextFlags != 0) { | if (m_contextFlags != 0) { | ||||
| iAttributes.push_back(WGL_CONTEXT_FLAGS_ARB); | iAttributes.push_back(WGL_CONTEXT_FLAGS_ARB); | ||||
| iAttributes.push_back(m_contextFlags); | iAttributes.push_back(m_contextFlags); | ||||
| } | } | ||||
| if (m_contextResetNotificationStrategy != 0) { | if (m_contextResetNotificationStrategy != 0) { | ||||
| if (WGLEW_ARB_create_context_robustness) { | if (dummy.has_WGL_ARB_create_context_robustness) { | ||||
| iAttributes.push_back(WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB); | iAttributes.push_back(WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB); | ||||
| iAttributes.push_back(m_contextResetNotificationStrategy); | iAttributes.push_back(m_contextResetNotificationStrategy); | ||||
| } | } | ||||
| else { | else { | ||||
| fprintf(stderr, "Warning! Cannot set the reset notification strategy."); | fprintf(stderr, "Warning! Cannot set the reset notification strategy."); | ||||
| } | } | ||||
| } | } | ||||
| iAttributes.push_back(0); | iAttributes.push_back(0); | ||||
| m_hGLRC = ::wglCreateContextAttribsARB(m_hDC, NULL, &(iAttributes[0])); | m_hGLRC = ::wglCreateContextAttribsARB(m_hDC, NULL, &(iAttributes[0])); | ||||
| } | } | ||||
| } | |||||
| /* Silence warnings interpreted as errors by users when trying to get | /* Silence warnings interpreted as errors by users when trying to get | ||||
| * a context with version higher than 3.3 Core. */ | * a context with version higher than 3.3 Core. */ | ||||
| { | { | ||||
| const bool silent = m_contextMajorVersion > 3; | const bool silent = m_contextMajorVersion > 3; | ||||
| if (!WIN32_CHK_SILENT(m_hGLRC != NULL, silent)) { | if (!WIN32_CHK_SILENT(m_hGLRC != NULL, silent)) { | ||||
| goto error; | goto error; | ||||
| } | } | ||||
| } | } | ||||
| s_sharedCount++; | s_sharedCount++; | ||||
| if (s_sharedHGLRC == NULL) { | if (s_sharedHGLRC == NULL) { | ||||
| s_sharedHGLRC = m_hGLRC; | s_sharedHGLRC = m_hGLRC; | ||||
| } | } | ||||
| else if (!WIN32_CHK(::wglShareLists(s_sharedHGLRC, m_hGLRC))) { | else if (!WIN32_CHK(::wglShareLists(s_sharedHGLRC, m_hGLRC))) { | ||||
| goto error; | goto error; | ||||
| } | } | ||||
| if (!WIN32_CHK(::wglMakeCurrent(m_hDC, m_hGLRC))) { | if (!WIN32_CHK(::wglMakeCurrent(m_hDC, m_hGLRC))) { | ||||
| goto error; | goto error; | ||||
| } | } | ||||
| initContextGLEW(); | |||||
| if (is_crappy_intel_card()) { | if (is_crappy_intel_card()) { | ||||
| /* Some Intel cards with context 4.1 or 4.2 | /* Some Intel cards with context 4.1 or 4.2 | ||||
| * don't have the point sprite enabled by default. | * don't have the point sprite enabled by default. | ||||
| * | * | ||||
| * However GL_POINT_SPRITE was removed in 3.2 and is now permanently ON. | * However GL_POINT_SPRITE was removed in 3.2 and is now permanently ON. | ||||
| * Then use brute force. */ | * Then use brute force. */ | ||||
| glEnable(GL_POINT_SPRITE); | glEnable(GL_POINT_SPRITE); | ||||
| } | } | ||||
| Show All 34 Lines | |||||