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

Revision 10774, 25.4 kB (checked in by robert, 5 years ago)

From Wojciech Lewandowski, "Building on earlier Paul's submission "[osg-users] Main branch MSFBO support change", I have added implicit buffer mask variables to DisplaySettings? for setting global defaults for Camera FBOs. These mask variables are named after variables in Camera class. In Paul's submission they were named _renderBufferMask & _resolveBufferMask but I renamed them to _implicitBufferAttachmentRenderMask & _implicitBufferAttachmentResolveMask. DisplaySettings? implementation includes reading of environment vars and command line options. Setters and getters follow typical OSG naming convention. I also updated names of ImplictBufferAttachment? enum bits to match changed naming scheme.

DisplaySettings? now define COLOR and DEPTH as defaults for implicit buffers. Consequently Camera by default uses the same defaults through USE_DISPLAY_SETTINGS_MASK. However, particular Camera mask can be easily overriden through Camera::setImplicitBufferAttachmentMask method. I hope, that in this way we can have global control over implicit buffer defaults, and we can still retain fine grained control at Camera level.

I have also replaced original unsigned ints used to store masks to signed ints because complier resolves enums as signed integer (I got a number of warnings with unsigned int)."

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