Re: [osg-users] Saving a Texture3D to an Image
Figured out how to solve the problem in the last post. I just set the texture I want to write on the camera itself so that its active once the post draw is executed. For instance, the code above simply changes to the following. Code: ... camera-getOrCreateStateSet()-setTextureAttributeAndModes(1, outputTexture, osg::StateAttribute::ON); camera-setFinalDrawCallback( new Capture(output.tiff) ); geode-getOrCreateStateSet()-setTextureAttributeAndModes(1, sampler, osg::StateAttribute::ON); geode-getOrCreateStateSet()-addUniform( new osg::Uniform(sampler, 1) ); camera-attach(osg::Camera::COLOR_BUFFER0, outputTexture); geode-getOrCreateStateSet()-setAttributeAndModes( prog, osg::StateAttribute::ON ); viewer.frame(); geode-getOrCreateStateSet()-removeAttribute( prog ); Thanks for pointing me in the right direction. I can get my 3d textures written out now! Thanks, Trystan -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=43854#43854 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Saving a Texture3D to an Image
Hi Trystan, Have a look at : Image::readImageFromCurrentTexture(..) You'd need to call this from the graphics thread that has you've have render to the texture from - for instance using a Camera Post or FinalDrawCallback. After this readImage you could do the writeImageFile as well to ensure that the correct ordering is maintained. Calling writeImageFile() after the viewer.frame() will only work in SingleThreaded and CullDrawThreadPerContext threading models as the other threading models have the graphics thread still running after the return form viewer.frame(). Robert. On 12 November 2011 07:52, Trystan Larey-Williams trys...@trystan.org wrote: Hi, I've been banging my head against how to save a 3D texture out to a dds file for some time now. I've read posts that suggest simply attaching the texture's image to the buffer rather than the texture itself. I've done that for 2D textures with no problem. However, I don't see how that will work in this case; given the setup below. Code: ... camera-setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT); camera-setImplicitBufferAttachmentMask(osg::Camera::IMPLICIT_COLOR_BUFFER_ATTACHMENT, osg::Camera::IMPLICIT_COLOR_BUFFER_ATTACHMENT ); camera-attach(osg::Camera::COLOR_BUFFER0, tex1, 0, osg::Camera::FACE_CONTROLLED_BY_GEOMETRY_SHADER); camera-attach(osg::Camera::COLOR_BUFFER1, tex2, 0, osg::Camera::FACE_CONTROLLED_BY_GEOMETRY_SHADER); viewer.frame(); ... So, after I render the frame I want to be able to say Code: osgDB::writeImageFile( *tex1-getImage(), foo.dds ) But, of course, this doesn't work since the image isn't updated when the texture changes. Is there a strait forward way to get the texture data back to an image that I'm missing? Thank you! Cheers, Trystan[/code][/list] -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=43837#43837 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Saving a Texture3D to an Image
Hi Robert, Thanks for the reply! That seems to work only if I don't need to set other texture states. For instance, the following fails (2D texture in this case but I need to do similar with 3D). If I comment out the sampler texture attribute, the image is written successfully. With it commented in, image-valid() is false . Code: ... camera-setFinalDrawCallback( new Capture(output.tiff) ); geode-getOrCreateStateSet()-setTextureAttributeAndModes(1, sampler, osg::StateAttribute::ON); geode-getOrCreateStateSet()-addUniform( new osg::Uniform(sampler, 1) ); camera-attach(osg::Camera::COLOR_BUFFER0, outputTexture); geode-getOrCreateStateSet()-setAttributeAndModes( prog, osg::StateAttribute::ON ); viewer.frame(); geode-getOrCreateStateSet()-removeAttribute( prog ); Capture is implemented as follows Code: class Capture : public osg::Camera::DrawCallback { public: Capture( const std::string imagename ) : m_imageName(imagename) {} virtual void operator () (osg::RenderInfo renderInfo) const { osg::ref_ptrosg::Image image = new osg::Image; image-readImageFromCurrentTexture(renderInfo.getContextID(), true); osgDB::writeImageFile(*image, m_imageName); } private: std::string m_imageName; }; So, I'm guessing this approach doesn't work with multiple texture units? Maybe there's a way to force a particular unit active in the callback? Cheers, Trystan -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=43841#43841 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Saving a Texture3D to an Image
Hi, I've been banging my head against how to save a 3D texture out to a dds file for some time now. I've read posts that suggest simply attaching the texture's image to the buffer rather than the texture itself. I've done that for 2D textures with no problem. However, I don't see how that will work in this case; given the setup below. Code: ... camera-setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT); camera-setImplicitBufferAttachmentMask(osg::Camera::IMPLICIT_COLOR_BUFFER_ATTACHMENT, osg::Camera::IMPLICIT_COLOR_BUFFER_ATTACHMENT ); camera-attach(osg::Camera::COLOR_BUFFER0, tex1, 0, osg::Camera::FACE_CONTROLLED_BY_GEOMETRY_SHADER); camera-attach(osg::Camera::COLOR_BUFFER1, tex2, 0, osg::Camera::FACE_CONTROLLED_BY_GEOMETRY_SHADER); viewer.frame(); ... So, after I render the frame I want to be able to say Code: osgDB::writeImageFile( *tex1-getImage(), foo.dds ) But, of course, this doesn't work since the image isn't updated when the texture changes. Is there a strait forward way to get the texture data back to an image that I'm missing? Thank you! Cheers, Trystan[/code][/list] -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=43837#43837 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org