Properly allow triggering a core context.

This will be useful on Mac.
This commit is contained in:
Unknown W. Brackets 2016-08-06 20:19:50 -07:00
parent 0924dbfdee
commit 2e2674be21
5 changed files with 41 additions and 6 deletions

View file

@ -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();

View file

@ -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");

View file

@ -30,6 +30,7 @@
#include "SDL_audio.h"
#endif
#include "QtMain.h"
#include "gfx_es2/gpu_features.h"
#include "math/math_util.h"
#include <string.h>
@ -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()

View file

@ -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;
}

View file

@ -103,3 +103,4 @@ extern std::string g_all_gl_extensions;
extern std::string g_all_egl_extensions;
void CheckGLExtensions();
void SetGLCoreContext(bool flag);