diff --git a/include/osg/GraphicsContext b/include/osg/GraphicsContext index 9fbeec5c7..14091924e 100644 --- a/include/osg/GraphicsContext +++ b/include/osg/GraphicsContext @@ -16,6 +16,8 @@ #include #include +#include + #include namespace osg { @@ -328,6 +330,8 @@ class OSG_EXPORT GraphicsContext : public Object * Note, must only be called from a thread with this context current.*/ virtual void clear(); + double getTimeSinceLastClear() const { return osg::Timer::instance()->delta_s(_lastClearTick, osg::Timer::instance()->tick()); } + /** Realize the GraphicsContext.*/ bool realize(); @@ -496,6 +500,7 @@ class OSG_EXPORT GraphicsContext : public Object ref_ptr _resizedCallback; + Timer_t _lastClearTick; }; diff --git a/src/osg/GraphicsContext.cpp b/src/osg/GraphicsContext.cpp index f8949b374..4c4dacd0c 100644 --- a/src/osg/GraphicsContext.cpp +++ b/src/osg/GraphicsContext.cpp @@ -382,7 +382,8 @@ GraphicsContext* GraphicsContext::getCompileContext(unsigned int contextID) GraphicsContext::GraphicsContext(): _clearColor(osg::Vec4(0.0f,0.0f,0.0f,1.0f)), _clearMask(0), - _threadOfLastMakeCurrent(0) + _threadOfLastMakeCurrent(0), + _lastClearTick(0) { setThreadSafeRefUnref(true); _operationsBlock = new RefBlock; @@ -393,7 +394,8 @@ GraphicsContext::GraphicsContext(): GraphicsContext::GraphicsContext(const GraphicsContext&, const osg::CopyOp&): _clearColor(osg::Vec4(0.0f,0.0f,0.0f,1.0f)), _clearMask(0), - _threadOfLastMakeCurrent(0) + _threadOfLastMakeCurrent(0), + _lastClearTick(0) { setThreadSafeRefUnref(true); _operationsBlock = new RefBlock; @@ -410,6 +412,8 @@ GraphicsContext::~GraphicsContext() void GraphicsContext::clear() { + _lastClearTick = osg::Timer::instance()->tick(); + if (_clearMask==0 || !_traits) return; glViewport(0, 0, _traits->width, _traits->height);