openscenegraph
DisplaySettings
Go to the documentation of this file.
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/Matrixd>
19#include <osg/ref_ptr>
20
21#include <string>
22#include <vector>
23#include <map>
24
25namespace osg {
26
27// forward declare
28class ArgumentParser;
29class ApplicationUsage;
30
31/** DisplaySettings class for encapsulating what visuals are required and
32 * have been set up, and the status of stereo viewing.*/
33class OSG_EXPORT DisplaySettings : public osg::Referenced
34{
35
36 public:
37
38 /** Maintain a DisplaySettings singleton for objects to query at runtime.*/
39 static ref_ptr<DisplaySettings>& instance();
40
41 DisplaySettings():
42 Referenced(true)
43 {
44 setDefaults();
45 readEnvironmentalVariables();
46 }
47
48 DisplaySettings(ArgumentParser& arguments):
49 Referenced(true)
50 {
51 setDefaults();
52 readEnvironmentalVariables();
53 readCommandLine(arguments);
54 }
55
56 DisplaySettings(const DisplaySettings& vs);
57
58
59 DisplaySettings& operator = (const DisplaySettings& vs);
60
61 void setDisplaySettings(const DisplaySettings& vs);
62
63 void merge(const DisplaySettings& vs);
64
65 void setDefaults();
66
67 /** read the environmental variables.*/
68 void readEnvironmentalVariables();
69
70 /** read the commandline arguments.*/
71 void readCommandLine(ArgumentParser& arguments);
72
73
74 enum DisplayType
75 {
76 MONITOR,
77 POWERWALL,
78 REALITY_CENTER,
79 HEAD_MOUNTED_DISPLAY
80 };
81
82 void setDisplayType(DisplayType type) { _displayType = type; }
83
84 DisplayType getDisplayType() const { return _displayType; }
85
86
87 void setStereo(bool on) { _stereo = on; }
88 bool getStereo() const { return _stereo; }
89
90 enum StereoMode
91 {
92 QUAD_BUFFER,
93 ANAGLYPHIC,
94 HORIZONTAL_SPLIT,
95 VERTICAL_SPLIT,
96 LEFT_EYE,
97 RIGHT_EYE,
98 HORIZONTAL_INTERLACE,
99 VERTICAL_INTERLACE,
100 CHECKERBOARD
101 };
102
103 void setStereoMode(StereoMode mode) { _stereoMode = mode; }
104 StereoMode getStereoMode() const { return _stereoMode; }
105
106 void setEyeSeparation(float eyeSeparation) { _eyeSeparation = eyeSeparation; }
107 float getEyeSeparation() const { return _eyeSeparation; }
108
109 enum SplitStereoHorizontalEyeMapping
110 {
111 LEFT_EYE_LEFT_VIEWPORT,
112 LEFT_EYE_RIGHT_VIEWPORT
113 };
114
115 void setSplitStereoHorizontalEyeMapping(SplitStereoHorizontalEyeMapping m) { _splitStereoHorizontalEyeMapping = m; }
116 SplitStereoHorizontalEyeMapping getSplitStereoHorizontalEyeMapping() const { return _splitStereoHorizontalEyeMapping; }
117
118 void setSplitStereoHorizontalSeparation(int s) { _splitStereoHorizontalSeparation = s; }
119 int getSplitStereoHorizontalSeparation() const { return _splitStereoHorizontalSeparation; }
120
121 enum SplitStereoVerticalEyeMapping
122 {
123 LEFT_EYE_TOP_VIEWPORT,
124 LEFT_EYE_BOTTOM_VIEWPORT
125 };
126
127 void setSplitStereoVerticalEyeMapping(SplitStereoVerticalEyeMapping m) { _splitStereoVerticalEyeMapping = m; }
128 SplitStereoVerticalEyeMapping getSplitStereoVerticalEyeMapping() const { return _splitStereoVerticalEyeMapping; }
129
130 void setSplitStereoVerticalSeparation(int s) { _splitStereoVerticalSeparation = s; }
131 int getSplitStereoVerticalSeparation() const { return _splitStereoVerticalSeparation; }
132
133 void setSplitStereoAutoAdjustAspectRatio(bool flag) { _splitStereoAutoAdjustAspectRatio=flag; }
134 bool getSplitStereoAutoAdjustAspectRatio() const { return _splitStereoAutoAdjustAspectRatio; }
135
136
137 void setScreenWidth(float width) { _screenWidth = width; }
138 float getScreenWidth() const { return _screenWidth; }
139
140 void setScreenHeight(float height) { _screenHeight = height; }
141 float getScreenHeight() const { return _screenHeight; }
142
143 void setScreenDistance(float distance) { _screenDistance = distance; }
144 float getScreenDistance() const { return _screenDistance; }
145
146
147
148 void setDoubleBuffer(bool flag) { _doubleBuffer = flag; }
149 bool getDoubleBuffer() const { return _doubleBuffer; }
150
151
152 void setRGB(bool flag) { _RGB = flag; }
153 bool getRGB() const { return _RGB; }
154
155
156 void setDepthBuffer(bool flag) { _depthBuffer = flag; }
157 bool getDepthBuffer() const { return _depthBuffer; }
158
159
160 void setMinimumNumAlphaBits(unsigned int bits) { _minimumNumberAlphaBits = bits; }
161 unsigned int getMinimumNumAlphaBits() const { return _minimumNumberAlphaBits; }
162 bool getAlphaBuffer() const { return _minimumNumberAlphaBits!=0; }
163
164 void setMinimumNumStencilBits(unsigned int bits) { _minimumNumberStencilBits = bits; }
165 unsigned int getMinimumNumStencilBits() const { return _minimumNumberStencilBits; }
166 bool getStencilBuffer() const { return _minimumNumberStencilBits!=0; }
167
168 void setMinimumNumAccumBits(unsigned int red, unsigned int green, unsigned int blue, unsigned int alpha);
169 unsigned int getMinimumNumAccumRedBits() const { return _minimumNumberAccumRedBits; }
170 unsigned int getMinimumNumAccumGreenBits() const { return _minimumNumberAccumGreenBits; }
171 unsigned int getMinimumNumAccumBlueBits() const { return _minimumNumberAccumBlueBits; }
172 unsigned int getMinimumNumAccumAlphaBits() const { return _minimumNumberAccumAlphaBits; }
173 bool getAccumBuffer() const { return (_minimumNumberAccumRedBits+_minimumNumberAccumGreenBits+_minimumNumberAccumBlueBits+_minimumNumberAccumAlphaBits)!=0; }
174
175
176 void setMaxNumberOfGraphicsContexts(unsigned int num);
177 unsigned int getMaxNumberOfGraphicsContexts() const;
178
179 void setNumMultiSamples(unsigned int samples) { _numMultiSamples = samples; }
180 unsigned int getNumMultiSamples() const { return _numMultiSamples; }
181 bool getMultiSamples() const { return _numMultiSamples!=0; }
182
183 void setCompileContextsHint(bool useCompileContexts) { _compileContextsHint = useCompileContexts; }
184 bool getCompileContextsHint() const { return _compileContextsHint; }
185
186 void setSerializeDrawDispatch(bool serializeDrawDispatch) { _serializeDrawDispatch = serializeDrawDispatch; }
187 bool getSerializeDrawDispatch() const { return _serializeDrawDispatch; }
188
189
190 void setUseSceneViewForStereoHint(bool hint) { _useSceneViewForStereoHint = hint; }
191 bool getUseSceneViewForStereoHint() const { return _useSceneViewForStereoHint; }
192
193
194 /** Set the hint for the total number of threads in the DatbasePager set up, inclusive of the number of http dedicated threads.*/
195 void setNumOfDatabaseThreadsHint(unsigned int numThreads) { _numDatabaseThreadsHint = numThreads; }
196
197 /** Get the hint for total number of threads in the DatbasePager set up, inclusive of the number of http dedicated threads.*/
198 unsigned int getNumOfDatabaseThreadsHint() const { return _numDatabaseThreadsHint; }
199
200 /** Set the hint for number of threads in the DatbasePager to dedicate to reading http requests.*/
201 void setNumOfHttpDatabaseThreadsHint(unsigned int numThreads) { _numHttpDatabaseThreadsHint = numThreads; }
202
203 /** Get the hint for number of threads in the DatbasePager dedicated to reading http requests.*/
204 unsigned int getNumOfHttpDatabaseThreadsHint() const { return _numHttpDatabaseThreadsHint; }
205
206 void setApplication(const std::string& application) { _application = application; }
207 const std::string& getApplication() { return _application; }
208
209
210 void setMaxTexturePoolSize(unsigned int size) { _maxTexturePoolSize = size; }
211 unsigned int getMaxTexturePoolSize() const { return _maxTexturePoolSize; }
212
213 void setMaxBufferObjectPoolSize(unsigned int size) { _maxBufferObjectPoolSize = size; }
214 unsigned int getMaxBufferObjectPoolSize() const { return _maxBufferObjectPoolSize; }
215
216 /**
217 Methods used to set and get defaults for Cameras implicit buffer attachments.
218 For more info: See description of Camera::setImplicitBufferAttachment method
219
220 DisplaySettings implicit buffer attachment selection defaults to: DEPTH and COLOR
221 for both primary (Render) FBO and secondary Multisample (Resolve) FBO
222 ie: IMPLICIT_DEPTH_BUFFER_ATTACHMENT | IMPLICIT_COLOR_BUFFER_ATTACHMENT
223 **/
224 enum ImplicitBufferAttachment
225 {
226 IMPLICIT_DEPTH_BUFFER_ATTACHMENT = (1 << 0),
227 IMPLICIT_STENCIL_BUFFER_ATTACHMENT = (1 << 1),
228 IMPLICIT_COLOR_BUFFER_ATTACHMENT = (1 << 2),
229 DEFAULT_IMPLICIT_BUFFER_ATTACHMENT = IMPLICIT_COLOR_BUFFER_ATTACHMENT | IMPLICIT_DEPTH_BUFFER_ATTACHMENT
230 };
231
232 typedef int ImplicitBufferAttachmentMask;
233
234 void setImplicitBufferAttachmentMask(ImplicitBufferAttachmentMask renderMask = DisplaySettings::DEFAULT_IMPLICIT_BUFFER_ATTACHMENT, ImplicitBufferAttachmentMask resolveMask = DisplaySettings::DEFAULT_IMPLICIT_BUFFER_ATTACHMENT )
235 {
236 _implicitBufferAttachmentRenderMask = renderMask;
237 _implicitBufferAttachmentResolveMask = resolveMask;
238 }
239
240 void setImplicitBufferAttachmentRenderMask(ImplicitBufferAttachmentMask implicitBufferAttachmentRenderMask)
241 {
242 _implicitBufferAttachmentRenderMask = implicitBufferAttachmentRenderMask;
243 }
244
245 void setImplicitBufferAttachmentResolveMask(ImplicitBufferAttachmentMask implicitBufferAttachmentResolveMask)
246 {
247 _implicitBufferAttachmentResolveMask = implicitBufferAttachmentResolveMask;
248 }
249
250 /** Get mask selecting default implicit buffer attachments for Cameras primary FBOs. */
251 ImplicitBufferAttachmentMask getImplicitBufferAttachmentRenderMask() const { return _implicitBufferAttachmentRenderMask; }
252
253 /** Get mask selecting default implicit buffer attachments for Cameras secondary MULTISAMPLE FBOs. */
254 ImplicitBufferAttachmentMask getImplicitBufferAttachmentResolveMask() const { return _implicitBufferAttachmentResolveMask;}
255
256 enum SwapMethod
257 {
258 SWAP_DEFAULT, // Leave swap method at default returned by choose Pixel Format.
259 SWAP_EXCHANGE, // Flip front / back buffer.
260 SWAP_COPY, // Copy back to front buffer.
261 SWAP_UNDEFINED // Move back to front buffer leaving contents of back buffer undefined.
262 };
263
264 /** Select preferred swap method */
265 void setSwapMethod( SwapMethod swapMethod ) { _swapMethod = swapMethod; }
266
267 /** Get preferred swap method */
268 SwapMethod getSwapMethod( void ) { return _swapMethod; }
269
270
271 /** Set whether Arb Sync should be used to manage the swaps buffers, 0 disables the use of the sync, greater than zero enables sync based on number of frames specified.*/
272 void setSyncSwapBuffers(unsigned int numFrames=0) { _syncSwapBuffers = numFrames; }
273
274 /** Set whether Arb Sync should be used to manage the swaps buffers.*/
275 unsigned int getSyncSwapBuffers() const { return _syncSwapBuffers; }
276
277
278
279 /** Set the hint of which OpenGL version to attempt to create a graphics context for.*/
280 void setGLContextVersion(const std::string& version) { _glContextVersion = version; }
281
282 /** Get the hint of which OpenGL version to attempt to create a graphics context for.*/
283 const std::string getGLContextVersion() const { return _glContextVersion; }
284
285 /** Set the hint of the flags to use in when creating graphic contexts.*/
286 void setGLContextFlags(unsigned int flags) { _glContextFlags = flags; }
287
288 /** Get the hint of the flags to use in when creating graphic contexts.*/
289 unsigned int getGLContextFlags() const { return _glContextFlags; }
290
291 /** Set the hint of the profile mask to use in when creating graphic contexts.*/
292 void setGLContextProfileMask(unsigned int mask) { _glContextProfileMask = mask; }
293
294 /** Get the hint of the profile mask to use in when creating graphic contexts.*/
295 unsigned int getGLContextProfileMask() const { return _glContextProfileMask; }
296
297 /** Set the NvOptimusEnablement value. Default can be set using OSG_NvOptimusEnablement env var.*/
298 void setNvOptimusEnablement(int value);
299 /** Get the NvOptimusEnablement value. */
300 int getNvOptimusEnablement() const;
301
302
303 enum VertexBufferHint
304 {
305 NO_PREFERENCE,
306 VERTEX_BUFFER_OBJECT,
307 VERTEX_ARRAY_OBJECT
308 };
309
310 void setVertexBufferHint(VertexBufferHint gi) { _vertexBufferHint = gi; }
311 VertexBufferHint getVertexBufferHint() const { return _vertexBufferHint; }
312
313
314 enum ShaderHint
315 {
316 SHADER_NONE,
317 SHADER_GL2,
318 SHADER_GLES2,
319 SHADER_GL3,
320 SHADER_GLES3
321 };
322
323 /** set the ShaderHint to tells shader generating cdoes version to create.
324 * By default also OSG_GLSL_VERSION and OSG_PRECISION_FLOAT values that can get use directly in shaders using $OSG_GLSL_VERSION and $OSG_PRECISION_FLOAT respectively.*/
325 void setShaderHint(ShaderHint hint, bool setShaderValues=true);
326 ShaderHint getShaderHint() const { return _shaderHint; }
327
328 /** Set the TextShaderTechnique that is used in the Text default constructor to choose which osgText::ShaderTechnique to use.*/
329 void setTextShaderTechnique(const std::string& str) { _textShaderTechnique = str; }
330 const std::string& getTextShaderTechnique() const { return _textShaderTechnique; }
331
332
333 void setKeystoneHint(bool enabled) { _keystoneHint = enabled; }
334 bool getKeystoneHint() const { return _keystoneHint; }
335
336 typedef std::vector<std::string> FileNames;
337 void setKeystoneFileNames(const FileNames& filenames) { _keystoneFileNames = filenames; }
338 FileNames& getKeystoneFileNames() { return _keystoneFileNames; }
339 const FileNames& getKeystoneFileNames() const { return _keystoneFileNames; }
340
341 typedef std::vector< osg::ref_ptr<osg::Object> > Objects;
342 void setKeystones(const Objects& objects) { _keystones = objects; }
343 Objects& getKeystones() { return _keystones; }
344 const Objects& getKeystones() const { return _keystones; }
345
346 enum OSXMenubarBehavior
347 {
348 MENUBAR_AUTO_HIDE,
349 MENUBAR_FORCE_HIDE,
350 MENUBAR_FORCE_SHOW
351 };
352
353 OSXMenubarBehavior getOSXMenubarBehavior() const { return _OSXMenubarBehavior; }
354 void setOSXMenubarBehavior(OSXMenubarBehavior hint) { _OSXMenubarBehavior = hint; }
355
356 /** helper function for computing the left eye projection matrix.*/
357 virtual osg::Matrixd computeLeftEyeProjectionImplementation(const osg::Matrixd& projection) const;
358
359 /** helper function for computing the left eye view matrix.*/
360 virtual osg::Matrixd computeLeftEyeViewImplementation(const osg::Matrixd& view, double eyeSeperationScale=1.0) const;
361
362 /** helper function for computing the right eye view matrix.*/
363 virtual osg::Matrixd computeRightEyeProjectionImplementation(const osg::Matrixd& projection) const;
364
365 /** helper function for computing the right eye view matrix.*/
366 virtual osg::Matrixd computeRightEyeViewImplementation(const osg::Matrixd& view, double eyeSeperationScale=1.0) const;
367
368
369 void setValue(const std::string& name, const std::string& value);
370
371 bool getValue(const std::string& name, std::string& value, bool use_getenv_fallback=true) const;
372
373 protected:
374
375 virtual ~DisplaySettings();
376
377
378 DisplayType _displayType;
379 bool _stereo;
380 StereoMode _stereoMode;
381 float _eyeSeparation;
382 float _screenWidth;
383 float _screenHeight;
384 float _screenDistance;
385
386 SplitStereoHorizontalEyeMapping _splitStereoHorizontalEyeMapping;
387 int _splitStereoHorizontalSeparation;
388 SplitStereoVerticalEyeMapping _splitStereoVerticalEyeMapping;
389 int _splitStereoVerticalSeparation;
390 bool _splitStereoAutoAdjustAspectRatio;
391
392 bool _doubleBuffer;
393 bool _RGB;
394 bool _depthBuffer;
395 unsigned int _minimumNumberAlphaBits;
396 unsigned int _minimumNumberStencilBits;
397 unsigned int _minimumNumberAccumRedBits;
398 unsigned int _minimumNumberAccumGreenBits;
399 unsigned int _minimumNumberAccumBlueBits;
400 unsigned int _minimumNumberAccumAlphaBits;
401
402 unsigned int _maxNumOfGraphicsContexts;
403
404 unsigned int _numMultiSamples;
405
406 bool _compileContextsHint;
407 bool _serializeDrawDispatch;
408 bool _useSceneViewForStereoHint;
409
410 unsigned int _numDatabaseThreadsHint;
411 unsigned int _numHttpDatabaseThreadsHint;
412
413 std::string _application;
414
415 unsigned int _maxTexturePoolSize;
416 unsigned int _maxBufferObjectPoolSize;
417
418 ImplicitBufferAttachmentMask _implicitBufferAttachmentRenderMask;
419 ImplicitBufferAttachmentMask _implicitBufferAttachmentResolveMask;
420
421 std::string _glContextVersion;
422 unsigned int _glContextFlags;
423 unsigned int _glContextProfileMask;
424
425 SwapMethod _swapMethod;
426 unsigned int _syncSwapBuffers;
427
428 VertexBufferHint _vertexBufferHint;
429 ShaderHint _shaderHint;
430 std::string _textShaderTechnique;
431
432 bool _keystoneHint;
433 FileNames _keystoneFileNames;
434 Objects _keystones;
435
436 OSXMenubarBehavior _OSXMenubarBehavior;
437
438 typedef std::map<std::string, std::string> ValueMap;
439
440 mutable OpenThreads::Mutex _valueMapMutex;
441 mutable ValueMap _valueMap;
442
443};
444
445}
446
447# endif