Hi Mark,

Thanks for the test code.  What version of the OSG are you using?

Robert.

On Thu, Dec 11, 2008 at 10:17 PM, Mark Sciabica <[email protected]> wrote:
> Hi Robert,
>
> I was testing how osg handled changing a texture's image when the texture
> was used in multiple viewers when I ran into the problem. Attached is my
> test code. Closing one of the windows unexpectedly reloaded the texture in
> the other window.
>
> My texture testing exposed another bug when changing the image attached to a
> texture. I'll provide a description and sample in a separate e-mail.
>
> Mark
>
>
> Robert Osfield wrote:
>
> Hi Mark,
>
> Could you modify one of the OSG examples to recreate this issue, once
> I can recreate it at my end I'll be able to look into solve the bug.
>
> Robert.
>
> On Thu, Dec 11, 2008 at 7:44 PM, Mark Sciabica <[email protected]> wrote:
>
>
> I encountered some unexpected behavior when a Viewer is destroyed. When the
> viewer is destructing, it destroys its contained camera, which removes
> itself from its graphics context. During the removal process, the graphics
> context calls releaseGLObjects on the camera's children, passing in the
> GraphicsContext's _state member as a parameter. The problem is that at this
> point, the state has been already been reset to zero so that
> releaseGLObjects releases objects for ALL contextIDs. This will cause all
> objects that are used in multiple contexts to reload whenever a Viewer
> window is closed. This is potentially expensive and should be avoided if
> possible.
>
> It appears that GraphicsContext::close already releases the GL objects from
> the relevant cameras so it may be that this call is redundant. Perhaps
> GraphicsContext::removeCamera can simply not call releaseGLObjects if it
> does not have a valid _state object. This fix seems to work for my code, but
> I'm using a modified version of osg that isn't dependent on cameras for
> cleanup of OpenGL resources.
>
>
> Mark
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
> #include <osg/Texture2D>
> #include <osg/Geometry>
>
> #include <osgViewer/Viewer>
> #include <osgGA/TrackballManipulator>
>
> int main()
> {
>    osg::ref_ptr<osg::Texture2D> texture1 = new osg::Texture2D;
>    osg::ref_ptr<osg::Image> images[4];
>    static unsigned char bytes[16] = {
>        0xff, 0x00, 0x00, 0xff,
>        0x00, 0xff, 0x00, 0xff,
>        0x00, 0x00, 0xff, 0xff,
>        0xff, 0x00, 0xff, 0xff,
>    };
>    for( int i = 0; i < 4; ++i )
>    {
>        images[i] = new osg::Image;
>        images[i]->setImage(i+1, 1, 1, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE,
> &bytes[0], osg::Image::NO_DELETE, 1);
>    }
>
>    osg::ref_ptr<osg::Geode> geode = new osg::Geode();
>    osg::ref_ptr<osg::Geometry> geom = new osg::Geometry();
>    geode->addDrawable(geom.get());
>
>    osg::ref_ptr<osg::Vec3Array> pVertices = new osg::Vec3Array;
>    pVertices->push_back( osg::Vec3(0, 0, 0) );
>    pVertices->push_back( osg::Vec3(0, 0, 1) );
>    pVertices->push_back( osg::Vec3(1, 0, 1) );
>    pVertices->push_back( osg::Vec3(1, 0, 0) );
>    geom->setVertexArray(pVertices.get());
>
>    osg::ref_ptr<osg::Vec2Array> pTexCoords = new osg::Vec2Array;
>    pTexCoords->push_back( osg::Vec2(0, 0) );
>    pTexCoords->push_back( osg::Vec2(0, 1) );
>    pTexCoords->push_back( osg::Vec2(1, 1) );
>    pTexCoords->push_back( osg::Vec2(1, 0) );
>    geom->setTexCoordArray(0, pTexCoords.get());
>    osg::ref_ptr<osg::DrawArrays> pDrawArrays = new osg::DrawArrays(GL_QUADS,
> 0, 4);
>    geom->addPrimitiveSet(pDrawArrays.get());
>
>    osg::StateSet* stateset = new osg::StateSet();
>    stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
>    stateset->setTextureAttributeAndModes(0, texture1.get(),
> osg::StateAttribute::ON);
>    geode->setStateSet( stateset );
>    texture1->setImage(images[1].get());
>    texture1->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
>    texture1->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
>    texture1->setResizeNonPowerOfTwoHint(false);
>    texture1->setFilter( osg::Texture::MAG_FILTER, osg::Texture::NEAREST );
>    texture1->setFilter( osg::Texture::MIN_FILTER, osg::Texture::NEAREST );
>
>
>    osg::ref_ptr<osgViewer::Viewer> viewer1 = new osgViewer::Viewer;
>    osg::ref_ptr<osgViewer::Viewer> viewer2 = new osgViewer::Viewer;
>    viewer1->setUpViewInWindow(20, 50, 200, 200);
>    viewer2->setUpViewInWindow(240, 300, 200, 200);
>    viewer1->setThreadingModel(osgViewer::ViewerBase::SingleThreaded);
>    viewer2->setThreadingModel(osgViewer::ViewerBase::SingleThreaded);
>
>    viewer1->setSceneData( geode.get() );
>    viewer2->setSceneData( geode.get() );
>
>    viewer1->setCameraManipulator(new osgGA::TrackballManipulator());
>    viewer2->setCameraManipulator(new osgGA::TrackballManipulator());
>
>    int nFrame = 0;
>    while( viewer1.get() || viewer2.get() )
>    {
>        if( nFrame == 1 )
>        {
>            texture1->setImage(images[2].get());
>        }
>
>        if( viewer1.get() )
>        {
>            if( !viewer1->done() )
>                viewer1->frame();
>            else
>                viewer1 = 0;
>        }
>
>        if( viewer2.get() )
>        {
>            if( !viewer2->done() )
>                viewer2->frame();
>            else
>                viewer2 = 0;
>        }
>
>        ++nFrame;
>    }
>
>    return 0;
> }
>
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to