Another idea would be a subclass of Uniform (MultiplexingUniform?) that you
can program per context.

Or, a variation on Aurelien's approach would be to use:

  osg::buffered_object<osg::ref_ptr<Uniform>> multiUniform;

And then index that by the GC ID if it's available through the
cv->getCurrentCamera(). This would be nice in that it doesn't require a
mutex.

Note: I've not tried this nor verified that it's possible :)


Glenn Waldron / @glennwaldron


On Thu, Oct 24, 2013 at 4:26 AM, Aurelien Albert <
[email protected]> wrote:

> Hi,
>
> At cull traversal, I do the following (this is pseudo-code!) :
>
>
> Code:
> cullTraversal(pCullVisitor)
> {
>     // Get per-view-data
>     perViewData = getOrCreatePerViewData(pCullVisitor);
>
>     // Compute "dynamic" uniforms
>     perViewData.pDynamicUniform_1->set(value);
>     perViewData.pDynamicUniform_2->set(value);
>     perViewData.pDynamicUniform_3->set(value);
>
>     // Push per-view data
>     pCullVisitor->pushStateSet(perViewData.pStateSet);
>
>     // Traverse node
>     traverse(....)
>
>     // Pop per-view data
>     pCullVisitor->popStateSet();
> }
>
>
>
> The "getOrCreatePerViewData" method returns a "PerViewData" struct :
>
>
> Code:
>
> struct PerViewData
> {
>     osg::ref_ptr<osg::StateSet> pStateSet;
>     osg::ref_ptr<osg::Uniform> pDynamicUniform_1;
>     osg::ref_ptr<osg::Uniform> pDynamicUniform_2;
>     osg::ref_ptr<osg::Uniform> pDynamicUniform_3;
>
>     PerViewData()
>     {
>         pStateSet = new osg::StateSet();
>
>         pDynamicUniform_1 = osg::Uniform();
>         pDynamicUniform_2 = osg::Uniform();
>         pDynamicUniform_3 = osg::Uniform();
>
>         pStateSet->addUniform(pDynamicUniform_1);
>         pStateSet->addUniform(pDynamicUniform_2);
>         pStateSet->addUniform(pDynamicUniform_3);
>      }
> }
>
> PerViewData getOrCreatePerViewData(pCullVisitor)
> {
>      return m_perViewDataMap[pCullVisitor];
> }
>
>
>
>
> Just be carrefull to :
>
> - remove "PerViewData" instance from the "m_perViewDataMap" when the
> corresponding "pCullVisitor" instance is destroyed. (use an osg::Observer
> here)
> - add any necessary mutex in multithreading mode
>
>
>
> Cheers,
> Aurelien
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=56957#56957
>
>
>
>
>
> _______________________________________________
> 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