summaryrefslogtreecommitdiff
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
parentcc78b74098e02311cc646fe5b82c13641ff705fa (diff)
downloadqtlocation-mapboxgl-2ec2860ce5de2bde751086db13de1c09e643c28c.tar.gz
[core] move OpenGL extension loading to their own headers
-rw-r--r--cmake/core-files.cmake4
-rw-r--r--include/mbgl/gl/gl.hpp47
-rw-r--r--include/mbgl/platform/default/headless_view.hpp1
-rwxr-xr-xplatform/android/src/native_map_view.cpp1
-rw-r--r--platform/default/glfw_view.cpp1
-rw-r--r--platform/ios/src/MGLMapView.mm2
-rw-r--r--platform/macos/src/MGLMapView.mm1
-rw-r--r--platform/qt/src/qmapbox.cpp2
-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
17 files changed, 142 insertions, 100 deletions
diff --git a/cmake/core-files.cmake b/cmake/core-files.cmake
index f9081e69c0..2fc17af76d 100644
--- a/cmake/core-files.cmake
+++ b/cmake/core-files.cmake
@@ -81,6 +81,8 @@ set(MBGL_CORE_FILES
src/mbgl/gl/context.hpp
src/mbgl/gl/debugging.cpp
src/mbgl/gl/debugging.hpp
+ src/mbgl/gl/extension.cpp
+ src/mbgl/gl/extension.hpp
src/mbgl/gl/gl.cpp
src/mbgl/gl/object.cpp
src/mbgl/gl/object.hpp
@@ -88,6 +90,8 @@ set(MBGL_CORE_FILES
src/mbgl/gl/types.hpp
src/mbgl/gl/value.cpp
src/mbgl/gl/value.hpp
+ src/mbgl/gl/vertex_array.cpp
+ src/mbgl/gl/vertex_array.hpp
# layout
src/mbgl/layout/clip_lines.cpp
diff --git a/include/mbgl/gl/gl.hpp b/include/mbgl/gl/gl.hpp
index c849a935c2..a499d731d6 100644
--- a/include/mbgl/gl/gl.hpp
+++ b/include/mbgl/gl/gl.hpp
@@ -1,8 +1,6 @@
#pragma once
-#include <string>
#include <stdexcept>
-#include <vector>
#if __APPLE__
#include "TargetConditionals.h"
@@ -38,51 +36,12 @@ struct Error : std::runtime_error {
void checkError(const char *cmd, const char *file, int line);
+} // namespace gl
+} // namespace mbgl
+
#ifndef NDEBUG
#define MBGL_CHECK_ERROR(cmd) ([&]() { struct __MBGL_C_E { ~__MBGL_C_E() { ::mbgl::gl::checkError(#cmd, __FILE__, __LINE__); } } __MBGL_C_E; return cmd; }())
#else
#define MBGL_CHECK_ERROR(cmd) (cmd)
#endif
-class ExtensionFunctionBase {
-public:
- static std::vector<ExtensionFunctionBase*>& functions();
- typedef std::pair<const char *, const char *> Probe;
- std::vector<Probe> probes;
- void (*ptr)();
-};
-
-template <class>
-class ExtensionFunction;
-
-template <class R, class... Args>
-class ExtensionFunction<R (Args...)> : protected ExtensionFunctionBase {
-public:
- ExtensionFunction(std::initializer_list<Probe> probes_) {
- probes = probes_;
- ExtensionFunctionBase::functions().push_back(this);
- }
-
- explicit operator bool() const {
- return ptr;
- }
-
- R operator()(Args... args) const {
- return (*reinterpret_cast<R (*)(Args...)>(ptr))(std::forward<Args>(args)...);
- }
-};
-
-using glProc = void (*)();
-void InitializeExtensions(glProc (*getProcAddress)(const char *));
-
-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
diff --git a/include/mbgl/platform/default/headless_view.hpp b/include/mbgl/platform/default/headless_view.hpp
index baa6a0382c..23f1e8251a 100644
--- a/include/mbgl/platform/default/headless_view.hpp
+++ b/include/mbgl/platform/default/headless_view.hpp
@@ -23,6 +23,7 @@ typedef XID GLXPbuffer;
#include <mbgl/mbgl.hpp>
#include <mbgl/gl/gl.hpp>
#include <mbgl/gl/types.hpp>
+#include <mbgl/gl/extension.hpp>
#include <memory>
#include <thread>
diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp
index 33ba115b94..2714b832e3 100755
--- a/platform/android/src/native_map_view.cpp
+++ b/platform/android/src/native_map_view.cpp
@@ -15,6 +15,7 @@
#include <mbgl/platform/platform.hpp>
#include <mbgl/platform/event.hpp>
#include <mbgl/platform/log.hpp>
+#include <mbgl/gl/extension.hpp>
#include <mbgl/gl/gl.hpp>
#include <mbgl/util/constants.hpp>
diff --git a/platform/default/glfw_view.cpp b/platform/default/glfw_view.cpp
index 17b233a414..fa5190c80c 100644
--- a/platform/default/glfw_view.cpp
+++ b/platform/default/glfw_view.cpp
@@ -3,6 +3,7 @@
#include <mbgl/sprite/sprite_image.hpp>
#include <mbgl/style/transition_options.hpp>
#include <mbgl/gl/gl.hpp>
+#include <mbgl/gl/extension.hpp>
#include <mbgl/platform/log.hpp>
#include <mbgl/platform/platform.hpp>
#include <mbgl/util/string.hpp>
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index f2a365f455..4d660f8f35 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -1,7 +1,7 @@
#import "MGLMapView_Private.h"
#include <mbgl/platform/log.hpp>
-#include <mbgl/gl/gl.hpp>
+#include <mbgl/gl/extension.hpp>
#import <GLKit/GLKit.h>
#import <OpenGLES/EAGL.h>
diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm
index 13ec4508dc..b40f6ebc62 100644
--- a/platform/macos/src/MGLMapView.mm
+++ b/platform/macos/src/MGLMapView.mm
@@ -22,6 +22,7 @@
#import <mbgl/annotation/annotation.hpp>
#import <mbgl/map/camera.hpp>
#import <mbgl/platform/darwin/reachability.h>
+#import <mbgl/gl/extension.hpp>
#import <mbgl/gl/gl.hpp>
#import <mbgl/sprite/sprite_image.hpp>
#import <mbgl/storage/default_file_source.hpp>
diff --git a/platform/qt/src/qmapbox.cpp b/platform/qt/src/qmapbox.cpp
index 7e7a3c5f84..118b1355e2 100644
--- a/platform/qt/src/qmapbox.cpp
+++ b/platform/qt/src/qmapbox.cpp
@@ -1,6 +1,6 @@
#include "qmapbox.hpp"
-#include <mbgl/gl/gl.hpp>
+#include <mbgl/gl/extension.hpp>
#include <mbgl/map/change.hpp>
#include <mbgl/storage/network_status.hpp>
#include <mbgl/util/default_styles.hpp>
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