root/OpenSceneGraph/trunk/src/osg/DisplaySettings.cpp @ 13041

Revision 13041, 27.4 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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#include <osg/DisplaySettings>
14#include <osg/ArgumentParser>
15#include <osg/ApplicationUsage>
16#include <osg/Math>
17#include <osg/Notify>
18#include <osg/ref_ptr>
19
20#include <algorithm>
21#include <string.h>
22
23using namespace osg;
24using namespace std;
25
26ref_ptr<DisplaySettings>& DisplaySettings::instance()
27{
28    static ref_ptr<DisplaySettings> s_displaySettings = new DisplaySettings;
29    return s_displaySettings;
30}
31
32DisplaySettings::DisplaySettings(const DisplaySettings& vs):Referenced(true)
33{
34    setDisplaySettings(vs);
35}
36
37DisplaySettings::~DisplaySettings()
38{
39}
40
41
42 DisplaySettings& DisplaySettings::operator = (const DisplaySettings& vs)
43{
44    if (this==&vs) return *this;
45    setDisplaySettings(vs);
46    return *this;
47}
48
49void DisplaySettings::setDisplaySettings(const DisplaySettings& vs)
50{
51    _displayType = vs._displayType;
52    _stereo = vs._stereo;
53    _stereoMode = vs._stereoMode;
54    _eyeSeparation = vs._eyeSeparation;
55    _screenWidth = vs._screenWidth;
56    _screenHeight = vs._screenHeight;
57    _screenDistance = vs._screenDistance;
58
59    _splitStereoHorizontalEyeMapping = vs._splitStereoHorizontalEyeMapping;
60    _splitStereoHorizontalSeparation = vs._splitStereoHorizontalSeparation;
61
62    _splitStereoVerticalEyeMapping = vs._splitStereoVerticalEyeMapping;
63    _splitStereoVerticalSeparation = vs._splitStereoVerticalSeparation;
64
65    _splitStereoAutoAdjustAspectRatio = vs._splitStereoAutoAdjustAspectRatio;
66
67    _doubleBuffer = vs._doubleBuffer;
68    _RGB = vs._RGB;
69    _depthBuffer = vs._depthBuffer;
70    _minimumNumberAlphaBits = vs._minimumNumberAlphaBits;
71    _minimumNumberStencilBits = vs._minimumNumberStencilBits;
72    _minimumNumberAccumRedBits = vs._minimumNumberAccumRedBits;
73    _minimumNumberAccumGreenBits = vs._minimumNumberAccumGreenBits;
74    _minimumNumberAccumBlueBits = vs._minimumNumberAccumBlueBits;
75    _minimumNumberAccumAlphaBits = vs._minimumNumberAccumAlphaBits;
76
77    _maxNumOfGraphicsContexts = vs._maxNumOfGraphicsContexts;
78    _numMultiSamples = vs._numMultiSamples;
79
80    _compileContextsHint = vs._compileContextsHint;
81    _serializeDrawDispatch = vs._serializeDrawDispatch;
82
83    _numDatabaseThreadsHint = vs._numDatabaseThreadsHint;
84    _numHttpDatabaseThreadsHint = vs._numHttpDatabaseThreadsHint;
85
86    _application = vs._application;
87
88    _maxTexturePoolSize = vs._maxTexturePoolSize;
89    _maxBufferObjectPoolSize = vs._maxBufferObjectPoolSize;
90
91    _implicitBufferAttachmentRenderMask = vs._implicitBufferAttachmentRenderMask;
92    _implicitBufferAttachmentResolveMask = vs._implicitBufferAttachmentResolveMask;
93
94    _glContextVersion = vs._glContextVersion;
95    _glContextFlags = vs._glContextFlags;
96    _glContextProfileMask = vs._glContextProfileMask;
97    _swapMethod = vs._swapMethod;
98}
99
100void DisplaySettings::merge(const DisplaySettings& vs)
101{
102    if (_stereo       || vs._stereo)        _stereo = true;
103
104    // need to think what to do about merging the stereo mode.
105
106    if (_doubleBuffer || vs._doubleBuffer)  _doubleBuffer = true;
107    if (_RGB          || vs._RGB)           _RGB = true;
108    if (_depthBuffer  || vs._depthBuffer)   _depthBuffer = true;
109
110    if (vs._minimumNumberAlphaBits>_minimumNumberAlphaBits) _minimumNumberAlphaBits = vs._minimumNumberAlphaBits;
111    if (vs._minimumNumberStencilBits>_minimumNumberStencilBits) _minimumNumberStencilBits = vs._minimumNumberStencilBits;
112    if (vs._numMultiSamples>_numMultiSamples) _numMultiSamples = vs._numMultiSamples;
113
114    if (vs._compileContextsHint) _compileContextsHint = vs._compileContextsHint;
115    if (vs._serializeDrawDispatch) _serializeDrawDispatch = vs._serializeDrawDispatch;
116
117    if (vs._numDatabaseThreadsHint>_numDatabaseThreadsHint) _numDatabaseThreadsHint = vs._numDatabaseThreadsHint;
118    if (vs._numHttpDatabaseThreadsHint>_numHttpDatabaseThreadsHint) _numHttpDatabaseThreadsHint = vs._numHttpDatabaseThreadsHint;
119
120    if (_application.empty()) _application = vs._application;
121
122    if (vs._maxTexturePoolSize>_maxTexturePoolSize) _maxTexturePoolSize = vs._maxTexturePoolSize;
123    if (vs._maxBufferObjectPoolSize>_maxBufferObjectPoolSize) _maxBufferObjectPoolSize = vs._maxBufferObjectPoolSize;
124
125    // these are bit masks so merging them is like logical or
126    _implicitBufferAttachmentRenderMask |= vs._implicitBufferAttachmentRenderMask;
127    _implicitBufferAttachmentResolveMask |= vs._implicitBufferAttachmentResolveMask;
128
129    // merge swap method to higher value
130    if( vs._swapMethod > _swapMethod )
131        _swapMethod = vs._swapMethod;
132}
133
134void DisplaySettings::setDefaults()
135{
136    _displayType = MONITOR;
137
138    _stereo = false;
139    _stereoMode = ANAGLYPHIC;
140    _eyeSeparation = 0.05f;
141    _screenWidth = 0.325f;
142    _screenHeight = 0.26f;
143    _screenDistance = 0.5f;
144
145    _splitStereoHorizontalEyeMapping = LEFT_EYE_LEFT_VIEWPORT;
146    _splitStereoHorizontalSeparation = 0;
147
148    _splitStereoVerticalEyeMapping = LEFT_EYE_TOP_VIEWPORT;
149    _splitStereoVerticalSeparation = 0;
150
151    _splitStereoAutoAdjustAspectRatio = true;
152
153    _doubleBuffer = true;
154    _RGB = true;
155    _depthBuffer = true;
156    _minimumNumberAlphaBits = 0;
157    _minimumNumberStencilBits = 0;
158    _minimumNumberAccumRedBits = 0;
159    _minimumNumberAccumGreenBits = 0;
160    _minimumNumberAccumBlueBits = 0;
161    _minimumNumberAccumAlphaBits = 0;
162
163    _maxNumOfGraphicsContexts = 32;
164    _numMultiSamples = 0;
165
166    #ifdef __sgi
167    // switch on anti-aliasing by default, just in case we have an Onyx :-)
168    _numMultiSamples = 4;
169    #endif
170
171    _compileContextsHint = false;
172    _serializeDrawDispatch = true;
173
174    _numDatabaseThreadsHint = 2;
175    _numHttpDatabaseThreadsHint = 1;
176
177    _maxTexturePoolSize = 0;
178    _maxBufferObjectPoolSize = 0;
179
180    _implicitBufferAttachmentRenderMask = DEFAULT_IMPLICIT_BUFFER_ATTACHMENT;
181    _implicitBufferAttachmentResolveMask = DEFAULT_IMPLICIT_BUFFER_ATTACHMENT;
182    _glContextVersion = "1.0";
183    _glContextFlags = 0;
184    _glContextProfileMask = 0;
185
186    _swapMethod = SWAP_DEFAULT;
187}
188
189void DisplaySettings::setMaxNumberOfGraphicsContexts(unsigned int num)
190{
191    _maxNumOfGraphicsContexts = num;
192}
193
194unsigned int DisplaySettings::getMaxNumberOfGraphicsContexts() const
195{
196    // OSG_NOTICE<<"getMaxNumberOfGraphicsContexts()="<<_maxNumOfGraphicsContexts<<std::endl;
197    return _maxNumOfGraphicsContexts;
198}
199
200void DisplaySettings::setMinimumNumAccumBits(unsigned int red, unsigned int green, unsigned int blue, unsigned int alpha)
201{
202    _minimumNumberAccumRedBits = red;
203    _minimumNumberAccumGreenBits = green;
204    _minimumNumberAccumBlueBits = blue;
205    _minimumNumberAccumAlphaBits = alpha;
206}
207
208static ApplicationUsageProxy DisplaySetting_e0(ApplicationUsage::ENVIRONMENTAL_VARIABLE,
209        "OSG_DISPLAY_TYPE <type>",
210        "MONITOR | POWERWALL | REALITY_CENTER | HEAD_MOUNTED_DISPLAY");
211static ApplicationUsageProxy DisplaySetting_e1(ApplicationUsage::ENVIRONMENTAL_VARIABLE,
212        "OSG_STEREO_MODE <mode>",
213        "QUAD_BUFFER | ANAGLYPHIC | HORIZONTAL_SPLIT | VERTICAL_SPLIT | LEFT_EYE | RIGHT_EYE | VERTICAL_INTERLACE | HORIZONTAL_INTERLACE");
214static ApplicationUsageProxy DisplaySetting_e2(ApplicationUsage::ENVIRONMENTAL_VARIABLE,
215        "OSG_STEREO <mode>",
216        "OFF | ON");
217static ApplicationUsageProxy DisplaySetting_e3(ApplicationUsage::ENVIRONMENTAL_VARIABLE,
218        "OSG_EYE_SEPARATION <float>",
219        "Physical distance between eyes.");
220static ApplicationUsageProxy DisplaySetting_e4(ApplicationUsage::ENVIRONMENTAL_VARIABLE,
221        "OSG_SCREEN_DISTANCE <float>",
222        "Physical distance between eyes and screen.");
223static ApplicationUsageProxy DisplaySetting_e5(ApplicationUsage::ENVIRONMENTAL_VARIABLE,
224        "OSG_SCREEN_HEIGHT <float>",
225        "Physical screen height.");
226static ApplicationUsageProxy DisplaySetting_e6(ApplicationUsage::ENVIRONMENTAL_VARIABLE,
227        "OSG_SCREEN_WIDTH <float>",
228        "Physical screen width.");
229static ApplicationUsageProxy DisplaySetting_e7(ApplicationUsage::ENVIRONMENTAL_VARIABLE,
230        "OSG_SPLIT_STEREO_HORIZONTAL_EYE_MAPPING <mode>",
231        "LEFT_EYE_LEFT_VIEWPORT | LEFT_EYE_RIGHT_VIEWPORT");
232static ApplicationUsageProxy DisplaySetting_e8(ApplicationUsage::ENVIRONMENTAL_VARIABLE,
233        "OSG_SPLIT_STEREO_HORIZONTAL_SEPARATION <float>",
234        "Number of pixels between viewports.");
235static ApplicationUsageProxy DisplaySetting_e9(ApplicationUsage::ENVIRONMENTAL_VARIABLE,
236        "OSG_SPLIT_STEREO_VERTICAL_EYE_MAPPING <mode>",
237        "LEFT_EYE_TOP_VIEWPORT | LEFT_EYE_BOTTOM_VIEWPORT");
238static ApplicationUsageProxy DisplaySetting_e10(ApplicationUsage::ENVIRONMENTAL_VARIABLE,
239        "OSG_SPLIT_STEREO_AUTO_ADJUST_ASPECT_RATIO <mode>",
240        "OFF | ON  Default to ON to compenstate for the compression of the aspect ratio when viewing in split screen stereo.  Note, if you are setting fovx and fovy explicityly OFF should be used.");
241static ApplicationUsageProxy DisplaySetting_e11(ApplicationUsage::ENVIRONMENTAL_VARIABLE,
242        "OSG_SPLIT_STEREO_VERTICAL_SEPARATION <float>",
243        "Number of pixels between viewports.");
244static ApplicationUsageProxy DisplaySetting_e12(ApplicationUsage::ENVIRONMENTAL_VARIABLE,
245        "OSG_MAX_NUMBER_OF_GRAPHICS_CONTEXTS <int>",
246        "Maximum number of graphics contexts to be used with applications.");
247static ApplicationUsageProxy DisplaySetting_e13(ApplicationUsage::ENVIRONMENTAL_VARIABLE,
248        "OSG_COMPILE_CONTEXTS <mode>",
249        "OFF | ON Disable/enable the use of background compiled contexts and threads.");
250static ApplicationUsageProxy DisplaySetting_e14(ApplicationUsage::ENVIRONMENTAL_VARIABLE,
251        "OSG_SERIALIZE_DRAW_DISPATCH <mode>",
252        "OFF | ON Disable/enable the use of a mutex to serialize the draw dispatch when there are multiple graphics threads.");
253static ApplicationUsageProxy DisplaySetting_e15(ApplicationUsage::ENVIRONMENTAL_VARIABLE,
254        "OSG_NUM_DATABASE_THREADS <int>",
255        "Set the hint for the total number of threads to set up in the DatabasePager.");
256static ApplicationUsageProxy DisplaySetting_e16(ApplicationUsage::ENVIRONMENTAL_VARIABLE,
257        "OSG_NUM_HTTP_DATABASE_THREADS <int>",
258        "Set the hint for the total number of threads dedicated to http requests to set up in the DatabasePager.");
259static ApplicationUsageProxy DisplaySetting_e17(ApplicationUsage::ENVIRONMENTAL_VARIABLE,
260        "OSG_MULTI_SAMPLES <int>",
261        "Set the hint for the number of samples to use when multi-sampling.");
262static ApplicationUsageProxy DisplaySetting_e18(ApplicationUsage::ENVIRONMENTAL_VARIABLE,
263        "OSG_TEXTURE_POOL_SIZE <int>",
264        "Set the hint for the size of the texture pool to manage.");
265static ApplicationUsageProxy DisplaySetting_e19(ApplicationUsage::ENVIRONMENTAL_VARIABLE,
266        "OSG_BUFFER_OBJECT_POOL_SIZE <int>",
267        "Set the hint for the size of the vertex buffer object pool to manage.");
268static ApplicationUsageProxy DisplaySetting_e20(ApplicationUsage::ENVIRONMENTAL_VARIABLE,
269        "OSG_FBO_POOL_SIZE <int>",
270        "Set the hint for the size of the frame buffer object pool to manage.");
271static ApplicationUsageProxy DisplaySetting_e21(ApplicationUsage::ENVIRONMENTAL_VARIABLE,
272        "OSG_IMPLICIT_BUFFER_ATTACHMENT_RENDER_MASK",
273        "OFF | DEFAULT | [~]COLOR | [~]DEPTH | [~]STENCIL. Substitute missing buffer attachments for render FBO.");
274static ApplicationUsageProxy DisplaySetting_e22(ApplicationUsage::ENVIRONMENTAL_VARIABLE,
275        "OSG_IMPLICIT_BUFFER_ATTACHMENT_RESOLVE_MASK",
276        "OFF | DEFAULT | [~]COLOR | [~]DEPTH | [~]STENCIL. Substitute missing buffer attachments for resolve FBO.");
277static ApplicationUsageProxy DisplaySetting_e23(ApplicationUsage::ENVIRONMENTAL_VARIABLE,
278        "OSG_GL_CONTEXT_VERSION <major.minor>",
279        "Set the hint for the GL version to create contexts for.");
280static ApplicationUsageProxy DisplaySetting_e24(ApplicationUsage::ENVIRONMENTAL_VARIABLE,
281        "OSG_GL_CONTEXT_FLAGS <uint>",
282        "Set the hint for the GL context flags to use when creating contexts.");
283static ApplicationUsageProxy DisplaySetting_e25(ApplicationUsage::ENVIRONMENTAL_VARIABLE,
284        "OSG_GL_CONTEXT_PROFILE_MASK <uint>",
285        "Set the hint for the GL context profile mask to use when creating contexts.");
286static ApplicationUsageProxy DisplaySetting_e26(ApplicationUsage::ENVIRONMENTAL_VARIABLE,
287        "OSG_SWAP_METHOD <method>",
288        "DEFAULT | EXCHANGE | COPY | UNDEFINED. Select preferred swap method.");
289
290
291void DisplaySettings::readEnvironmentalVariables()
292{
293    const char* ptr = 0;
294
295    if ((ptr = getenv("OSG_DISPLAY_TYPE")) != 0)
296    {
297        if (strcmp(ptr,"MONITOR")==0)
298        {
299            _displayType = MONITOR;
300        }
301        else
302        if (strcmp(ptr,"POWERWALL")==0)
303        {
304            _displayType = POWERWALL;
305        }
306        else
307        if (strcmp(ptr,"REALITY_CENTER")==0)
308        {
309            _displayType = REALITY_CENTER;
310        }
311        else
312        if (strcmp(ptr,"HEAD_MOUNTED_DISPLAY")==0)
313        {
314            _displayType = HEAD_MOUNTED_DISPLAY;
315        }
316    }
317
318    if( (ptr = getenv("OSG_STEREO_MODE")) != 0)
319    {
320        if (strcmp(ptr,"QUAD_BUFFER")==0)
321        {
322            _stereoMode = QUAD_BUFFER;
323        }
324        else if (strcmp(ptr,"ANAGLYPHIC")==0)
325        {
326            _stereoMode = ANAGLYPHIC;
327        }
328        else if (strcmp(ptr,"HORIZONTAL_SPLIT")==0)
329        {
330            _stereoMode = HORIZONTAL_SPLIT;
331        }
332        else if (strcmp(ptr,"VERTICAL_SPLIT")==0)
333        {
334            _stereoMode = VERTICAL_SPLIT;
335        }
336        else if (strcmp(ptr,"LEFT_EYE")==0)
337        {
338            _stereoMode = LEFT_EYE;
339        }
340        else if (strcmp(ptr,"RIGHT_EYE")==0)
341        {
342            _stereoMode = RIGHT_EYE;
343        }
344        else if (strcmp(ptr,"HORIZONTAL_INTERLACE")==0)
345        {
346            _stereoMode = HORIZONTAL_INTERLACE;
347        }
348        else if (strcmp(ptr,"VERTICAL_INTERLACE")==0)
349        {
350            _stereoMode = VERTICAL_INTERLACE;
351        }
352        else if (strcmp(ptr,"CHECKERBOARD")==0)
353        {
354            _stereoMode = CHECKERBOARD;
355        }
356    }
357
358    if( (ptr = getenv("OSG_STEREO")) != 0)
359    {
360        if (strcmp(ptr,"OFF")==0)
361        {
362            _stereo = false;
363        }
364        else
365        if (strcmp(ptr,"ON")==0)
366        {
367            _stereo = true;
368        }
369    }
370
371    if( (ptr = getenv("OSG_EYE_SEPARATION")) != 0)
372    {
373        _eyeSeparation = osg::asciiToFloat(ptr);
374    }
375
376    if( (ptr = getenv("OSG_SCREEN_WIDTH")) != 0)
377    {
378        _screenWidth = osg::asciiToFloat(ptr);
379    }
380
381    if( (ptr = getenv("OSG_SCREEN_HEIGHT")) != 0)
382    {
383        _screenHeight = osg::asciiToFloat(ptr);
384    }
385
386    if( (ptr = getenv("OSG_SCREEN_DISTANCE")) != 0)
387    {
388        _screenDistance = osg::asciiToFloat(ptr);
389    }
390
391    if( (ptr = getenv("OSG_SPLIT_STEREO_HORIZONTAL_EYE_MAPPING")) != 0)
392    {
393        if (strcmp(ptr,"LEFT_EYE_LEFT_VIEWPORT")==0)
394        {
395            _splitStereoHorizontalEyeMapping = LEFT_EYE_LEFT_VIEWPORT;
396        }
397        else
398        if (strcmp(ptr,"LEFT_EYE_RIGHT_VIEWPORT")==0)
399        {
400            _splitStereoHorizontalEyeMapping = LEFT_EYE_RIGHT_VIEWPORT;
401        }
402    }
403
404    if( (ptr = getenv("OSG_SPLIT_STEREO_HORIZONTAL_SEPARATION")) != 0)
405    {
406        _splitStereoHorizontalSeparation = atoi(ptr);
407    }
408
409
410    if( (ptr = getenv("OSG_SPLIT_STEREO_VERTICAL_EYE_MAPPING")) != 0)
411    {
412        if (strcmp(ptr,"LEFT_EYE_TOP_VIEWPORT")==0)
413        {
414            _splitStereoVerticalEyeMapping = LEFT_EYE_TOP_VIEWPORT;
415        }
416        else
417        if (strcmp(ptr,"LEFT_EYE_BOTTOM_VIEWPORT")==0)
418        {
419            _splitStereoVerticalEyeMapping = LEFT_EYE_BOTTOM_VIEWPORT;
420        }
421    }
422
423    if( (ptr = getenv("OSG_SPLIT_STEREO_AUTO_ADJUST_ASPECT_RATIO")) != 0)
424    {
425        if (strcmp(ptr,"OFF")==0)
426        {
427            _splitStereoAutoAdjustAspectRatio = false;
428        }
429        else
430        if (strcmp(ptr,"ON")==0)
431        {
432            _splitStereoAutoAdjustAspectRatio = true;
433        }
434    }
435
436    if( (ptr = getenv("OSG_SPLIT_STEREO_VERTICAL_SEPARATION")) != 0)
437    {
438        _splitStereoVerticalSeparation = atoi(ptr);
439    }
440
441    if( (ptr = getenv("OSG_MAX_NUMBER_OF_GRAPHICS_CONTEXTS")) != 0)
442    {
443        _maxNumOfGraphicsContexts = atoi(ptr);
444    }
445
446    if( (ptr = getenv("OSG_COMPIlE_CONTEXTS")) != 0)
447    {
448        if (strcmp(ptr,"OFF")==0)
449        {
450            _compileContextsHint = false;
451        }
452        else
453        if (strcmp(ptr,"ON")==0)
454        {
455            _compileContextsHint = true;
456        }
457    }
458
459    if( (ptr = getenv("OSG_SERIALIZE_DRAW_DISPATCH")) != 0)
460    {
461        if (strcmp(ptr,"OFF")==0)
462        {
463            _serializeDrawDispatch = false;
464        }
465        else
466        if (strcmp(ptr,"ON")==0)
467        {
468            _serializeDrawDispatch = true;
469        }
470    }
471
472    if( (ptr = getenv("OSG_NUM_DATABASE_THREADS")) != 0)
473    {
474        _numDatabaseThreadsHint = atoi(ptr);
475    }
476
477    if( (ptr = getenv("OSG_NUM_HTTP_DATABASE_THREADS")) != 0)
478    {
479        _numHttpDatabaseThreadsHint = atoi(ptr);
480    }
481
482    if( (ptr = getenv("OSG_MULTI_SAMPLES")) != 0)
483    {
484        _numMultiSamples = atoi(ptr);
485    }
486
487    if( (ptr = getenv("OSG_TEXTURE_POOL_SIZE")) != 0)
488    {
489        _maxTexturePoolSize = atoi(ptr);
490    }
491
492    if( (ptr = getenv("OSG_BUFFER_OBJECT_POOL_SIZE")) != 0)
493    {
494        _maxBufferObjectPoolSize = atoi(ptr);
495    }
496
497
498    {  // Read implicit buffer attachments combinations for both render and resolve mask
499        const char * variable[] = {
500            "OSG_IMPLICIT_BUFFER_ATTACHMENT_RENDER_MASK",
501            "OSG_IMPLICIT_BUFFER_ATTACHMENT_RESOLVE_MASK",
502        };
503
504        int * mask[] = {
505            &_implicitBufferAttachmentRenderMask,
506            &_implicitBufferAttachmentResolveMask,
507        };
508
509        for( unsigned int n = 0; n < sizeof( variable ) / sizeof( variable[0] ); n++ )
510        {
511            const char* env = getenv( variable[n] );
512            if ( !env ) continue;
513            std::string str(env);
514
515            if(str.find("OFF")!=std::string::npos) *mask[n] = 0;
516
517            if(str.find("~DEFAULT")!=std::string::npos) *mask[n] ^= DEFAULT_IMPLICIT_BUFFER_ATTACHMENT;
518            else if(str.find("DEFAULT")!=std::string::npos) *mask[n] |= DEFAULT_IMPLICIT_BUFFER_ATTACHMENT;
519
520            if(str.find("~COLOR")!=std::string::npos) *mask[n] ^= IMPLICIT_COLOR_BUFFER_ATTACHMENT;
521            else if(str.find("COLOR")!=std::string::npos) *mask[n] |= IMPLICIT_COLOR_BUFFER_ATTACHMENT;
522
523            if(str.find("~DEPTH")!=std::string::npos) *mask[n] ^= IMPLICIT_DEPTH_BUFFER_ATTACHMENT;
524            else if(str.find("DEPTH")!=std::string::npos) *mask[n] |= (int)IMPLICIT_DEPTH_BUFFER_ATTACHMENT;
525
526            if(str.find("~STENCIL")!=std::string::npos) *mask[n] ^= (int)IMPLICIT_STENCIL_BUFFER_ATTACHMENT;
527            else if(str.find("STENCIL")!=std::string::npos) *mask[n] |= (int)IMPLICIT_STENCIL_BUFFER_ATTACHMENT;
528        }
529    }
530
531    if( (ptr = getenv("OSG_GL_VERSION")) != 0 || (ptr = getenv("OSG_GL_CONTEXT_VERSION")) != 0)
532    {
533        _glContextVersion = ptr;
534    }
535
536    if( (ptr = getenv("OSG_GL_CONTEXT_FLAGS")) != 0)
537    {
538        _glContextFlags = atoi(ptr);
539    }
540
541    if( (ptr = getenv("OSG_GL_CONTEXT_PROFILE_MASK")) != 0)
542    {
543        _glContextProfileMask = atoi(ptr);
544    }
545
546    if ((ptr = getenv("OSG_SWAP_METHOD")) != 0)
547    {
548        if (strcmp(ptr,"DEFAULT")==0)
549        {
550            _swapMethod = SWAP_DEFAULT;
551        }
552        else
553        if (strcmp(ptr,"EXCHANGE")==0)
554        {
555            _swapMethod = SWAP_EXCHANGE;
556        }
557        else
558        if (strcmp(ptr,"COPY")==0)
559        {
560            _swapMethod = SWAP_COPY;
561        }
562        else
563        if (strcmp(ptr,"UNDEFINED")==0)
564        {
565            _swapMethod = SWAP_UNDEFINED;
566        }
567
568    }
569}
570
571void DisplaySettings::readCommandLine(ArgumentParser& arguments)
572{
573    if (_application.empty()) _application = arguments[0];
574
575    // report the usage options.
576    if (arguments.getApplicationUsage())
577    {
578        arguments.getApplicationUsage()->addCommandLineOption("--display <type>","MONITOR | POWERWALL | REALITY_CENTER | HEAD_MOUNTED_DISPLAY");
579        arguments.getApplicationUsage()->addCommandLineOption("--stereo","Use default stereo mode which is ANAGLYPHIC if not overriden by environmental variable");
580        arguments.getApplicationUsage()->addCommandLineOption("--stereo <mode>","ANAGLYPHIC | QUAD_BUFFER | HORIZONTAL_SPLIT | VERTICAL_SPLIT | LEFT_EYE | RIGHT_EYE | HORIZONTAL_INTERLACE | VERTICAL_INTERLACE | CHECKERBOARD | ON | OFF ");
581        arguments.getApplicationUsage()->addCommandLineOption("--rgba","Request a RGBA color buffer visual");
582        arguments.getApplicationUsage()->addCommandLineOption("--stencil","Request a stencil buffer visual");
583        arguments.getApplicationUsage()->addCommandLineOption("--accum-rgb","Request a rgb accumulator buffer visual");
584        arguments.getApplicationUsage()->addCommandLineOption("--accum-rgba","Request a rgb accumulator buffer visual");
585        arguments.getApplicationUsage()->addCommandLineOption("--samples <num>","Request a multisample visual");
586        arguments.getApplicationUsage()->addCommandLineOption("--cc","Request use of compile contexts and threads");
587        arguments.getApplicationUsage()->addCommandLineOption("--serialize-draw <mode>","OFF | ON - set the serialization of draw dispatch");
588        arguments.getApplicationUsage()->addCommandLineOption("--implicit-buffer-attachment-render-mask","OFF | DEFAULT | [~]COLOR | [~]DEPTH | [~]STENCIL. Substitute missing buffer attachments for render FBO");
589        arguments.getApplicationUsage()->addCommandLineOption("--implicit-buffer-attachment-resolve-mask","OFF | DEFAULT | [~]COLOR | [~]DEPTH | [~]STENCIL. Substitute missing buffer attachments for resolve FBO");
590        arguments.getApplicationUsage()->addCommandLineOption("--gl-version <major.minor>","Set the hint of which GL version to use when creating graphics contexts.");
591        arguments.getApplicationUsage()->addCommandLineOption("--gl-flags <mask>","Set the hint of which GL flags projfile mask to use when creating graphics contexts.");
592        arguments.getApplicationUsage()->addCommandLineOption("--gl-profile-mask <mask>","Set the hint of which GL context profile mask to use when creating graphics contexts.");
593        arguments.getApplicationUsage()->addCommandLineOption("--swap-method <method>","DEFAULT | EXCHANGE | COPY | UNDEFINED. Select preferred swap method.");
594    }
595
596    std::string str;
597    while(arguments.read("--display",str))
598    {
599        if (str=="MONITOR") _displayType = MONITOR;
600        else if (str=="POWERWALL") _displayType = POWERWALL;
601        else if (str=="REALITY_CENTER") _displayType = REALITY_CENTER;
602        else if (str=="HEAD_MOUNTED_DISPLAY") _displayType = HEAD_MOUNTED_DISPLAY;
603    }
604
605    int pos;
606    while ((pos=arguments.find("--stereo"))>0)
607    {
608        if (arguments.match(pos+1,"ANAGLYPHIC"))            { arguments.remove(pos,2); _stereo = true;_stereoMode = ANAGLYPHIC; }
609        else if (arguments.match(pos+1,"QUAD_BUFFER"))      { arguments.remove(pos,2); _stereo = true;_stereoMode = QUAD_BUFFER; }
610        else if (arguments.match(pos+1,"HORIZONTAL_SPLIT")) { arguments.remove(pos,2); _stereo = true;_stereoMode = HORIZONTAL_SPLIT; }
611        else if (arguments.match(pos+1,"VERTICAL_SPLIT"))   { arguments.remove(pos,2); _stereo = true;_stereoMode = VERTICAL_SPLIT; }
612        else if (arguments.match(pos+1,"HORIZONTAL_INTERLACE")) { arguments.remove(pos,2); _stereo = true;_stereoMode = HORIZONTAL_INTERLACE; }
613        else if (arguments.match(pos+1,"VERTICAL_INTERLACE"))   { arguments.remove(pos,2); _stereo = true;_stereoMode = VERTICAL_INTERLACE; }
614        else if (arguments.match(pos+1,"CHECKERBOARD"))     { arguments.remove(pos,2); _stereo = true;_stereoMode = CHECKERBOARD; }
615        else if (arguments.match(pos+1,"LEFT_EYE"))         { arguments.remove(pos,2); _stereo = true;_stereoMode = LEFT_EYE; }
616        else if (arguments.match(pos+1,"RIGHT_EYE"))        { arguments.remove(pos,2); _stereo = true;_stereoMode = RIGHT_EYE; }
617        else if (arguments.match(pos+1,"ON"))               { arguments.remove(pos,2); _stereo = true; }
618        else if (arguments.match(pos+1,"OFF"))              { arguments.remove(pos,2); _stereo = false; }
619        else                                                { arguments.remove(pos); _stereo = true; }
620    }
621
622    while (arguments.read("--rgba"))
623    {
624        _RGB = true;
625        _minimumNumberAlphaBits = 1;
626    }
627
628    while (arguments.read("--stencil"))
629    {
630        _minimumNumberStencilBits = 1;
631    }
632
633    while (arguments.read("--accum-rgb"))
634    {
635        setMinimumNumAccumBits(8,8,8,0);
636    }
637
638    while (arguments.read("--accum-rgba"))
639    {
640        setMinimumNumAccumBits(8,8,8,8);
641    }
642
643    while(arguments.read("--samples",str))
644    {
645        _numMultiSamples = atoi(str.c_str());
646    }
647
648    while(arguments.read("--cc"))
649    {
650        _compileContextsHint = true;
651    }
652
653    while(arguments.read("--serialize-draw",str))
654    {
655        if (str=="ON") _serializeDrawDispatch = true;
656        else if (str=="OFF") _serializeDrawDispatch = false;
657    }
658
659    while(arguments.read("--num-db-threads",_numDatabaseThreadsHint)) {}
660    while(arguments.read("--num-http-threads",_numHttpDatabaseThreadsHint)) {}
661
662    while(arguments.read("--texture-pool-size",_maxTexturePoolSize)) {}
663    while(arguments.read("--buffer-object-pool-size",_maxBufferObjectPoolSize)) {}
664
665    {  // Read implicit buffer attachments combinations for both render and resolve mask
666        const char* option[] = {
667            "--implicit-buffer-attachment-render-mask",
668            "--implicit-buffer-attachment-resolve-mask",
669        };
670
671        int * mask[] = {
672            &_implicitBufferAttachmentRenderMask,
673            &_implicitBufferAttachmentResolveMask,
674        };
675
676        for( unsigned int n = 0; n < sizeof( option ) / sizeof( option[0]); n++ )
677        {
678            while(arguments.read( option[n],str))
679            {
680                if(str.find("OFF")!=std::string::npos) *mask[n] = 0;
681
682                if(str.find("~DEFAULT")!=std::string::npos) *mask[n] ^= DEFAULT_IMPLICIT_BUFFER_ATTACHMENT;
683                else if(str.find("DEFAULT")!=std::string::npos) *mask[n] |= DEFAULT_IMPLICIT_BUFFER_ATTACHMENT;
684
685                if(str.find("~COLOR")!=std::string::npos) *mask[n] ^= IMPLICIT_COLOR_BUFFER_ATTACHMENT;
686                else if(str.find("COLOR")!=std::string::npos) *mask[n] |= IMPLICIT_COLOR_BUFFER_ATTACHMENT;
687
688                if(str.find("~DEPTH")!=std::string::npos) *mask[n] ^= IMPLICIT_DEPTH_BUFFER_ATTACHMENT;
689                else if(str.find("DEPTH")!=std::string::npos) *mask[n] |= IMPLICIT_DEPTH_BUFFER_ATTACHMENT;
690
691                if(str.find("~STENCIL")!=std::string::npos) *mask[n] ^= IMPLICIT_STENCIL_BUFFER_ATTACHMENT;
692                else if(str.find("STENCIL")!=std::string::npos) *mask[n] |= IMPLICIT_STENCIL_BUFFER_ATTACHMENT;
693            }
694        }
695    }
696
697    while (arguments.read("--gl-version", _glContextVersion)) {}
698    while (arguments.read("--gl-flags", _glContextFlags)) {}
699    while (arguments.read("--gl-profile-mask", _glContextProfileMask)) {}
700
701    while(arguments.read("--swap-method",str))
702    {
703        if (str=="DEFAULT") _swapMethod = SWAP_DEFAULT;
704        else if (str=="EXCHANGE") _swapMethod = SWAP_EXCHANGE;
705        else if (str=="COPY") _swapMethod = SWAP_COPY;
706        else if (str=="UNDEFINED") _swapMethod = SWAP_UNDEFINED;
707    }
708
709
710}
Note: See TracBrowser for help on using the browser.