diff --git a/source/Platform/Win32/Win32GLContext.cpp b/source/Platform/Win32/Win32GLContext.cpp index 1870856..bdc0f99 100644 --- a/source/Platform/Win32/Win32GLContext.cpp +++ b/source/Platform/Win32/Win32GLContext.cpp @@ -11,16 +11,12 @@ // Ensure that OpenGL extensions are loaded. static void ensureExtensionsLoaded() { - static bool glewInitOK = false; - - if (!glewInitOK) { - GLenum ret = glewInit(); - if (ret != GLEW_OK) { - log("Win32: Could not initialize GLEW %s\n", - glewGetErrorString(ret)); - return; - } - glewInitOK = true; + glewExperimental = GL_TRUE; + GLenum ret = glewInit(); + if (ret != GLEW_OK) { + log("Win32: Could not initialize GLEW %s\n", + glewGetErrorString(ret)); + return; } } @@ -80,19 +76,55 @@ void Win32GLContext::destroy() void Win32GLContext::createGLContext() { + HGLRC tmpDC; + // First set pixel format. if (!setPixelFormat()) { return; } - m_renderContext = ::wglCreateContext(m_deviceContext); + // This is one reason why Win32 context creation is wierd. + // I need to create some context first so that GLEW knows if + // It supports the "wglCreateContextAttribsARB". That is a 3.2+ Core function. + tmpDC = ::wglCreateContext(m_deviceContext); + ::wglMakeCurrent(m_deviceContext, tmpDC); + + ensureExtensionsLoaded(); + + // Dont need to old one anymore. + wglMakeCurrent(m_deviceContext, NULL); + ::wglDeleteContext(tmpDC); + + // Have new CreateContextAttribs function. + if (WGLEW_ARB_create_context_profile) { + + // TODO: For now.. We force 3.2 Core but this should not be implementation specific. + // The Display class should force that for all GLContext Implementations. + + int attriblist[] = { + WGL_CONTEXT_MAJOR_VERSION_ARB, 3, + WGL_CONTEXT_MINOR_VERSION_ARB, 2, + WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, + 0, 0 + }; + + // Create real context. + m_renderContext = ::wglCreateContextAttribsARB(m_deviceContext, 0, attriblist); + + } + // Could create a old context, but anything below 3.2 is so so old. + else { + log("Win32 - OpenGL 3.2 is not available!\n"); + } } bool Win32GLContext::activate() { // Make sure we have dc and rc before calling MakeCurrent. if (m_deviceContext && m_renderContext) { - return ::wglMakeCurrent(m_deviceContext, m_renderContext); + bool ret = ::wglMakeCurrent(m_deviceContext, m_renderContext); + ensureExtensionsLoaded(); + return ret; } return false; }