Added support for set/getUniform and set/getProgram into osg::StateSet.

This commit is contained in:
Robert Osfield
2005-03-11 20:29:21 +00:00
parent 3005f34cc4
commit a2e8bc6267
13 changed files with 1635 additions and 248 deletions

View File

@@ -1912,7 +1912,7 @@ Program::Program()
Program::Program(const Program& rhs, const osg::CopyOp& copyop):
osg::StateAttribute(rhs, copyop)
osg::Object(rhs, copyop)
{
osg::notify(osg::FATAL) << "how got here?" << std::endl;
}
@@ -1932,7 +1932,7 @@ Program::~Program()
}
}
int Program::compare(const osg::StateAttribute& sa) const
int Program::compare(const osg::Program& sa) const
{
// check the types are equal and then create the rhs variable
// used by the COMPARE_StateAttribute_Paramter macro's below.

View File

@@ -55,8 +55,8 @@ Shader::Shader(Type type, const char* sourceText) :
setShaderSource( sourceText );
}
Shader::Shader(const Shader& rhs, const osg::CopyOp& /*copyop*/):
Referenced( rhs ),
Shader::Shader(const Shader& rhs, const osg::CopyOp& copyop):
Object( rhs, copyop ),
_type(rhs._type)
{
/*TODO*/

View File

@@ -281,6 +281,37 @@ int StateSet::compare(const StateSet& rhs,bool compareAttributeContents) const
}
else if (rhs_mode_itr == rhs._modeList.end()) return 1;
// check uniforms.
UniformList::const_iterator lhs_uniform_itr = _uniformList.begin();
UniformList::const_iterator rhs_uniform_itr = rhs._uniformList.begin();
while (lhs_uniform_itr!=_uniformList.end() && rhs_uniform_itr!=rhs._uniformList.end())
{
if (lhs_uniform_itr->first<rhs_uniform_itr->first) return -1;
else if (rhs_uniform_itr->first<lhs_uniform_itr->first) return 1;
if (lhs_uniform_itr->second<rhs_uniform_itr->second) return -1;
else if (rhs_uniform_itr->second<lhs_uniform_itr->second) return 1;
++lhs_uniform_itr;
++rhs_uniform_itr;
}
if (lhs_uniform_itr==_uniformList.end())
{
if (rhs_uniform_itr!=rhs._uniformList.end()) return -1;
}
else if (rhs_uniform_itr == rhs._uniformList.end()) return 1;
if (_program.valid())
{
if (rhs._program.valid())
{
int result = _program->compare(*rhs._program);
if (result!=0) return result;
}
else return 1;
}
else if (rhs._program.valid()) return -1;
return 0;
}
@@ -631,6 +662,58 @@ const StateSet::RefAttributePair* StateSet::getAttributePair(StateAttribute::Typ
return getAttributePair(_attributeList,type,member);
}
void StateSet::setUniform(Uniform* uniform, StateAttribute::OverrideValue value)
{
if (uniform)
{
RefUniformPair& up = _uniformList[uniform->getName()];
up.first = uniform;
up.second = value;
}
}
void StateSet::removeUniform(const std::string& name)
{
UniformList::iterator itr = _uniformList.find(name);
if (itr!=_uniformList.end())
{
_uniformList.erase(itr);
}
}
void StateSet::removeUniform(Uniform* uniform)
{
if (!uniform) return;
UniformList::iterator itr = _uniformList.find(uniform->getName());
if (itr!=_uniformList.end())
{
if (itr->second.first != uniform) return;
_uniformList.erase(itr);
}
}
Uniform* StateSet::getUniform(const std::string& name)
{
UniformList::iterator itr = _uniformList.find(name);
if (itr!=_uniformList.end()) return itr->second.first.get();
else return 0;
}
const Uniform* StateSet::getUniform(const std::string& name) const
{
UniformList::const_iterator itr = _uniformList.find(name);
if (itr!=_uniformList.end()) return itr->second.first.get();
else return 0;
}
const StateSet::RefUniformPair* StateSet::getUniformPair(const std::string& name) const
{
UniformList::const_iterator itr = _uniformList.find(name);
if (itr!=_uniformList.end()) return &(itr->second);
else return 0;
}
void StateSet::setTextureMode(unsigned int unit,StateAttribute::GLMode mode, StateAttribute::GLModeValue value)
{
if (s_textureGLModeSet.isTextureMode(mode))

View File

@@ -424,32 +424,12 @@ Uniform::Uniform( const char* name, int i ) :
Uniform::Uniform( const Uniform& gu, const CopyOp& copyop ) :
StateAttribute(gu,copyop),
Object(gu,copyop),
_value( gu._value )
{
}
void Uniform::apply( State& /*state*/ ) const
{
// The definition of apply() for Uniforms is unique among
// osg::StateAttributes...
// If a Program is not active, then cannot apply the uniform value,
// but must wait for a Program to do that itself later when it
// does become active.
// If a Program is active, then the Uniform may be applied
// immediately.
// something like...
//
// Program* program = state->getActiveProgram();
// if( program )
// {
// program->applyUniform( this );
// }
}
bool Uniform::set( float f )
{
if( ! isCompatibleType( Value::FLOAT ) ) return false;