From ee54220c7df2863dbbda191ad666416a6c84531b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Wed, 15 Oct 2014 09:56:57 -0700 Subject: lower our expectations towards the pbuffer and use framebuffers instead --- common/headless_display.cpp | 12 ++---------- common/headless_view.cpp | 38 ++++++++++++++------------------------ common/headless_view.hpp | 8 +++++--- 3 files changed, 21 insertions(+), 37 deletions(-) (limited to 'common') diff --git a/common/headless_display.cpp b/common/headless_display.cpp index 3e30d62749..3aaf2020b9 100644 --- a/common/headless_display.cpp +++ b/common/headless_display.cpp @@ -45,15 +45,9 @@ HeadlessDisplay::HeadlessDisplay() { throw std::runtime_error("Cannot find glXCreateContextAttribsARB"); } - + // We're creating a dummy pbuffer anyway that we're not using. static int pixelFormat[] = { - GLX_DOUBLEBUFFER, False, - GLX_RED_SIZE, 8, - GLX_GREEN_SIZE, 8, - GLX_BLUE_SIZE, 8, - GLX_ALPHA_SIZE, 8, - GLX_DEPTH_SIZE, 24, - GLX_STENCIL_SIZE, 8, + GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT, None }; @@ -62,8 +56,6 @@ HeadlessDisplay::HeadlessDisplay() { if (configs <= 0) { throw std::runtime_error("No Framebuffer configurations"); } - - XSync(x_display, False); #endif } diff --git a/common/headless_view.cpp b/common/headless_view.cpp index c482bbd8b3..7b739e1d67 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -47,18 +47,25 @@ void HeadlessView::createContext() { fb_configs = display_->fb_configs; - int attributes[] = { + int context_attributes[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, 2, GLX_CONTEXT_MINOR_VERSION_ARB, 1, GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB, GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, None }; - gl_context = glXCreateContextAttribsARB(x_display, fb_configs[0], 0, True, attributes); + gl_context = glXCreateContextAttribsARB(x_display, fb_configs[0], 0, True, context_attributes); if (gl_context == nullptr) { throw std::runtime_error("Error creating GL context object"); } + int pbuffer_attributes[] = { + GLX_PBUFFER_WIDTH, 32, + GLX_PBUFFER_HEIGHT, 32, + None + }; + glx_pbuffer = glXCreatePbuffer(x_display, fb_configs[0], pbuffer_attributes); + #endif } @@ -72,7 +79,6 @@ void HeadlessView::resize(uint16_t width, uint16_t height, float pixelRatio) { const unsigned int w = width_ * pixelRatio_; const unsigned int h = height_ * pixelRatio_; -#if MBGL_USE_CGL make_active(); // Create depth/stencil buffer @@ -110,16 +116,6 @@ void HeadlessView::resize(uint16_t width, uint16_t height, float pixelRatio) { } make_inactive(); -#endif - -#if MBGL_USE_GLX - int attributes[] = { - GLX_PBUFFER_WIDTH, static_cast(w), - GLX_PBUFFER_HEIGHT, static_cast(h), - None - }; - glx_pbuffer = glXCreatePbuffer(x_display, fb_configs[0], attributes); -#endif } const std::unique_ptr HeadlessView::readPixels() { @@ -136,7 +132,6 @@ const std::unique_ptr HeadlessView::readPixels() { } void HeadlessView::clear_buffers() { -#if MBGL_USE_CGL make_active(); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); @@ -157,16 +152,6 @@ void HeadlessView::clear_buffers() { } make_inactive(); -#endif - -#if MBGL_USE_GLX - make_inactive(); - - if (glx_pbuffer) { - glXDestroyPbuffer(x_display, glx_pbuffer); - glx_pbuffer = 0; - } -#endif } HeadlessView::~HeadlessView() { @@ -177,6 +162,11 @@ HeadlessView::~HeadlessView() { #endif #if MBGL_USE_GLX + if (glx_pbuffer) { + glXDestroyPbuffer(x_display, glx_pbuffer); + glx_pbuffer = 0; + } + glXDestroyContext(x_display, gl_context); #endif } diff --git a/common/headless_view.hpp b/common/headless_view.hpp index ec76f1a077..195364db6e 100644 --- a/common/headless_view.hpp +++ b/common/headless_view.hpp @@ -4,6 +4,7 @@ #ifdef __APPLE__ #define MBGL_USE_CGL 1 #else +#define GL_GLEXT_PROTOTYPES #include #define MBGL_USE_GLX 1 #endif @@ -46,9 +47,6 @@ private: #if MBGL_USE_CGL CGLContextObj gl_context; - GLuint fbo = 0; - GLuint fbo_depth_stencil = 0; - GLuint fbo_color = 0; #endif #if MBGL_USE_GLX @@ -57,6 +55,10 @@ private: GLXContext gl_context = nullptr; GLXPbuffer glx_pbuffer = 0; #endif + + GLuint fbo = 0; + GLuint fbo_depth_stencil = 0; + GLuint fbo_color = 0; }; } -- cgit v1.2.1