summaryrefslogtreecommitdiff
path: root/platform/default
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2014-12-18 18:00:33 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2014-12-18 18:00:33 -0800
commit4a2cf4aa62b9f467f0757844b4a4c3dbf75fdc40 (patch)
tree1d8941347f425073147dbe87913569555b0d7489 /platform/default
parenta8dec01230a00f9e701fc6403110c4f5017ba905 (diff)
parente57c57516fd3dd2513b6bae579f38f2f404fa545 (diff)
downloadqtlocation-mapboxgl-4a2cf4aa62b9f467f0757844b4a4c3dbf75fdc40.tar.gz
Merge pull request #718 from mapbox/cli-render
CLI render
Diffstat (limited to 'platform/default')
-rw-r--r--platform/default/headless_view.cpp120
1 files changed, 27 insertions, 93 deletions
diff --git a/platform/default/headless_view.cpp b/platform/default/headless_view.cpp
index b0fa60fc12..4053af226d 100644
--- a/platform/default/headless_view.cpp
+++ b/platform/default/headless_view.cpp
@@ -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>
@@ -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>
@@ -52,88 +47,39 @@ HeadlessView::HeadlessView(std::shared_ptr<HeadlessDisplay> display)
void HeadlessView::loadExtensions() {
make_active();
- const std::string extensions = (char *)MBGL_CHECK_ERROR(glGetString(GL_EXTENSIONS));
+ const char *extension_ptr = (char *)MBGL_CHECK_ERROR(glGetString(GL_EXTENSIONS));
+
+ if (extension_ptr) {
+ const std::string extensions = extension_ptr;
#ifdef MBGL_USE_CGL
- if (extensions.find("GL_APPLE_vertex_array_object") != std::string::npos) {
- gl::BindVertexArray = (gl::PFNGLBINDVERTEXARRAYPROC)CGLGetProcAddress("glBindVertexArrayAPPLE");
- gl::DeleteVertexArrays = (gl::PFNGLDELETEVERTEXARRAYSPROC)CGLGetProcAddress("glDeleteVertexArraysAPPLE");
- gl::GenVertexArrays = (gl::PFNGLGENVERTEXARRAYSPROC)CGLGetProcAddress("glGenVertexArraysAPPLE");
- gl::IsVertexArray = (gl::PFNGLISVERTEXARRAYPROC)CGLGetProcAddress("glIsVertexArrayAPPLE");
- assert(gl::BindVertexArray != nullptr);
- assert(gl::DeleteVertexArrays != nullptr);
- assert(gl::GenVertexArrays != nullptr);
- assert(gl::IsVertexArray != nullptr);
- }
+ if (extensions.find("GL_APPLE_vertex_array_object") != std::string::npos) {
+ gl::BindVertexArray = (gl::PFNGLBINDVERTEXARRAYPROC)CGLGetProcAddress("glBindVertexArrayAPPLE");
+ gl::DeleteVertexArrays = (gl::PFNGLDELETEVERTEXARRAYSPROC)CGLGetProcAddress("glDeleteVertexArraysAPPLE");
+ gl::GenVertexArrays = (gl::PFNGLGENVERTEXARRAYSPROC)CGLGetProcAddress("glGenVertexArraysAPPLE");
+ gl::IsVertexArray = (gl::PFNGLISVERTEXARRAYPROC)CGLGetProcAddress("glIsVertexArrayAPPLE");
+ assert(gl::BindVertexArray != nullptr);
+ assert(gl::DeleteVertexArrays != nullptr);
+ assert(gl::GenVertexArrays != nullptr);
+ assert(gl::IsVertexArray != nullptr);
+ }
#endif
#ifdef MBGL_USE_GLX
- if (extensions.find("GL_ARB_vertex_array_object") != std::string::npos) {
- gl::BindVertexArray = (gl::PFNGLBINDVERTEXARRAYPROC)glXGetProcAddress((const GLubyte *)"glBindVertexArray");
- gl::DeleteVertexArrays = (gl::PFNGLDELETEVERTEXARRAYSPROC)glXGetProcAddress((const GLubyte *)"glDeleteVertexArrays");
- gl::GenVertexArrays = (gl::PFNGLGENVERTEXARRAYSPROC)glXGetProcAddress((const GLubyte *)"glGenVertexArrays");
- gl::IsVertexArray = (gl::PFNGLISVERTEXARRAYPROC)glXGetProcAddress((const GLubyte *)"glIsVertexArray");
- assert(gl::BindVertexArray != nullptr);
- assert(gl::DeleteVertexArrays != nullptr);
- assert(gl::GenVertexArrays != nullptr);
- assert(gl::IsVertexArray != nullptr);
- }
-#endif
-
- 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;
+ if (extensions.find("GL_ARB_vertex_array_object") != std::string::npos) {
+ gl::BindVertexArray = (gl::PFNGLBINDVERTEXARRAYPROC)glXGetProcAddress((const GLubyte *)"glBindVertexArray");
+ gl::DeleteVertexArrays = (gl::PFNGLDELETEVERTEXARRAYSPROC)glXGetProcAddress((const GLubyte *)"glDeleteVertexArrays");
+ gl::GenVertexArrays = (gl::PFNGLGENVERTEXARRAYSPROC)glXGetProcAddress((const GLubyte *)"glGenVertexArrays");
+ gl::IsVertexArray = (gl::PFNGLISVERTEXARRAYPROC)glXGetProcAddress((const GLubyte *)"glIsVertexArray");
+ assert(gl::BindVertexArray != nullptr);
+ assert(gl::DeleteVertexArrays != nullptr);
+ assert(gl::GenVertexArrays != nullptr);
+ assert(gl::IsVertexArray != nullptr);
}
+#endif
}
- // Restore the old error handler.
- XSetErrorHandler(previousErrorHandler);
- return ctx;
+ make_inactive();
}
-#endif
-#endif
void HeadlessView::createContext() {
#if MBGL_USE_CGL
@@ -149,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;
}