diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2015-02-13 16:11:42 -0800 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2015-03-06 15:42:34 +0100 |
commit | e8389d82cdd84d470deb072d82ee9a613cd15df8 (patch) | |
tree | 211e461c0956147cf9fcf04e829dca719219c017 /platform | |
parent | c30bb1a9f80a7a772578d8742e122c013a56202d (diff) | |
download | qtlocation-mapboxgl-e8389d82cdd84d470deb072d82ee9a613cd15df8.tar.gz |
guard against concurrent OpenGL extension loading
Diffstat (limited to 'platform')
-rw-r--r-- | platform/default/glfw_view.cpp | 8 | ||||
-rw-r--r-- | platform/default/headless_view.cpp | 18 | ||||
-rw-r--r-- | platform/ios/MGLMapView.mm | 8 |
3 files changed, 25 insertions, 9 deletions
diff --git a/platform/default/glfw_view.cpp b/platform/default/glfw_view.cpp index 865636aebf..6d23a51ffb 100644 --- a/platform/default/glfw_view.cpp +++ b/platform/default/glfw_view.cpp @@ -2,6 +2,8 @@ #include <mbgl/platform/gl.hpp> #include <mbgl/platform/log.hpp> +pthread_once_t loadGLExtensions = PTHREAD_ONCE_INIT; + GLFWView::GLFWView(bool fullscreen_) : fullscreen(fullscreen_) { #ifdef NVIDIA glDiscardFramebufferEXT = reinterpret_cast<PFNGLDISCARDFRAMEBUFFEREXTPROC>(glfwGetProcAddress("glDiscardFramebufferEXT")); @@ -71,8 +73,8 @@ void GLFWView::initialize(mbgl::Map *map_) { glfwSetScrollCallback(window, onScroll); glfwSetKeyCallback(window, onKey); - const std::string extensions = reinterpret_cast<const char *>(MBGL_CHECK_ERROR(glGetString(GL_EXTENSIONS))); - { + pthread_once(&loadGLExtensions, [] { + const std::string extensions = reinterpret_cast<const char *>(MBGL_CHECK_ERROR(glGetString(GL_EXTENSIONS))); using namespace mbgl; if (extensions.find("GL_KHR_debug") != std::string::npos) { @@ -152,7 +154,7 @@ void GLFWView::initialize(mbgl::Map *map_) { // Require packed depth stencil gl::isPackedDepthStencilSupported = true; gl::isDepth24Supported = true; - } + }); glfwMakeContextCurrent(nullptr); } diff --git a/platform/default/headless_view.cpp b/platform/default/headless_view.cpp index a3128234ea..5f41994c27 100644 --- a/platform/default/headless_view.cpp +++ b/platform/default/headless_view.cpp @@ -10,6 +10,8 @@ #include <cstring> #include <cassert> +pthread_once_t loadGLExtensions = PTHREAD_ONCE_INIT; + #ifdef MBGL_USE_CGL #include <CoreFoundation/CoreFoundation.h> @@ -48,10 +50,18 @@ HeadlessView::HeadlessView(std::shared_ptr<HeadlessDisplay> display) } void HeadlessView::loadExtensions() { + if (extensionsLoaded) { + return; + } + activate(); - const char *extensionPtr = reinterpret_cast<const char *>(MBGL_CHECK_ERROR(glGetString(GL_EXTENSIONS))); - if (extensionPtr) { + pthread_once(&loadGLExtensions, [] { + const char *extensionPtr = reinterpret_cast<const char *>(MBGL_CHECK_ERROR(glGetString(GL_EXTENSIONS))); + + if (!extensionPtr) { + return; + } const std::string extensions = extensionPtr; #ifdef MBGL_USE_CGL @@ -78,12 +88,14 @@ void HeadlessView::loadExtensions() { assert(gl::IsVertexArray != nullptr); } #endif - } + }); // HeadlessView requires packed depth stencil gl::isPackedDepthStencilSupported = true; gl::isDepth24Supported = true; + extensionsLoaded = true; + deactivate(); } diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm index b1932737b7..45c96e7c3b 100644 --- a/platform/ios/MGLMapView.mm +++ b/platform/ios/MGLMapView.mm @@ -37,6 +37,7 @@ const std::string &defaultCacheDatabase() { return path; } +static dispatch_once_t loadGLExtensions; extern NSString *const MGLStyleKeyGeneric; extern NSString *const MGLStyleKeyFill; @@ -213,8 +214,9 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr; // load extensions // - const std::string extensions = (char *)glGetString(GL_EXTENSIONS); - { + dispatch_once(&loadGLExtensions, ^{ + const std::string extensions = (char *)glGetString(GL_EXTENSIONS); + using namespace mbgl; if (extensions.find("GL_OES_vertex_array_object") != std::string::npos) { @@ -231,7 +233,7 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr; if (extensions.find("GL_OES_depth24") != std::string::npos) { gl::isDepth24Supported = YES; } - } + }); // setup mbgl map // |