From 053ba0c543f95ed3fecf5dd3e3fe0cd36e23e8c5 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 1 Jun 2007 19:45:24 +0000 Subject: [PATCH] From Wojciech Lewandowski, "I did few tests to see whether adding PreDraw callback would help us with SPI problems when using Viewer. Results were positive so I decided to give it a try and ask you to verify and maybe merge with existing codebase. I added _preDrawCallback member and neccessary access methods plus modified osgUtil RenderStage.cpp to invoke it before all drawInner calls are made. I tried to maintain symmetry with postDrawCallback but you know better where is a proper place for this call ;-) " --- include/osg/Camera | 13 ++++++++++++- src/osg/Camera.cpp | 1 + src/osgUtil/RenderStage.cpp | 6 ++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/osg/Camera b/include/osg/Camera index a6592775b..596dc0623 100644 --- a/include/osg/Camera +++ b/include/osg/Camera @@ -384,7 +384,17 @@ class OSG_EXPORT Camera : public Transform, public CullSettings virtual void operator () (const osg::Camera& /*camera*/) const {} }; - /** Set the post draw callback for custom operations to do done after the drawing of the camera's subgraph has been completed.*/ + /** Set the pre draw callback for custom operations to be done before the drawing of the camera's subgraph has been completed.*/ + void setPreDrawCallback(DrawCallback* cb) { _preDrawCallback = cb; } + + /** Get the pre draw callback.*/ + DrawCallback* getPreDrawCallback() { return _preDrawCallback.get(); } + + /** Get the const pre draw callback.*/ + const DrawCallback* getPreDrawCallback() const { return _preDrawCallback.get(); } + + + /** Set the post draw callback for custom operations to be done after the drawing of the camera's subgraph has been completed.*/ void setPostDrawCallback(DrawCallback* cb) { _postDrawCallback = cb; } /** Get the post draw callback.*/ @@ -451,6 +461,7 @@ class OSG_EXPORT Camera : public Transform, public CullSettings buffered_object< ref_ptr > _renderingCache; + ref_ptr _preDrawCallback; ref_ptr _postDrawCallback; }; diff --git a/src/osg/Camera.cpp b/src/osg/Camera.cpp index c247020bf..4f8f1d062 100644 --- a/src/osg/Camera.cpp +++ b/src/osg/Camera.cpp @@ -52,6 +52,7 @@ Camera::Camera(const Camera& camera,const CopyOp& copyop): _renderTargetImplementation(camera._renderTargetImplementation), _renderTargetFallback(camera._renderTargetFallback), _bufferAttachmentMap(camera._bufferAttachmentMap), + _preDrawCallback(camera._preDrawCallback), _postDrawCallback(camera._postDrawCallback) { // need to copy/share graphics context? diff --git a/src/osgUtil/RenderStage.cpp b/src/osgUtil/RenderStage.cpp index ec959ded1..80dbc744f 100644 --- a/src/osgUtil/RenderStage.cpp +++ b/src/osgUtil/RenderStage.cpp @@ -864,6 +864,12 @@ void RenderStage::draw(osg::RenderInfo& renderInfo,RenderLeaf*& previous) if (!useThread) useContext->makeCurrent(); } + + if (_camera && _camera->getPreDrawCallback()) + { + // if we have a camera with a post draw callback invoke it. + (*(_camera->getPreDrawCallback()))(*_camera); + } bool doCopyTexture = _texture.valid() ? (callingContext != useContext) :