OpenSceneGraph icon indicating copy to clipboard operation
OpenSceneGraph copied to clipboard

[*] Fixed bug in RenderStage: prevent duplicates in _{pre,post}Render…

Open valid-ptr opened this issue 3 years ago • 1 comments

…List. Unconditional wait (in ViewerBase till the dynamic draw is complete) fixed using DrawThreadPerContext viewer's threading model for graphs with multiple instances of the same {PRE,POST}_RENDER camera which contain geometry with DYNAMIC datavariance (or multiple traverses in the CullCallback like in osgFX).

valid-ptr avatar May 18 '22 12:05 valid-ptr

Example to demonstrate solved problem:

// NOTE:
// g++ osg_wait.cpp -I /opt/OpenSceneGraph/include/ -L /opt/OpenSceneGraph/lib64/ -losgViewer -losg -losgDB -losgGA
// Example: OSG_WINDOW="0 0 800 450" ./a.out --DrawThreadPerContext

#include <iostream>
#include <osgViewer/Viewer>

using namespace osg;

class MultipassCullCallback : public osg::NodeCallback
{
public:
	virtual void operator()(Node* node, NodeVisitor* nv)
	{
		node->traverse(*nv);
		node->traverse(*nv);
	}
};

int main(int argc, char** argv)
{
	osg::ArgumentParser parser(&argc, argv);
	osgViewer::Viewer viewer(parser);

	osg::ref_ptr<osg::Geometry> geometry =
		osg::createTexturedQuadGeometry(osg::Vec3d(-0.5, 0.0, -0.5),
										osg::Vec3d(1.0, 0.0, 0.0),
										osg::Vec3d(0.0, 0.0, 1.0));
	geometry->setDataVariance(osg::Object::DYNAMIC);	// Important!

	osg::ref_ptr<osg::Group> root = new osg::Group;

	osg::ref_ptr<osg::Camera> camera = new osg::Camera();
	camera->setRenderOrder(osg::Camera::POST_RENDER, 1);	// Same with PRE_RENDER
	camera->addChild(geometry);

	root->addChild(camera);

#if 1
	// Add the same camera one more time cause unconditional wait
	root->addChild(camera);
#else
	// Add such CullCallback cause unconditional wait
	osg::ref_ptr<MultipassCullCallback> multipassCullCallback = new MultipassCullCallback;
	root->setCullCallback(multipassCullCallback);
#endif

	viewer.setSceneData(root);
	viewer.run();

	return 0;
}

valid-ptr avatar May 18 '22 12:05 valid-ptr