So you are executing an update callback from a cull callback? Assuming your update callback actually modifies the uniform, this is not thread-safe and will likely crash if there are multiple concurrent cull traversals.

I got around this by keeping a StateSet (and Uniform) per CullVisitor. I used the CullVisitor address to look up the StateSet from a std::map. Then I could safely set the Uniform value.

Paul Martz
Skew Matrix Software LLC
_http://www.skew-matrix.com_ <http://www.skew-matrix.com/>
+1 303 859 9466



Emmanuel Roche wrote:
Hi Paul,

On my side I finally ended with the initial design I had in mind:

I use a specific nodecallback on the node where the stateset containing my uniforms is. This callbacks, used as a CullCallback give me the opportunity to call the uniform update callbacks with a cullvisitor during the cull phase.

It's not the cleanest option (I'd really wish there were cull callbacks for uniforms directly!) but it works very well for me:

void UniformCullCallbackBridge::operator()(osg::Node * node, osg::NodeVisitor * nv) {

  // Bouml preserved body begin 00035E8A
    // retrieve the stateset on the node:
    osg::StateSet* ss = node->getStateSet();
    if(ss) {
        osg::StateSet::UniformList& uniforms = ss->getUniformList();

        for(osg::StateSet::UniformList::iterator uitr = uniforms.begin();
            uitr != uniforms.end();
            ++uitr)
        {
osg::Uniform::Callback* callback = uitr->second.first->getUpdateCallback();
            if (callback) (*callback)(uitr->second.first.get(),nv);
        }
    }

    return traverse(node,nv);
  // Bouml preserved body end 00035E8A
}

Thanks to everyone for your help/explanations on this.

Manu.


2010/1/30 Paul Martz <pma...@skew-matrix.com <mailto:pma...@skew-matrix.com>>

    Emmanuel Roche wrote:

        Those questions were indeed closely related. Yet since I'm not
        planing to use slave cameras for the moment I guess I'm better
        of with my "node cullcallback to update uniforms", at least I
        will try that.


    The subject was poorly chosen. The thread was more related to how to
    set a different uniform per cull/draw pair - per display or per
    window. Setting the uniforms in the slave camera StateSet is one
    solution, and Robert's recent code change is designed to support
    that usage.

    I wanted my solution to work whether the application used slave
    cameras or not, so, like you, I needed this to work without slave
    cameras. The solution I choose was to push a StateSet containing a
    uniform onto the CullVisitor's state stack.

    Hope that helps.
      -Paul


    _______________________________________________
    osg-users mailing list
    osg-users@lists.openscenegraph.org
    <mailto:osg-users@lists.openscenegraph.org>
    http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org



------------------------------------------------------------------------

_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to