HI Aurelien,

I have just had a look at the osgshadercomposition example and the
ShaderAttribute implementation and have spotted that it already
includes handling of uniforms, while this is still part of the
ShaderComposition framework potentially we can relaxed some of the
functionality so we can apply uniforms from StateAttribute subclasses
such as osg::Material.  The ShaderAttribute::apply() method looks
like:

void ShaderAttribute::apply(State& state) const
{
    OSG_INFO<<"ShaderAttribute::apply(State&) this="<<this<<" type =
"<<getType()<<std::endl;

    for(Uniforms::const_iterator itr = _uniforms.begin();
        itr != _uniforms.end();
        ++itr)
    {
        state.applyShaderCompositionUniform(itr->get());
    }
}

And the code in osg::State header for handling this is (note the
doxygen comment):

        /** Convinience method for StateAttribute:::apply(State&)
methods to pass on their uniforms to osg::State so it can apply them
at the appropriate point.*/
        void applyShaderCompositionUniform(const osg::Uniform*
uniform, StateAttribute::OverrideValue value=StateAttribute::ON)
        {
            StateSet::RefUniformPair& up =
_currentShaderCompositionUniformList[uniform->getName()];
            up.first = const_cast<Uniform*>(uniform);
            up.second = value;
        }


And in the State.cpp code handling the currentShaderCompositionUniformList is:

void State::apply(const StateSet* dstate)
{
...
        if (_shaderCompositionEnabled)
        {
            applyShaderComposition();

            if (dstate->getUniformList().empty())
            {
                if (_currentShaderCompositionUniformList.empty())
applyUniformMap(_uniformMap);
                else applyUniformList(_uniformMap,
_currentShaderCompositionUniformList);
            }
            else
            {
                if (_currentShaderCompositionUniformList.empty())
applyUniformList(_uniformMap, dstate->getUniformList());
                else
                {
                    // need top merge uniforms lists, but cheat for
now by just applying both.

_currentShaderCompositionUniformList.insert(dstate->getUniformList().begin(),
dstate->getUniformList().end());
                    applyUniformList(_uniformMap,
_currentShaderCompositionUniformList);
                }
            }

        }
        else
        {
            applyUniformList(_uniformMap,dstate->getUniformList());
        }
..
}


The key part being the applyUniformList(_uniformMap,
_currentShaderCompositionUniformList), now potentially we could change
the code so that it's something like:

       if (_shaderCompositionEnabled)
       {
            applyShaderComposition();
       }

       if (dstate->getUniformList().empty())
       {
             if (_currentShaderCompositionUniformList.empty())
applyUniformMap(_uniformMap);
             else applyUniformList(_uniformMap,
_currentShaderCompositionUniformList);
       }
       else
       {
            if (_currentShaderCompositionUniformList.empty())
applyUniformList(_uniformMap, dstate->getUniformList());
            else
            {
                // need top merge uniforms lists, but cheat for now by
just applying both.

_currentShaderCompositionUniformList.insert(dstate->getUniformList().begin(),
dstate->getUniformList().end());
                applyUniformList(_uniformMap,
_currentShaderCompositionUniformList);
            }
        }

Potentially we could split out another osg::State bool along the lines
of _shaderCompositionEnabled, such as
_shaderCompositionUniformsEnabled, or.. come up with a more
appropriate name for the later.

The key motivation here is to enable apply uniforms from the
osg::StateAttribute::apply() methods.

I think this topic probably deserves moving on to osg-users rather
than osg-submissions.

Right now I'm going to concentrate on trying to clear more of the
submissions backlog so I'll keep my head down.

Robert.
_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org

Reply via email to