Added osg::SyncSwapBuffersCallback to include/osg/GraphicsContext and support for enabling it to include/osg/DisplaySettings, and to the Viewer/CompositeViewer::realize() methods.

To enable the sync of swap buffers set the env var OSG_SYNC_SWAP_BUFFERS to ON or 1, to switch off set to OFF or 0.

One can also use the --sync command line option for application that pass on command line options to the osg::DisplaySettings::instance().


git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14456 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
Robert Osfield
2014-10-21 14:46:12 +00:00
parent fec06828cf
commit 4c1fd06252
6 changed files with 147 additions and 1 deletions

View File

@@ -266,6 +266,15 @@ class OSG_EXPORT DisplaySettings : public osg::Referenced
/** Get preferred swap method */
SwapMethod getSwapMethod( void ) { return _swapMethod; }
/** 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.*/
void setSyncSwapBuffers(unsigned int numFrames=0) { _syncSwapBuffers = numFrames; }
/** Set whether Arb Sync should be used to manage the swaps buffers.*/
unsigned int getSyncSwapBuffers() const { return _syncSwapBuffers; }
/** Set the hint of which OpenGL version to attempt to create a graphics context for.*/
void setGLContextVersion(const std::string& version) { _glContextVersion = version; }
@@ -372,7 +381,7 @@ class OSG_EXPORT DisplaySettings : public osg::Referenced
unsigned int _glContextProfileMask;
SwapMethod _swapMethod;
unsigned int _syncSwapBuffers;
bool _keystoneHint;
FileNames _keystoneFileNames;

View File

@@ -531,6 +531,57 @@ class OSG_EXPORT GraphicsContext : public Object
GLuint _defaultFboId;
};
//#include <osg/GLExtensions>
#ifndef GL_ARB_sync
#define GL_MAX_SERVER_WAIT_TIMEOUT 0x9111
#define GL_OBJECT_TYPE 0x9112
#define GL_SYNC_CONDITION 0x9113
#define GL_SYNC_STATUS 0x9114
#define GL_SYNC_FLAGS 0x9115
#define GL_SYNC_FENCE 0x9116
#define GL_SYNC_GPU_COMMANDS_COMPLETE 0x9117
#define GL_UNSIGNALED 0x9118
#define GL_SIGNALED 0x9119
#define GL_ALREADY_SIGNALED 0x911A
#define GL_TIMEOUT_EXPIRED 0x911B
#define GL_CONDITION_SATISFIED 0x911C
#define GL_WAIT_FAILED 0x911D
#define GL_SYNC_FLUSH_COMMANDS_BIT 0x00000001
#define GL_TIMEOUT_IGNORED 0xFFFFFFFFFFFFFFFFull
#endif
class OSG_EXPORT SyncSwapBuffersCallback : public GraphicsContext::SwapCallback
{
public:
SyncSwapBuffersCallback();
void setUpExtensions();
virtual void swapBuffersImplementation(GraphicsContext* gc);
typedef struct __GLsync *GLsync;
typedef GLsync (GL_APIENTRY * PFNGLFENCESYNCPROC) (GLenum condition, GLbitfield flags);
typedef GLboolean (GL_APIENTRY * PFNGLISSYNCPROC) (GLsync sync);
typedef void (GL_APIENTRY * PFNGLDELETESYNCPROC) (GLsync sync);
typedef GLenum (GL_APIENTRY * PFNGLCLIENTWAITSYNCPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout);
typedef void (GL_APIENTRY * PFNGLWAITSYNCPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout);
typedef void (GL_APIENTRY * PFNGLGETINTEGER64VPROC) (GLenum pname, GLint64 *params);
typedef void (GL_APIENTRY * PFNGLGETSYNCIVPROC) (GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values);
bool _extensionInitialized;
PFNGLFENCESYNCPROC _glFenceSync;
PFNGLISSYNCPROC _glIsSync;
PFNGLDELETESYNCPROC _glDeleteSync;
PFNGLCLIENTWAITSYNCPROC _glClientWaitSync;
PFNGLWAITSYNCPROC _glWaitSync;
PFNGLGETINTEGER64VPROC _glGetInteger64v;
PFNGLGETSYNCIVPROC _glGetSynciv;
GLsync _previousSync;
};
}