From 10bed7ca586eaecee20524c582decacef7a3a1d1 Mon Sep 17 00:00:00 2001 From: Utkarsh Ayachit Date: Wed, 6 Jul 2016 15:26:16 -0400 Subject: [PATCH 1/2] Create correct OSMesa context. Bringing in changes from vtkOSOpenGLRenderWindow to vtkXOpenGLRenderWindow to create correct OSMesa context for OpenGL2 backend. --- Rendering/OpenGL2/vtkXOpenGLRenderWindow.cxx | 37 ++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/Rendering/OpenGL2/vtkXOpenGLRenderWindow.cxx b/Rendering/OpenGL2/vtkXOpenGLRenderWindow.cxx index fb741a3d40a..728b1b20f0f 100644 --- a/Rendering/OpenGL2/vtkXOpenGLRenderWindow.cxx +++ b/Rendering/OpenGL2/vtkXOpenGLRenderWindow.cxx @@ -30,10 +30,25 @@ typedef ptrdiff_t GLintptr; typedef ptrdiff_t GLsizeiptr; #include "GL/glx.h" + +#ifndef GLAPI +#define GLAPI extern +#endif + +#ifndef GLAPIENTRY +#define GLAPIENTRY +#endif + +#ifndef APIENTRY +#define APIENTRY GLAPIENTRY +#endif + #include "vtkToolkits.h" #ifdef VTK_USE_OSMESA #include + +typedef OSMesaContext GLAPIENTRY (*OSMesaCreateContextAttribs_func)( const int *attribList, OSMesaContext sharelist ); #endif #include "vtkCommand.h" @@ -769,6 +784,28 @@ void vtkXOpenGLRenderWindow::CreateOffScreenWindow(int width, int height) this->Size[1] = height; this->OwnWindow = 1; } + +#if (OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 1102) && defined(OSMESA_CONTEXT_MAJOR_VERSION) + static const int attribs[] = { + OSMESA_FORMAT, OSMESA_RGBA, + OSMESA_DEPTH_BITS, 32, + OSMESA_STENCIL_BITS, 0, + OSMESA_ACCUM_BITS, 0, + OSMESA_PROFILE, OSMESA_CORE_PROFILE, + OSMESA_CONTEXT_MAJOR_VERSION, 3, + OSMESA_CONTEXT_MINOR_VERSION, 2, + 0 }; + + OSMesaCreateContextAttribs_func OSMesaCreateContextAttribs = + (OSMesaCreateContextAttribs_func) + OSMesaGetProcAddress("OSMesaCreateContextAttribs"); + + if (OSMesaCreateContextAttribs != NULL) + { + this->Internal->OffScreenContextId = OSMesaCreateContextAttribs(attribs, NULL); + } +#endif + // if we still have no context fall back to the generic signature if (!this->Internal->OffScreenContextId) { this->Internal->OffScreenContextId = OSMesaCreateContext(GL_RGBA, NULL); -- GitLab From 561c9b6403f4562d91e4fe36e55713747fa22d39 Mon Sep 17 00:00:00 2001 From: Utkarsh Ayachit Date: Wed, 6 Jul 2016 15:26:57 -0400 Subject: [PATCH 2/2] Add support for on and off screen Mesa in same build. On and Off scrreen Mesa can now be enabled in the same version of VTK. Tested with Mesa 12.0.0-rc2, but has been reported to work with 11.2 as well. --- CMake/vtkOpenGL.cmake | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/CMake/vtkOpenGL.cmake b/CMake/vtkOpenGL.cmake index a1d69c2927f..f4177f4ecaf 100644 --- a/CMake/vtkOpenGL.cmake +++ b/CMake/vtkOpenGL.cmake @@ -19,9 +19,11 @@ option(VTK_USE_X "Use X for VTK render windows" ${VTK_USE_X_DEFAULT}) # OSMesa logic for offscreen mesa rendering. option(VTK_OPENGL_HAS_OSMESA "The OpenGL library being used supports off screen Mesa calls" OFF) + # EGL offscreen rendering option(VTK_USE_OFFSCREEN_EGL "Use EGL for OpenGL client API for offscreen rendering." OFF) + set(VTK_EGL_DEVICE_INDEX 0 CACHE STRING "Index of the EGL device (graphics card) to use.") @@ -33,21 +35,26 @@ if (VTK_USE_OFFSCREEN_EGL AND ANDROID) endif() option(VTK_USE_OFFSCREEN "Use off screen calls by default" OFF) + unset(VTK_CAN_DO_OFFSCREEN) +unset(VTK_CAN_DO_ONSCREEN) + if(VTK_OPENGL_HAS_OSMESA OR WIN32 OR VTK_USE_OFFSCREEN_EGL) set(VTK_CAN_DO_OFFSCREEN 1) endif() + if(VTK_USE_X OR VTK_USE_COCOA OR WIN32 OR ANDROID OR APPLE_IOS) - set(VTK_USE_OSMESA FALSE) + set(VTK_USE_OSMESA ${VTK_OPENGL_HAS_OSMESA}) if (VTK_USE_OFFSCREEN_EGL) message(FATAL_ERROR "VTK_USE_OFFSCREEN_EGL set together with one of (" "VTK_USE_X, VTK_USE_COCOA, WIN32, ANDROID OR APPLE_IOS). " "You cannot use both offscreen and one of the listed windowing systems.") endif() + set(VTK_CAN_DO_ONSCREEN 1) elseif(VTK_USE_OFFSCREEN_EGL) set(VTK_USE_OSMESA FALSE) else() - set(VTK_USE_OSMESA TRUE) + set(VTK_USE_OSMESA ${VTK_OPENGL_HAS_OSMESA}) endif() mark_as_advanced(VTK_USE_X VTK_OPENGL_HAS_OSMESA VTK_USE_OFFSCREEN_EGL @@ -56,10 +63,17 @@ mark_as_advanced(VTK_USE_X VTK_OPENGL_HAS_OSMESA VTK_USE_OFFSCREEN_EGL if(VTK_USE_OSMESA) find_package(OSMesa REQUIRED) include_directories(SYSTEM ${OSMESA_INCLUDE_DIR}) -elseif(VTK_USE_OFFSCREEN_EGL) - find_package(EGL REQUIRED) - include_directories(SYSTEM ${EGL_INCLUDE_DIR}) -else() +endif() + +if(VTK_USE_OFFSCREEN_EGL) + find_package(EGL REQUIRED) + include_directories(SYSTEM ${EGL_INCLUDE_DIR}) +endif() + +if(VTK_CAN_DO_ONSCREEN) + # OpenGL libraries are explicity needed if windowing system-based API is being + # used. Otherwise, if only doing OFFSCREEN, the GL API is provided by the + # offscreen library be it EGL or OSMESA. find_package(OpenGL REQUIRED) include_directories(SYSTEM ${OPENGL_INCLUDE_DIR}) if(APPLE) @@ -83,9 +97,11 @@ endif() function(vtk_opengl_link target) if(VTK_USE_OSMESA) vtk_module_link_libraries(${target} LINK_PRIVATE ${OSMESA_LIBRARY}) - elseif(VTK_USE_OFFSCREEN_EGL) + endif() + if(VTK_USE_OFFSCREEN_EGL) vtk_module_link_libraries(${target} LINK_PRIVATE ${EGL_LIBRARIES}) - else() + endif() + if(VTK_CAN_DO_ONSCREEN) vtk_module_link_libraries(${target} LINK_PRIVATE ${OPENGL_LIBRARIES}) endif() endfunction() -- GitLab