diff --git a/Windows/GPU/WindowsGLContext.cpp b/Windows/GPU/WindowsGLContext.cpp index e345cc9886..65881c6eaf 100644 --- a/Windows/GPU/WindowsGLContext.cpp +++ b/Windows/GPU/WindowsGLContext.cpp @@ -251,10 +251,17 @@ bool WindowsGLContext::Init(HINSTANCE hInst, HWND window, std::string *error_mes ExitProcess(1); } + // Some core profile drivers elide certain extensions from GL_EXTENSIONS/etc. + // glewExperimental allows us to force GLEW to search for the pointers anyway. + if (gl_extensions.IsCoreContext) + glewExperimental = true; if (GLEW_OK != glewInit()) { *error_message = "Failed to initialize GLEW."; return false; } + // Unfortunately, glew will generate an invalid enum error, ignore. + if (gl_extensions.IsCoreContext) + glGetError(); CheckGLExtensions(); diff --git a/ext/native/base/PCMain.cpp b/ext/native/base/PCMain.cpp index 00ec49a2a6..c3754b73e0 100644 --- a/ext/native/base/PCMain.cpp +++ b/ext/native/base/PCMain.cpp @@ -587,10 +587,17 @@ int main(int argc, char *argv[]) { #ifndef USING_GLES2 + // Some core profile drivers elide certain extensions from GL_EXTENSIONS/etc. + // glewExperimental allows us to force GLEW to search for the pointers anyway. + if (gl_extensions.IsCoreContext) + glewExperimental = true; if (GLEW_OK != glewInit()) { printf("Failed to initialize glew!\n"); return 1; } + // Unfortunately, glew will generate an invalid enum error, ignore. + if (gl_extensions.IsCoreContext) + glGetError(); if (GLEW_VERSION_2_0) { printf("OpenGL 2.0 or higher.\n"); diff --git a/ext/native/base/QtMain.cpp b/ext/native/base/QtMain.cpp index cad9257f6a..57006bbc14 100644 --- a/ext/native/base/QtMain.cpp +++ b/ext/native/base/QtMain.cpp @@ -30,6 +30,7 @@ #include "SDL_audio.h" #endif #include "QtMain.h" +#include "gfx_es2/gpu_features.h" #include "math/math_util.h" #include @@ -349,10 +350,17 @@ bool MainUI::event(QEvent *e) void MainUI::initializeGL() { #ifndef USING_GLES2 - glewInit(); + // Some core profile drivers elide certain extensions from GL_EXTENSIONS/etc. + // glewExperimental allows us to force GLEW to search for the pointers anyway. + if (gl_extensions.IsCoreContext) + glewExperimental = true; + glewInit(); + // Unfortunately, glew will generate an invalid enum error, ignore. + if (gl_extensions.IsCoreContext) + glGetError(); #endif - graphicsContext = new QtDummyGraphicsContext(); - NativeInitGraphics(graphicsContext); + graphicsContext = new QtDummyGraphicsContext(); + NativeInitGraphics(graphicsContext); } void MainUI::paintGL() diff --git a/ext/native/gfx_es2/gpu_features.cpp b/ext/native/gfx_es2/gpu_features.cpp index c2312fc5ff..f31af4643a 100644 --- a/ext/native/gfx_es2/gpu_features.cpp +++ b/ext/native/gfx_es2/gpu_features.cpp @@ -32,6 +32,9 @@ GLExtensions gl_extensions; std::string g_all_gl_extensions; std::string g_all_egl_extensions; +static bool extensionsDone = false; +static bool useCoreContext = false; + bool GLExtensions::VersionGEThan(int major, int minor, int sub) { if (gl_extensions.ver[0] > major) return true; @@ -73,11 +76,11 @@ void ProcessGPUFeatures() { void CheckGLExtensions() { // Make sure to only do this once. It's okay to call CheckGLExtensions from wherever. - static bool done = false; - if (done) + if (extensionsDone) return; - done = true; + extensionsDone = true; memset(&gl_extensions, 0, sizeof(gl_extensions)); + gl_extensions.IsCoreContext = useCoreContext; #ifdef USING_GLES2 gl_extensions.IsGLES = true; @@ -377,3 +380,12 @@ void CheckGLExtensions() { if (error) ELOG("GL error in init: %i", error); } + +void SetGLCoreContext(bool flag) { + if (extensionsDone) + FLOG("SetGLCoreContext() after CheckGLExtensions()"); + + useCoreContext = flag; + // For convenience, it'll get reset later. + gl_extensions.IsCoreContext = useCoreContext; +} diff --git a/ext/native/gfx_es2/gpu_features.h b/ext/native/gfx_es2/gpu_features.h index 1679419ccb..920d6fd298 100644 --- a/ext/native/gfx_es2/gpu_features.h +++ b/ext/native/gfx_es2/gpu_features.h @@ -103,3 +103,4 @@ extern std::string g_all_gl_extensions; extern std::string g_all_egl_extensions; void CheckGLExtensions(); +void SetGLCoreContext(bool flag);