From 4514af9d6e988e14c93b4e475387f9f2eb23d724 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 18 Mar 2017 13:45:51 -0700 Subject: [PATCH] Windows: Improve core context init. This clears the error from glewInit(), and ensures we check GL extensions only after selecting the desired GL profile. Also, consistently use the core profile flag to select the context. --- Windows/GPU/WindowsGLContext.cpp | 13 ++++++++----- ext/native/gfx/gl_debug_log.cpp | 1 + 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Windows/GPU/WindowsGLContext.cpp b/Windows/GPU/WindowsGLContext.cpp index 80bd7e495c..6309551475 100644 --- a/Windows/GPU/WindowsGLContext.cpp +++ b/Windows/GPU/WindowsGLContext.cpp @@ -20,6 +20,7 @@ #include "Common/Log.h" #include "Common/CommonWindows.h" #include "gfx/gl_common.h" +#include "gfx/gl_debug_log.h" #include "gfx_es2/gpu_features.h" #include "GL/gl.h" #include "GL/wglew.h" @@ -263,8 +264,6 @@ bool WindowsGLContext::Init(HINSTANCE hInst, HWND window, std::string *error_mes if (gl_extensions.IsCoreContext) glGetError(); - CheckGLExtensions(); - int contextFlags = g_Config.bGfxDebugOutput ? WGL_CONTEXT_DEBUG_BIT_ARB : 0; // Alright, now for the modernity. First try a 4.4, then 4.3, context, if that fails try 3.3. @@ -273,21 +272,21 @@ bool WindowsGLContext::Init(HINSTANCE hInst, HWND window, std::string *error_mes WGL_CONTEXT_MAJOR_VERSION_ARB, 4, WGL_CONTEXT_MINOR_VERSION_ARB, 4, WGL_CONTEXT_FLAGS_ARB, contextFlags, - WGL_CONTEXT_PROFILE_MASK_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 }; const int attribs43[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, 4, WGL_CONTEXT_MINOR_VERSION_ARB, 3, WGL_CONTEXT_FLAGS_ARB, contextFlags, - WGL_CONTEXT_PROFILE_MASK_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 }; 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, 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 }; @@ -316,6 +315,9 @@ bool WindowsGLContext::Init(HINSTANCE hInst, HWND window, std::string *error_mes *error_message = "Failed to re-initialize GLEW."; return false; } + // Unfortunately, glew will generate an invalid enum error, ignore. + if (gl_extensions.IsCoreContext) + glGetError(); if (!m_hrc) { *error_message = "No m_hrc"; @@ -364,6 +366,7 @@ bool WindowsGLContext::Init(HINSTANCE hInst, HWND window, std::string *error_mes CheckGLExtensions(); draw_ = Draw::T3DCreateGLContext(); + CHECK_GL_ERROR_IF_DEBUG(); return true; // Success } diff --git a/ext/native/gfx/gl_debug_log.cpp b/ext/native/gfx/gl_debug_log.cpp index 4f313f62f8..e72e286e7f 100644 --- a/ext/native/gfx/gl_debug_log.cpp +++ b/ext/native/gfx/gl_debug_log.cpp @@ -11,6 +11,7 @@ std::string GLEnumToString(uint16_t value) { case GL_UNSIGNED_SHORT_4_4_4_4: return "GL_UNSIGNED_SHORT_4_4_4_4"; case GL_UNSIGNED_SHORT_5_5_5_1: return "GL_UNSIGNED_SHORT_5_5_5_1"; case GL_UNSIGNED_SHORT_5_6_5: return "GL_UNSIGNED_SHORT_5_6_5"; + case GL_UNSIGNED_BYTE: return "GL_UNSIGNED_BYTE"; case GL_RGBA: return "GL_RGBA"; case GL_RGB: return "GL_RGB"; #if !defined(USING_GLES2)