From WojciechLewandowski, Added DispaySettings::SwapMethod and support for it in GraphicsContext::Traits

This commit is contained in:
Robert Osfield
2010-09-30 14:25:27 +00:00
parent ff68236bad
commit 0eded3efbe
4 changed files with 61 additions and 1 deletions

View File

@@ -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;
};
}

View File

@@ -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.

View File

@@ -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;
}
}

View File

@@ -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();
}
}