summaryrefslogtreecommitdiff
path: root/src/mbgl/gl
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/gl
parent8e5214144ec4f3a4fb40b7a7e4d8f09fd10dbb78 (diff)
downloadqtlocation-mapboxgl-234384ece9c70f2a803ed2b1d1eb55b248ec43d1.tar.gz
[core] Move OpenGL extension initialization to Backend
Diffstat (limited to 'src/mbgl/gl')
-rw-r--r--src/mbgl/gl/extension.cpp25
-rw-r--r--src/mbgl/gl/extension.hpp7
2 files changed, 14 insertions, 18 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