summaryrefslogtreecommitdiff
path: root/src/mbgl
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2017-02-27 18:33:16 +0100
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-03-23 14:50:11 -0700
commit234384ece9c70f2a803ed2b1d1eb55b248ec43d1 (patch)
treea69fa3e64179667d79546f4f3d1b33f041e4ea22 /src/mbgl
parent8e5214144ec4f3a4fb40b7a7e4d8f09fd10dbb78 (diff)
downloadqtlocation-mapboxgl-234384ece9c70f2a803ed2b1d1eb55b248ec43d1.tar.gz
[core] Move OpenGL extension initialization to Backend
Diffstat (limited to 'src/mbgl')
-rw-r--r--src/mbgl/gl/extension.cpp25
-rw-r--r--src/mbgl/gl/extension.hpp7
-rw-r--r--src/mbgl/map/backend.cpp11
-rw-r--r--src/mbgl/renderer/painter.cpp2
4 files changed, 23 insertions, 22 deletions
diff --git a/src/mbgl/gl/extension.cpp b/src/mbgl/gl/extension.cpp
index e6b4d9156e..41a5ea175e 100644
--- a/src/mbgl/gl/extension.cpp
+++ b/src/mbgl/gl/extension.cpp
@@ -1,7 +1,6 @@
#include <mbgl/gl/extension.hpp>
#include <mbgl/gl/gl.hpp>
-#include <mutex>
#include <string>
#include <vector>
#include <cstring>
@@ -11,7 +10,7 @@ namespace gl {
namespace detail {
using Probes = std::vector<ExtensionFunctionBase::Probe>;
-using ExtensionFunctions = std::vector<std::pair<glProc*, Probes>>;
+using ExtensionFunctions = std::vector<std::pair<ProcAddress*, Probes>>;
ExtensionFunctions& extensionFunctions() {
static ExtensionFunctions functions;
return functions;
@@ -23,22 +22,18 @@ ExtensionFunctionBase::ExtensionFunctionBase(std::initializer_list<Probe> probes
} // namespace detail
-static std::once_flag initializeExtensionsOnce;
-
-void InitializeExtensions(glProc (*getProcAddress)(const char*)) {
- std::call_once(initializeExtensionsOnce, [getProcAddress] {
- if (const char* extensions =
- reinterpret_cast<const char*>(MBGL_CHECK_ERROR(glGetString(GL_EXTENSIONS)))) {
- for (auto fn : detail::extensionFunctions()) {
- for (auto probe : fn.second) {
- if (strstr(extensions, probe.first) != nullptr) {
- *fn.first = getProcAddress(probe.second);
- break;
- }
+void initializeExtensions(const std::function<ProcAddress(const char*)>& getProcAddress) {
+ if (const char* extensions =
+ reinterpret_cast<const char*>(MBGL_CHECK_ERROR(glGetString(GL_EXTENSIONS)))) {
+ for (auto fn : detail::extensionFunctions()) {
+ for (auto probe : fn.second) {
+ if (strstr(extensions, probe.first) != nullptr) {
+ *fn.first = getProcAddress(probe.second);
+ break;
}
}
}
- });
+ }
}
} // namespace gl
diff --git a/src/mbgl/gl/extension.hpp b/src/mbgl/gl/extension.hpp
index ea5a1ae5f5..7d1d9a4d7d 100644
--- a/src/mbgl/gl/extension.hpp
+++ b/src/mbgl/gl/extension.hpp
@@ -2,12 +2,13 @@
#include <initializer_list>
#include <utility>
+#include <functional>
namespace mbgl {
namespace gl {
-using glProc = void (*)();
-void InitializeExtensions(glProc (*getProcAddress)(const char*));
+using ProcAddress = void (*)();
+void initializeExtensions(const std::function<ProcAddress(const char*)>&);
namespace detail {
@@ -15,7 +16,7 @@ class ExtensionFunctionBase {
public:
using Probe = std::pair<const char*, const char*>;
ExtensionFunctionBase(std::initializer_list<Probe>);
- glProc ptr;
+ ProcAddress ptr;
};
} // namespace detail
diff --git a/src/mbgl/map/backend.cpp b/src/mbgl/map/backend.cpp
index a1a2f8f3a8..29f7522e4f 100644
--- a/src/mbgl/map/backend.cpp
+++ b/src/mbgl/map/backend.cpp
@@ -1,16 +1,23 @@
#include <mbgl/map/backend.hpp>
#include <mbgl/map/backend_scope.hpp>
#include <mbgl/gl/context.hpp>
+#include <mbgl/gl/extension.hpp>
+#include <mbgl/gl/debugging.hpp>
#include <cassert>
namespace mbgl {
-Backend::Backend() : context(std::make_unique<gl::Context>()) {
-}
+Backend::Backend() = default;
gl::Context& Backend::getContext() {
assert(BackendScope::exists());
+ std::call_once(initialized, [this] {
+ context = std::make_unique<gl::Context>();
+ gl::debugging::enable();
+ gl::initializeExtensions(
+ std::bind(&Backend::initializeExtension, this, std::placeholders::_1));
+ });
return *context;
}
diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp
index 754959438b..73a084c8c6 100644
--- a/src/mbgl/renderer/painter.cpp
+++ b/src/mbgl/renderer/painter.cpp
@@ -94,8 +94,6 @@ Painter::Painter(gl::Context& context_,
tileBorderSegments.emplace_back(0, 0, 4, 5);
rasterSegments.emplace_back(0, 0, 4, 6);
- gl::debugging::enable();
-
programs = std::make_unique<Programs>(context,
ProgramParameters{ pixelRatio, false, programCacheDir });
#ifndef NDEBUG