DisplaySettings 19 KB

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