diff options
Diffstat (limited to 'common/headless_view.cpp')
-rw-r--r-- | common/headless_view.cpp | 58 |
1 files changed, 58 insertions, 0 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; } } |