From 99f7bfab3b2698ddc743f443ef9b2d8816ac869a Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 31 Mar 2015 15:08:13 +0000 Subject: [PATCH] Introduced Camera::resizeAttachments(int width, int height) to resize all the Texture and Image assigned the the Camera attachments. git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14810 16af8721-9629-0410-8352-f15c8da7e697 --- examples/osgdistortion/osgdistortion.cpp | 20 +------ include/osg/Camera | 4 ++ src/osg/Camera.cpp | 73 ++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 19 deletions(-) diff --git a/examples/osgdistortion/osgdistortion.cpp b/examples/osgdistortion/osgdistortion.cpp index b6cfe5db3..c32877d60 100644 --- a/examples/osgdistortion/osgdistortion.cpp +++ b/examples/osgdistortion/osgdistortion.cpp @@ -112,25 +112,7 @@ public: { camera->setViewport(0, 0, width, height); - osg::Camera::BufferAttachmentMap& cbam = camera->getBufferAttachmentMap(); - for(osg::Camera::BufferAttachmentMap::iterator itr = cbam.begin(); - itr != cbam.end(); - ++itr) - { - osg::Camera::Attachment& attachment = itr->second; - if (attachment._texture.get()) - { - osg::Texture2D* texture2D = dynamic_cast(attachment._texture.get()); - if (texture2D) - { - OSG_NOTICE<<"Resetting Texture size"<setTextureSize(width, height); - texture2D->dirtyTextureObject(); - } - } - } - - camera->dirtyAttachmentMap(); + camera->resizeAttachments(width, height); } virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, osg::Object* object, osg::NodeVisitor* nv) diff --git a/include/osg/Camera b/include/osg/Camera index b9e115636..98cb7b282 100644 --- a/include/osg/Camera +++ b/include/osg/Camera @@ -159,6 +159,7 @@ class OSG_EXPORT Camera : public Transform, public CullSettings Viewport* getViewport() { return _viewport.get(); } + enum TransformOrder { PRE_MULTIPLY, @@ -425,6 +426,9 @@ class OSG_EXPORT Camera : public Transform, public CullSettings /** Get the AttachmentMapModifiedCount. */ unsigned int getAttachmentMapModifiedCount() const { return _attachmentMapModifiedCount; } + /** Resize the image and textures in the AttachementMap.*/ + void resizeAttachments(int width, int height); + /** Explicit control over implicit allocation of buffers when using FBO. Implicit buffers are automatically substituted when user have not attached such buffer. diff --git a/src/osg/Camera.cpp b/src/osg/Camera.cpp index 823b63aad..975ea5dee 100644 --- a/src/osg/Camera.cpp +++ b/src/osg/Camera.cpp @@ -12,6 +12,12 @@ */ #include #include +#include +#include +#include +#include +#include +#include #include using namespace osg; @@ -408,6 +414,73 @@ void Camera::inheritCullSettings(const CullSettings& settings, unsigned int inhe } } +void Camera::resizeAttachments(int width, int height) +{ + bool modified = false; + for(BufferAttachmentMap::iterator itr = _bufferAttachmentMap.begin(); + itr != _bufferAttachmentMap.end(); + ++itr) + { + Attachment& attachment = itr->second; + if (attachment._texture.valid()) + { + { + osg::Texture1D* texture = dynamic_cast(attachment._texture.get()); + if (texture && (texture->getTextureWidth()!=width)) + { + modified = true; + texture->setTextureWidth(width); + texture->dirtyTextureObject(); + } + } + + { + osg::Texture2D* texture = dynamic_cast(attachment._texture.get()); + if (texture && ((texture->getTextureWidth()!=width) || (texture->getTextureHeight()!=height))) + { + modified = true; + texture->setTextureSize(width, height); + texture->dirtyTextureObject(); + } + } + + { + osg::Texture3D* texture = dynamic_cast(attachment._texture.get()); + if (texture && ((texture->getTextureWidth()!=width) || (texture->getTextureHeight()!=height))) + { + modified = true; + texture->setTextureSize(width, height, texture->getTextureDepth()); + texture->dirtyTextureObject(); + } + } + + { + osg::Texture2DArray* texture = dynamic_cast(attachment._texture.get()); + if (texture && ((texture->getTextureWidth()!=width) || (texture->getTextureHeight()!=height))) + { + modified = true; + texture->setTextureSize(width, height, texture->getTextureDepth()); + texture->dirtyTextureObject(); + } + } + } + + if (attachment._image.valid() && (attachment._image->s()!=width || attachment._image->s()!=height) ) + { + modified = true; + osg::Image* image = attachment._image.get(); + image->allocateImage(width, height, image->r(), + image->getPixelFormat(), image->getDataType(), + image->getPacking()); + } + } + + if (modified) + { + dirtyAttachmentMap(); + } +} + void Camera::createCameraThread() { if (!_cameraThread)