1
0
Fork 0

source/Platform/Win32/Win32GLContext.cpp: forcing 3.2 Core context.

This commit is contained in:
Henrik Hautakoski 2018-02-28 11:58:41 +01:00
parent 03e692cd50
commit 9e1f6271cd

View file

@ -11,17 +11,13 @@
// Ensure that OpenGL extensions are loaded. // Ensure that OpenGL extensions are loaded.
static void ensureExtensionsLoaded() static void ensureExtensionsLoaded()
{ {
static bool glewInitOK = false; glewExperimental = GL_TRUE;
if (!glewInitOK) {
GLenum ret = glewInit(); GLenum ret = glewInit();
if (ret != GLEW_OK) { if (ret != GLEW_OK) {
log("Win32: Could not initialize GLEW %s\n", log("Win32: Could not initialize GLEW %s\n",
glewGetErrorString(ret)); glewGetErrorString(ret));
return; return;
} }
glewInitOK = true;
}
} }
Win32GLContext::Win32GLContext() : Win32GLContext::Win32GLContext() :
@ -80,19 +76,55 @@ void Win32GLContext::destroy()
void Win32GLContext::createGLContext() void Win32GLContext::createGLContext()
{ {
HGLRC tmpDC;
// First set pixel format. // First set pixel format.
if (!setPixelFormat()) { if (!setPixelFormat()) {
return; 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() bool Win32GLContext::activate()
{ {
// Make sure we have dc and rc before calling MakeCurrent. // Make sure we have dc and rc before calling MakeCurrent.
if (m_deviceContext && m_renderContext) { if (m_deviceContext && m_renderContext) {
return ::wglMakeCurrent(m_deviceContext, m_renderContext); bool ret = ::wglMakeCurrent(m_deviceContext, m_renderContext);
ensureExtensionsLoaded();
return ret;
} }
return false; return false;
} }