diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2014-11-07 18:17:24 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2014-11-07 18:17:24 +0100 |
commit | 582d616deb5b1febbaa1c8dfb5e3fb405f8cad53 (patch) | |
tree | dde9456630f0e529ca0f062023b876721b11a3ed /platform | |
parent | 7e65c88b464b2faa35f8aa9c3ec3029d5c359393 (diff) | |
download | qtlocation-mapboxgl-582d616deb5b1febbaa1c8dfb5e3fb405f8cad53.tar.gz |
load VAO extension
Diffstat (limited to 'platform')
-rw-r--r-- | platform/default/glfw_view.cpp | 18 | ||||
-rw-r--r-- | platform/default/headless_view.cpp | 38 |
2 files changed, 56 insertions, 0 deletions
diff --git a/platform/default/glfw_view.cpp b/platform/default/glfw_view.cpp index baacfbfd9c..7f8ca69944 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,19 @@ 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_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..8ce93030de 100644 --- a/platform/default/headless_view.cpp +++ b/platform/default/headless_view.cpp @@ -11,16 +11,54 @@ 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 + make_inactive(); } |