diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2014-07-07 14:49:23 -0700 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2014-07-07 14:49:23 -0700 |
commit | f51bd7fcf17c474f106a2c14c00d527d3f8601a4 (patch) | |
tree | 2b5ae2d4816248767bf2e6a294f283c0ba4ef34b /common | |
parent | 9b61e39ef33463ffa7cb2e987c39565f092e1890 (diff) | |
download | qtlocation-mapboxgl-f51bd7fcf17c474f106a2c14c00d527d3f8601a4.tar.gz |
first draft at glx headless rendering
[skip ci]
Diffstat (limited to 'common')
-rw-r--r-- | common/headless_view.cpp | 58 | ||||
-rw-r--r-- | common/headless_view.hpp | 21 |
2 files changed, 78 insertions, 1 deletions
diff --git a/common/headless_view.cpp b/common/headless_view.cpp index 7fa5b83946..4fd7b42aeb 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -13,6 +13,7 @@ void notify_map_change(MapChange change) { } HeadlessView::HeadlessView() { +#if LLMR_USE_CGL // TODO: test if OpenGL 4.1 with GL_ARB_ES2_compatibility is supported // If it is, use kCGLOGLPVersion_3_2_Core and enable that extension. CGLPixelFormatAttribute attributes[] = { @@ -36,6 +37,26 @@ HeadlessView::HeadlessView() { fprintf(stderr, "Error creating GL context object\n"); return; } +#endif + + #ifdef USE_GLX + x_display = XOpenDisplay(0); + + static int pixelFormat[] = { + GLX_RGBA, + GLX_DOUBLEBUFFER, + GLX_RED_SIZE, 8, + GLX_GREEN_SIZE, 8, + GLX_BLUE_SIZE, 8, + GLX_ALPHA_SIZE, 8, + GLX_DEPTH_SIZE, 24, + GLX_STENCIL_SIZE, 8, + None + }; + + x_info = glXChooseVisual(x_display, DefaultScreen(x_display), pixelFormat); + gl_context = glXCreateContext(display, x_info, 0, GL_TRUE); + #endif make_active(); } @@ -44,6 +65,7 @@ HeadlessView::HeadlessView() { void HeadlessView::resize(int width, int height) { clear_buffers(); +#if LLMR_USE_CGL // Create depth/stencil buffer glGenRenderbuffersEXT(1, &fbo_depth_stencil); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, fbo_depth_stencil); @@ -74,9 +96,17 @@ void HeadlessView::resize(int width, int height) { } return; } +#endif + +#if LLMR_USE_GLX + x_pixmap = XCreatePixmap(display, DefaultRootWindow(display), width, height, 32); + glx_pixmap = glXCreateGLXPixmap(display, x_info, x_pixmap); +#endif + } void HeadlessView::clear_buffers() { +#if LLMR_USE_CGL glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); if (fbo) { @@ -93,24 +123,52 @@ void HeadlessView::clear_buffers() { glDeleteRenderbuffersEXT(1, &fbo_depth_stencil); fbo_depth_stencil = 0; } +#endif + +#if LLMR_USE_GLX + if (glx_pixmap) { + glXDestroyGLXPixmap(x_display, glx_pixmap); + glx_pixmap = nullptr; + } + + if (x_pixmap) { + XFreePixmap(x_display, x_pixmap); + x_pixmap = nullptr; + } +#endif } HeadlessView::~HeadlessView() { clear_buffers(); + +#if LLMR_USE_CGL CGLDestroyContext(gl_context); +#endif } void HeadlessView::make_active() { +#if LLMR_USE_CGL CGLError error = CGLSetCurrentContext(gl_context); if (error) { fprintf(stderr, "Switching OpenGL context failed\n"); } +#endif + +#if LLMR_USE_GLX + if (!glXMakeCurrent(display, glx_pixmap, gl_context)) { + fprintf(stderr, "Switching OpenGL context failed\n"); + } +#endif } void HeadlessView::swap() {} unsigned int HeadlessView::root_fbo() { +#if LLMR_USE_CGL return fbo; +#endif + + return 0; } } diff --git a/common/headless_view.hpp b/common/headless_view.hpp index b79b0c9746..57cdec5246 100644 --- a/common/headless_view.hpp +++ b/common/headless_view.hpp @@ -1,6 +1,15 @@ #ifndef LLMR_COMMON_HEADLESS_CGL #define LLMR_COMMON_HEADLESS_CGL +#ifdef __APPLE__ +#define LLMR_USE_CGL 1 +#define LLMR_CONTEXT_OBJ CGLContextObj +#else +#include <GL/glx.h> +#define LLMR_USE_GLX 1 +#define LLMR_CONTEXT_OBJ GLXContext +#endif + #include <llmr/map/view.hpp> #include <llmr/platform/gl.hpp> @@ -22,10 +31,20 @@ private: private: - CGLContextObj gl_context; + LLMR_CONTEXT_OBJ gl_context; + +#ifdef LLMR_USE_CGL GLuint fbo = 0; GLuint fbo_depth_stencil = 0; GLuint fbo_color = 0; +#endif + +#ifdef LLMR_USE_GLX + XVisualInfo *x_info = nullptr; + Display *x_display = nullptr; + Pixmap x_pixmap; + GLXPixmap glx_pixmap; +#endif }; } |