diff --git a/VisualStudio/osgWrappers/osg/wrapper_osg.dsp b/VisualStudio/osgWrappers/osg/wrapper_osg.dsp index 0783e140d..fbe0f1237 100644 --- a/VisualStudio/osgWrappers/osg/wrapper_osg.dsp +++ b/VisualStudio/osgWrappers/osg/wrapper_osg.dsp @@ -423,6 +423,10 @@ SOURCE=..\..\..\src\osgWrappers\osg\RefNodePath.cpp SOURCE=..\..\..\src\osgWrappers\osg\Referenced.cpp # End Source File +# Begin Source File +SOURCE=..\..\..\src\osgWrappers\osg\Scissor.cpp +# End Source File + # Begin Source File SOURCE=..\..\..\src\osgWrappers\osg\Sequence.cpp # End Source File diff --git a/VisualStudio/osgWrappers/osgProducer/wrapper_osgProducer.dsp b/VisualStudio/osgWrappers/osgProducer/wrapper_osgProducer.dsp index 48f6c039a..7a5bce0cd 100644 --- a/VisualStudio/osgWrappers/osgProducer/wrapper_osgProducer.dsp +++ b/VisualStudio/osgWrappers/osgProducer/wrapper_osgProducer.dsp @@ -99,6 +99,10 @@ LINK32=link.exe SOURCE=..\..\..\src\osgWrappers\osgProducer\EventAdapter.cpp # End Source File +# Begin Source File +SOURCE=..\..\..\src\osgWrappers\osgProducer\GraphicsContextImplementation.cpp +# End Source File + # Begin Source File SOURCE=..\..\..\src\osgWrappers\osgProducer\KeyboardMouseCallback.cpp # End Source File diff --git a/include/osg/CameraNode b/include/osg/CameraNode index dd9eb968b..7802e8f0b 100644 --- a/include/osg/CameraNode +++ b/include/osg/CameraNode @@ -279,8 +279,30 @@ class OSG_EXPORT CameraNode : public Transform, public CullSettings /** Get the const Rendering object that is used to implement rendering of the subgraph.*/ const osg::Object* getRenderingCache() const { return _renderingCache.get(); } - public: + /** Draw callback for custom operations.*/ + struct DrawCallback : public Object + { + DrawCallback() {} + + DrawCallback(const DrawCallback&,const CopyOp&) {} + + META_Object(osg,DrawCallback) + + virtual void operator () (const osg::CameraNode& camera) const {} + }; + + /** Set the post draw callback for custom operations to do done after the drawing of the camera's subgraph has been completed.*/ + void setPostDrawCallback(DrawCallback* cb) { _postDrawCallback = cb; } + + /** Get the post draw callback.*/ + DrawCallback* getPostDrawCallback() { return _postDrawCallback.get(); } + + /** Get the const post draw callback.*/ + const DrawCallback* getPostDrawCallback() const { return _postDrawCallback.get(); } + + + public: /** Transform method that must be defined to provide generic interface for scene graph traversals.*/ virtual bool computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor*) const; @@ -311,6 +333,8 @@ class OSG_EXPORT CameraNode : public Transform, public CullSettings ref_ptr _graphicsContext; ref_ptr _renderingCache; + + ref_ptr _postDrawCallback; }; } diff --git a/include/osgUtil/RenderToTextureStage b/include/osgUtil/RenderToTextureStage index 9cc1ac1d6..08e03feb9 100644 --- a/include/osgUtil/RenderToTextureStage +++ b/include/osgUtil/RenderToTextureStage @@ -14,9 +14,9 @@ #ifndef OSGUTIL_RENDERTOTEXTURESTAGE #define OSGUTIL_RENDERTOTEXTURESTAGE 1 -#include +#include #include -#include +#include #include @@ -41,9 +41,12 @@ class OSGUTIL_EXPORT RenderToTextureStage : public RenderStage virtual const char* className() const { return "RenderToTextureStage"; } virtual void reset(); + + void setCameraNode(const osg::CameraNode* camera) { _camera = camera; } + const osg::CameraNode* getCameraNode() const { return _camera; } - void setTexture(osg::Texture2D* texture) { _texture = texture; } - osg::Texture2D* getTexture() { return _texture.get(); } + void setTexture(osg::Texture* texture, unsigned int level = 0, unsigned int face=0) { _texture = texture; _level = level; _face = face; } + osg::Texture* getTexture() { return _texture.get(); } void setImage(osg::Image* image) { _image = image; } osg::Image* getImage() { return _image.get(); } @@ -53,6 +56,7 @@ class OSGUTIL_EXPORT RenderToTextureStage : public RenderStage void setImageReadPixelDataType(GLenum type) { _imageReadPixelDataType = type; } GLenum getImageReadPixelDataType() const { return _imageReadPixelDataType; } + void setFrameBufferObject(osg::FrameBufferObject* fbo) { _fbo = fbo; } osg::FrameBufferObject* getFrameBufferObject() { return _fbo.get(); } @@ -70,8 +74,13 @@ class OSGUTIL_EXPORT RenderToTextureStage : public RenderStage protected: virtual ~RenderToTextureStage(); + + const osg::CameraNode* _camera; - osg::ref_ptr _texture; + osg::ref_ptr _texture; + unsigned int _level; + unsigned int _face; + osg::ref_ptr _image; GLenum _imageReadPixelFormat; GLenum _imageReadPixelDataType; diff --git a/src/osg/CameraNode.cpp b/src/osg/CameraNode.cpp index ab687408b..81dd21487 100644 --- a/src/osg/CameraNode.cpp +++ b/src/osg/CameraNode.cpp @@ -38,7 +38,8 @@ CameraNode::CameraNode(const CameraNode& camera,const CopyOp& copyop): _viewMatrix(camera._viewMatrix), _renderOrder(camera._renderOrder), _renderTargetImplementation(camera._renderTargetImplementation), - _bufferAttachmentMap(camera._bufferAttachmentMap) + _bufferAttachmentMap(camera._bufferAttachmentMap), + _postDrawCallback(camera._postDrawCallback) { } diff --git a/src/osgProducer/GraphicsContextImplementation.cpp b/src/osgProducer/GraphicsContextImplementation.cpp index fba702c0b..90cc0e748 100644 --- a/src/osgProducer/GraphicsContextImplementation.cpp +++ b/src/osgProducer/GraphicsContextImplementation.cpp @@ -41,6 +41,8 @@ namespace osgProducer GraphicsContextImplementation::GraphicsContextImplementation(Traits* traits) { + _traits = traits; + _rs = new Producer::RenderSurface; _rs->setWindowName(traits->_windowName); _rs->setWindowRectangle(traits->_x, traits->_y, traits->_width, traits->_height); @@ -50,7 +52,7 @@ GraphicsContextImplementation::GraphicsContextImplementation(Traits* traits) { _rs->setDrawableType( Producer::RenderSurface::DrawableType_PBuffer ); - if (_traits->_alpha>0) + if (traits->_alpha>0) { _rs->setRenderToTextureMode(Producer::RenderSurface::RenderToRGBATexture); } @@ -65,7 +67,6 @@ GraphicsContextImplementation::GraphicsContextImplementation(Traits* traits) _rs->realize(); - _traits = traits; } GraphicsContextImplementation::GraphicsContextImplementation(Producer::RenderSurface* rs) diff --git a/src/osgUtil/CullVisitor.cpp b/src/osgUtil/CullVisitor.cpp index 898f090e5..e78920e5e 100644 --- a/src/osgUtil/CullVisitor.cpp +++ b/src/osgUtil/CullVisitor.cpp @@ -1142,22 +1142,13 @@ void CullVisitor::apply(osg::CameraNode& camera) break; } - osg::Texture2D* tex = 0; - osg::CameraNode::BufferAttachmentMap& bufferAttachements = camera.getBufferAttachmentMap(); for(osg::CameraNode::BufferAttachmentMap::iterator itr = bufferAttachements.begin(); itr != bufferAttachements.end(); ++itr) { - - // if one exist attach texture to the RenderToTextureStage. - osg::Texture2D* texture2D = dynamic_cast(itr->second._texture.get()); - if (texture2D) - { - tex = texture2D; - rtts->setTexture(texture2D); - } - + // assign the texture... pro + if (itr->second._texture.valid()) rtts->setTexture(itr->second._texture.get()); // if one exist attach image to the RenderToTextureStage. if (itr->second._image.valid()) rtts->setImage(itr->second._image.get()); diff --git a/src/osgUtil/RenderToTextureStage.cpp b/src/osgUtil/RenderToTextureStage.cpp index d95d0bd05..f6f2313f8 100644 --- a/src/osgUtil/RenderToTextureStage.cpp +++ b/src/osgUtil/RenderToTextureStage.cpp @@ -11,6 +11,11 @@ * OpenSceneGraph Public License for more details. */ #include +#include +#include +#include +#include +#include using namespace osg; using namespace osgUtil; @@ -20,6 +25,11 @@ using namespace osgUtil; RenderToTextureStage::RenderToTextureStage() { + _camera = 0; + + _level = 0; + _face = 0; + _imageReadPixelFormat = GL_RGBA; _imageReadPixelDataType = GL_UNSIGNED_BYTE; } @@ -78,7 +88,35 @@ void RenderToTextureStage::draw(osg::State& state,RenderLeaf*& previous) } // need to implement texture cube map etc... - _texture->copyTexImage2D(state,_viewport->x(),_viewport->y(),_viewport->width(),_viewport->height()); + osg::Texture1D* texture1D = 0; + osg::Texture2D* texture2D = 0; + osg::Texture3D* texture3D = 0; + osg::TextureRectangle* textureRec = 0; + osg::TextureCubeMap* textureCubeMap = 0; + + if ((texture2D = dynamic_cast(_texture.get())) != 0) + { + texture2D->copyTexImage2D(state,_viewport->x(),_viewport->y(),_viewport->width(),_viewport->height()); + } + else if ((textureRec = dynamic_cast(_texture.get())) != 0) + { + textureRec->copyTexImage2D(state,_viewport->x(),_viewport->y(),_viewport->width(),_viewport->height()); + } + else if ((texture1D = dynamic_cast(_texture.get())) != 0) + { + // need to implement + texture1D->copyTexImage1D(state,_viewport->x(),_viewport->y(),_viewport->width()); + } + else if ((texture3D = dynamic_cast(_texture.get())) != 0) + { + // need to implement + texture3D->copyTexSubImage3D(state, 0, 0, _face, _viewport->x(), _viewport->y(), _viewport->width(), _viewport->height()); + } + else if ((textureCubeMap = dynamic_cast(_texture.get())) != 0) + { + // need to implement + // textureCubeMap->copyTexImageCubeMap(state,_viewport->x(),_viewport->y(),_viewport->width(),_viewport->height()); + } } if (_image.valid()) @@ -86,6 +124,12 @@ void RenderToTextureStage::draw(osg::State& state,RenderLeaf*& previous) _image->readPixels(_viewport->x(),_viewport->y(),_viewport->width(),_viewport->height(),_imageReadPixelFormat,_imageReadPixelDataType); } + if (_camera && _camera->getPostDrawCallback()) + { + // if we have a camera with a post draw callback invoke it. + (*(_camera->getPostDrawCallback()))(*_camera); + } + if (fbo_supported) { // switch of the frame buffer object @@ -99,5 +143,6 @@ void RenderToTextureStage::draw(osg::State& state,RenderLeaf*& previous) glReadBuffer(GL_BACK); } + }