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

Revision 10813, 6.3 kB (checked in by robert, 3 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
Line 
1
2# FIXME: For OS X, need flag for Framework or dylib
3IF(DYNAMIC_OPENSCENEGRAPH)
4    ADD_DEFINITIONS(-DOSGVIEWER_LIBRARY)
5ELSE()
6    ADD_DEFINITIONS(-DOSG_LIBRARY_STATIC)
7ENDIF()
8
9SET(LIB_NAME osgViewer)
10
11SET(HEADER_PATH ${OpenSceneGraph_SOURCE_DIR}/include/${LIB_NAME})
12SET(LIB_PUBLIC_HEADERS
13    ${HEADER_PATH}/CompositeViewer
14    ${HEADER_PATH}/Export
15    ${HEADER_PATH}/GraphicsWindow
16    ${HEADER_PATH}/Renderer
17    ${HEADER_PATH}/Scene
18    ${HEADER_PATH}/Version
19    ${HEADER_PATH}/View
20    ${HEADER_PATH}/Viewer
21    ${HEADER_PATH}/ViewerBase
22    ${HEADER_PATH}/ViewerEventHandlers
23)
24
25SET(LIB_COMMON_FILES
26    CompositeViewer.cpp
27    HelpHandler.cpp
28    Renderer.cpp
29    Scene.cpp
30    ScreenCaptureHandler.cpp
31    StatsHandler.cpp
32    Version.cpp
33    View.cpp
34    Viewer.cpp
35    ViewerBase.cpp
36    ViewerEventHandlers.cpp
37    ${OPENSCENEGRAPH_VERSIONINFO_RC}
38)
39
40SET(LIB_EXTRA_LIBS)
41
42IF(WIN32)
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    #
49    OPTION(OSG_MULTIMONITOR_MULTITHREAD_WIN32_NVIDIA_WORKAROUND "Set to ON if you have NVidia board and drivers earlier than 177.92 ver" OFF)
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)
53    ENDIF()
54
55    SET(LIB_PUBLIC_HEADERS ${LIB_PUBLIC_HEADERS}
56        ${HEADER_PATH}/api/Win32/GraphicsHandleWin32
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    )
65ELSE()
66    IF(APPLE)
67        SET(OSG_WINDOWING_SYSTEM "Carbon" CACHE STRING "Windowing system type for graphics window creation, options Carbon, Cocoa or X11.")
68    ELSE()
69        SET(OSG_WINDOWING_SYSTEM "X11" CACHE STRING "Windowing system type for graphics window creation. options only X11")
70    ENDIF()
71   
72    IF(${OSG_WINDOWING_SYSTEM} STREQUAL "Cocoa")
73        ADD_DEFINITIONS(-DUSE_DARWIN_COCOA_IMPLEMENTATION)
74        SET(LIB_PUBLIC_HEADERS ${LIB_PUBLIC_HEADERS}
75            ${HEADER_PATH}/api/Cocoa/GraphicsWindowCocoa
76            ${HEADER_PATH}/api/Cocoa/PixelBufferCocoa
77        )
78        SET(LIB_COMMON_FILES ${LIB_COMMON_FILES}
79            GraphicsWindowCocoa.mm
80            DarwinUtils.h
81            DarwinUtils.mm
82            PixelBufferCocoa.mm
83        )
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}
88            ${HEADER_PATH}/api/Carbon/GraphicsHandleCarbon
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()
107                SET(OSGVIEWER_USE_XRANDR OFF)
108            ENDIF()
109        ELSE()
110            SET(OSGVIEWER_USE_XRANDR OFF)
111        ENDIF()
112
113        SET(LIB_PUBLIC_HEADERS ${LIB_PUBLIC_HEADERS}
114            ${HEADER_PATH}/api/X11/GraphicsHandleX11
115            ${HEADER_PATH}/api/X11/GraphicsWindowX11
116            ${HEADER_PATH}/api/X11/PixelBufferX11
117        )
118
119        SET(LIB_COMMON_FILES ${LIB_COMMON_FILES}
120            GraphicsWindowX11.cpp
121            PixelBufferX11.cpp
122        )
123       
124        IF(OSGVIEWER_USE_XRANDR)
125            ADD_DEFINITIONS(-DOSGVIEWER_USE_XRANDR)
126            SET(LIB_PRIVATE_HEADERS ${LIB_PRIVATE_HEADERS} ${XRANDR_INCLUDE_DIRS} )
127
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()
134
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})
146
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()
152
153
154ADD_LIBRARY(${LIB_NAME}
155    ${OPENSCENEGRAPH_USER_DEFINED_DYNAMIC_OR_STATIC}
156    ${LIB_PUBLIC_HEADERS}
157    ${LIB_PRIVATE_HEADERS}
158    ${LIB_COMMON_FILES}
159)
160
161
162LINK_INTERNAL(${LIB_NAME}     
163    osgGA
164    osgText
165    osgDB
166    osgUtil
167    osg
168    OpenThreads
169)
170
171LINK_EXTERNAL(${LIB_NAME} ${LIB_EXTRA_LIBS})
172
173LINK_CORELIB_DEFAULT(${LIB_NAME})
174
175IF(MINGW OR CYGWIN)
176    LINK_EXTERNAL(${LIB_NAME} gdi32 )
177ENDIF()
178
179INCLUDE(ModuleInstall OPTIONAL)
180
181FOREACH(INCLUDEFILE ${LIB_PUBLIC_HEADERS} )
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}
187   COMPONENT libopenscenegraph-dev
188   )
189ENDFOREACH()
Note: See TracBrowser for help on using the browser.