summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-09-28 17:21:20 +0200
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-09-29 13:19:27 -0700
commit2ec2860ce5de2bde751086db13de1c09e643c28c (patch)
treed9539718dde07e3ddeaf2b502032828157a25e27 /src
parentcc78b74098e02311cc646fe5b82c13641ff705fa (diff)
downloadqtlocation-mapboxgl-2ec2860ce5de2bde751086db13de1c09e643c28c.tar.gz
[core] move OpenGL extension loading to their own headers
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/geometry/vao.cpp1
-rw-r--r--src/mbgl/gl/context.cpp1
-rw-r--r--src/mbgl/gl/debugging.cpp1
-rw-r--r--src/mbgl/gl/extension.cpp48
-rw-r--r--src/mbgl/gl/extension.hpp41
-rw-r--r--src/mbgl/gl/gl.cpp54
-rw-r--r--src/mbgl/gl/value.cpp1
-rw-r--r--src/mbgl/gl/vertex_array.cpp22
-rw-r--r--src/mbgl/gl/vertex_array.hpp14
9 files changed, 129 insertions, 54 deletions
diff --git a/src/mbgl/geometry/vao.cpp b/src/mbgl/geometry/vao.cpp
index 214ed7a88d..2c5e1677ff 100644
--- a/src/mbgl/geometry/vao.cpp
+++ b/src/mbgl/geometry/vao.cpp
@@ -1,4 +1,5 @@
#include <mbgl/geometry/vao.hpp>
+#include <mbgl/gl/vertex_array.hpp>
#include <mbgl/platform/log.hpp>
#include <mbgl/util/string.hpp>
#include <mbgl/gl/gl.hpp>
diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp
index 3c1b5e45ae..ae50e64cbc 100644
--- a/src/mbgl/gl/context.cpp
+++ b/src/mbgl/gl/context.cpp
@@ -1,5 +1,6 @@
#include <mbgl/gl/context.hpp>
#include <mbgl/gl/gl.hpp>
+#include <mbgl/gl/vertex_array.hpp>
#include <mbgl/util/traits.hpp>
namespace mbgl {
diff --git a/src/mbgl/gl/debugging.cpp b/src/mbgl/gl/debugging.cpp
index e61de42bc3..943710ab7f 100644
--- a/src/mbgl/gl/debugging.cpp
+++ b/src/mbgl/gl/debugging.cpp
@@ -1,5 +1,6 @@
#include <mbgl/gl/debugging.hpp>
#include <mbgl/gl/gl.hpp>
+#include <mbgl/gl/extension.hpp>
#include <mbgl/platform/event.hpp>
#include <mbgl/platform/log.hpp>
diff --git a/src/mbgl/gl/extension.cpp b/src/mbgl/gl/extension.cpp
new file mode 100644
index 0000000000..ee94e8ecfd
--- /dev/null
+++ b/src/mbgl/gl/extension.cpp
@@ -0,0 +1,48 @@
+#include <mbgl/gl/extension.hpp>
+#include <mbgl/gl/gl.hpp>
+
+#include <mutex>
+#include <string>
+#include <vector>
+
+namespace mbgl {
+namespace gl {
+namespace detail {
+
+using Probes = std::vector<ExtensionFunctionBase::Probe>;
+using ExtensionFunctions = std::vector<std::pair<glProc*, Probes>>;
+ExtensionFunctions& extensionFunctions() {
+ static ExtensionFunctions functions;
+ return functions;
+}
+
+ExtensionFunctionBase::ExtensionFunctionBase(std::initializer_list<Probe> probes) {
+ extensionFunctions().emplace_back(&ptr, probes);
+}
+
+} // namespace detail
+
+static std::once_flag initializeExtensionsOnce;
+
+void InitializeExtensions(glProc (*getProcAddress)(const char*)) {
+ std::call_once(initializeExtensionsOnce, [getProcAddress] {
+ const char* extensionsPtr =
+ reinterpret_cast<const char*>(MBGL_CHECK_ERROR(glGetString(GL_EXTENSIONS)));
+
+ if (!extensionsPtr)
+ return;
+
+ const std::string extensions = extensionsPtr;
+ for (auto fn : detail::extensionFunctions()) {
+ for (auto probe : fn.second) {
+ if (extensions.find(probe.first) != std::string::npos) {
+ *fn.first = getProcAddress(probe.second);
+ break;
+ }
+ }
+ }
+ });
+}
+
+} // namespace gl
+} // namespace mbgl
diff --git a/src/mbgl/gl/extension.hpp b/src/mbgl/gl/extension.hpp
new file mode 100644
index 0000000000..ea5a1ae5f5
--- /dev/null
+++ b/src/mbgl/gl/extension.hpp
@@ -0,0 +1,41 @@
+#pragma once
+
+#include <initializer_list>
+#include <utility>
+
+namespace mbgl {
+namespace gl {
+
+using glProc = void (*)();
+void InitializeExtensions(glProc (*getProcAddress)(const char*));
+
+namespace detail {
+
+class ExtensionFunctionBase {
+public:
+ using Probe = std::pair<const char*, const char*>;
+ ExtensionFunctionBase(std::initializer_list<Probe>);
+ glProc ptr;
+};
+
+} // namespace detail
+
+template <class>
+class ExtensionFunction;
+
+template <class R, class... Args>
+class ExtensionFunction<R(Args...)> : protected detail::ExtensionFunctionBase {
+public:
+ using detail::ExtensionFunctionBase::ExtensionFunctionBase;
+
+ explicit operator bool() const {
+ return ptr;
+ }
+
+ R operator()(Args... args) const {
+ return (*reinterpret_cast<R (*)(Args...)>(ptr))(std::forward<Args>(args)...);
+ }
+};
+
+} // namespace gl
+} // namespace mbgl
diff --git a/src/mbgl/gl/gl.cpp b/src/mbgl/gl/gl.cpp
index 2040ff0573..5cef254160 100644
--- a/src/mbgl/gl/gl.cpp
+++ b/src/mbgl/gl/gl.cpp
@@ -1,63 +1,9 @@
#include <mbgl/gl/gl.hpp>
#include <mbgl/util/string.hpp>
-#include <mbgl/platform/log.hpp>
-
-#include <cassert>
-#include <iostream>
-#include <unordered_map>
-#include <mutex>
namespace mbgl {
namespace gl {
-ExtensionFunction<void (GLuint array)>
- BindVertexArray({
- {"GL_ARB_vertex_array_object", "glBindVertexArray"},
- {"GL_OES_vertex_array_object", "glBindVertexArrayOES"},
- {"GL_APPLE_vertex_array_object", "glBindVertexArrayAPPLE"}
- });
-
-ExtensionFunction<void (GLsizei n, const GLuint* arrays)>
- DeleteVertexArrays({
- {"GL_ARB_vertex_array_object", "glDeleteVertexArrays"},
- {"GL_OES_vertex_array_object", "glDeleteVertexArraysOES"},
- {"GL_APPLE_vertex_array_object", "glDeleteVertexArraysAPPLE"}
- });
-
-ExtensionFunction<void (GLsizei n, GLuint* arrays)>
- GenVertexArrays({
- {"GL_ARB_vertex_array_object", "glGenVertexArrays"},
- {"GL_OES_vertex_array_object", "glGenVertexArraysOES"},
- {"GL_APPLE_vertex_array_object", "glGenVertexArraysAPPLE"}
- });
-
-std::vector<ExtensionFunctionBase*>& ExtensionFunctionBase::functions() {
- static std::vector<ExtensionFunctionBase*> functions;
- return functions;
-}
-
-static std::once_flag initializeExtensionsOnce;
-
-void InitializeExtensions(glProc (*getProcAddress)(const char *)) {
- std::call_once(initializeExtensionsOnce, [getProcAddress] {
- const char * extensionsPtr = reinterpret_cast<const char *>(
- MBGL_CHECK_ERROR(glGetString(GL_EXTENSIONS)));
-
- if (!extensionsPtr)
- return;
-
- const std::string extensions = extensionsPtr;
- for (auto fn : ExtensionFunctionBase::functions()) {
- for (auto probe : fn->probes) {
- if (extensions.find(probe.first) != std::string::npos) {
- fn->ptr = getProcAddress(probe.second);
- break;
- }
- }
- }
- });
-}
-
namespace {
constexpr const char* stringFromError(GLenum err) {
diff --git a/src/mbgl/gl/value.cpp b/src/mbgl/gl/value.cpp
index ae7d648a45..e78b97ef2e 100644
--- a/src/mbgl/gl/value.cpp
+++ b/src/mbgl/gl/value.cpp
@@ -1,5 +1,6 @@
#include <mbgl/gl/value.hpp>
#include <mbgl/gl/gl.hpp>
+#include <mbgl/gl/vertex_array.hpp>
namespace mbgl {
namespace gl {
diff --git a/src/mbgl/gl/vertex_array.cpp b/src/mbgl/gl/vertex_array.cpp
new file mode 100644
index 0000000000..df63bbc4b7
--- /dev/null
+++ b/src/mbgl/gl/vertex_array.cpp
@@ -0,0 +1,22 @@
+#include <mbgl/gl/vertex_array.hpp>
+
+namespace mbgl {
+namespace gl {
+
+ExtensionFunction<void(GLuint array)>
+ BindVertexArray({ { "GL_ARB_vertex_array_object", "glBindVertexArray" },
+ { "GL_OES_vertex_array_object", "glBindVertexArrayOES" },
+ { "GL_APPLE_vertex_array_object", "glBindVertexArrayAPPLE" } });
+
+ExtensionFunction<void(GLsizei n, const GLuint* arrays)>
+ DeleteVertexArrays({ { "GL_ARB_vertex_array_object", "glDeleteVertexArrays" },
+ { "GL_OES_vertex_array_object", "glDeleteVertexArraysOES" },
+ { "GL_APPLE_vertex_array_object", "glDeleteVertexArraysAPPLE" } });
+
+ExtensionFunction<void(GLsizei n, GLuint* arrays)>
+ GenVertexArrays({ { "GL_ARB_vertex_array_object", "glGenVertexArrays" },
+ { "GL_OES_vertex_array_object", "glGenVertexArraysOES" },
+ { "GL_APPLE_vertex_array_object", "glGenVertexArraysAPPLE" } });
+
+} // namespace gl
+} // namespace mbgl
diff --git a/src/mbgl/gl/vertex_array.hpp b/src/mbgl/gl/vertex_array.hpp
new file mode 100644
index 0000000000..6215e56f21
--- /dev/null
+++ b/src/mbgl/gl/vertex_array.hpp
@@ -0,0 +1,14 @@
+#pragma once
+
+#include <mbgl/gl/extension.hpp>
+#include <mbgl/gl/gl.hpp>
+
+namespace mbgl {
+namespace gl {
+
+extern ExtensionFunction<void(GLuint array)> BindVertexArray;
+extern ExtensionFunction<void(GLsizei n, const GLuint* arrays)> DeleteVertexArrays;
+extern ExtensionFunction<void(GLsizei n, GLuint* arrays)> GenVertexArrays;
+
+} // namespace gl
+} // namespace mbgl \ No newline at end of file