diff --git a/include/osg/DisplaySettings b/include/osg/DisplaySettings index 1b6e4d4a3..6f0ddda04 100644 --- a/include/osg/DisplaySettings +++ b/include/osg/DisplaySettings @@ -246,6 +246,19 @@ class OSG_EXPORT DisplaySettings : public osg::Referenced /** Get mask selecting default implict buffer attachments for Cameras secondary MULTISAMPLE FBOs. */ ImplicitBufferAttachmentMask getImplicitBufferAttachmentResolveMask() const { return _implicitBufferAttachmentResolveMask;} + enum SwapMethod + { + SWAP_DEFAULT, // Leave swap method at default returned by choose Pixel Format. + SWAP_EXCHANGE, // Flip front / back buffer. + SWAP_COPY, // Copy back to front buffer. + SWAP_UNDEFINED // Move back to front buffer leaving contents of back buffer undefined. + }; + + /** Select preferred swap method */ + void setSwapMethod( SwapMethod swapMethod ) { _swapMethod = swapMethod; } + + /** Get preferred swap method */ + SwapMethod getSwapMethod( void ) { return _swapMethod; } /** Set the hint of which OpenGL version to attempt to create a graphics context for.*/ void setGLContextVersion(const std::string& version) { _glContextVersion = version; } @@ -315,6 +328,8 @@ class OSG_EXPORT DisplaySettings : public osg::Referenced std::string _glContextVersion; unsigned int _glContextFlags; unsigned int _glContextProfileMask; + + SwapMethod _swapMethod; }; } diff --git a/include/osg/GraphicsContext b/include/osg/GraphicsContext index 019799579..3f8a2d9aa 100644 --- a/include/osg/GraphicsContext +++ b/include/osg/GraphicsContext @@ -130,6 +130,8 @@ class OSG_EXPORT GraphicsContext : public Object // X11 hint whether to override the window managers window size/position redirection bool overrideRedirect; + + DisplaySettings::SwapMethod swapMethod; }; /** Simple resolution structure used by WindowingSystemInterface to get and set screen resolution. diff --git a/src/osg/DisplaySettings.cpp b/src/osg/DisplaySettings.cpp index cd71f133c..155502cf4 100644 --- a/src/osg/DisplaySettings.cpp +++ b/src/osg/DisplaySettings.cpp @@ -90,6 +90,7 @@ void DisplaySettings::setDisplaySettings(const DisplaySettings& vs) _glContextVersion = vs._glContextVersion; _glContextFlags = vs._glContextFlags; _glContextProfileMask = vs._glContextProfileMask; + _swapMethod = vs._swapMethod; } void DisplaySettings::merge(const DisplaySettings& vs) @@ -120,6 +121,10 @@ void DisplaySettings::merge(const DisplaySettings& vs) // these are bit masks so merging them is like logical or _implicitBufferAttachmentRenderMask |= vs._implicitBufferAttachmentRenderMask; _implicitBufferAttachmentResolveMask |= vs._implicitBufferAttachmentResolveMask; + + // merge swap method to higher value + if( vs._swapMethod > _swapMethod ) + _swapMethod = vs._swapMethod; } void DisplaySettings::setDefaults() @@ -173,6 +178,8 @@ void DisplaySettings::setDefaults() _glContextVersion = "1.0"; _glContextFlags = 0; _glContextProfileMask = 0; + + _swapMethod = SWAP_DEFAULT; } void DisplaySettings::setMaxNumberOfGraphicsContexts(unsigned int num) @@ -475,6 +482,30 @@ void DisplaySettings::readEnvironmentalVariables() { _glContextProfileMask = atoi(ptr); } + + if ((ptr = getenv("OSG_SWAP_METHOD")) != 0) + { + if (strcmp(ptr,"DEFAULT")==0) + { + _swapMethod = SWAP_DEFAULT; + } + else + if (strcmp(ptr,"EXCHANGE")==0) + { + _swapMethod = SWAP_EXCHANGE; + } + else + if (strcmp(ptr,"COPY")==0) + { + _swapMethod = SWAP_COPY; + } + else + if (strcmp(ptr,"UNDEFINED")==0) + { + _swapMethod = SWAP_UNDEFINED; + } + + } } void DisplaySettings::readCommandLine(ArgumentParser& arguments) @@ -606,4 +637,13 @@ void DisplaySettings::readCommandLine(ArgumentParser& arguments) while (arguments.read("--gl-flags", _glContextFlags)) {} while (arguments.read("--gl-profile-mask", _glContextProfileMask)) {} + while(arguments.read("--swap-method",str)) + { + if (str=="DEFAULT") _swapMethod = SWAP_DEFAULT; + else if (str=="EXCHANGE") _swapMethod = SWAP_EXCHANGE; + else if (str=="COPY") _swapMethod = SWAP_COPY; + else if (str=="UNDEFINED") _swapMethod = SWAP_UNDEFINED; + } + + } diff --git a/src/osg/GraphicsContext.cpp b/src/osg/GraphicsContext.cpp index 0ce65e4de..e12b63bf5 100644 --- a/src/osg/GraphicsContext.cpp +++ b/src/osg/GraphicsContext.cpp @@ -185,7 +185,8 @@ GraphicsContext::Traits::Traits(DisplaySettings* ds): glContextProfileMask(0), sharedContext(0), setInheritedWindowPixelFormat(false), - overrideRedirect(false) + overrideRedirect(false), + swapMethod( DisplaySettings::SWAP_DEFAULT ) { if (ds) { @@ -208,6 +209,8 @@ GraphicsContext::Traits::Traits(DisplaySettings* ds): glContextVersion = ds->getGLContextVersion(); glContextFlags = ds->getGLContextFlags(); glContextProfileMask = ds->getGLContextProfileMask(); + + swapMethod = ds->getSwapMethod(); } }