Fixed compare(ProgramObject) and added UniformeValue::compare and ShaderObject::compare
to support proper sorting of shaders.
This commit is contained in:
parent
40a1a39bff
commit
3d61e25cce
@ -68,18 +68,7 @@ class OSGGL2_EXPORT ProgramObject : public osg::StateAttribute
|
||||
META_StateAttribute(osgGL2, ProgramObject, PROGRAMOBJECT);
|
||||
|
||||
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
|
||||
virtual int compare(const osg::StateAttribute& sa) const
|
||||
{
|
||||
// check the types are equal and then create the rhs variable
|
||||
// used by the COMPARE_StateAttribute_Paramter macro's below.
|
||||
COMPARE_StateAttribute_Types(ProgramObject,sa)
|
||||
|
||||
// compare each parameter in turn against the rhs.
|
||||
COMPARE_StateAttribute_Parameter(_shaderObjectList);
|
||||
// COMPARE_StateAttribute_Parameter(_pcpoList);
|
||||
|
||||
return 0; // passed all the above comparison macro's, must be equal.
|
||||
}
|
||||
virtual int compare(const osg::StateAttribute& sa) const;
|
||||
|
||||
/** If enabled, install our shader program in the GL pipeline,
|
||||
* performing any shader program rebuild operations that might
|
||||
@ -182,7 +171,9 @@ class OSGGL2_EXPORT ProgramObject : public osg::StateAttribute
|
||||
|
||||
protected: /*data*/
|
||||
bool _enabled;
|
||||
std::vector< ShaderObjectPtr > _shaderObjectList;
|
||||
|
||||
typedef std::vector< ShaderObjectPtr > ShaderObjectList;
|
||||
ShaderObjectList _shaderObjectList;
|
||||
mutable osg::buffered_value< osg::ref_ptr<PerContextProgObj> > _pcpoList;
|
||||
mutable int _frameNumberOfLastPCPOUpdate;
|
||||
mutable UniformValueList _univalList;
|
||||
@ -219,6 +210,8 @@ class OSGGL2_EXPORT ShaderObject : public osg::Object
|
||||
ShaderObject(const ShaderObject& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
META_Object(osgGL2, ShaderObject);
|
||||
|
||||
int compare(const ShaderObject& sa) const;
|
||||
|
||||
// data access methods.
|
||||
|
||||
/** Load the ShaderObject's source code text from a string. */
|
||||
|
@ -48,6 +48,8 @@ class UniformValue : public osg::Referenced
|
||||
public:
|
||||
virtual void apply( Extensions *ext, const GLhandleARB progObj ) const = 0;
|
||||
|
||||
virtual int compare(const UniformValue& uv) const;
|
||||
|
||||
protected:
|
||||
UniformValue( const char* uniformName ) : _name( uniformName ) {};
|
||||
virtual ~UniformValue() {};
|
||||
@ -73,8 +75,27 @@ class UniformValueTemplate: public UniformValue
|
||||
public:
|
||||
UniformValueTemplate( const char* uniformName, T value ) :
|
||||
UniformValue( uniformName ), _value( value ) {}
|
||||
|
||||
virtual void apply( Extensions *ext, const GLhandleARB progObj ) const;
|
||||
|
||||
virtual int compare(const UniformValue& uv) const
|
||||
{
|
||||
if (this==&uv) return 0;
|
||||
const std::type_info* type_lhs = &typeid(*this);
|
||||
const std::type_info* type_rhs = &typeid(uv);
|
||||
if (type_lhs->before(*type_rhs)) return -1;
|
||||
if (*type_lhs != *type_rhs) return 1;
|
||||
const UniformValueTemplate& rhs = static_cast<const UniformValueTemplate&>(uv);
|
||||
|
||||
if (_name<rhs._name) return -1;
|
||||
if (rhs._name<_name) return 1;
|
||||
|
||||
if (_value<rhs._value) return -1;
|
||||
if (rhs._value<_value) return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected:
|
||||
UniformValueTemplate();
|
||||
const T _value;
|
||||
|
@ -171,6 +171,42 @@ ProgramObject::~ProgramObject()
|
||||
}
|
||||
}
|
||||
|
||||
int ProgramObject::compare(const osg::StateAttribute& sa) const
|
||||
{
|
||||
// check the types are equal and then create the rhs variable
|
||||
// used by the COMPARE_StateAttribute_Paramter macro's below.
|
||||
COMPARE_StateAttribute_Types(ProgramObject,sa)
|
||||
|
||||
if (_shaderObjectList.size()<rhs._shaderObjectList.size()) return -1;
|
||||
if (_shaderObjectList.size()>rhs._shaderObjectList.size()) return 1;
|
||||
|
||||
ShaderObjectList::const_iterator litr=_shaderObjectList.begin();
|
||||
ShaderObjectList::const_iterator ritr=rhs._shaderObjectList.begin();
|
||||
for(;
|
||||
litr!=_shaderObjectList.end();
|
||||
++litr,++ritr)
|
||||
{
|
||||
int result = (*litr)->compare(*(*ritr));
|
||||
if (result!=0) return result;
|
||||
}
|
||||
|
||||
|
||||
if (_univalList.size()<rhs._univalList.size()) return -1;
|
||||
if (_univalList.size()>rhs._univalList.size()) return 1;
|
||||
|
||||
UniformValueList::const_iterator luitr=_univalList.begin();
|
||||
UniformValueList::const_iterator ruitr=rhs._univalList.begin();
|
||||
for(;
|
||||
luitr!=_univalList.end();
|
||||
++luitr,++ruitr)
|
||||
{
|
||||
int result = (*luitr)->compare(*(*ruitr));
|
||||
if (result!=0) return result;
|
||||
}
|
||||
|
||||
return 0; // passed all the above comparison macro's, must be equal.
|
||||
}
|
||||
|
||||
|
||||
// mark all PCPOs as needing a relink
|
||||
void ProgramObject::dirtyProgramObject()
|
||||
@ -415,6 +451,13 @@ ShaderObject::~ShaderObject()
|
||||
/*TODO*/
|
||||
}
|
||||
|
||||
int ShaderObject::compare(const ShaderObject& so) const
|
||||
{
|
||||
if (getShaderSource()<so.getShaderSource()) return -1;
|
||||
if (so.getShaderSource()<getShaderSource()) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// mark each PCSO (per-context Shader Object) as needing a recompile
|
||||
void ShaderObject::dirtyShaderObject()
|
||||
{
|
||||
|
@ -25,6 +25,13 @@
|
||||
using namespace osgGL2;
|
||||
using namespace osg;
|
||||
|
||||
int UniformValue::compare(const UniformValue& uv) const
|
||||
{
|
||||
if (_name<uv._name) return -1;
|
||||
if (uv._name<_name) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int UniformValue::getLocation( Extensions *ext, const GLhandleARB progObj ) const
|
||||
{
|
||||
GLint loc = ext->glGetUniformLocation( progObj, _name.c_str() );
|
||||
|
Loading…
Reference in New Issue
Block a user