Commit f09903e4 authored by Dan Lipsa's avatar Dan Lipsa

COMP: Add logic to selectively use OpenGL or OSMesa.

Use vtkOpenGL.cmake to decide to use (LINK_PRIVATE) OpenGL or Offscreen Mesa.
OpenGL is now LINK_PRIVATE, so additional libraries and tests need to include OpenGL.
Include the following in your CMakeLists.txt:

include(vtkOpenGL)
vtk_opengl_link(${module})

for every ${module} that uses OpenGL. This takes care of include directories and
linking of proper libraries.
parent c2a63124
......@@ -31,3 +31,20 @@ else()
endif()
mark_as_advanced(VTK_USE_X VTK_OPENGL_HAS_OSMESA VTK_USE_OFFSCREEN)
if(VTK_USE_OSMESA)
find_package(OSMesa REQUIRED)
include_directories(SYSTEM ${OSMESA_INCLUDE_DIR})
else()
find_package(OpenGL REQUIRED)
include_directories(SYSTEM ${OPENGL_INCLUDE_DIR})
endif()
# Function to link a VTK target to the necessary OpenGL libraries.
function(vtk_opengl_link target)
if(VTK_USE_OSMESA)
vtk_module_link_libraries(${target} LINK_PRIVATE ${OSMESA_LIBRARY})
else()
vtk_module_link_libraries(${target} LINK_PRIVATE ${OPENGL_LIBRARIES})
endif()
endfunction()
......@@ -49,3 +49,5 @@ list(APPEND Module_SRCS
set_source_files_properties(${vtk-module}ObjectFactory.cxx WRAP_EXCLUDE)
vtk_module_library(vtkDomainsChemistryOpenGL2 ${Module_SRCS})
include(vtkOpenGL)
vtk_opengl_link(vtkDomainsChemistryOpenGL2)
......@@ -36,8 +36,10 @@ set(HYBRID_EXAMPLES_SRCS
)
if(vtkTestingCore_LOADED)
include(vtkOpenGL)
foreach(name ${HYBRID_EXAMPLES_SRCS})
add_executable(${name} MACOSX_BUNDLE ${name}.cxx)
target_link_libraries(${name} ${VTK_LIBRARIES})
target_link_libraries(${name} LINK_PRIVATE ${VTK_LIBRARIES})
vtk_opengl_link(${name})
endforeach()
endif()
......@@ -34,4 +34,6 @@ endif()
set(${vtk-module}_NO_HeaderTest 1)
vtk_module_library(${vtk-module} ${LibSrcs} ${LibMocSrcs})
include(vtkOpenGL)
vtk_opengl_link(${vtk-module})
vtk_module_link_libraries(${vtk-module} LINK_PRIVATE ${QT_LIBRARIES})
......@@ -33,5 +33,4 @@ set_source_files_properties(
ABSTRACT
)
include_directories(${OPENGL_INCLUDE_DIR})
vtk_module_library(vtkGeovisCore ${Module_SRCS})
......@@ -36,3 +36,5 @@ set_source_files_properties(
)
vtk_module_library(vtkIOExport ${Module_SRCS})
include(vtkOpenGL)
vtk_opengl_link(vtkIOExport)
......@@ -32,3 +32,5 @@ list(APPEND module_SRCS
set_source_files_properties(${vtk-module}ObjectFactory WRAP_EXCLUDE)
vtk_module_library(${vtk-module} ${module_SRCS})
include(vtkOpenGL)
vtk_opengl_link(${vtk-module})
find_package(OpenGL REQUIRED)
include_directories(SYSTEM
${OPENGL_INCLUDE_DIR})
include(vtkObjectFactory)
set(module_SRCS
......@@ -35,3 +31,5 @@ set_source_files_properties(${vtk-module}ObjectFactory WRAP_EXCLUDE)
vtk_module_library(${vtk-module} ${module_SRCS})
vtk_module_link_libraries(${vtk-module}
LINK_PRIVATE ${GLEW_LIBRARY} ${OPENGL_LIBRARIES})
include(vtkOpenGL)
vtk_opengl_link(${vtk-module})
......@@ -6,3 +6,5 @@ set_source_files_properties(
vtkGL2PSContextDevice2D
WRAP_EXCLUDE)
vtk_module_library(${vtk-module} ${Module_SRCS})
include(vtkOpenGL)
vtk_opengl_link(${vtk-module})
......@@ -60,4 +60,5 @@ endforeach()
vtk_module_library(${vtk-module} ${Module_SRCS})
include_directories(${OPENGL_INCLUDE_DIR})
include(vtkOpenGL)
vtk_opengl_link(${vtk-module})
......@@ -24,6 +24,10 @@ vtk_test_cxx_executable(${vtk-module}CxxTests tests
vtkStructuredGridLIC2DTestDriver.cxx
vtkSurfaceLICTestDriver.cxx
)
# vtkSurfaceLICTestDriver needs OpenGL
include(vtkOpenGL)
vtk_opengl_link(${vtk-module}CxxTests)
# surface lic on a curved surface
ExternalData_add_test(VTKData
NAME ${vtk-module}Cxx-SurfaceLICCurvedDefaults
......
......@@ -56,5 +56,3 @@ endforeach()
vtk_module_library(${vtk-module} ${Module_SRCS})
include_directories(${OPENGL_INCLUDE_DIR})
......@@ -2,35 +2,6 @@
if(TARGET vtkRenderingOpenGL2)
message(FATAL_ERROR "vtkRenderingOpenGL cannot be built with vtkRenderingOpenGL2, please disable one of them.")
endif()
# FIXME: This should probably be fixed, vtkgl generation needs some refinement
# to allow for things to split up properly.
set(VTK_USE_X_DEFAULT OFF)
if(APPLE)
option(VTK_USE_COCOA "Use Cocoa for VTK render windows" ON)
mark_as_advanced(VTK_USE_COCOA)
elseif(UNIX)
set(VTK_USE_X_DEFAULT ON)
endif()
option(VTK_USE_X "Use X for VTK render windows" ${VTK_USE_X_DEFAULT})
mark_as_advanced(VTK_USE_X)
# OSMesa logic for offscreen mesa rendering.
option(VTK_OPENGL_HAS_OSMESA
"The OpenGL library being used supports off screen Mesa calls" OFF)
option(VTK_USE_OFFSCREEN "Use off screen calls by default" OFF)
unset(VTK_CAN_DO_OFFSCREEN)
if(VTK_OPENGL_HAS_OSMESA OR WIN32)
set(VTK_CAN_DO_OFFSCREEN 1)
endif()
mark_as_advanced(VTK_OPENGL_HAS_OSMESA VTK_USE_OFFSCREEN)
if(VTK_USE_X OR VTK_USE_COCOA OR WIN32)
set(VTK_USE_OSMESA FALSE)
else()
set(VTK_USE_OSMESA TRUE)
endif()
# FIXME: The TDx support needs some refactoring before we can build it in a
# modular fashion, for now it must remain an option on vtkRenderingOpenGL.
......@@ -189,11 +160,7 @@ set_source_files_properties(
WRAP_EXCLUDE
)
if(VTK_USE_OSMESA)
find_package(OpenGL)
else()
find_package(OpenGL REQUIRED)
endif()
include(vtkOpenGL)
# Configuration for vtkOpenGLExtensionManager
if(WIN32)
......@@ -274,8 +241,6 @@ add_custom_command(
DEPENDS ${VTK_GLEXT_FILE} ${VTK_GLXEXT_FILE} ${VTK_WGLEXT_FILE}
)
include_directories(${OPENGL_INCLUDE_DIR})
set(shader_files
vtkColorMaterialHelper_vs.glsl
vtkDepthPeeling_fs.glsl
......@@ -355,12 +320,6 @@ if(VTK_USE_X)
vtkXOpenGLRenderWindow.cxx
)
elseif(VTK_USE_OSMESA)
message(STATUS "VTK will be built with OSMesa support!")
find_package(OSMesa REQUIRED)
if(NOT OSMESA_FOUND)
message(FATAL_ERROR "The OSMesa library could not be found. REQUIRED for off screen rendering")
endif()
include_directories(${OSMESA_INCLUDE_DIR})
list(APPEND vtk_module_overrides "vtkRenderWindow")
set(vtk_module_vtkRenderWindow_override "vtkOSOpenGLRenderWindow")
list(APPEND Module_SRCS vtkOSOpenGLRenderWindow.cxx)
......@@ -437,7 +396,13 @@ set(${vtk-module}_EXPORT_CODE "#include \"vtkRenderingOpenGLConfigure.h\"")
# Since several headers in this module include vtkOpenGL.h which needed GL.h,
# need to ensure that any dependent modules inherit the include directory
# automatically.
set(${vtk-module}_INCLUDE_DIRS "${OPENGL_INCLUDE_DIR}")
if(VTK_USE_OSMESA)
set(${vtk-module}_SYSTEM_INCLUDE_DIRS
${OSMESA_INCLUDE_DIR})
else()
set(${vtk-module}_SYSTEM_INCLUDE_DIRS
${OPENGL_INCLUDE_DIR})
endif()
# Detect and clear OpenGL errors. If not then other classes/user code
# may detect VTK's OpenGL errors and vice-versa.
......@@ -464,15 +429,12 @@ if (VTK_IGNORE_GLDRIVER_BUGS)
endif()
vtk_module_library(vtkRenderingOpenGL ${Module_SRCS})
vtk_opengl_link(vtkRenderingOpenGL)
vtk_module_link_libraries(vtkRenderingOpenGL
LINK_PUBLIC ${OPENGL_LIBRARIES} ${extra_libs})
LINK_PUBLIC ${extra_libs})
if(VTK_USE_X)
vtk_module_link_libraries(vtkRenderingOpenGL
LINK_PUBLIC ${X11_LIBRARIES} ${X11_Xt_LIB})
elseif(VTK_USE_COCOA)
vtk_module_link_libraries(vtkRenderingOpenGL LINK_PUBLIC "-framework Cocoa")
endif()
if(VTK_OPENGL_HAS_OSMESA)
vtk_module_link_libraries(vtkRenderingOpenGL LINK_PUBLIC ${OSMESA_LIBRARY})
endif()
......@@ -3,6 +3,8 @@ INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}
)
include(vtkOpenGL)
# For tests that actually use a vtkRenderWindow
vtk_add_test_cxx(${vtk-module}CxxTests render_window_tests
LoadOpenGLExtension.cxx
......@@ -37,8 +39,6 @@ if(WIN32 AND NOT VTK_USE_X)
TestWin32OpenGLRenderWindow.cxx NO_VALID)
endif()
include_directories(${OPENGL_INCLUDE_DIR})
vtk_add_test_cxx(${vtk-module}CxxTests ogl_tests
TestScenePicker.cxx,NO_VALID
TestMultiblockDisplayProperties.cxx
......@@ -61,6 +61,9 @@ set(all_tests
${render_window_tests}
${ogl_tests})
vtk_test_cxx_executable(${vtk-module}CxxTests all_tests)
# LoadOpenGLExtension and TestGenericVertexAttributesGLSLDepthPeelingPass
# requires OpenGL
vtk_opengl_link(${vtk-module}CxxTests)
set(TEST_FBO_IMPLEMENTATION_EXE
TestFBOImplementation)
......
......@@ -2,15 +2,9 @@ if(TARGET vtkRenderingOpenGL)
message(FATAL_ERROR "vtkRenderingOpenGL2 cannot be built with vtkRenderingOpenGL, please disable one of them.")
endif()
find_package(OpenGL REQUIRED)
include_directories(SYSTEM
${OPENGL_INCLUDE_DIR})
set(${vtk-module}_SYSTEM_INCLUDE_DIRS
${OPENGL_INCLUDE_DIR})
include(vtkOpenGL)
include(vtkObjectFactory)
include(vtkOpenGLMesaLogic)
# The TDx support has not been moved, this header is here to define nothing,
# and so allow classes in other modules to safely include it and keep going.
......@@ -220,12 +214,6 @@ if(VTK_USE_X)
vtkXOpenGLRenderWindow.cxx
)
elseif(VTK_USE_OSMESA)
message(STATUS "VTK will be built with OSMesa support!")
find_package(OSMesa REQUIRED)
if(NOT OSMESA_FOUND)
message(FATAL_ERROR "The OSMesa library could not be found. REQUIRED for off screen rendering")
endif()
include_directories(${OSMESA_INCLUDE_DIR})
list(APPEND vtk_module_overrides "vtkRenderWindow")
set(vtk_module_vtkRenderWindow_override "vtkOSOpenGLRenderWindow")
list(APPEND Module_SRCS vtkOSOpenGLRenderWindow.cxx)
......@@ -313,13 +301,10 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/vtkRenderingOpenGLConfigure.h.in
set(${vtk-module}_EXPORT_CODE "#include \"vtkRenderingOpenGLConfigure.h\"")
vtk_module_library(${vtk-module} ${Module_SRCS})
vtk_module_link_libraries(${vtk-module}
LINK_PUBLIC ${OPENGL_LIBRARIES})
vtk_opengl_link(${vtk-module})
if(VTK_USE_X)
vtk_module_link_libraries(${vtk-module}
LINK_PUBLIC ${X11_LIBRARIES} ${X11_Xt_LIB})
elseif(VTK_USE_OSMESA)
vtk_module_link_libraries(${vtk-module} LINK_PUBLIC ${OSMESA_LIBRARY})
elseif(VTK_USE_COCOA)
vtk_module_link_libraries(${vtk-module} LINK_PUBLIC "-framework Cocoa")
endif()
......
......@@ -51,3 +51,5 @@ if("${VTK_RENDERING_BACKEND}" STREQUAL "OpenGL2")
endif()
vtk_module_library(vtkRenderingParallel ${Module_SRCS})
include(vtkOpenGL)
vtk_opengl_link(vtkRenderingParallel)
......@@ -86,4 +86,7 @@ vtk_object_factory_configure("${vtk_module_overrides}")
include(vtkMPI)
vtk_module_library(${vtk-module} ${Module_SRCS})
include(vtkOpenGL)
vtk_opengl_link(${vtk-module})
vtk_mpi_link(${vtk-module})
......@@ -105,3 +105,5 @@ list(APPEND Module_SRCS
set_source_files_properties(${vtk-module}ObjectFactory.cxx WRAP_EXCLUDE)
vtk_module_library(vtkRenderingVolumeOpenGL ${Module_SRCS})
include(vtkOpenGL)
vtk_opengl_link(vtkRenderingVolumeOpenGL)
\ No newline at end of file
......@@ -55,3 +55,5 @@ list(APPEND Module_SRCS
set_source_files_properties(${vtk-module}ObjectFactory.cxx WRAP_EXCLUDE)
vtk_module_library(vtkRenderingVolumeOpenGL2 ${Module_SRCS})
include(vtkOpenGL)
vtk_opengl_link(vtkRenderingVolumeOpenGL2)
\ No newline at end of file
......@@ -95,24 +95,10 @@ IF (UNIX)
ENDIF()
ENDIF ()
#
# We need OpenGL
#
# Use GL library provided by parent VTK if possible.
#
IF(NOT OPENGL_FOUND)
FIND_PACKAGE(OpenGL)
ENDIF()
include(vtkOpenGL)
IF (OPENGL_INCLUDE_PATH)
INCLUDE_DIRECTORIES (${OPENGL_INCLUDE_PATH})
ENDIF ()
IF(OPENGL_gl_LIBRARY)
SET (VTKFTGL_LIBS "${VTKFTGL_LIBS};${OPENGL_gl_LIBRARY}")
ENDIF()
IF (VTK_OPENGL_HAS_OSMESA AND OSMESA_LIBRARY)
SET (VTKFTGL_LIBS ${VTKFTGL_LIBS} ${OSMESA_LIBRARY} )
ENDIF ()
#
# We obviously need FreeType
......@@ -123,7 +109,8 @@ SET (VTKFTGL_LIBS "${VTKFTGL_LIBS};${VTK_FREETYPE_LIBRARIES}")
# Define the library (and install it)
#
VTK_ADD_LIBRARY (vtkftgl ${FTGL_SRCS})
TARGET_LINK_LIBRARIES(vtkftgl ${VTKFTGL_LIBS})
vtk_opengl_link(vtkftgl)
TARGET_LINK_LIBRARIES(vtkftgl LINK_PRIVATE ${VTKFTGL_LIBS})
#
# Create the configuration file
......@@ -214,13 +201,15 @@ IF (FTGL_BUILD_EXAMPLES)
demo/FTGLDemo.cpp
)
ADD_EXECUTABLE (ftgl_demo ${FTGL_DEMO_SRCS})
TARGET_LINK_LIBRARIES(ftgl_demo ${VTKFTGL_EXAMPLES_LIBS})
vtk_opengl_link(ftgl_demo)
TARGET_LINK_LIBRARIES(ftgl_demo LINK_PRIVATE ${VTKFTGL_EXAMPLES_LIBS})
#
# Example 2
#
ADD_EXECUTABLE (ftgl_demo2 demo/demo.cpp)
TARGET_LINK_LIBRARIES(ftgl_demo2 ${VTKFTGL_EXAMPLES_LIBS})
vtk_opengl_link(ftgl_demo2)
TARGET_LINK_LIBRARIES(ftgl_demo2 LINK_PRIVATE ${VTKFTGL_EXAMPLES_LIBS})
ENDIF ()
......
......@@ -4,27 +4,11 @@ project(VTKGL2PS)
include_regular_expression(".*")
# Depend on OpenGL
if(NOT VTK_OPENGL_HAS_OSMESA)
find_package(OpenGL REQUIRED)
set(GL2PS_GL_LIBRARIES ${OPENGL_LIBRARIES})
set(GL2PS_GL_INCLUDE_DIR ${OPENGL_INCLUDE_DIR})
else()
set(GL2PS_GL_LIBRARIES ${OSMESA_LIBRARY})
set(GL2PS_GL_INCLUDE_DIR ${OSMESA_INCLUDE_DIR})
if(OPENGL_gl_LIBRARY)
list(APPEND GL2PS_GL_LIBRARIES ${OPENGL_gl_LIBRARY})
endif()
endif()
# Need math on UNIX
if(UNIX)
set(GL2PS_GL_LIBRARIES ${GL2PS_GL_LIBRARIES} m)
endif()
include(vtkOpenGL)
# Include paths
include_directories(
${VTKGL2PS_SOURCE_DIR}/
${GL2PS_GL_INCLUDE_DIR}
${VTKGL2PS_SOURCE_DIR}
)
# Source files
......@@ -48,13 +32,14 @@ set_property(TARGET vtkgl2ps
)
# Linking
target_link_libraries(vtkgl2ps
${GL2PS_GL_LIBRARIES}
target_link_libraries(vtkgl2ps LINK_PRIVATE
${vtkzlib_LIBRARIES}
${vtkpng_LIBRARIES}
)
vtk_opengl_link(vtkgl2ps)
if(UNIX)
target_link_libraries(vtkgl2ps m)
target_link_libraries(vtkgl2ps LINK_PRIVATE m)
endif()
# Install headers
......
project(VTKGLEW)
find_package(OpenGL REQUIRED)
include(vtkOpenGLMesaLogic)
include(vtkOpenGL)
include_directories(${VTKGLEW_SOURCE_DIR} ${VTKGLEW_SOURCE_DIR}/include)
......@@ -18,8 +17,7 @@ if(VTK_USE_OSMESA AND UNIX AND NOT APPLE)
endif()
vtk_add_library(vtkglew ${common_SRCS})
target_link_libraries(vtkglew
LINK_PUBLIC ${OPENGL_LIBRARIES})
vtk_opengl_link(vtkglew)
if(VTK_USE_OSMESA AND UNIX AND NOT APPLE)
target_link_libraries(vtkglew LINK_PRIVATE ${CMAKE_DL_LIBS})
endif()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment