root/OpenSceneGraph/trunk/src/osgViewer/CMakeLists.txt @ 10813

Revision 10813, 6.3 kB (checked in by robert, 5 years ago)

From Colin MacDonald?, "In my application I have a custom graphics context class, derived from
osg::GraphicsContext?, in order to give good integration with the
application's GUI toolkit. This works really well.

However, I need to share OpenGL texture resources with the standard
osgViewer GraphicsContext? implementations, in particular the
PixelBuffers?. This is essential for my application to conserve graphics
memory on low-end hardware. Currently the standard osg implementations
will not share resources with another derived osg::GraphicsContext?,
other than the pre-defined osgViewer classes e.g. PixelBufferX11 is
hardcoded to only share resources with GraphicsWindowX11 and
PixelBufferX11 objects, and no other osg::GraphicsContext? object.

To address this in the cleanest way I could think of, I have moved the
OpenGL handle variables for each platform into a small utility class,
e.g. GraphicsHandleX11 for unix. Then GraphicsWindowX11, PixelBufferX11
and any other derived osg::GraphicsContext? class can inherit from
GraphicsHandleX11 to share OpenGL resources.

I have updated the X11, Win32 and Carbon implementations to use this.
The changes are minor. I haven't touched the Cocoa implmentation as
I'm not familiar with it at all and couldn't test it - it will work
unchanged.

Without this I had some horrible hacks in my application, this greatly
simplifies things for me. It also simplifies the osgViewer
implementations slightly. Perhaps it may help with other users'
desires to share resources with external graphics contexts, as was
discussed on the user list recently."

Notes from Robert Osfield, adapted Colin's submission to work with the new EGL related changes.

  • Property svn:eol-style set to native
