Skip to content

Commit

Permalink
Windows: Request a core profile by default.
Browse files Browse the repository at this point in the history
Also, update to OpenGL 4.6.
  • Loading branch information
unknownbrackets committed Dec 3, 2017
1 parent 66832d2 commit c30e4a9
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions Windows/GPU/WindowsGLContext.cpp
Expand Up @@ -253,47 +253,50 @@ bool WindowsGLContext::Init(HINSTANCE hInst, HWND window, std::string *error_mes


// Some core profile drivers elide certain extensions from GL_EXTENSIONS/etc. // Some core profile drivers elide certain extensions from GL_EXTENSIONS/etc.
// glewExperimental allows us to force GLEW to search for the pointers anyway. // glewExperimental allows us to force GLEW to search for the pointers anyway.
if (gl_extensions.IsCoreContext) glewExperimental = true;
glewExperimental = true;
if (GLEW_OK != glewInit()) { if (GLEW_OK != glewInit()) {
*error_message = "Failed to initialize GLEW."; *error_message = "Failed to initialize GLEW.";
return false; return false;
} }
// Unfortunately, glew will generate an invalid enum error, ignore. // Unfortunately, glew will generate an invalid enum error, ignore.
if (gl_extensions.IsCoreContext) glGetError();
glGetError();


int contextFlags = g_Config.bGfxDebugOutput ? WGL_CONTEXT_DEBUG_BIT_ARB : 0; int contextFlags = g_Config.bGfxDebugOutput ? WGL_CONTEXT_DEBUG_BIT_ARB : 0;


HGLRC m_hrc = NULL; HGLRC m_hrc = nullptr;
// Alright, now for the modernity. First try a 4.4, then 4.3, context, if that fails try 3.3. // Alright, now for the modernity. First try a 4.4, then 4.3, context, if that fails try 3.3.
// I can't seem to find a way that lets you simply request the newest version available. // I can't seem to find a way that lets you simply request the newest version available.
if (wglewIsSupported("WGL_ARB_create_context") == 1) { if (wglewIsSupported("WGL_ARB_create_context") == 1) {
for (int minor = 5; minor >= 0 && m_hrc == NULL; --minor) { for (int tryCore = 1; tryCore >= 0 && m_hrc == nullptr; --tryCore) {
const int attribs4x[] = { SetGLCoreContext(tryCore == 1);
WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
WGL_CONTEXT_MINOR_VERSION_ARB, minor, for (int minor = 6; minor >= 0 && m_hrc == nullptr; --minor) {
const int attribs4x[] = {
WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
WGL_CONTEXT_MINOR_VERSION_ARB, minor,
WGL_CONTEXT_FLAGS_ARB, contextFlags,
WGL_CONTEXT_PROFILE_MASK_ARB, gl_extensions.IsCoreContext ? WGL_CONTEXT_CORE_PROFILE_BIT_ARB : WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
0
};
m_hrc = wglCreateContextAttribsARB(hDC, 0, attribs4x);
}
const int attribs33[] = {
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
WGL_CONTEXT_MINOR_VERSION_ARB, 3,
WGL_CONTEXT_FLAGS_ARB, contextFlags, WGL_CONTEXT_FLAGS_ARB, contextFlags,
WGL_CONTEXT_PROFILE_MASK_ARB, gl_extensions.IsCoreContext ? WGL_CONTEXT_CORE_PROFILE_BIT_ARB : WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, WGL_CONTEXT_PROFILE_MASK_ARB, gl_extensions.IsCoreContext ? WGL_CONTEXT_CORE_PROFILE_BIT_ARB : WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
0 0
}; };
m_hrc = wglCreateContextAttribsARB(hDC, 0, attribs4x); if (!m_hrc)
m_hrc = wglCreateContextAttribsARB(hDC, 0, attribs33);
} }
const int attribs33[] = {
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
WGL_CONTEXT_MINOR_VERSION_ARB, 3,
WGL_CONTEXT_FLAGS_ARB, contextFlags,
WGL_CONTEXT_PROFILE_MASK_ARB, gl_extensions.IsCoreContext ? WGL_CONTEXT_CORE_PROFILE_BIT_ARB : WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
0
};
if (!m_hrc)
m_hrc = wglCreateContextAttribsARB(hDC, 0, attribs33);
if (!m_hrc) { if (!m_hrc) {
// Fall back // Fall back
m_hrc = hRC; m_hrc = hRC;
} else { } else {
// Switch to the new ARB context. // Switch to the new ARB context.
wglMakeCurrent(NULL, NULL); wglMakeCurrent(nullptr, nullptr);
wglDeleteContext(hRC); wglDeleteContext(hRC);
wglMakeCurrent(hDC, m_hrc); wglMakeCurrent(hDC, m_hrc);
} }
Expand Down

0 comments on commit c30e4a9

Please sign in to comment.