Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
never create core profile contexts; their API is subtly different
Browse files Browse the repository at this point in the history
(e.g. glGetString(GL_EXTENSIONS) doesn't work, you'd have to use glGetStringi(GL_EXTENSIONS, ...);)
  • Loading branch information
kkaefer committed Dec 16, 2014
1 parent 9082a83 commit 40a5bcd
Showing 1 changed file with 2 additions and 72 deletions.
74 changes: 2 additions & 72 deletions platform/default/headless_view.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <mbgl/platform/default/headless_view.hpp>
#include <mbgl/platform/default/headless_display.hpp>
#include <mbgl/platform/log.hpp>

#include <mbgl/util/std.hpp>

Expand All @@ -9,12 +10,6 @@
#include <cstring>
#include <cassert>

#if MBGL_USE_GLX
#ifdef GLX_ARB_create_context
static PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = nullptr;
#endif
#endif

#ifdef MBGL_USE_CGL
#include <CoreFoundation/CoreFoundation.h>

Expand Down Expand Up @@ -86,59 +81,6 @@ void HeadlessView::loadExtensions() {
make_inactive();
}


#if MBGL_USE_GLX
#ifdef GLX_ARB_create_context

// These are all of the OpenGL Core profile version that we know about.
struct core_profile_version { int major, minor; };
static const core_profile_version coreProfileVersions[] = {
{4, 5},
{4, 4},
{4, 3},
{4, 2},
{4, 1},
{4, 0},
{3, 3},
{3, 2},
{3, 1},
{3, 0},
{0, 0},
};

GLXContext createCoreProfile(Display *dpy, GLXFBConfig fbconfig) {
static bool contextCreationFailed = false;
GLXContext ctx = 0;

// Set the Error Handler to avoid crashing the program when the context creation fails.
// It is expected that some context creation attempts fail, e.g. because the OpenGL
// implementation does not support the version we're requesting.
int (*previousErrorHandler)(Display *, XErrorEvent *) = XSetErrorHandler([](Display *, XErrorEvent *) {
contextCreationFailed = true;
return 0;
});

// Try to create core profiles from the highest known version on down.
for (int i = 0; !ctx && coreProfileVersions[i].major; i++) {
contextCreationFailed = false;
const int contextFlags[] = {
GLX_CONTEXT_MAJOR_VERSION_ARB, coreProfileVersions[i].major,
GLX_CONTEXT_MINOR_VERSION_ARB, coreProfileVersions[i].minor,
0
};
ctx = glXCreateContextAttribsARB(dpy, fbconfig, 0, True, contextFlags);
if (contextCreationFailed) {
ctx = 0;
}
}

// Restore the old error handler.
XSetErrorHandler(previousErrorHandler);
return ctx;
}
#endif
#endif

void HeadlessView::createContext() {
#if MBGL_USE_CGL
CGLError error = CGLCreateContext(display_->pixelFormat, NULL, &glContext);
Expand All @@ -153,27 +95,15 @@ void HeadlessView::createContext() {
#endif

#if MBGL_USE_GLX
#ifdef GLX_ARB_create_context
if (glXCreateContextAttribsARB == nullptr) {
glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddressARB((const GLubyte *)"glXCreateContextAttribsARB");
}
#endif

xDisplay = display_->xDisplay;
fbConfigs = display_->fbConfigs;

#ifdef GLX_ARB_create_context
if (glXCreateContextAttribsARB) {
// Try to create a core profile context.
glContext = createCoreProfile(xDisplay, fbConfigs[0]);
}
#endif

if (!glContext) {
// Try to create a legacy context
glContext = glXCreateNewContext(xDisplay, fbConfigs[0], GLX_RGBA_TYPE, 0, True);
if (glContext) {
if (!glXIsDirect(xDisplay, glContext)) {
mbgl::Log::Error(mbgl::Event::OpenGL, "Failed to create direct OpenGL Legacy context");
glXDestroyContext(xDisplay, glContext);
glContext = 0;
}
Expand Down

3 comments on commit 40a5bcd

@jfirebaugh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is essentially reverting 8b08772? Wasn't that key to getting headless rendering working?

@ljbade
Copy link
Contributor

@ljbade ljbade commented on 40a5bcd Dec 18, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should always be able to create a legacy context.

@kkaefer
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jfirebaugh no; headless rendering works also without core profile contexts.

Please sign in to comment.