summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2014-11-07 20:11:45 +0100
committerKonstantin Käfer <mail@kkaefer.com>2014-11-07 20:11:45 +0100
commit9038e963bea3dc40d0ba422d3fa88c924c595da8 (patch)
tree62875224a5a43bcd1d9f48b899fc61590ef3c73e
parentb5198374e766b7c67e3e87a1b9c729038e0b9b68 (diff)
parent8fe8b2f739e997b76fcc768348c66f2007e0968b (diff)
downloadqtlocation-mapboxgl-ios-v0.2.0.tar.gz
Merge pull request #564 from mapbox/load-extensionsios-v0.2.0ios-preview
Load extensions with *GetProcAddress
-rw-r--r--include/mbgl/geometry/vao.hpp24
-rw-r--r--include/mbgl/platform/default/headless_view.hpp1
-rw-r--r--include/mbgl/platform/event.hpp2
-rw-r--r--include/mbgl/platform/gl.hpp41
m---------ios/mapbox-gl-cocoa0
-rw-r--r--platform/default/glfw_view.cpp24
-rw-r--r--platform/default/headless_view.cpp46
-rw-r--r--src/geometry/vao.cpp22
-rw-r--r--src/platform/gl.cpp14
-rw-r--r--src/renderer/prerendered_texture.cpp4
10 files changed, 130 insertions, 48 deletions
diff --git a/include/mbgl/geometry/vao.hpp b/include/mbgl/geometry/vao.hpp
index bb1f571fff..2ecba731f7 100644
--- a/include/mbgl/geometry/vao.hpp
+++ b/include/mbgl/geometry/vao.hpp
@@ -9,7 +9,6 @@
namespace mbgl {
-#if GL_ARB_vertex_array_object
class VertexArrayObject : public util::noncopyable {
public:
inline VertexArrayObject() {};
@@ -28,7 +27,9 @@ public:
if (bound_shader == 0) {
vertexBuffer.bind();
shader.bind(offset);
- storeBinding(shader, vertexBuffer.getID(), 0, offset);
+ if (vao) {
+ storeBinding(shader, vertexBuffer.getID(), 0, offset);
+ }
} else {
verifyBinding(shader, vertexBuffer.getID(), 0, offset);
}
@@ -41,7 +42,9 @@ public:
vertexBuffer.bind();
elementsBuffer.bind();
shader.bind(offset);
- storeBinding(shader, vertexBuffer.getID(), elementsBuffer.getID(), offset);
+ if (vao) {
+ storeBinding(shader, vertexBuffer.getID(), elementsBuffer.getID(), offset);
+ }
} else {
verifyBinding(shader, vertexBuffer.getID(), elementsBuffer.getID(), offset);
}
@@ -65,21 +68,6 @@ private:
char *bound_offset = 0;
};
-#else
-
-class VertexArrayObject : public util::noncopyable {
-public:
- template <typename Shader, typename Buffers>
- void bind(Shader& shader, Buffers& buffers, char *offset) {
- for (auto &buffer : buffers) {
- buffer.bind();
- }
- shader.bind(offset);
- }
-};
-
-#endif
-
}
#endif
diff --git a/include/mbgl/platform/default/headless_view.hpp b/include/mbgl/platform/default/headless_view.hpp
index f140338349..f599dde27a 100644
--- a/include/mbgl/platform/default/headless_view.hpp
+++ b/include/mbgl/platform/default/headless_view.hpp
@@ -25,6 +25,7 @@ public:
~HeadlessView();
void createContext();
+ void loadExtensions();
void resize(uint16_t width, uint16_t height, float pixelRatio);
std::unique_ptr<uint32_t[]> readPixels();
diff --git a/include/mbgl/platform/event.hpp b/include/mbgl/platform/event.hpp
index 2aa4aa0c95..df2d8b03e9 100644
--- a/include/mbgl/platform/event.hpp
+++ b/include/mbgl/platform/event.hpp
@@ -32,6 +32,7 @@ enum class Event : uint8_t {
Database,
HttpRequest,
Sprite,
+ OpenGL,
};
MBGL_DEFINE_ENUM_CLASS(EventClass, Event, {
@@ -44,6 +45,7 @@ MBGL_DEFINE_ENUM_CLASS(EventClass, Event, {
{ Event::Database, "Database" },
{ Event::HttpRequest, "HttpRequest" },
{ Event::Sprite, "Sprite" },
+ { Event::OpenGL, "OpenGL" },
{ Event(-1), "Unknown" },
});
diff --git a/include/mbgl/platform/gl.hpp b/include/mbgl/platform/gl.hpp
index d5162f2c70..6685d1f379 100644
--- a/include/mbgl/platform/gl.hpp
+++ b/include/mbgl/platform/gl.hpp
@@ -3,38 +3,28 @@
#include <string>
-#ifdef NVIDIA
- #include <GLES2/gl2.h>
- #include <GLES2/gl2ext.h>
-
- extern PFNGLDISCARDFRAMEBUFFEREXTPROC glDiscardFramebufferEXT;
-
- #define GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8_OES
-#elif __APPLE__
+#if __APPLE__
#include "TargetConditionals.h"
#if TARGET_OS_IPHONE
#include <OpenGLES/ES2/gl.h>
#include <OpenGLES/ES2/glext.h>
- #define glGenVertexArrays glGenVertexArraysOES
- #define glBindVertexArray glBindVertexArrayOES
- #define glDeleteVertexArrays glDeleteVertexArraysOES
- #define GL_ARB_vertex_array_object 1
- #define GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8_OES
+ // #define glGenVertexArrays glGenVertexArraysOES
+ // #define glBindVertexArray glBindVertexArrayOES
+ // #define glDeleteVertexArrays glDeleteVertexArraysOES
+ // #define GL_ARB_vertex_array_object 1
+ // #define GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8_OES
#elif TARGET_IPHONE_SIMULATOR
#include <OpenGLES/ES2/gl.h>
#include <OpenGLES/ES2/glext.h>
#elif TARGET_OS_MAC
#include <OpenGL/OpenGL.h>
#include <OpenGL/gl.h>
- #if GL_APPLE_vertex_array_object
- #define GL_ARB_vertex_array_object 1
- #define glGenVertexArrays glGenVertexArraysAPPLE
- #define glBindVertexArray glBindVertexArrayAPPLE
- #define glDeleteVertexArrays glDeleteVertexArraysAPPLE
- #endif
#else
#error Unsupported Apple platform
#endif
+#elif MBGL_USE_GLES2
+ #include <GLES2/gl2.h>
+ #include <GLES2/gl2ext.h>
#else
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
@@ -43,8 +33,19 @@
namespace mbgl {
namespace gl {
+
+typedef void (* PFNGLBINDVERTEXARRAYPROC) (GLuint array);
+typedef void (* PFNGLDELETEVERTEXARRAYSPROC) (GLsizei n, const GLuint* arrays);
+typedef void (* PFNGLGENVERTEXARRAYSPROC) (GLsizei n, GLuint* arrays);
+typedef GLboolean (* PFNGLISVERTEXARRAYPROC) (GLuint array);
+extern PFNGLBINDVERTEXARRAYPROC BindVertexArray;
+extern PFNGLDELETEVERTEXARRAYSPROC DeleteVertexArrays;
+extern PFNGLGENVERTEXARRAYSPROC GenVertexArrays;
+extern PFNGLISVERTEXARRAYPROC IsVertexArray;
+
+
// Debug group markers, useful for debuggin on iOS
-#if defined(__APPLE__) && defined(DEBUG) && defined(GL_EXT_debug_marker)
+#if __APPLE__ && defined(DEBUG) && defined(GL_EXT_debug_marker)
// static int indent = 0;
inline void start_group(const std::string &str) {
glPushGroupMarkerEXT(0, str.c_str());
diff --git a/ios/mapbox-gl-cocoa b/ios/mapbox-gl-cocoa
-Subproject eb8f0b81bdec68be0e0cc7e511e62eb8061829f
+Subproject f801f5b9fa9ca0e55c379f95295bc13338b1911
diff --git a/platform/default/glfw_view.cpp b/platform/default/glfw_view.cpp
index baacfbfd9c..34b9ddbef1 100644
--- a/platform/default/glfw_view.cpp
+++ b/platform/default/glfw_view.cpp
@@ -1,4 +1,5 @@
#include <mbgl/platform/default/glfw_view.hpp>
+#include <mbgl/platform/gl.hpp>
#include <mbgl/util/string.hpp>
@@ -26,6 +27,10 @@ void GLFWView::initialize(mbgl::Map *map_) {
monitor = glfwGetPrimaryMonitor();
}
+#ifdef DEBUG
+ glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
+#endif
+
#ifdef GL_ES_VERSION_2_0
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
@@ -63,6 +68,25 @@ void GLFWView::initialize(mbgl::Map *map_) {
glfwSetScrollCallback(window, scroll);
glfwSetKeyCallback(window, key);
+
+ const std::string extensions = (char *)glGetString(GL_EXTENSIONS);
+ {
+ using namespace mbgl;
+
+
+ if (extensions.find("GL_ARB_vertex_array_object") != std::string::npos) {
+ gl::BindVertexArray = (gl::PFNGLBINDVERTEXARRAYPROC)glfwGetProcAddress("glBindVertexArrayARB");
+ gl::DeleteVertexArrays = (gl::PFNGLDELETEVERTEXARRAYSPROC)glfwGetProcAddress("glDeleteVertexArraysARB");
+ gl::GenVertexArrays = (gl::PFNGLGENVERTEXARRAYSPROC)glfwGetProcAddress("glGenVertexArraysARB");
+ gl::IsVertexArray = (gl::PFNGLISVERTEXARRAYPROC)glfwGetProcAddress("glIsVertexArrayARB");
+ } else if (extensions.find("GL_APPLE_vertex_array_object") != std::string::npos) {
+ gl::BindVertexArray = (gl::PFNGLBINDVERTEXARRAYPROC)glfwGetProcAddress("glBindVertexArrayAPPLE");
+ gl::DeleteVertexArrays = (gl::PFNGLDELETEVERTEXARRAYSPROC)glfwGetProcAddress("glDeleteVertexArraysAPPLE");
+ gl::GenVertexArrays = (gl::PFNGLGENVERTEXARRAYSPROC)glfwGetProcAddress("glGenVertexArraysAPPLE");
+ gl::IsVertexArray = (gl::PFNGLISVERTEXARRAYPROC)glfwGetProcAddress("glIsVertexArrayAPPLE");
+ }
+ }
+
glfwMakeContextCurrent(nullptr);
}
diff --git a/platform/default/headless_view.cpp b/platform/default/headless_view.cpp
index 71096beba0..687f3ecf7d 100644
--- a/platform/default/headless_view.cpp
+++ b/platform/default/headless_view.cpp
@@ -11,16 +11,62 @@ static PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = nullptr;
#endif
#endif
+#ifdef MBGL_USE_CGL
+#include <CoreFoundation/CoreFoundation.h>
+
+typedef void (* CGLProc)(void);
+CGLProc CGLGetProcAddress(const char *proc) {
+ static CFBundleRef framework = nullptr;
+ if (!framework) {
+ framework = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl"));
+ if (!framework) {
+ throw std::runtime_error("Failed to load OpenGL.framework");
+ }
+ }
+
+ CFStringRef name = CFStringCreateWithCString(kCFAllocatorDefault, proc, kCFStringEncodingASCII);
+ CGLProc symbol = (CGLProc)CFBundleGetFunctionPointerForName(framework, name);
+ CFRelease(name);
+ return symbol;
+}
+#endif
+
namespace mbgl {
+
HeadlessView::HeadlessView()
: display_(std::make_shared<HeadlessDisplay>()) {
createContext();
+ loadExtensions();
}
HeadlessView::HeadlessView(std::shared_ptr<HeadlessDisplay> display)
: display_(display) {
createContext();
+ loadExtensions();
+}
+
+void HeadlessView::loadExtensions() {
+ make_active();
+ const std::string extensions = (char *)glGetString(GL_EXTENSIONS);
+
+#ifdef MBGL_USE_CGL
+ if (extensions.find("GL_APPLE_vertex_array_object") != std::string::npos) {
+ gl::BindVertexArray = (gl::PFNGLBINDVERTEXARRAYPROC)CGLGetProcAddress("glBindVertexArrayAPPLE");
+ gl::DeleteVertexArrays = (gl::PFNGLDELETEVERTEXARRAYSPROC)CGLGetProcAddress("glDeleteVertexArraysAPPLE");
+ gl::GenVertexArrays = (gl::PFNGLGENVERTEXARRAYSPROC)CGLGetProcAddress("glGenVertexArraysAPPLE");
+ gl::IsVertexArray = (gl::PFNGLISVERTEXARRAYPROC)CGLGetProcAddress("glIsVertexArrayAPPLE");
+ }
+#endif
+#ifdef MBGL_USE_GLX
+ if (extensions.find("GL_ARB_vertex_array_object") != std::string::npos) {
+ gl::BindVertexArray = (gl::PFNGLBINDVERTEXARRAYPROC)glXGetProcAddress((const GLubyte *)"glBindVertexArrayARB");
+ gl::DeleteVertexArrays = (gl::PFNGLDELETEVERTEXARRAYSPROC)glXGetProcAddress((const GLubyte *)"glDeleteVertexArraysARB");
+ gl::GenVertexArrays = (gl::PFNGLGENVERTEXARRAYSPROC)glXGetProcAddress((const GLubyte *)"glGenVertexArraysARB");
+ gl::IsVertexArray = (gl::PFNGLISVERTEXARRAYPROC)glXGetProcAddress((const GLubyte *)"glIsVertexArrayARB");
+ }
+#endif
+ make_inactive();
}
diff --git a/src/geometry/vao.cpp b/src/geometry/vao.cpp
index 4c459c436d..d2fd2727ef 100644
--- a/src/geometry/vao.cpp
+++ b/src/geometry/vao.cpp
@@ -1,20 +1,30 @@
#include <mbgl/geometry/vao.hpp>
+#include <mbgl/platform/log.hpp>
namespace mbgl {
-#if GL_ARB_vertex_array_object
-
VertexArrayObject::~VertexArrayObject() {
+ if (!gl::DeleteVertexArrays) return;
+
if (vao) {
- glDeleteVertexArrays(1, &vao);
+ gl::DeleteVertexArrays(1, &vao);
}
}
void VertexArrayObject::bindVertexArrayObject() {
+ if (!gl::GenVertexArrays || !gl::BindVertexArray) {
+ static bool reported = false;
+ if (!reported) {
+ Log::Warning(Event::OpenGL, "Not using Vertex Array Objects");
+ reported = true;
+ }
+ return;
+ }
+
if (!vao) {
- glGenVertexArrays(1, &vao);
+ gl::GenVertexArrays(1, &vao);
}
- glBindVertexArray(vao);
+ gl::BindVertexArray(vao);
}
void VertexArrayObject::verifyBinding(Shader &shader, GLuint vertexBuffer, GLuint elementsBuffer,
@@ -41,6 +51,4 @@ void VertexArrayObject::storeBinding(Shader &shader, GLuint vertexBuffer, GLuint
bound_elements_buffer = elementsBuffer;
}
-#endif
-
}
diff --git a/src/platform/gl.cpp b/src/platform/gl.cpp
index a1bf0ffc6c..3133f128b9 100644
--- a/src/platform/gl.cpp
+++ b/src/platform/gl.cpp
@@ -2,9 +2,17 @@
#include <iostream>
-#ifdef NVIDIA
-PFNGLDISCARDFRAMEBUFFEREXTPROC glDiscardFramebufferEXT;
-#endif
+
+namespace mbgl {
+namespace gl {
+
+PFNGLBINDVERTEXARRAYPROC BindVertexArray = nullptr;
+PFNGLDELETEVERTEXARRAYSPROC DeleteVertexArrays = nullptr;
+PFNGLGENVERTEXARRAYSPROC GenVertexArrays = nullptr;
+PFNGLISVERTEXARRAYPROC IsVertexArray = nullptr;
+
+}
+}
void _CHECK_GL_ERROR(const char *cmd, const char *file, int line) {
std::cout << cmd << ";" << std::endl;
diff --git a/src/renderer/prerendered_texture.cpp b/src/renderer/prerendered_texture.cpp
index adb7a59105..c9507d6026 100644
--- a/src/renderer/prerendered_texture.cpp
+++ b/src/renderer/prerendered_texture.cpp
@@ -49,7 +49,11 @@ void PrerenderedTexture::bindFramebuffer() {
// Create depth/stencil buffer
glGenRenderbuffers(1, &fbo_depth_stencil);
glBindRenderbuffer(GL_RENDERBUFFER, fbo_depth_stencil);
+#ifdef GL_ES_VERSION_2_0
+ glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, properties.size, properties.size);
+#else
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, properties.size, properties.size);
+#endif
glBindRenderbuffer(GL_RENDERBUFFER, 0);
}