diff --git a/include/mbgl/geometry/vao.hpp b/include/mbgl/geometry/vao.hpp index bb1f571ff..2ecba731f 100644 --- a/include/mbgl/geometry/vao.hpp +++ b/include/mbgl/geometry/vao.hpp @@ -9,7 +9,6 @@ namespace mbgl { -#if GL_ARB_vertex_array_object class VertexArrayObject : public util::noncopyable { public: inline VertexArrayObject() {}; @@ -28,7 +27,9 @@ public: if (bound_shader == 0) { vertexBuffer.bind(); shader.bind(offset); - storeBinding(shader, vertexBuffer.getID(), 0, offset); + if (vao) { + storeBinding(shader, vertexBuffer.getID(), 0, offset); + } } else { verifyBinding(shader, vertexBuffer.getID(), 0, offset); } @@ -41,7 +42,9 @@ public: vertexBuffer.bind(); elementsBuffer.bind(); shader.bind(offset); - storeBinding(shader, vertexBuffer.getID(), elementsBuffer.getID(), offset); + if (vao) { + storeBinding(shader, vertexBuffer.getID(), elementsBuffer.getID(), offset); + } } else { verifyBinding(shader, vertexBuffer.getID(), elementsBuffer.getID(), offset); } @@ -65,21 +68,6 @@ private: char *bound_offset = 0; }; -#else - -class VertexArrayObject : public util::noncopyable { -public: - template - void bind(Shader& shader, Buffers& buffers, char *offset) { - for (auto &buffer : buffers) { - buffer.bind(); - } - shader.bind(offset); - } -}; - -#endif - } #endif diff --git a/include/mbgl/platform/default/headless_view.hpp b/include/mbgl/platform/default/headless_view.hpp index f14033834..9d8acf70f 100644 --- a/include/mbgl/platform/default/headless_view.hpp +++ b/include/mbgl/platform/default/headless_view.hpp @@ -5,7 +5,7 @@ #define MBGL_USE_CGL 1 #else #define GL_GLEXT_PROTOTYPES -#include +#include #define MBGL_USE_GLX 1 #endif @@ -25,6 +25,7 @@ public: ~HeadlessView(); void createContext(); + void loadExtensions(); void resize(uint16_t width, uint16_t height, float pixelRatio); std::unique_ptr readPixels(); diff --git a/include/mbgl/platform/event.hpp b/include/mbgl/platform/event.hpp index 2aa4aa0c9..df2d8b03e 100644 --- a/include/mbgl/platform/event.hpp +++ b/include/mbgl/platform/event.hpp @@ -32,6 +32,7 @@ enum class Event : uint8_t { Database, HttpRequest, Sprite, + OpenGL, }; MBGL_DEFINE_ENUM_CLASS(EventClass, Event, { @@ -44,6 +45,7 @@ MBGL_DEFINE_ENUM_CLASS(EventClass, Event, { { Event::Database, "Database" }, { Event::HttpRequest, "HttpRequest" }, { Event::Sprite, "Sprite" }, + { Event::OpenGL, "OpenGL" }, { Event(-1), "Unknown" }, }); diff --git a/include/mbgl/platform/gl.hpp b/include/mbgl/platform/gl.hpp index d5162f2c7..6685d1f37 100644 --- a/include/mbgl/platform/gl.hpp +++ b/include/mbgl/platform/gl.hpp @@ -3,38 +3,28 @@ #include -#ifdef NVIDIA - #include - #include - - extern PFNGLDISCARDFRAMEBUFFEREXTPROC glDiscardFramebufferEXT; - - #define GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8_OES -#elif __APPLE__ +#if __APPLE__ #include "TargetConditionals.h" #if TARGET_OS_IPHONE #include #include - #define glGenVertexArrays glGenVertexArraysOES - #define glBindVertexArray glBindVertexArrayOES - #define glDeleteVertexArrays glDeleteVertexArraysOES - #define GL_ARB_vertex_array_object 1 - #define GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8_OES + // #define glGenVertexArrays glGenVertexArraysOES + // #define glBindVertexArray glBindVertexArrayOES + // #define glDeleteVertexArrays glDeleteVertexArraysOES + // #define GL_ARB_vertex_array_object 1 + // #define GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8_OES #elif TARGET_IPHONE_SIMULATOR #include #include #elif TARGET_OS_MAC #include #include - #if GL_APPLE_vertex_array_object - #define GL_ARB_vertex_array_object 1 - #define glGenVertexArrays glGenVertexArraysAPPLE - #define glBindVertexArray glBindVertexArrayAPPLE - #define glDeleteVertexArrays glDeleteVertexArraysAPPLE - #endif #else #error Unsupported Apple platform #endif +#elif MBGL_USE_GLES2 + #include + #include #else #define GL_GLEXT_PROTOTYPES #include @@ -43,8 +33,19 @@ namespace mbgl { namespace gl { + +typedef void (* PFNGLBINDVERTEXARRAYPROC) (GLuint array); +typedef void (* PFNGLDELETEVERTEXARRAYSPROC) (GLsizei n, const GLuint* arrays); +typedef void (* PFNGLGENVERTEXARRAYSPROC) (GLsizei n, GLuint* arrays); +typedef GLboolean (* PFNGLISVERTEXARRAYPROC) (GLuint array); +extern PFNGLBINDVERTEXARRAYPROC BindVertexArray; +extern PFNGLDELETEVERTEXARRAYSPROC DeleteVertexArrays; +extern PFNGLGENVERTEXARRAYSPROC GenVertexArrays; +extern PFNGLISVERTEXARRAYPROC IsVertexArray; + + // Debug group markers, useful for debuggin on iOS -#if defined(__APPLE__) && defined(DEBUG) && defined(GL_EXT_debug_marker) +#if __APPLE__ && defined(DEBUG) && defined(GL_EXT_debug_marker) // static int indent = 0; inline void start_group(const std::string &str) { glPushGroupMarkerEXT(0, str.c_str()); diff --git a/ios/mapbox-gl-cocoa b/ios/mapbox-gl-cocoa index 63d166d3d..f801f5b9f 160000 --- a/ios/mapbox-gl-cocoa +++ b/ios/mapbox-gl-cocoa @@ -1 +1 @@ -Subproject commit 63d166d3dd33a460a5158159ea9656ea651aa179 +Subproject commit f801f5b9fa9ca0e55c379f95295bc13338b19110 diff --git a/platform/default/glfw_view.cpp b/platform/default/glfw_view.cpp index baacfbfd9..34b9ddbef 100644 --- a/platform/default/glfw_view.cpp +++ b/platform/default/glfw_view.cpp @@ -1,4 +1,5 @@ #include +#include #include @@ -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 409fcbf05..ada48b864 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 71096beba..1f5a0ec98 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 + +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()) { createContext(); + loadExtensions(); } HeadlessView::HeadlessView(std::shared_ptr 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 b8b4bac5f..02e9497c9 100644 --- a/platform/default/http_request_baton_curl.cpp +++ b/platform/default/http_request_baton_curl.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -9,6 +10,20 @@ #include #include + +// 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 397a6b192..96d01ab71 100644 --- a/platform/default/image.cpp +++ b/platform/default/image.cpp @@ -1,4 +1,5 @@ #include +#include #include @@ -8,6 +9,19 @@ #include #include +// 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 { diff --git a/src/geometry/vao.cpp b/src/geometry/vao.cpp index 4c459c436..d2fd2727e 100644 --- a/src/geometry/vao.cpp +++ b/src/geometry/vao.cpp @@ -1,20 +1,30 @@ #include +#include namespace mbgl { -#if GL_ARB_vertex_array_object - VertexArrayObject::~VertexArrayObject() { + if (!gl::DeleteVertexArrays) return; + if (vao) { - glDeleteVertexArrays(1, &vao); + gl::DeleteVertexArrays(1, &vao); } } void VertexArrayObject::bindVertexArrayObject() { - if (!vao) { - glGenVertexArrays(1, &vao); + if (!gl::GenVertexArrays || !gl::BindVertexArray) { + static bool reported = false; + if (!reported) { + Log::Warning(Event::OpenGL, "Not using Vertex Array Objects"); + reported = true; + } + return; } - glBindVertexArray(vao); + + if (!vao) { + gl::GenVertexArrays(1, &vao); + } + gl::BindVertexArray(vao); } void VertexArrayObject::verifyBinding(Shader &shader, GLuint vertexBuffer, GLuint elementsBuffer, @@ -41,6 +51,4 @@ void VertexArrayObject::storeBinding(Shader &shader, GLuint vertexBuffer, GLuint bound_elements_buffer = elementsBuffer; } -#endif - } diff --git a/src/map/map.cpp b/src/map/map.cpp index d0a279b64..6e9e47fd5 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -28,6 +29,60 @@ #define _USE_MATH_DEFINES #include +#include + +// Check libuv library version. +const static bool uv_version_check = []() { + const unsigned int version = uv_version(); + const unsigned int major = (version >> 16) & 0xFF; + const unsigned int minor = (version >> 8) & 0xFF; + const unsigned int patch = version & 0xFF; + +#ifndef UV_VERSION_PATCH + // 0.10 doesn't have UV_VERSION_PATCH defined, so we "fake" it by using the library patch level. + const unsigned int UV_VERSION_PATCH = version & 0xFF; +#endif + + if (major != UV_VERSION_MAJOR || minor != UV_VERSION_MINOR || patch != UV_VERSION_PATCH) { + throw std::runtime_error(mbgl::util::sprintf<96>( + "libuv version mismatch: headers report %d.%d.%d, but library reports %d.%d.%d", UV_VERSION_MAJOR, + UV_VERSION_MINOR, UV_VERSION_PATCH, major, minor, patch)); + } + return true; +}(); + + +#include +// Check zlib library version. +const static bool zlib_version_check = []() { + const char *const version = zlibVersion(); + if (version[0] != ZLIB_VERSION[0]) { + throw std::runtime_error(mbgl::util::sprintf<96>( + "zlib version mismatch: headers report %s, but library reports %s", ZLIB_VERSION, version)); + } + + return true; +}(); + + +#include +// Check sqlite3 library version. +const static bool sqlite_version_check = []() { + if (sqlite3_libversion_number() != SQLITE_VERSION_NUMBER) { + throw std::runtime_error(mbgl::util::sprintf<96>( + "sqlite3 libversion mismatch: headers report %d, but library reports %d", + SQLITE_VERSION_NUMBER, sqlite3_libversion_number())); + } + if (strcmp(sqlite3_sourceid(), SQLITE_SOURCE_ID) != 0) { + throw std::runtime_error(mbgl::util::sprintf<256>( + "sqlite3 sourceid mismatch: headers report \"%s\", but library reports \"%s\"", + SQLITE_SOURCE_ID, sqlite3_sourceid())); + } + + return true; +}(); + + using namespace mbgl; Map::Map(View& view_) diff --git a/src/platform/gl.cpp b/src/platform/gl.cpp index a1bf0ffc6..3133f128b 100644 --- a/src/platform/gl.cpp +++ b/src/platform/gl.cpp @@ -2,9 +2,17 @@ #include -#ifdef NVIDIA -PFNGLDISCARDFRAMEBUFFEREXTPROC glDiscardFramebufferEXT; -#endif + +namespace mbgl { +namespace gl { + +PFNGLBINDVERTEXARRAYPROC BindVertexArray = nullptr; +PFNGLDELETEVERTEXARRAYSPROC DeleteVertexArrays = nullptr; +PFNGLGENVERTEXARRAYSPROC GenVertexArrays = nullptr; +PFNGLISVERTEXARRAYPROC IsVertexArray = nullptr; + +} +} void _CHECK_GL_ERROR(const char *cmd, const char *file, int line) { std::cout << cmd << ";" << std::endl; diff --git a/src/renderer/prerendered_texture.cpp b/src/renderer/prerendered_texture.cpp index adb7a5910..c9507d602 100644 --- a/src/renderer/prerendered_texture.cpp +++ b/src/renderer/prerendered_texture.cpp @@ -49,7 +49,11 @@ void PrerenderedTexture::bindFramebuffer() { // Create depth/stencil buffer glGenRenderbuffers(1, &fbo_depth_stencil); glBindRenderbuffer(GL_RENDERBUFFER, fbo_depth_stencil); +#ifdef GL_ES_VERSION_2_0 + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, properties.size, properties.size); +#else glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, properties.size, properties.size); +#endif glBindRenderbuffer(GL_RENDERBUFFER, 0); } diff --git a/test/test.gyp b/test/test.gyp index b245a057b..fecb6ed93 100644 --- a/test/test.gyp +++ b/test/test.gyp @@ -199,9 +199,19 @@ '../mapboxgl.gyp:mbgl-standalone', '<(platform_library)', ], + 'variables': { + 'cflags_cc': [ + '-I<(boost_root)/include', + ] + }, 'conditions': [ - ['OS == "mac"', { 'xcode_settings': { 'OTHER_LDFLAGS': [ '<@(ldflags)', '-framework Foundation' ] } + ['OS == "mac"', { + 'xcode_settings': { + 'OTHER_CPLUSPLUSFLAGS': [ '<@(cflags_cc)' ], + 'OTHER_LDFLAGS': [ '<@(ldflags)', '-framework Foundation' ] + }, }, { + 'cflags_cc': [ '<@(cflags_cc)' ], 'libraries': [ '<@(ldflags)'], }] ]