diff options
author | Leith Bade <leith@mapbox.com> | 2014-12-10 19:22:25 +1100 |
---|---|---|
committer | Leith Bade <leith@mapbox.com> | 2014-12-10 19:22:25 +1100 |
commit | 6bb1a5a146bcffde0f5f25587413c5fb076890b5 (patch) | |
tree | b8141fb0de4d565ffbe92d53ebdb26bb8412f370 /platform | |
parent | c38bd5e40355493fb23b6efbe3a3063cfc9cbe3b (diff) | |
parent | 392150dd4856e1e576a9fa91c52873936504e755 (diff) | |
download | qtlocation-mapboxgl-6bb1a5a146bcffde0f5f25587413c5fb076890b5.tar.gz |
Merge branch 'master' of github.com:mapbox/mapbox-gl-native into android-mason
Conflicts:
include/mbgl/platform/default/headless_view.hpp
platform/default/glfw_view.cpp
platform/default/headless_view.cpp
Diffstat (limited to 'platform')
-rw-r--r-- | platform/default/glfw_view.cpp | 1 | ||||
-rw-r--r-- | platform/default/headless_display.cpp | 36 | ||||
-rw-r--r-- | platform/default/headless_view.cpp | 151 |
3 files changed, 101 insertions, 87 deletions
diff --git a/platform/default/glfw_view.cpp b/platform/default/glfw_view.cpp index 2ac047b8a1..d45dfec59b 100644 --- a/platform/default/glfw_view.cpp +++ b/platform/default/glfw_view.cpp @@ -65,7 +65,6 @@ void GLFWView::initialize(mbgl::Map *map_) { glfwSetScrollCallback(window, scroll); glfwSetKeyCallback(window, key); - const std::string extensions = reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)); { using namespace mbgl; diff --git a/platform/default/headless_display.cpp b/platform/default/headless_display.cpp index ada48b8648..40cc0640a9 100644 --- a/platform/default/headless_display.cpp +++ b/platform/default/headless_display.cpp @@ -18,31 +18,35 @@ HeadlessDisplay::HeadlessDisplay() { GLint num; CGLError error = CGLChoosePixelFormat(attributes, &pixelFormat, &num); - if (error) { - fprintf(stderr, "Error pixel format: %s\n", CGLErrorString(error)); + if (error != kCGLNoError) { + throw std::runtime_error(std::string("Error choosing pixel format:") + CGLErrorString(error) + "\n"); + return; + } + if (num <= 0) { + throw std::runtime_error("No pixel formats found."); return; } #endif #if MBGL_USE_GLX if (!XInitThreads()) { - throw std::runtime_error("Failed to XInitThreads"); + throw std::runtime_error("Failed to XInitThreads."); } - x_display = XOpenDisplay(nullptr); - if (x_display == nullptr) { - throw std::runtime_error("Failed to open X display"); + xDisplay = XOpenDisplay(nullptr); + if (xDisplay == nullptr) { + throw std::runtime_error("Failed to open X display."); } - const char *extensions = (char *)glXQueryServerString(x_display, DefaultScreen(x_display), GLX_EXTENSIONS); + const char *extensions = (char *)glXQueryServerString(xDisplay, DefaultScreen(xDisplay), GLX_EXTENSIONS); if (!extensions) { - throw std::runtime_error("Cannot read GLX extensions"); + throw std::runtime_error("Cannot read GLX extensions."); } if (!strstr(extensions,"GLX_SGIX_fbconfig")) { - throw std::runtime_error("Extension GLX_SGIX_fbconfig was not found"); + throw std::runtime_error("Extension GLX_SGIX_fbconfig was not found."); } if (!strstr(extensions, "GLX_SGIX_pbuffer")) { - throw std::runtime_error("Cannot find glXCreateContextAttribsARB"); + throw std::runtime_error("Cannot find glXCreateContextAttribsARB."); } // We're creating a dummy pbuffer anyway that we're not using. @@ -52,9 +56,12 @@ HeadlessDisplay::HeadlessDisplay() { }; int configs = 0; - fb_configs = glXChooseFBConfig(x_display, DefaultScreen(x_display), pixelFormat, &configs); + fbConfigs = glXChooseFBConfig(xDisplay, DefaultScreen(xDisplay), pixelFormat, &configs); + if (fbConfigs == nullptr) { + throw std::runtime_error("Failed to glXChooseFBConfig."); + } if (configs <= 0) { - throw std::runtime_error("No Framebuffer configurations"); + throw std::runtime_error("No Framebuffer configurations."); } #endif } @@ -65,10 +72,9 @@ HeadlessDisplay::~HeadlessDisplay() { #endif #if MBGL_USE_GLX - XFree(fb_configs); - XCloseDisplay(x_display); + XFree(fbConfigs); + XCloseDisplay(xDisplay); #endif } } - diff --git a/platform/default/headless_view.cpp b/platform/default/headless_view.cpp index 0041fb3bbb..5942f2c46e 100644 --- a/platform/default/headless_view.cpp +++ b/platform/default/headless_view.cpp @@ -7,6 +7,7 @@ #include <sstream> #include <string> #include <cstring> +#include <cassert> #if MBGL_USE_GLX #ifdef GLX_ARB_create_context @@ -23,7 +24,7 @@ CGLProc CGLGetProcAddress(const char *proc) { if (!framework) { framework = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl")); if (!framework) { - throw std::runtime_error("Failed to load OpenGL.framework"); + throw std::runtime_error("Failed to load OpenGL framework."); } } @@ -75,14 +76,22 @@ void HeadlessView::loadExtensions() { gl::DeleteVertexArrays = (gl::PFNGLDELETEVERTEXARRAYSPROC)CGLGetProcAddress("glDeleteVertexArraysAPPLE"); gl::GenVertexArrays = (gl::PFNGLGENVERTEXARRAYSPROC)CGLGetProcAddress("glGenVertexArraysAPPLE"); gl::IsVertexArray = (gl::PFNGLISVERTEXARRAYPROC)CGLGetProcAddress("glIsVertexArrayAPPLE"); + assert(gl::BindVertexArray != nullptr); + assert(gl::DeleteVertexArrays != nullptr); + assert(gl::GenVertexArrays != nullptr); + assert(gl::IsVertexArray != nullptr); } #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"); + gl::BindVertexArray = (gl::PFNGLBINDVERTEXARRAYPROC)glXGetProcAddress((const GLubyte *)"glBindVertexArray"); + gl::DeleteVertexArrays = (gl::PFNGLDELETEVERTEXARRAYSPROC)glXGetProcAddress((const GLubyte *)"glDeleteVertexArrays"); + gl::GenVertexArrays = (gl::PFNGLGENVERTEXARRAYSPROC)glXGetProcAddress((const GLubyte *)"glGenVertexArrays"); + gl::IsVertexArray = (gl::PFNGLISVERTEXARRAYPROC)glXGetProcAddress((const GLubyte *)"glIsVertexArray"); + assert(gl::BindVertexArray != nullptr); + assert(gl::DeleteVertexArrays != nullptr); + assert(gl::GenVertexArrays != nullptr); + assert(gl::IsVertexArray != nullptr); } #endif @@ -99,7 +108,7 @@ void HeadlessView::loadExtensions() { // These are all of the OpenGL Core profile version that we know about. struct core_profile_version { int major, minor; }; -static const core_profile_version core_profile_versions[] = { +static const core_profile_version coreProfileVersions[] = { {4, 5}, {4, 4}, {4, 3}, @@ -113,39 +122,39 @@ static const core_profile_version core_profile_versions[] = { {0, 0}, }; -GLXContext createCoreProfile(Display *dpy, GLXFBConfig fbconfig, bool& usingGl3OrNewer) { - static bool context_creation_failed = false; +GLXContext createCoreProfile(Display *dpy, GLXFBConfig fbConfig, bool& usingGl3OrNewer) { + static bool contextCreationFailed = false; GLXContext ctx = 0; // Set the Error Handler to avoid crashing the program when the context creation fails. // It is expected that some context creation attempts fail, e.g. because the OpenGL // implementation does not support the version we're requesting. - int (*previous_error_handler)(Display *, XErrorEvent *) = XSetErrorHandler([](Display *, XErrorEvent *) { - context_creation_failed = true; + int (*previousErrorHandler)(Display *, XErrorEvent *) = XSetErrorHandler([](Display *, XErrorEvent *) { + contextCreationFailed = true; return 0; }); // Try to create core profiles from the highest known version on down. int i = 0; - for (; !ctx && core_profile_versions[i].major; i++) { - context_creation_failed = false; - const int context_flags[] = { - GLX_CONTEXT_MAJOR_VERSION_ARB, core_profile_versions[i].major, - GLX_CONTEXT_MINOR_VERSION_ARB, core_profile_versions[i].minor, + for (; !ctx && coreProfileVersions[i].major; i++) { + contextCreationFailed = false; + const int contextFlags[] = { + GLX_CONTEXT_MAJOR_VERSION_ARB, coreProfileVersions[i].major, + GLX_CONTEXT_MINOR_VERSION_ARB, coreProfileVersions[i].minor, 0 }; - ctx = glXCreateContextAttribsARB(dpy, fbconfig, 0, True, context_flags); - if (context_creation_failed) { + ctx = glXCreateContextAttribsARB(dpy, fbConfig, 0, True, contextFlags); + if (contextCreationFailed) { ctx = 0; } } - if (core_profile_versions[i].major >= 3) { + if (coreProfileVersions[i].major >= 3) { usingGl3OrNewer = true; } // Restore the old error handler. - XSetErrorHandler(previous_error_handler); + XSetErrorHandler(previousErrorHandler); return ctx; } #endif @@ -153,14 +162,14 @@ GLXContext createCoreProfile(Display *dpy, GLXFBConfig fbconfig, bool& usingGl3O void HeadlessView::createContext() { #if MBGL_USE_CGL - CGLError error = CGLCreateContext(display_->pixelFormat, NULL, &gl_context); - if (error) { - throw std::runtime_error("Error creating GL context object\n"); + CGLError error = CGLCreateContext(display_->pixelFormat, NULL, &glContext); + if (error != kCGLNoError) { + throw std::runtime_error(std::string("Error creating GL context object:") + CGLErrorString(error) + "\n"); } - error = CGLEnable(gl_context, kCGLCEMPEngine); - if (error != kCGLNoError ) { - throw std::runtime_error("Error enabling OpenGL multithreading\n"); + error = CGLEnable(glContext, kCGLCEMPEngine); + if (error != kCGLNoError) { + throw std::runtime_error(std::string("Error enabling OpenGL multithreading:") + CGLErrorString(error) + "\n"); } #endif @@ -171,39 +180,39 @@ void HeadlessView::createContext() { } #endif - x_display = display_->x_display; - fb_configs = display_->fb_configs; + xDisplay = display_->xDisplay; + fbConfigs = display_->fbConfigs; #ifdef GLX_ARB_create_context if (glXCreateContextAttribsARB) { // Try to create a core profile context. - gl_context = createCoreProfile(x_display, fb_configs[0], usingGl3OrNewer); + glContext = createCoreProfile(xDisplay, fbConfigs[0], usingGl3OrNewer); } #endif - if (gl_context == 0) { + if (glContext == 0) { // Try to create a legacy context - gl_context = glXCreateNewContext(x_display, fb_configs[0], GLX_RGBA_TYPE, 0, True); - if (gl_context) { - if (!glXIsDirect(x_display, gl_context)) { - glXDestroyContext(x_display, gl_context); - gl_context = 0; + glContext = glXCreateNewContext(xDisplay, fbConfigs[0], GLX_RGBA_TYPE, 0, True); + if (glContext) { + if (!glXIsDirect(xDisplay, glContext)) { + glXDestroyContext(xDisplay, glContext); + glContext = 0; } } } - if (gl_context == 0) { - throw std::runtime_error("Error creating GL context object"); + if (glContext == 0) { + throw std::runtime_error("Error creating GL context object."); } // Create a dummy pbuffer. We will render to framebuffers anyway, but we need a pbuffer to // activate the context. - int pbuffer_attributes[] = { + int pbufferAttributes[] = { GLX_PBUFFER_WIDTH, 8, GLX_PBUFFER_HEIGHT, 8, 0 }; - glx_pbuffer = glXCreatePbuffer(x_display, fb_configs[0], pbuffer_attributes); + glxPbuffer = glXCreatePbuffer(xDisplay, fbConfigs[0], pbufferAttributes); #endif } @@ -220,34 +229,34 @@ void HeadlessView::resize(uint16_t width, uint16_t height, float pixelRatio) { make_active(); // Create depth/stencil buffer - glGenRenderbuffersEXT(1, &fbo_depth_stencil); - glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, fbo_depth_stencil); + glGenRenderbuffersEXT(1, &fboDepthStencil); + glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, fboDepthStencil); glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH24_STENCIL8_EXT, w, h); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0); - glGenRenderbuffersEXT(1, &fbo_color); - glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, fbo_color); + glGenRenderbuffersEXT(1, &fboColor); + glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, fboColor); glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, w, h); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0); glGenFramebuffersEXT(1, &fbo); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); - glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, fbo_color); - glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER_EXT, fbo_depth_stencil); + glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, fboColor); + glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER_EXT, fboDepthStencil); GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { std::stringstream error("Couldn't create framebuffer: "); switch (status) { - case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT: (error << "incomplete attachment\n"); break; - case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT: error << "incomplete missing attachment\n"; break; - case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT: error << "incomplete dimensions\n"; break; - case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT: error << "incomplete formats\n"; break; - case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT: error << "incomplete draw buffer\n"; break; - case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT: error << "incomplete read buffer\n"; break; - case GL_FRAMEBUFFER_UNSUPPORTED: error << "unsupported\n"; break; + case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT: (error << "incomplete attachment.\n"); break; + case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT: error << "incomplete missing attachment.\n"; break; + case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT: error << "incomplete dimensions.\n"; break; + case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT: error << "incomplete formats.\n"; break; + case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT: error << "incomplete draw buffer.\n"; break; + case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT: error << "incomplete read buffer.\n"; break; + case GL_FRAMEBUFFER_UNSUPPORTED: error << "unsupported.\n"; break; default: error << "other\n"; break; } throw std::runtime_error(error.str()); @@ -288,14 +297,14 @@ void HeadlessView::clear_buffers() { fbo = 0; } - if (fbo_color) { - glDeleteTextures(1, &fbo_color); - fbo_color = 0; + if (fboColor) { + glDeleteTextures(1, &fboColor); + fboColor = 0; } - if (fbo_depth_stencil) { - glDeleteRenderbuffersEXT(1, &fbo_depth_stencil); - fbo_depth_stencil = 0; + if (fboDepthStencil) { + glDeleteRenderbuffersEXT(1, &fboDepthStencil); + fboDepthStencil = 0; } make_inactive(); @@ -305,16 +314,16 @@ HeadlessView::~HeadlessView() { clear_buffers(); #if MBGL_USE_CGL - CGLDestroyContext(gl_context); + CGLDestroyContext(glContext); #endif #if MBGL_USE_GLX - if (glx_pbuffer) { - glXDestroyPbuffer(x_display, glx_pbuffer); - glx_pbuffer = 0; + if (glxPbuffer) { + glXDestroyPbuffer(xDisplay, glxPbuffer); + glxPbuffer = 0; } - glXDestroyContext(x_display, gl_context); + glXDestroyContext(xDisplay, glContext); #endif } @@ -328,15 +337,15 @@ void HeadlessView::notify_map_change(mbgl::MapChange /*change*/, mbgl::timestamp void HeadlessView::make_active() { #if MBGL_USE_CGL - CGLError error = CGLSetCurrentContext(gl_context); - if (error) { - throw std::runtime_error("Switching OpenGL context failed\n"); + CGLError error = CGLSetCurrentContext(glContext); + if (error != kCGLNoError) { + throw std::runtime_error(std::string("Switching OpenGL context failed:") + CGLErrorString(error) + "\n"); } #endif #if MBGL_USE_GLX - if (!glXMakeContextCurrent(x_display, glx_pbuffer, glx_pbuffer, gl_context)) { - throw std::runtime_error("Switching OpenGL context failed\n"); + if (!glXMakeContextCurrent(xDisplay, glxPbuffer, glxPbuffer, glContext)) { + throw std::runtime_error("Switching OpenGL context failed.\n"); } #endif } @@ -344,14 +353,14 @@ void HeadlessView::make_active() { void HeadlessView::make_inactive() { #if MBGL_USE_CGL CGLError error = CGLSetCurrentContext(nullptr); - if (error) { - throw std::runtime_error("Removing OpenGL context failed\n"); + if (error != kCGLNoError) { + throw std::runtime_error(std::string("Removing OpenGL context failed:") + CGLErrorString(error) + "\n"); } #endif #if MBGL_USE_GLX - if (!glXMakeContextCurrent(x_display, 0, 0, nullptr)) { - throw std::runtime_error("Removing OpenGL context failed\n"); + if (!glXMakeContextCurrent(xDisplay, 0, 0, nullptr)) { + throw std::runtime_error("Removing OpenGL context failed.\n"); } #endif } |