Hello all,I've noticed some odd behaviour in the .osg reader/writers with both OSG v1.0 and v1.2 (I had trouble getting the CVS to compile, but I'll try that again tomorrow)
I've attached two files; one called openmarker.osg which is a file demonstrating the odd behaviour I'm seeing. The following code demonstrates the odd behaviour when run over the openmarker.osg:
osg::ref_ptr<osg::Node> om; // useful variables for the loop
osg::StateSet *ss;
osg::Program *ssprog;
long i = 0;
while(i < 3) // do the test three times, at least two runs are
needed to demonstrate apparent bug
{
om = osgDB::readNodeFile("/openmarker.osg"); // load our model once
for each iteration of the test
if(om != NULL) // if we have a model...
{
ss = om->getStateSet(); // get the root node's
stateset...
if(ss != NULL) // if it does have a stateset....
{
ssprog = dynamic_cast<osg::Program*>(ss->getAttribute
(osg::StateAttribute::PROGRAM)); // get any glsl program attached to
the stateset
if(ssprog != NULL) // if there is a glsl
program...
{
cout << "!Program name: " << ssprog->getName() << ", num
shaders: " << ssprog->getNumShaders() << "\n"; // tell us how many
shaders the program has
osgDB::writeObjectFile(*(om.get()), "/dumpedopenmarker.osg"); //
write our correctly loaded file to disk
}
else cout << "!Could not find program!\n"; // there was no glsl
program
}
else cout << "!Could not find stateset!\n"; // there
was no stateset
}
else cout << "!Could not load model!\n"; // we failed to load the
model
i++; // run test again
}
When the code is executed from somewhere with a valid opengl context
(try pasting the above code into osgsimple or somewhere similar), it
outputs the following to the standard console:
!Program name: openmarker program, num shaders: 2!
!Program name: openmarker program, num shaders: 0!
!Program name: openmarker program, num shaders: 0!
The first time the loop loads the file, the shaders are loaded
correctly (and render correctly if you attach the node to a rendered
scenegraph). The second and third time the loop runs however the .osg
reader seems to miss the program attached to the root node. All other
properties and state atributes appear to be preserved.
The code snippet you will also notice dumps the .osg back out to disk in the event the shaders are correctly loaded; however manual inspection of the written file (dumpedopenmarker.osg; attached) shows the shaders have been lost somewhere in the writing process.
The node loaded is never attached to a scenegraph, never tampered with in anyway as you can see in the above code and only resides in memory for one iteration of the outer loop. This is as pure and isolated an example of the problem as I can possibly hope to demonstrate. It exhibits the mentioned bug with all versions of the OSG I have tested.
openmarker.osg
Description: Binary data
dumpedopenmarker.osg
Description: Binary data
_______________________________________________ osg-users mailing list [email protected] http://openscenegraph.net/mailman/listinfo/osg-users http://www.openscenegraph.org/
