Hi,
I just implement a kind of dirty texture read back node and ran into several 
problems:
As you can notice in the attached code, I had a problem with 
Image::readImageFromCurrentTexture.
I have would like to read back a 2D texture but as a 1D texture is binded too 
it the 1D->2d->3d->cubemap priority scheme in osg::Image
(   GLenum textureMode = binding1D ? GL_TEXTURE_1D : binding2D ? GL_TEXTURE_2D 
: binding3D ? GL_TEXTURE_3D : binding2DArray ? GL_TEXTURE_2D_ARRAY_EXT : 0;
 )
force me to disable the 1D binding.
My proposal would be to make textureMode a parameter of 
readImageFromCurrentTexture.
Further I suggest to remove Image::dirty() at the end of 
readImageFromCurrentTexture (as image is read from the actual texture i don't 
think it usefull to make it dirty, but i may  miss a usecase) 


Code:

class ImageReadBackNode:public osg::Group{

void ImageReadBackNode::setTexture(osg::Texture*tex){
        //assert(tex->getImage());
        class ImageReadBackNodeCallback : public osg::Camera::DrawCallback
        {
                osg::Texture *_texture; osg::Node *_n; 
        public:
                ImageReadBackNodeCallback(osg::Texture3D *texture, 
osg::Node*toremove) :_texture(texture), _n(toremove){ };

                virtual void operator () (osg::RenderInfo& renderInfo) const
                {
                        // get OpenGL driver to create texture from image.
                        _texture->apply(*renderInfo.getState());
///
 glBindTexture(GL_TEXTURE_1D, 0);
                        // restore the original setting
                        glDisable(GL_TEXTURE_1D);
                        
_texture->getImage()->readImageFromCurrentTexture(renderInfo.getContextID(),true,GL_FLOAT);

                        glEnable(GL_TEXTURE_1D);


///Node self removal in drawthread (dirty but seams to works:/ ..)
                        std::list<osg::Group*> gr;
                        for (int i = 0; i < _n->getNumParents(); 
i++)gr.push_back((_n->getParent(i)));
                        for (std::list<osg::Group*>::iterator it = gr.begin(); 
it != gr.end(); it++)
                                (*it)->removeChild(_n);

                }
        };
        osg::ref_ptr<osg::Camera > cam = new osg::Camera();
        cam->setFinalDrawCallback(new ImageReadBackNodeCallback(tex,this));
                this->addChild(cam);

}
};



Thank you!
Any advice would be welcome
Cheers,
Julien
Code:


[/code]

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=61592#61592





_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org

Reply via email to