From a28907a67f1ccd83d7eccb8288ab8c272a77da27 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 24 May 2012 18:15:44 +0000 Subject: [PATCH] From Jaap Gas, added missing break, and missing removeDraggerCallback. --- applications/osgviewer/osgviewer.cpp | 114 +++++++++++++++++++++++++++ src/osgManipulator/Dragger.cpp | 14 ++++ 2 files changed, 128 insertions(+) diff --git a/applications/osgviewer/osgviewer.cpp b/applications/osgviewer/osgviewer.cpp index d94a0f5fe..b0dd33805 100644 --- a/applications/osgviewer/osgviewer.cpp +++ b/applications/osgviewer/osgviewer.cpp @@ -30,6 +30,106 @@ #include +#include + +#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 MySwapBuffersCallback : public osg::GraphicsContext::SwapCallback +{ +public: + MySwapBuffersCallback(): + _extensionInitialized(false), + _glFenceSync(0), + _glIsSync(0), + _glDeleteSync(0), + _glClientWaitSync(0), + _glWaitSync(0), + _glGetInteger64v(0), + _glGetSynciv(0), + _previousSync(0) + { + OSG_NOTICE<<"Created Swap callback."<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"<getOrCreateStateSet()) ); @@ -161,6 +263,18 @@ int main(int argc, char** argv) viewer.realize(); + if (doArbSync) + { + osgViewer::ViewerBase::Contexts contexts; + viewer.getContexts(contexts); + for(osgViewer::ViewerBase::Contexts::iterator itr = contexts.begin(); + itr != contexts.end(); + ++itr) + { + (*itr)->setSwapCallback(new MySwapBuffersCallback); + } + } + return viewer.run(); } diff --git a/src/osgManipulator/Dragger.cpp b/src/osgManipulator/Dragger.cpp index 9f6aa1238..b667ca599 100644 --- a/src/osgManipulator/Dragger.cpp +++ b/src/osgManipulator/Dragger.cpp @@ -275,6 +275,19 @@ void Dragger::addDraggerCallback(DraggerCallback* dc) void Dragger::removeDraggerCallback(DraggerCallback* dc) { + for(Dragger::DraggerCallbacks::iterator itr = _draggerCallbacks.begin(); + itr != _draggerCallbacks.end(); + ) + { + if (dc==itr->get()) + { + itr = _draggerCallbacks.erase(itr); + } + else + { + ++itr; + } + } } @@ -390,6 +403,7 @@ bool Dragger::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& } } } + break; } case osgGA::GUIEventAdapter::DRAG: case osgGA::GUIEventAdapter::RELEASE: