[osg-users] How to access the view parameters from which the Cull Visitor came?

Jannik Heller scrawl at baseoftrash.de
Mon Oct 2 13:52:22 PDT 2017


Hi Miguel,

Overriding traverse() is possible, it's also possible to add a callback via node->addCullCallback(myCallback) which is essentially the same just via a callback object that can be reused for multiple nodes (of possibly different types). I would usually go with callbacks as they are a little more flexible but both methods are fine. From there if it's a cull visitor you can just cast it: 


Code:

osgUtil::CullVisitor* cv = static_cast<osgUtil::CullVisitor*>(nv)



and get all the info you need from the CullVisitor, its Camera, etc.

It should be noted that OSG can (but does not by default) run culling for multiple cameras simultaneously, with the CullThreadPerCamera threading mode. If this is the case, making modifications to a subgraph like setNodeMask(), changing uniform's etc. is going to create race conditions. This can be worked around by not modifying the scene graph with your changes, but instead push them onto the active CullVisitor only (e.g. by pushing a StateSet with new state, or push a new ModelViewMatrix - have  a look at the CullVisitor's  push/popStateSet and push/PopModelViewMatrix). I would argue this is the cleaner way in any case, as the act of viewing a scene should not fundamentally change it (unless we're talking about quantum mechanics ;) ).


> 
> 1) to access view width and height in pixels (Viewport in pixels) and pass them to a specific node shader as uniforms,
> 

This part is easy - the CullVisitor has the Camera and the Camera has a Viewport.


> 
> 2) Check some View attributes depending on which I show or hide the child nodes. I set the View attributes when I create the osgViewer::View, for example, there is an attribute determining if the View is Primary (Main) or Secondary (Zoom).
> 

As far as I remember, the osgViewer::View isn't directly exposed from the CullVisitor or the Camera because the core OSG is not dependent on the osgViewer component. You might be able to use dynamic_cast's to get at the View regardless, but I'd suggest try using masks instead to differentiate views (e.g. the Camera's CullMask). 

Hope this helps,

Cheers,
Jannik

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







More information about the osg-users mailing list