RevLine 
[6321]1
2# FIXME: For OS X, need flag for Framework or dylib
[9949]3IF(DYNAMIC_OPENSCENEGRAPH)
[6660]4    ADD_DEFINITIONS(-DOSGVIEWER_LIBRARY)
[9949]5ELSE()
[6660]6    ADD_DEFINITIONS(-DOSG_LIBRARY_STATIC)
[9949]7ENDIF()
[6321]8
9SET(LIB_NAME osgViewer)
[9001]10
[6321]11SET(HEADER_PATH ${OpenSceneGraph_SOURCE_DIR}/include/${LIB_NAME})
12SET(LIB_PUBLIC_HEADERS
[6660]13    ${HEADER_PATH}/CompositeViewer
14    ${HEADER_PATH}/Export
15    ${HEADER_PATH}/GraphicsWindow
[7178]16    ${HEADER_PATH}/Renderer
[6660]17    ${HEADER_PATH}/Scene
18    ${HEADER_PATH}/Version
19    ${HEADER_PATH}/View
20    ${HEADER_PATH}/Viewer
[7507]21    ${HEADER_PATH}/ViewerBase
[6663]22    ${HEADER_PATH}/ViewerEventHandlers
[6321]23)
24
25SET(LIB_COMMON_FILES
[6660]26    CompositeViewer.cpp
[7178]27    HelpHandler.cpp
28    Renderer.cpp
[6660]29    Scene.cpp
[8629]30    ScreenCaptureHandler.cpp
[6660]31    StatsHandler.cpp
32    Version.cpp
33    View.cpp
34    Viewer.cpp
[7507]35    ViewerBase.cpp
[6663]36    ViewerEventHandlers.cpp
[9671]37    ${OPENSCENEGRAPH_VERSIONINFO_RC}
[6321]38)
39
[8737]40SET(LIB_EXTRA_LIBS)
[6321]41
42IF(WIN32)
[9001]43    #
44    # Enable workaround for OpenGL driver issues when used in multithreaded/multiscreen with NVidia drivers on Windows XP
45    # For example: osgviewer dumptruck.osg was showing total garbage (screen looked like shattered, splashed hedgehog)
46    # There were also serious issues with render to texture cameras.
47    # Workaround repeats makeCurrentContext call as it was found that this causes the problems to dissapear.
48    #
[9165]49    OPTION(OSG_MULTIMONITOR_MULTITHREAD_WIN32_NVIDIA_WORKAROUND "Set to ON if you have NVidia board and drivers earlier than 177.92 ver" OFF)
[9001]50    MARK_AS_ADVANCED(OSG_MULTIMONITOR_MULTITHREAD_WIN32_NVIDIA_WORKAROUND)
51    IF(OSG_MULTIMONITOR_MULTITHREAD_WIN32_NVIDIA_WORKAROUND)
52        ADD_DEFINITIONS(-DOSG_MULTIMONITOR_MULTITHREAD_WIN32_NVIDIA_WORKAROUND)
[9949]53    ENDIF()
[9001]54
[7012]55    SET(LIB_PUBLIC_HEADERS ${LIB_PUBLIC_HEADERS}
[10813]56        ${HEADER_PATH}/api/Win32/GraphicsHandleWin32
[7012]57        ${HEADER_PATH}/api/Win32/GraphicsWindowWin32
58        ${HEADER_PATH}/api/Win32/PixelBufferWin32
59    )
60       
61    SET(LIB_COMMON_FILES ${LIB_COMMON_FILES}
62        GraphicsWindowWin32.cpp
63        PixelBufferWin32.cpp
64    )
[9949]65ELSE()
[6660]66    IF(APPLE)
[9879]67        SET(OSG_WINDOWING_SYSTEM "Carbon" CACHE STRING "Windowing system type for graphics window creation, options Carbon, Cocoa or X11.")
[9949]68    ELSE()
[8479]69        SET(OSG_WINDOWING_SYSTEM "X11" CACHE STRING "Windowing system type for graphics window creation. options only X11")
[9949]70    ENDIF()
[8479]71   
[9879]72    IF(${OSG_WINDOWING_SYSTEM} STREQUAL "Cocoa")
[9949]73        ADD_DEFINITIONS(-DUSE_DARWIN_COCOA_IMPLEMENTATION)
[7039]74        SET(LIB_PUBLIC_HEADERS ${LIB_PUBLIC_HEADERS}
[9879]75            ${HEADER_PATH}/api/Cocoa/GraphicsWindowCocoa
76            ${HEADER_PATH}/api/Cocoa/PixelBufferCocoa
[7039]77        )
78        SET(LIB_COMMON_FILES ${LIB_COMMON_FILES}
[9879]79            GraphicsWindowCocoa.mm
80            DarwinUtils.h
81            DarwinUtils.mm
82            PixelBufferCocoa.mm
[7039]83        )
[9949]84    SET(LIB_EXTRA_LIBS ${COCOA_LIBRARY} ${LIB_EXTRA_LIBS})
85    ELSEIF(${OSG_WINDOWING_SYSTEM} STREQUAL "Carbon")
86        ADD_DEFINITIONS(-DUSE_DARWIN_CARBON_IMPLEMENTATION)
87        SET(LIB_PUBLIC_HEADERS ${LIB_PUBLIC_HEADERS}
[10813]88            ${HEADER_PATH}/api/Carbon/GraphicsHandleCarbon
[9949]89            ${HEADER_PATH}/api/Carbon/GraphicsWindowCarbon
90            ${HEADER_PATH}/api/Carbon/PixelBufferCarbon
91        )
92        SET(LIB_COMMON_FILES ${LIB_COMMON_FILES}
93            GraphicsWindowCarbon.cpp
94            DarwinUtils.h
95            DarwinUtils.mm
96            PixelBufferCarbon.cpp
97        )
98        SET(LIB_EXTRA_LIBS ${COCOA_LIBRARY} ${LIB_EXTRA_LIBS})
99    ELSE()
100        # X11 for everybody else
101        INCLUDE(FindPkgConfig OPTIONAL)
102        IF(PKG_CONFIG_FOUND)
103            PKG_CHECK_MODULES(XRANDR xrandr)
104            IF(XRANDR_FOUND)
105                OPTION(OSGVIEWER_USE_XRANDR "Set to ON to enable Xrandr support for GraphicsWindowX11." ON)
106            ELSE()
[9363]107                SET(OSGVIEWER_USE_XRANDR OFF)
[9949]108            ENDIF()
109        ELSE()
110            SET(OSGVIEWER_USE_XRANDR OFF)
111        ENDIF()
[9363]112
[10703]113        SET(LIB_PUBLIC_HEADERS ${LIB_PUBLIC_HEADERS}
[10813]114            ${HEADER_PATH}/api/X11/GraphicsHandleX11
[10703]115            ${HEADER_PATH}/api/X11/GraphicsWindowX11
116            ${HEADER_PATH}/api/X11/PixelBufferX11
117        )
[9363]118
[10703]119        SET(LIB_COMMON_FILES ${LIB_COMMON_FILES}
120            GraphicsWindowX11.cpp
121            PixelBufferX11.cpp
122        )
[10813]123       
[9949]124        IF(OSGVIEWER_USE_XRANDR)
125            ADD_DEFINITIONS(-DOSGVIEWER_USE_XRANDR)
126            SET(LIB_PRIVATE_HEADERS ${LIB_PRIVATE_HEADERS} ${XRANDR_INCLUDE_DIRS} )
[9548]127
[9949]128            IF(X11_Xrandr_LIB)
129                SET(LIB_EXTRA_LIBS ${X11_Xrandr_LIB} ${LIB_EXTRA_LIBS})
130            ELSE()
131                SET(LIB_EXTRA_LIBS ${XRANDR_LIBRARIES} ${LIB_EXTRA_LIBS})
132            ENDIF()
133        ENDIF()
[9548]134
[9949]135        # X11 on Apple requires X11 library plus OpenGL linking hack on Leopard
136        IF(APPLE)
137            # Find GL/glx.h
138            IF(EXISTS ${CMAKE_OSX_SYSROOT}/usr/X11/include/GL/glx.h)
139                SET(OPENGL_INCLUDE_DIR /usr/X11/include)
140                SET(OPENGL_LIBRARIES /usr/X11/lib/libGL.dylib)
141            ELSEIF(EXISTS ${CMAKE_OSX_SYSROOT}/usr/X11R6/include/GL/glx.h)
142                SET(OPENGL_INCLUDE_DIR /usr/X11R6/include)
143                SET(OPENGL_LIBRARIES /usr/X11R6/lib/libGL.dylib)
144            ENDIF()
145            INCLUDE_DIRECTORIES(BEFORE SYSTEM ${OPENGL_INCLUDE_DIR})
[7727]146
[9949]147            SET(LIB_EXTRA_LIBS ${X11_X11_LIB} ${OPENGL_LIBRARIES} ${LIB_EXTRA_LIBS})
148            SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-dylib_file,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:${CMAKE_OSX_SYSROOT}/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib")
149        ENDIF(APPLE)
150    ENDIF()
151ENDIF()
[8737]152
153
[6735]154ADD_LIBRARY(${LIB_NAME}
155    ${OPENSCENEGRAPH_USER_DEFINED_DYNAMIC_OR_STATIC}
[8211]156    ${LIB_PUBLIC_HEADERS}
157    ${LIB_PRIVATE_HEADERS}
[6735]158    ${LIB_COMMON_FILES}
159)
160
161
[6660]162LINK_INTERNAL(${LIB_NAME}     
163    osgGA
164    osgText
165    osgDB
166    osgUtil
167    osg
168    OpenThreads
[6321]169)
[6403]170
[9994]171LINK_EXTERNAL(${LIB_NAME} ${LIB_EXTRA_LIBS})
172
[6402]173LINK_CORELIB_DEFAULT(${LIB_NAME})
[6321]174
[6403]175IF(MINGW OR CYGWIN)
176    LINK_EXTERNAL(${LIB_NAME} gdi32 )
[9949]177ENDIF()
[6363]178
[6743]179INCLUDE(ModuleInstall OPTIONAL)
[6403]180
[9949]181FOREACH(INCLUDEFILE ${LIB_PUBLIC_HEADERS} )
[6743]182   FILE(RELATIVE_PATH REL_INCLUDEFILE ${HEADER_PATH} ${INCLUDEFILE})
183   GET_FILENAME_COMPONENT(REL_INCLUDE_PATH ${REL_INCLUDEFILE} PATH)
184   INSTALL(
185   FILES        ${INCLUDEFILE}
186   DESTINATION ${INSTALL_INCDIR}/${LIB_NAME}/${REL_INCLUDE_PATH}
[9342]187   COMPONENT libopenscenegraph-dev
[6743]188   )
[9949]189ENDFOREACH()
Note: See TracBrowser for help on using the browser.