summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorLeith Bade <leith@mapbox.com>2014-12-21 15:02:47 +1300
committerLeith Bade <leith@mapbox.com>2014-12-21 15:02:47 +1300
commitdf19683b6a871350c9f5ef2576d327ef2033d56c (patch)
treee27e22d7e06310cc45b705b4b5b7342cd9e9ba42 /platform
parent38e2f9831425e7a6dc2d69bd5fa196a5b7cb836f (diff)
parent2731b582f24063e339c047635c6d7b2316eb8037 (diff)
downloadqtlocation-mapboxgl-df19683b6a871350c9f5ef2576d327ef2033d56c.tar.gz
Merge branch 'master' of github.com:mapbox/mapbox-gl-native into android-mason
Conflicts: Makefile platform/default/headless_view.cpp src/mbgl/map/map.cpp
Diffstat (limited to 'platform')
-rw-r--r--platform/default/glfw_view.cpp16
-rw-r--r--platform/default/headless_view.cpp142
2 files changed, 38 insertions, 120 deletions
diff --git a/platform/default/glfw_view.cpp b/platform/default/glfw_view.cpp
index cba1f9ba6a..1b6c06a99b 100644
--- a/platform/default/glfw_view.cpp
+++ b/platform/default/glfw_view.cpp
@@ -152,12 +152,16 @@ void GLFWView::initialize(mbgl::Map *map_) {
}
if (extensions.find("GL_ARB_get_program_binary") != std::string::npos) {
- gl::GetProgramBinary = (gl::PFNGLGETPROGRAMBINARYPROC)glfwGetProcAddress("glGetProgramBinary");
- gl::ProgramBinary = (gl::PFNGLPROGRAMBINARYPROC)glfwGetProcAddress("glProgramBinary");
- gl::ProgramParameteri = (gl::PFNGLPROGRAMPARAMETERIPROC)glfwGetProcAddress("glProgramParameteri");
- assert(gl::GetProgramBinary != nullptr);
- assert(gl::ProgramBinary != nullptr);
- assert(gl::ProgramParameteri != nullptr);
+ GLint numBinaryFormats;
+ MBGL_CHECK_ERROR(glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &numBinaryFormats));
+ if (numBinaryFormats > 0) {
+ gl::GetProgramBinary = (gl::PFNGLGETPROGRAMBINARYPROC)glfwGetProcAddress("glGetProgramBinary");
+ gl::ProgramBinary = (gl::PFNGLPROGRAMBINARYPROC)glfwGetProcAddress("glProgramBinary");
+ gl::ProgramParameteri = (gl::PFNGLPROGRAMPARAMETERIPROC)glfwGetProcAddress("glProgramParameteri");
+ assert(gl::GetProgramBinary != nullptr);
+ assert(gl::ProgramBinary != nullptr);
+ assert(gl::ProgramParameteri != nullptr);
+ }
}
// Require packed depth stencil
diff --git a/platform/default/headless_view.cpp b/platform/default/headless_view.cpp
index fcf93c0e57..5bc5966908 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>
@@ -53,47 +48,36 @@ HeadlessView::HeadlessView(std::shared_ptr<HeadlessDisplay> display)
void HeadlessView::loadExtensions() {
make_active();
- std::string extensions;
- if (usingGl3OrNewer) {
-#ifdef GL_VERSION_3_0
- GLuint num_extensions = 0;
- MBGL_CHECK_ERROR(glGetIntegerv(GL_NUM_EXTENSIONS, reinterpret_cast<GLint *>(&num_extensions)));
- for (GLuint i = 0; i < num_extensions; i++) {
- std::string extension = MBGL_CHECK_ERROR(reinterpret_cast<const char *>(glGetStringi(GL_EXTENSIONS, i)));
- extensions.append(extension);
- extensions.append(" ");
- }
-#else
- throw std::runtime_error("Using GL 3.0+ context with out correct headers.\n");
-#endif
- } else {
- extensions = MBGL_CHECK_ERROR(reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)));
- }
+ const char *extensionPtr = (char *)MBGL_CHECK_ERROR(glGetString(GL_EXTENSIONS));
+
+ if (extensionPtr) {
+ const std::string extensions = extensionPtr;
#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);
- }
+ 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
+ }
// HeadlessView requires packed depth stencil
gl::isPackedDepthStencilSupported = true;
@@ -102,64 +86,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, bool& usingGl3OrNewer) {
- 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.
- int i = 0;
- for (; !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 (coreProfileVersions[i].major >= 3) {
- usingGl3OrNewer = true;
- }
-
- // 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);
@@ -174,27 +100,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], usingGl3OrNewer);
- }
-#endif
-
- if (glContext == 0) {
+ 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;
}