| 1 | /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield |
|---|
| 2 | * |
|---|
| 3 | * This library is open source and may be redistributed and/or modified under |
|---|
| 4 | * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or |
|---|
| 5 | * (at your option) any later version. The full license is in LICENSE file |
|---|
| 6 | * included with this distribution, and on the openscenegraph.org website. |
|---|
| 7 | * |
|---|
| 8 | * This library is distributed in the hope that it will be useful, |
|---|
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 11 | * OpenSceneGraph Public License for more details. |
|---|
| 12 | */ |
|---|
| 13 | |
|---|
| 14 | #ifndef OSG_DisplaySettings |
|---|
| 15 | #define OSG_DisplaySettings 1 |
|---|
| 16 | |
|---|
| 17 | #include <osg/Referenced> |
|---|
| 18 | #include <osg/ref_ptr> |
|---|
| 19 | |
|---|
| 20 | #include <string> |
|---|
| 21 | #include <vector> |
|---|
| 22 | |
|---|
| 23 | namespace osg { |
|---|
| 24 | |
|---|
| 25 | // forward declare |
|---|
| 26 | class ArgumentParser; |
|---|
| 27 | class ApplicationUsage; |
|---|
| 28 | |
|---|
| 29 | /** DisplaySettings class for encapsulating what visuals are required and |
|---|
| 30 | * have been set up, and the status of stereo viewing.*/ |
|---|
| 31 | class OSG_EXPORT DisplaySettings : public osg::Referenced |
|---|
| 32 | { |
|---|
| 33 | |
|---|
| 34 | public: |
|---|
| 35 | |
|---|
| 36 | /** Maintain a DisplaySettings singleton for objects to query at runtime.*/ |
|---|
| 37 | static ref_ptr<DisplaySettings>& instance(); |
|---|
| 38 | |
|---|
| 39 | DisplaySettings(): |
|---|
| 40 | Referenced(true) |
|---|
| 41 | { |
|---|
| 42 | setDefaults(); |
|---|
| 43 | readEnvironmentalVariables(); |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | DisplaySettings(ArgumentParser& arguments): |
|---|
| 47 | Referenced(true) |
|---|
| 48 | { |
|---|
| 49 | setDefaults(); |
|---|
| 50 | readEnvironmentalVariables(); |
|---|
| 51 | readCommandLine(arguments); |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | DisplaySettings(const DisplaySettings& vs); |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | DisplaySettings& operator = (const DisplaySettings& vs); |
|---|
| 58 | |
|---|
| 59 | void setDisplaySettings(const DisplaySettings& vs); |
|---|
| 60 | |
|---|
| 61 | void merge(const DisplaySettings& vs); |
|---|
| 62 | |
|---|
| 63 | void setDefaults(); |
|---|
| 64 | |
|---|
| 65 | /** read the environmental variables.*/ |
|---|
| 66 | void readEnvironmentalVariables(); |
|---|
| 67 | |
|---|
| 68 | /** read the commandline arguments.*/ |
|---|
| 69 | void readCommandLine(ArgumentParser& arguments); |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | enum DisplayType |
|---|
| 73 | { |
|---|
| 74 | MONITOR, |
|---|
| 75 | POWERWALL, |
|---|
| 76 | REALITY_CENTER, |
|---|
| 77 | HEAD_MOUNTED_DISPLAY |
|---|
| 78 | }; |
|---|
| 79 | |
|---|
| 80 | void setDisplayType(DisplayType type) { _displayType = type; } |
|---|
| 81 | |
|---|
| 82 | DisplayType getDisplayType() const { return _displayType; } |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | void setStereo(bool on) { _stereo = on; } |
|---|
| 86 | bool getStereo() const { return _stereo; } |
|---|
| 87 | |
|---|
| 88 | enum StereoMode |
|---|
| 89 | { |
|---|
| 90 | QUAD_BUFFER, |
|---|
| 91 | ANAGLYPHIC, |
|---|
| 92 | HORIZONTAL_SPLIT, |
|---|
| 93 | VERTICAL_SPLIT, |
|---|
| 94 | LEFT_EYE, |
|---|
| 95 | RIGHT_EYE, |
|---|
| 96 | HORIZONTAL_INTERLACE, |
|---|
| 97 | VERTICAL_INTERLACE, |
|---|
| 98 | CHECKERBOARD |
|---|
| 99 | }; |
|---|
| 100 | |
|---|
| 101 | void setStereoMode(StereoMode mode) { _stereoMode = mode; } |
|---|
| 102 | StereoMode getStereoMode() const { return _stereoMode; } |
|---|
| 103 | |
|---|
| 104 | void setEyeSeparation(float eyeSeparation) { _eyeSeparation = eyeSeparation; } |
|---|
| 105 | float getEyeSeparation() const { return _eyeSeparation; } |
|---|
| 106 | |
|---|
| 107 | enum SplitStereoHorizontalEyeMapping |
|---|
| 108 | { |
|---|
| 109 | LEFT_EYE_LEFT_VIEWPORT, |
|---|
| 110 | LEFT_EYE_RIGHT_VIEWPORT |
|---|
| 111 | }; |
|---|
| 112 | |
|---|
| 113 | void setSplitStereoHorizontalEyeMapping(SplitStereoHorizontalEyeMapping m) { _splitStereoHorizontalEyeMapping = m; } |
|---|
| 114 | SplitStereoHorizontalEyeMapping getSplitStereoHorizontalEyeMapping() const { return _splitStereoHorizontalEyeMapping; } |
|---|
| 115 | |
|---|
| 116 | void setSplitStereoHorizontalSeparation(int s) { _splitStereoHorizontalSeparation = s; } |
|---|
| 117 | int getSplitStereoHorizontalSeparation() const { return _splitStereoHorizontalSeparation; } |
|---|
| 118 | |
|---|
| 119 | enum SplitStereoVerticalEyeMapping |
|---|
| 120 | { |
|---|
| 121 | LEFT_EYE_TOP_VIEWPORT, |
|---|
| 122 | LEFT_EYE_BOTTOM_VIEWPORT |
|---|
| 123 | }; |
|---|
| 124 | |
|---|
| 125 | void setSplitStereoVerticalEyeMapping(SplitStereoVerticalEyeMapping m) { _splitStereoVerticalEyeMapping = m; } |
|---|
| 126 | SplitStereoVerticalEyeMapping getSplitStereoVerticalEyeMapping() const { return _splitStereoVerticalEyeMapping; } |
|---|
| 127 | |
|---|
| 128 | void setSplitStereoVerticalSeparation(int s) { _splitStereoVerticalSeparation = s; } |
|---|
| 129 | int getSplitStereoVerticalSeparation() const { return _splitStereoVerticalSeparation; } |
|---|
| 130 | |
|---|
| 131 | void setSplitStereoAutoAdjustAspectRatio(bool flag) { _splitStereoAutoAdjustAspectRatio=flag; } |
|---|
| 132 | bool getSplitStereoAutoAdjustAspectRatio() const { return _splitStereoAutoAdjustAspectRatio; } |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | void setScreenWidth(float width) { _screenWidth = width; } |
|---|
| 136 | float getScreenWidth() const { return _screenWidth; } |
|---|
| 137 | |
|---|
| 138 | void setScreenHeight(float height) { _screenHeight = height; } |
|---|
| 139 | float getScreenHeight() const { return _screenHeight; } |
|---|
| 140 | |
|---|
| 141 | void setScreenDistance(float distance) { _screenDistance = distance; } |
|---|
| 142 | float getScreenDistance() const { return _screenDistance; } |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 146 | void setDoubleBuffer(bool flag) { _doubleBuffer = flag; } |
|---|
| 147 | bool getDoubleBuffer() const { return _doubleBuffer; } |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | void setRGB(bool flag) { _RGB = flag; } |
|---|
| 151 | bool getRGB() const { return _RGB; } |
|---|
| 152 | |
|---|
| 153 | |
|---|
| 154 | void setDepthBuffer(bool flag) { _depthBuffer = flag; } |
|---|
| 155 | bool getDepthBuffer() const { return _depthBuffer; } |
|---|
| 156 | |
|---|
| 157 | |
|---|
| 158 | void setMinimumNumAlphaBits(unsigned int bits) { _minimumNumberAlphaBits = bits; } |
|---|
| 159 | unsigned int getMinimumNumAlphaBits() const { return _minimumNumberAlphaBits; } |
|---|
| 160 | bool getAlphaBuffer() const { return _minimumNumberAlphaBits!=0; } |
|---|
| 161 | |
|---|
| 162 | void setMinimumNumStencilBits(unsigned int bits) { _minimumNumberStencilBits = bits; } |
|---|
| 163 | unsigned int getMinimumNumStencilBits() const { return _minimumNumberStencilBits; } |
|---|
| 164 | bool getStencilBuffer() const { return _minimumNumberStencilBits!=0; } |
|---|
| 165 | |
|---|
| 166 | void setMinimumNumAccumBits(unsigned int red, unsigned int green, unsigned int blue, unsigned int alpha); |
|---|
| 167 | unsigned int getMinimumNumAccumRedBits() const { return _minimumNumberAccumRedBits; } |
|---|
| 168 | unsigned int getMinimumNumAccumGreenBits() const { return _minimumNumberAccumGreenBits; } |
|---|
| 169 | unsigned int getMinimumNumAccumBlueBits() const { return _minimumNumberAccumBlueBits; } |
|---|
| 170 | unsigned int getMinimumNumAccumAlphaBits() const { return _minimumNumberAccumAlphaBits; } |
|---|
| 171 | bool getAccumBuffer() const { return (_minimumNumberAccumRedBits+_minimumNumberAccumGreenBits+_minimumNumberAccumBlueBits+_minimumNumberAccumAlphaBits)!=0; } |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | void setMaxNumberOfGraphicsContexts(unsigned int num); |
|---|
| 175 | unsigned int getMaxNumberOfGraphicsContexts() const; |
|---|
| 176 | |
|---|
| 177 | void setNumMultiSamples(unsigned int samples) { _numMultiSamples = samples; } |
|---|
| 178 | unsigned int getNumMultiSamples() const { return _numMultiSamples; } |
|---|
| 179 | bool getMultiSamples() const { return _numMultiSamples!=0; } |
|---|
| 180 | |
|---|
| 181 | void setCompileContextsHint(bool useCompileContexts) { _compileContextsHint = useCompileContexts; } |
|---|
| 182 | bool getCompileContextsHint() const { return _compileContextsHint; } |
|---|
| 183 | |
|---|
| 184 | void setSerializeDrawDispatch(bool serializeDrawDispatch) { _serializeDrawDispatch = serializeDrawDispatch; } |
|---|
| 185 | bool getSerializeDrawDispatch() const { return _serializeDrawDispatch; } |
|---|
| 186 | |
|---|
| 187 | /** Set the hint for the total number of threads in the DatbasePager set up, inclusive of the number of http dedicated threads.*/ |
|---|
| 188 | void setNumOfDatabaseThreadsHint(unsigned int numThreads) { _numDatabaseThreadsHint = numThreads; } |
|---|
| 189 | |
|---|
| 190 | /** Get the hint for total number of threads in the DatbasePager set up, inclusive of the number of http dedicated threads.*/ |
|---|
| 191 | unsigned int getNumOfDatabaseThreadsHint() const { return _numDatabaseThreadsHint; } |
|---|
| 192 | |
|---|
| 193 | /** Set the hint for number of threads in the DatbasePager to dedicate to reading http requests.*/ |
|---|
| 194 | void setNumOfHttpDatabaseThreadsHint(unsigned int numThreads) { _numHttpDatabaseThreadsHint = numThreads; } |
|---|
| 195 | |
|---|
| 196 | /** Get the hint for number of threads in the DatbasePager dedicated to reading http requests.*/ |
|---|
| 197 | unsigned int getNumOfHttpDatabaseThreadsHint() const { return _numHttpDatabaseThreadsHint; } |
|---|
| 198 | |
|---|
| 199 | void setApplication(const std::string& application) { _application = application; } |
|---|
| 200 | const std::string& getApplication() { return _application; } |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | void setMaxTexturePoolSize(unsigned int size) { _maxTexturePoolSize = size; } |
|---|
| 204 | unsigned int getMaxTexturePoolSize() const { return _maxTexturePoolSize; } |
|---|
| 205 | |
|---|
| 206 | void setMaxBufferObjectPoolSize(unsigned int size) { _maxBufferObjectPoolSize = size; } |
|---|
| 207 | unsigned int getMaxBufferObjectPoolSize() const { return _maxBufferObjectPoolSize; } |
|---|
| 208 | |
|---|
| 209 | /** |
|---|
| 210 | Methods used to set and get defaults for Cameras implicit buffer attachments. |
|---|
| 211 | For more info: See description of Camera::setImplicitBufferAttachment method |
|---|
| 212 | |
|---|
| 213 | DisplaySettings implicit buffer attachment selection defaults to: DEPTH and COLOR |
|---|
| 214 | for both primary (Render) FBO and seconday Multisample (Resolve) FBO |
|---|
| 215 | ie: IMPLICT_DEPTH_BUFFER_ATTACHMENT | IMPLICIT_COLOR_BUFFER_ATTACHMENT |
|---|
| 216 | **/ |
|---|
| 217 | enum ImplicitBufferAttachment |
|---|
| 218 | { |
|---|
| 219 | IMPLICIT_DEPTH_BUFFER_ATTACHMENT = (1 << 0), |
|---|
| 220 | IMPLICIT_STENCIL_BUFFER_ATTACHMENT = (1 << 1), |
|---|
| 221 | IMPLICIT_COLOR_BUFFER_ATTACHMENT = (1 << 2), |
|---|
| 222 | DEFAULT_IMPLICIT_BUFFER_ATTACHMENT = IMPLICIT_COLOR_BUFFER_ATTACHMENT | IMPLICIT_DEPTH_BUFFER_ATTACHMENT |
|---|
| 223 | }; |
|---|
| 224 | |
|---|
| 225 | typedef int ImplicitBufferAttachmentMask; |
|---|
| 226 | |
|---|
| 227 | void setImplicitBufferAttachmentMask(ImplicitBufferAttachmentMask renderMask = DisplaySettings::DEFAULT_IMPLICIT_BUFFER_ATTACHMENT, ImplicitBufferAttachmentMask resolveMask = DisplaySettings::DEFAULT_IMPLICIT_BUFFER_ATTACHMENT ) |
|---|
| 228 | { |
|---|
| 229 | _implicitBufferAttachmentRenderMask = renderMask; |
|---|
| 230 | _implicitBufferAttachmentResolveMask = resolveMask; |
|---|
| 231 | } |
|---|
| 232 | |
|---|
| 233 | void setImplicitBufferAttachmentRenderMask(ImplicitBufferAttachmentMask implicitBufferAttachmentRenderMask) |
|---|
| 234 | { |
|---|
| 235 | _implicitBufferAttachmentRenderMask = implicitBufferAttachmentRenderMask; |
|---|
| 236 | } |
|---|
| 237 | |
|---|
| 238 | void setImplicitBufferAttachmentResolveMask(ImplicitBufferAttachmentMask implicitBufferAttachmentResolveMask) |
|---|
| 239 | { |
|---|
| 240 | _implicitBufferAttachmentResolveMask = implicitBufferAttachmentResolveMask; |
|---|
| 241 | } |
|---|
| 242 | |
|---|
| 243 | /** Get mask selecting default implict buffer attachments for Cameras primary FBOs. */ |
|---|
| 244 | ImplicitBufferAttachmentMask getImplicitBufferAttachmentRenderMask() const { return _implicitBufferAttachmentRenderMask; } |
|---|
| 245 | |
|---|
| 246 | /** Get mask selecting default implict buffer attachments for Cameras secondary MULTISAMPLE FBOs. */ |
|---|
| 247 | ImplicitBufferAttachmentMask getImplicitBufferAttachmentResolveMask() const { return _implicitBufferAttachmentResolveMask;} |
|---|
| 248 | |
|---|
| 249 | enum SwapMethod |
|---|
| 250 | { |
|---|
| 251 | SWAP_DEFAULT, // Leave swap method at default returned by choose Pixel Format. |
|---|
| 252 | SWAP_EXCHANGE, // Flip front / back buffer. |
|---|
| 253 | SWAP_COPY, // Copy back to front buffer. |
|---|
| 254 | SWAP_UNDEFINED // Move back to front buffer leaving contents of back buffer undefined. |
|---|
| 255 | }; |
|---|
| 256 | |
|---|
| 257 | /** Select preferred swap method */ |
|---|
| 258 | void setSwapMethod( SwapMethod swapMethod ) { _swapMethod = swapMethod; } |
|---|
| 259 | |
|---|
| 260 | /** Get preferred swap method */ |
|---|
| 261 | SwapMethod getSwapMethod( void ) { return _swapMethod; } |
|---|
| 262 | |
|---|
| 263 | /** Set the hint of which OpenGL version to attempt to create a graphics context for.*/ |
|---|
| 264 | void setGLContextVersion(const std::string& version) { _glContextVersion = version; } |
|---|
| 265 | |
|---|
| 266 | /** Get the hint of which OpenGL version to attempt to create a graphics context for.*/ |
|---|
| 267 | const std::string getGLContextVersion() const { return _glContextVersion; } |
|---|
| 268 | |
|---|
| 269 | /** Set the hint of the flags to use in when creating graphic contexts.*/ |
|---|
| 270 | void setGLContextFlags(unsigned int flags) { _glContextFlags = flags; } |
|---|
| 271 | |
|---|
| 272 | /** Get the hint of the flags to use in when creating graphic contexts.*/ |
|---|
| 273 | unsigned int getGLContextFlags() const { return _glContextFlags; } |
|---|
| 274 | |
|---|
| 275 | /** Set the hint of the profile mask to use in when creating graphic contexts.*/ |
|---|
| 276 | void setGLContextProfileMask(unsigned int mask) { _glContextProfileMask = mask; } |
|---|
| 277 | |
|---|
| 278 | /** Get the hint of the profile mask to use in when creating graphic contexts.*/ |
|---|
| 279 | unsigned int getGLContextProfileMask() const { return _glContextProfileMask; } |
|---|
| 280 | |
|---|
| 281 | protected: |
|---|
| 282 | |
|---|
| 283 | virtual ~DisplaySettings(); |
|---|
| 284 | |
|---|
| 285 | |
|---|
| 286 | DisplayType _displayType; |
|---|
| 287 | bool _stereo; |
|---|
| 288 | StereoMode _stereoMode; |
|---|
| 289 | float _eyeSeparation; |
|---|
| 290 | float _screenWidth; |
|---|
| 291 | float _screenHeight; |
|---|
| 292 | float _screenDistance; |
|---|
| 293 | |
|---|
| 294 | SplitStereoHorizontalEyeMapping _splitStereoHorizontalEyeMapping; |
|---|
| 295 | int _splitStereoHorizontalSeparation; |
|---|
| 296 | SplitStereoVerticalEyeMapping _splitStereoVerticalEyeMapping; |
|---|
| 297 | int _splitStereoVerticalSeparation; |
|---|
| 298 | bool _splitStereoAutoAdjustAspectRatio; |
|---|
| 299 | |
|---|
| 300 | bool _doubleBuffer; |
|---|
| 301 | bool _RGB; |
|---|
| 302 | bool _depthBuffer; |
|---|
| 303 | unsigned int _minimumNumberAlphaBits; |
|---|
| 304 | unsigned int _minimumNumberStencilBits; |
|---|
| 305 | unsigned int _minimumNumberAccumRedBits; |
|---|
| 306 | unsigned int _minimumNumberAccumGreenBits; |
|---|
| 307 | unsigned int _minimumNumberAccumBlueBits; |
|---|
| 308 | unsigned int _minimumNumberAccumAlphaBits; |
|---|
| 309 | |
|---|
| 310 | unsigned int _maxNumOfGraphicsContexts; |
|---|
| 311 | |
|---|
| 312 | unsigned int _numMultiSamples; |
|---|
| 313 | |
|---|
| 314 | bool _compileContextsHint; |
|---|
| 315 | bool _serializeDrawDispatch; |
|---|
| 316 | |
|---|
| 317 | unsigned int _numDatabaseThreadsHint; |
|---|
| 318 | unsigned int _numHttpDatabaseThreadsHint; |
|---|
| 319 | |
|---|
| 320 | std::string _application; |
|---|
| 321 | |
|---|
| 322 | unsigned int _maxTexturePoolSize; |
|---|
| 323 | unsigned int _maxBufferObjectPoolSize; |
|---|
| 324 | |
|---|
| 325 | ImplicitBufferAttachmentMask _implicitBufferAttachmentRenderMask; |
|---|
| 326 | ImplicitBufferAttachmentMask _implicitBufferAttachmentResolveMask; |
|---|
| 327 | |
|---|
| 328 | std::string _glContextVersion; |
|---|
| 329 | unsigned int _glContextFlags; |
|---|
| 330 | unsigned int _glContextProfileMask; |
|---|
| 331 | |
|---|
| 332 | SwapMethod _swapMethod; |
|---|
| 333 | }; |
|---|
| 334 | |
|---|
| 335 | } |
|---|
| 336 | |
|---|
| 337 | # endif |
|---|