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:
@@ -23,6 +23,7 @@
|
||||
#include <osg/Drawable>
|
||||
#include <osg/FragmentProgram>
|
||||
#include <osg/VertexProgram>
|
||||
#include <osg/GLExtensions>
|
||||
|
||||
#include <OpenThreads/ReentrantMutex>
|
||||
|
||||
@@ -975,3 +976,60 @@ void GraphicsContext::resizedImplementation(int x, int y, int width, int height)
|
||||
_traits->width = width;
|
||||
_traits->height = height;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SyncSwapBuffersCallback
|
||||
//
|
||||
SyncSwapBuffersCallback::SyncSwapBuffersCallback():
|
||||
_extensionInitialized(false),
|
||||
_glFenceSync(0),
|
||||
_glIsSync(0),
|
||||
_glDeleteSync(0),
|
||||
_glClientWaitSync(0),
|
||||
_glWaitSync(0),
|
||||
_glGetInteger64v(0),
|
||||
_glGetSynciv(0),
|
||||
_previousSync(0)
|
||||
{
|
||||
OSG_NOTICE<<"Created Swap callback."<<std::endl;
|
||||
}
|
||||
|
||||
void SyncSwapBuffersCallback::setUpExtensions()
|
||||
{
|
||||
_extensionInitialized = true;
|
||||
osg::setGLExtensionFuncPtr(_glFenceSync, "glFenceSync");
|
||||
osg::setGLExtensionFuncPtr(_glIsSync, "glIsSync");
|
||||
osg::setGLExtensionFuncPtr(_glDeleteSync, "glDeleteSync");
|
||||
osg::setGLExtensionFuncPtr(_glClientWaitSync, "glClientWaitSync");
|
||||
osg::setGLExtensionFuncPtr(_glWaitSync, "glWaitSync");
|
||||
osg::setGLExtensionFuncPtr(_glGetInteger64v, "glGetInteger64v");
|
||||
osg::setGLExtensionFuncPtr(_glGetSynciv, "glGetSynciv");
|
||||
}
|
||||
|
||||
void SyncSwapBuffersCallback::swapBuffersImplementation(osg::GraphicsContext* gc)
|
||||
{
|
||||
// OSG_NOTICE<<"Before swap - place to do swap ready sync"<<std::endl;
|
||||
gc->swapBuffersImplementation();
|
||||
//glFinish();
|
||||
|
||||
if (!_extensionInitialized) setUpExtensions();
|
||||
|
||||
if (_glClientWaitSync)
|
||||
{
|
||||
if (_previousSync)
|
||||
{
|
||||
unsigned int num_seconds = 1;
|
||||
GLuint64 timeout = num_seconds * ((GLuint64)1000 * 1000 * 1000);
|
||||
_glClientWaitSync(_previousSync, 0, timeout);
|
||||
|
||||
_glDeleteSync(_previousSync);
|
||||
}
|
||||
|
||||
_previousSync = _glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
|
||||
}
|
||||
//gc->getState()->checkGLErrors("after glWaitSync");
|
||||
|
||||
//OSG_NOTICE<<"After swap"<<std::endl;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user