From 296c12a8e929f2a72897afd5866611b62eb5a9b5 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 31 Mar 2015 10:41:33 +0000 Subject: [PATCH] Refactor the RTT Camera resize code into a seperate Callback method in prep for this all being done by a single Camera API call. git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14809 16af8721-9629-0410-8352-f15c8da7e697 --- examples/osgdistortion/osgdistortion.cpp | 45 ++++++++++++++---------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/examples/osgdistortion/osgdistortion.cpp b/examples/osgdistortion/osgdistortion.cpp index b3181c632..b6cfe5db3 100644 --- a/examples/osgdistortion/osgdistortion.cpp +++ b/examples/osgdistortion/osgdistortion.cpp @@ -108,6 +108,31 @@ public: { } + void resizeRTTCamera(osg::Camera* camera,unsigned int width, unsigned int height) + { + 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(); + } + virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, osg::Object* object, osg::NodeVisitor* nv) { osg::Camera* camera = dynamic_cast(object); @@ -126,26 +151,8 @@ public: // reset the Camera and associated Texture's to make sure it tracks the new window size. int width = ea.getWindowWidth(); int height = ea.getWindowHeight(); - camera->setViewport(0, 0, width, height); - camera->setRenderingCache(0); - 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(); - } - } - } + resizeRTTCamera(camera, width, height); } return false; }