summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorartemp <artem@mapnik.org>2014-11-13 15:46:11 +0000
committerartemp <artem@mapnik.org>2014-11-13 15:46:11 +0000
commit782a0be4bf307877f960983346b16628899e38a3 (patch)
treea7693fd95fdd5bc17800972addb6557b628ba33d /platform
parent9fd9ced95647a721e9c2f7f539ce9dfac3356f43 (diff)
parent27cf24171a014b63e139e7fc77422753beac44e1 (diff)
downloadqtlocation-mapboxgl-782a0be4bf307877f960983346b16628899e38a3.tar.gz
Merge branch 'master' into image-readers
Diffstat (limited to 'platform')
-rw-r--r--platform/default/glfw_view.cpp24
-rw-r--r--platform/default/headless_display.cpp2
-rw-r--r--platform/default/headless_view.cpp50
-rw-r--r--platform/default/http_request_baton_curl.cpp15
-rw-r--r--platform/default/image.cpp14
5 files changed, 102 insertions, 3 deletions
diff --git a/platform/default/glfw_view.cpp b/platform/default/glfw_view.cpp
index baacfbfd9c..34b9ddbef1 100644
--- a/platform/default/glfw_view.cpp
+++ b/platform/default/glfw_view.cpp
@@ -1,4 +1,5 @@
#include <mbgl/platform/default/glfw_view.hpp>
+#include <mbgl/platform/gl.hpp>
#include <mbgl/util/string.hpp>
@@ -26,6 +27,10 @@ void GLFWView::initialize(mbgl::Map *map_) {
monitor = glfwGetPrimaryMonitor();
}
+#ifdef DEBUG
+ glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
+#endif
+
#ifdef GL_ES_VERSION_2_0
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
@@ -63,6 +68,25 @@ void GLFWView::initialize(mbgl::Map *map_) {
glfwSetScrollCallback(window, scroll);
glfwSetKeyCallback(window, key);
+
+ const std::string extensions = (char *)glGetString(GL_EXTENSIONS);
+ {
+ using namespace mbgl;
+
+
+ if (extensions.find("GL_ARB_vertex_array_object") != std::string::npos) {
+ gl::BindVertexArray = (gl::PFNGLBINDVERTEXARRAYPROC)glfwGetProcAddress("glBindVertexArrayARB");
+ gl::DeleteVertexArrays = (gl::PFNGLDELETEVERTEXARRAYSPROC)glfwGetProcAddress("glDeleteVertexArraysARB");
+ gl::GenVertexArrays = (gl::PFNGLGENVERTEXARRAYSPROC)glfwGetProcAddress("glGenVertexArraysARB");
+ gl::IsVertexArray = (gl::PFNGLISVERTEXARRAYPROC)glfwGetProcAddress("glIsVertexArrayARB");
+ } else if (extensions.find("GL_APPLE_vertex_array_object") != std::string::npos) {
+ gl::BindVertexArray = (gl::PFNGLBINDVERTEXARRAYPROC)glfwGetProcAddress("glBindVertexArrayAPPLE");
+ gl::DeleteVertexArrays = (gl::PFNGLDELETEVERTEXARRAYSPROC)glfwGetProcAddress("glDeleteVertexArraysAPPLE");
+ gl::GenVertexArrays = (gl::PFNGLGENVERTEXARRAYSPROC)glfwGetProcAddress("glGenVertexArraysAPPLE");
+ gl::IsVertexArray = (gl::PFNGLISVERTEXARRAYPROC)glfwGetProcAddress("glIsVertexArrayAPPLE");
+ }
+ }
+
glfwMakeContextCurrent(nullptr);
}
diff --git a/platform/default/headless_display.cpp b/platform/default/headless_display.cpp
index 409fcbf057..ada48b8648 100644
--- a/platform/default/headless_display.cpp
+++ b/platform/default/headless_display.cpp
@@ -48,7 +48,7 @@ HeadlessDisplay::HeadlessDisplay() {
// We're creating a dummy pbuffer anyway that we're not using.
static int pixelFormat[] = {
GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
- None
+ 0
};
int configs = 0;
diff --git a/platform/default/headless_view.cpp b/platform/default/headless_view.cpp
index 71096beba0..1f5a0ec987 100644
--- a/platform/default/headless_view.cpp
+++ b/platform/default/headless_view.cpp
@@ -11,16 +11,62 @@ static PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = nullptr;
#endif
#endif
+#ifdef MBGL_USE_CGL
+#include <CoreFoundation/CoreFoundation.h>
+
+typedef void (* CGLProc)(void);
+CGLProc CGLGetProcAddress(const char *proc) {
+ static CFBundleRef framework = nullptr;
+ if (!framework) {
+ framework = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl"));
+ if (!framework) {
+ throw std::runtime_error("Failed to load OpenGL.framework");
+ }
+ }
+
+ CFStringRef name = CFStringCreateWithCString(kCFAllocatorDefault, proc, kCFStringEncodingASCII);
+ CGLProc symbol = (CGLProc)CFBundleGetFunctionPointerForName(framework, name);
+ CFRelease(name);
+ return symbol;
+}
+#endif
+
namespace mbgl {
+
HeadlessView::HeadlessView()
: display_(std::make_shared<HeadlessDisplay>()) {
createContext();
+ loadExtensions();
}
HeadlessView::HeadlessView(std::shared_ptr<HeadlessDisplay> display)
: display_(display) {
createContext();
+ loadExtensions();
+}
+
+void HeadlessView::loadExtensions() {
+ make_active();
+ const std::string extensions = (char *)glGetString(GL_EXTENSIONS);
+
+#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");
+ }
+#endif
+#ifdef MBGL_USE_GLX
+ if (extensions.find("GL_ARB_vertex_array_object") != std::string::npos) {
+ gl::BindVertexArray = (gl::PFNGLBINDVERTEXARRAYPROC)glXGetProcAddress((const GLubyte *)"glBindVertexArrayARB");
+ gl::DeleteVertexArrays = (gl::PFNGLDELETEVERTEXARRAYSPROC)glXGetProcAddress((const GLubyte *)"glDeleteVertexArraysARB");
+ gl::GenVertexArrays = (gl::PFNGLGENVERTEXARRAYSPROC)glXGetProcAddress((const GLubyte *)"glGenVertexArraysARB");
+ gl::IsVertexArray = (gl::PFNGLISVERTEXARRAYPROC)glXGetProcAddress((const GLubyte *)"glIsVertexArrayARB");
+ }
+#endif
+ make_inactive();
}
@@ -61,7 +107,7 @@ GLXContext createCoreProfile(Display *dpy, GLXFBConfig fbconfig) {
const int context_flags[] = {
GLX_CONTEXT_MAJOR_VERSION_ARB, core_profile_versions[i].major,
GLX_CONTEXT_MINOR_VERSION_ARB, core_profile_versions[i].minor,
- None
+ 0
};
ctx = glXCreateContextAttribsARB(dpy, fbconfig, 0, True, context_flags);
if (context_creation_failed) {
@@ -126,7 +172,7 @@ void HeadlessView::createContext() {
int pbuffer_attributes[] = {
GLX_PBUFFER_WIDTH, 8,
GLX_PBUFFER_HEIGHT, 8,
- None
+ 0
};
glx_pbuffer = glXCreatePbuffer(x_display, fb_configs[0], pbuffer_attributes);
#endif
diff --git a/platform/default/http_request_baton_curl.cpp b/platform/default/http_request_baton_curl.cpp
index b8b4bac5fd..02e9497c9e 100644
--- a/platform/default/http_request_baton_curl.cpp
+++ b/platform/default/http_request_baton_curl.cpp
@@ -1,6 +1,7 @@
#include <mbgl/storage/http_request_baton.hpp>
#include <mbgl/util/uv-messenger.h>
#include <mbgl/util/time.hpp>
+#include <mbgl/util/string.hpp>
#include <uv.h>
#include <curl/curl.h>
@@ -9,6 +10,20 @@
#include <cassert>
#include <cstring>
+
+// Check curl library version.
+const static bool curl_version_check = []() {
+ const auto version = curl_version_info(CURLVERSION_NOW);
+ if (version->version_num != LIBCURL_VERSION_NUM) {
+ throw std::runtime_error(mbgl::util::sprintf<96>(
+ "libcurl version mismatch: headers report %d.%d.%d, but library reports %d.%d.%d",
+ (LIBCURL_VERSION_NUM >> 16) & 0xFF, (LIBCURL_VERSION_NUM >> 8) & 0xFF, LIBCURL_VERSION_NUM & 0xFF,
+ (version->version_num >> 16) & 0xFF, (version->version_num >> 8) & 0xFF, version->version_num & 0xFF));
+ }
+ return true;
+}();
+
+
// This file contains code from http://curl.haxx.se/libcurl/c/multi-uv.html:
/***************************************************************************
diff --git a/platform/default/image.cpp b/platform/default/image.cpp
index 397a6b1928..96d01ab718 100644
--- a/platform/default/image.cpp
+++ b/platform/default/image.cpp
@@ -1,4 +1,5 @@
#include <mbgl/util/image.hpp>
+#include <mbgl/util/string.hpp>
#include <png.h>
@@ -8,6 +9,19 @@
#include <cstring>
#include <mbgl/util/image_reader.hpp>
+// Check png library version.
+const static bool png_version_check = []() {
+ const png_uint_32 version = png_access_version_number();
+ if (version != PNG_LIBPNG_VER) {
+ throw std::runtime_error(mbgl::util::sprintf<96>(
+ "libpng version mismatch: headers report %d.%d.%d, but library reports %d.%d.%d",
+ PNG_LIBPNG_VER / 10000, (PNG_LIBPNG_VER / 100) % 100, PNG_LIBPNG_VER % 100,
+ version / 10000, (version / 100) % 100, version % 100));
+ }
+ return true;
+}();
+
+
namespace mbgl {
namespace util {