Added new getMember() method and TypeMemberPair into StateAttribute and
support for the unsigned int member to be paired with types in osg::StateSet so that lights, clipplanes and other attributes that have a type group but then need to differentiate within that group via a member uint.
This commit is contained in:
@@ -41,7 +41,7 @@ class SG_EXPORT ClipPlane : public StateAttribute
|
||||
_clipPlaneNum=cp._clipPlaneNum;
|
||||
}
|
||||
|
||||
META_StateAttribute(osg, ClipPlane, (Type)(CLIPPLANE+_clipPlaneNum));
|
||||
META_StateAttribute(osg, ClipPlane, CLIPPLANE);
|
||||
|
||||
/** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
|
||||
virtual int compare(const StateAttribute& sa) const
|
||||
@@ -60,6 +60,8 @@ class SG_EXPORT ClipPlane : public StateAttribute
|
||||
return 0; // Passed all the above comparison macros, so must be equal.
|
||||
}
|
||||
|
||||
virtual unsigned int getMember() { return _clipPlaneNum; }
|
||||
|
||||
virtual bool getModeUsage(ModeUsage& usage) const
|
||||
{
|
||||
usage.usesMode((GLMode)(GL_CLIP_PLANE0+_clipPlaneNum));
|
||||
|
||||
@@ -42,7 +42,7 @@ class SG_EXPORT Light : public StateAttribute
|
||||
_spot_exponent(light._spot_exponent),
|
||||
_spot_cutoff(light._spot_cutoff) {}
|
||||
|
||||
META_StateAttribute(osg, Light, (Type)(LIGHT_0+_lightnum));
|
||||
META_StateAttribute(osg, Light, LIGHT);
|
||||
|
||||
/** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
|
||||
virtual int compare(const StateAttribute& sa) const
|
||||
@@ -67,11 +67,15 @@ class SG_EXPORT Light : public StateAttribute
|
||||
return 0; // passed all the above comparison macro's, must be equal.
|
||||
}
|
||||
|
||||
virtual unsigned int getMember() { return _lightnum; }
|
||||
|
||||
virtual bool getModeUsage(ModeUsage& usage) const
|
||||
{
|
||||
usage.usesMode(GL_LIGHT0+_lightnum);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Set which OpenGL light to operate on. */
|
||||
void setLightNum(int num) { _lightnum = num; }
|
||||
|
||||
@@ -202,20 +202,20 @@ class SG_EXPORT State : public Referenced
|
||||
|
||||
inline void setGlobalDefaultAttribute(const StateAttribute* attribute)
|
||||
{
|
||||
AttributeStack& as = _attributeMap[attribute->getType()];
|
||||
AttributeStack& as = _attributeMap[attribute->getTypeMemberPair()];
|
||||
as.global_default_attribute = attribute;
|
||||
}
|
||||
|
||||
inline const StateAttribute* getGlobalDefaultAttribute(StateAttribute::Type type)
|
||||
inline const StateAttribute* getGlobalDefaultAttribute(StateAttribute::Type type, unsigned int member=0)
|
||||
{
|
||||
AttributeStack& as = _attributeMap[type];
|
||||
AttributeStack& as = _attributeMap[StateAttribute::TypeMemberPair(type,member)];
|
||||
return as.global_default_attribute.get();
|
||||
}
|
||||
|
||||
/** Apply an attribute if required. */
|
||||
inline bool applyAttribute(const StateAttribute* attribute)
|
||||
{
|
||||
AttributeStack& as = _attributeMap[attribute->getType()];
|
||||
AttributeStack& as = _attributeMap[attribute->getTypeMemberPair()];
|
||||
as.changed = true;
|
||||
return applyAttribute(attribute,as);
|
||||
}
|
||||
@@ -223,14 +223,14 @@ class SG_EXPORT State : public Referenced
|
||||
inline void setGlobalDefaultTextureAttribute(unsigned int unit, const StateAttribute* attribute)
|
||||
{
|
||||
AttributeMap& attributeMap = getOrCreateTextureAttributeMap(unit);
|
||||
AttributeStack& as = attributeMap[attribute->getType()];
|
||||
AttributeStack& as = attributeMap[attribute->getTypeMemberPair()];
|
||||
as.global_default_attribute = attribute;
|
||||
}
|
||||
|
||||
inline const StateAttribute* getGlobalDefaultTextureAttribute(unsigned int unit, StateAttribute::Type type)
|
||||
inline const StateAttribute* getGlobalDefaultTextureAttribute(unsigned int unit, StateAttribute::Type type, unsigned int member = 0)
|
||||
{
|
||||
AttributeMap& attributeMap = getOrCreateTextureAttributeMap(unit);
|
||||
AttributeStack& as = attributeMap[type];
|
||||
AttributeStack& as = attributeMap[StateAttribute::TypeMemberPair(type,member)];
|
||||
return as.global_default_attribute.get();
|
||||
}
|
||||
|
||||
@@ -240,7 +240,7 @@ class SG_EXPORT State : public Referenced
|
||||
if (setActiveTextureUnit(unit))
|
||||
{
|
||||
AttributeMap& attributeMap = getOrCreateTextureAttributeMap(unit);
|
||||
AttributeStack& as = attributeMap[attribute->getType()];
|
||||
AttributeStack& as = attributeMap[attribute->getTypeMemberPair()];
|
||||
as.changed = true;
|
||||
return applyAttribute(attribute,as);
|
||||
}
|
||||
@@ -265,13 +265,13 @@ class SG_EXPORT State : public Referenced
|
||||
* then use the have_applied(attribute) method as this will cause the osg::State to
|
||||
* track the current state more accurately and enable lazy state updating such
|
||||
* that only changed state will be applied.*/
|
||||
void haveAppliedAttribute(StateAttribute::Type type);
|
||||
void haveAppliedAttribute(StateAttribute::Type type, unsigned int member=0);
|
||||
|
||||
/** Get whether the current specified mode is enabled (true) or disabled (false).*/
|
||||
bool getLastAppliedMode(StateAttribute::GLMode mode) const;
|
||||
|
||||
/** Get the current specified attribute, return NULL if one has not yet been applied.*/
|
||||
const StateAttribute* getLastAppliedAttribute(StateAttribute::Type type) const;
|
||||
const StateAttribute* getLastAppliedAttribute(StateAttribute::Type type, unsigned int member=0) const;
|
||||
|
||||
/** texture Mode has been set externally, update state to reflect this setting.*/
|
||||
void haveAppliedTextureMode(unsigned int unit, StateAttribute::GLMode mode,StateAttribute::GLModeValue value);
|
||||
@@ -290,13 +290,13 @@ class SG_EXPORT State : public Referenced
|
||||
* then use the have_applied(attribute) method as this will the osg::State to
|
||||
* track the current state more accurately and enable lazy state updating such
|
||||
* that only changed state will be applied.*/
|
||||
void haveAppliedTextureAttribute(unsigned int unit, StateAttribute::Type type);
|
||||
void haveAppliedTextureAttribute(unsigned int unit, StateAttribute::Type type, unsigned int member=0);
|
||||
|
||||
/** Get whether the current specified texture mode is enabled (true) or disabled (false).*/
|
||||
bool getLastAppliedTextureMode(unsigned int unit, StateAttribute::GLMode mode) const;
|
||||
|
||||
/** Get the current specified texture attribute, return NULL if one has not yet been applied.*/
|
||||
const StateAttribute* getLastAppliedTextureAttribute(unsigned int unit, StateAttribute::Type type) const;
|
||||
const StateAttribute* getLastAppliedTextureAttribute(unsigned int unit, StateAttribute::Type type, unsigned int member=0) const;
|
||||
|
||||
|
||||
/** Dirty the modes previously applied in osg::State.*/
|
||||
@@ -788,22 +788,22 @@ class SG_EXPORT State : public Referenced
|
||||
}
|
||||
|
||||
|
||||
typedef std::map<StateAttribute::GLMode,ModeStack> ModeMap;
|
||||
typedef std::vector<ModeMap> TextureModeMapList;
|
||||
typedef std::map<StateAttribute::GLMode,ModeStack> ModeMap;
|
||||
typedef std::vector<ModeMap> TextureModeMapList;
|
||||
|
||||
typedef std::map<StateAttribute::Type,AttributeStack> AttributeMap;
|
||||
typedef std::vector<AttributeMap> TextureAttributeMapList;
|
||||
typedef std::map<StateAttribute::TypeMemberPair,AttributeStack> AttributeMap;
|
||||
typedef std::vector<AttributeMap> TextureAttributeMapList;
|
||||
|
||||
typedef std::vector<const StateSet*> StateSetStack;
|
||||
typedef std::vector<ref_ptr<const Matrix> > MatrixStack;
|
||||
typedef std::vector<const StateSet*> StateSetStack;
|
||||
typedef std::vector<ref_ptr<const Matrix> > MatrixStack;
|
||||
|
||||
ModeMap _modeMap;
|
||||
AttributeMap _attributeMap;
|
||||
ModeMap _modeMap;
|
||||
AttributeMap _attributeMap;
|
||||
|
||||
TextureModeMapList _textureModeMapList;
|
||||
TextureAttributeMapList _textureAttributeMapList;
|
||||
TextureModeMapList _textureModeMapList;
|
||||
TextureAttributeMapList _textureAttributeMapList;
|
||||
|
||||
StateSetStack _drawStateStack;
|
||||
StateSetStack _drawStateStack;
|
||||
|
||||
struct EnabledArrayPair
|
||||
{
|
||||
@@ -860,9 +860,9 @@ class SG_EXPORT State : public Referenced
|
||||
void haveAppliedMode(ModeMap& modeMap,StateAttribute::GLMode mode,StateAttribute::GLModeValue value);
|
||||
void haveAppliedMode(ModeMap& modeMap,StateAttribute::GLMode mode);
|
||||
void haveAppliedAttribute(AttributeMap& attributeMap,const StateAttribute* attribute);
|
||||
void haveAppliedAttribute(AttributeMap& attributeMap,StateAttribute::Type type);
|
||||
void haveAppliedAttribute(AttributeMap& attributeMap,StateAttribute::Type type, unsigned int member);
|
||||
bool getLastAppliedMode(const ModeMap& modeMap,StateAttribute::GLMode mode) const;
|
||||
const StateAttribute* getLastAppliedAttribute(const AttributeMap& attributeMap,StateAttribute::Type type) const;
|
||||
const StateAttribute* getLastAppliedAttribute(const AttributeMap& attributeMap,StateAttribute::Type type, unsigned int member) const;
|
||||
|
||||
|
||||
mutable bool _isSecondaryColorSupportResolved;
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <osg/GL>
|
||||
|
||||
#include <typeinfo>
|
||||
#include <utility>
|
||||
|
||||
namespace osg {
|
||||
|
||||
@@ -128,14 +129,6 @@ class SG_EXPORT StateAttribute : public Object
|
||||
FRONTFACE,
|
||||
|
||||
LIGHT,
|
||||
LIGHT_0 =LIGHT,
|
||||
LIGHT_1,
|
||||
LIGHT_2,
|
||||
LIGHT_3,
|
||||
LIGHT_4,
|
||||
LIGHT_5,
|
||||
LIGHT_6,
|
||||
LIGHT_7,
|
||||
|
||||
POINT,
|
||||
LINEWIDTH,
|
||||
@@ -156,12 +149,6 @@ class SG_EXPORT StateAttribute : public Object
|
||||
|
||||
|
||||
CLIPPLANE,
|
||||
CLIPPLANE_0 =CLIPPLANE,
|
||||
CLIPPLANE_1,
|
||||
CLIPPLANE_2,
|
||||
CLIPPLANE_3,
|
||||
CLIPPLANE_4,
|
||||
CLIPPLANE_5,
|
||||
|
||||
COLORMATRIX,
|
||||
|
||||
@@ -178,6 +165,26 @@ class SG_EXPORT StateAttribute : public Object
|
||||
VALIDATOR,
|
||||
VIEWMATRIXEXTRACTOR,
|
||||
};
|
||||
|
||||
/** Simple pairing between an attribute type and the member within that attribute type group.*/
|
||||
typedef std::pair<Type,unsigned int> TypeMemberPair;
|
||||
|
||||
/*
|
||||
struct TypeMember
|
||||
{
|
||||
inline TypeMember(Type type, unsigned int member=0):
|
||||
_type(type),
|
||||
_member(member) {}
|
||||
|
||||
inline bool operator < (const TypeMember& tm) const
|
||||
{
|
||||
return (_type<tm._type) ? true : ( (tm._type<_type) ? false : (_member<tm._member) );
|
||||
}
|
||||
|
||||
Type _type;
|
||||
unsigned int _member;
|
||||
};
|
||||
*/
|
||||
|
||||
|
||||
StateAttribute() { setDataVariance(STATIC); }
|
||||
@@ -194,22 +201,28 @@ class SG_EXPORT StateAttribute : public Object
|
||||
Must be defined by derived classes.*/
|
||||
virtual Object* clone(const CopyOp&) const = 0;
|
||||
|
||||
/** return true if this and obj are of the same kind of object.*/
|
||||
/** Return true if this and obj are of the same kind of object.*/
|
||||
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const StateAttribute*>(obj)!=NULL; }
|
||||
|
||||
/** return the name of the attribute's library.*/
|
||||
/** Return the name of the attribute's library.*/
|
||||
virtual const char* libraryName() const { return "osg"; }
|
||||
|
||||
/** return the name of the attribute's class type.*/
|
||||
/** Return the name of the attribute's class type.*/
|
||||
virtual const char* className() const { return "StateAttribute"; }
|
||||
|
||||
/** return the Type identifier of the attribute's class type.*/
|
||||
/** Return the Type identifier of the attribute's class type.*/
|
||||
virtual Type getType() const = 0;
|
||||
|
||||
/** return true if StateAttribute is a type which controls texturing and needs to be issued w.r.t to specific texture unit.*/
|
||||
/** Return the member identifier within the attribute's class type. Used for light number/clip plane number etc.*/
|
||||
virtual unsigned int getMember() const { return 0; }
|
||||
|
||||
/** Return the TypeMemberPair that uniquely identifies this type member.*/
|
||||
inline TypeMemberPair getTypeMemberPair() const { return TypeMemberPair(getType(),getMember()); }
|
||||
|
||||
/** Return true if StateAttribute is a type which controls texturing and needs to be issued w.r.t to specific texture unit.*/
|
||||
virtual bool isTextureAttribute() const { return false; }
|
||||
|
||||
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
|
||||
/** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
|
||||
virtual int compare(const StateAttribute& sa) const = 0;
|
||||
|
||||
bool operator < (const StateAttribute& rhs) const { return compare(rhs)<0; }
|
||||
@@ -223,7 +236,7 @@ class SG_EXPORT StateAttribute : public Object
|
||||
virtual void usesTextureMode(GLMode mode) = 0;
|
||||
};
|
||||
|
||||
/** return the modes associated with this StateAttribute.*/
|
||||
/** Return the modes associated with this StateAttribute.*/
|
||||
virtual bool getModeUsage(ModeUsage&) const
|
||||
{
|
||||
// default to no GLMode's associated with use of the StateAttribute.
|
||||
|
||||
@@ -101,12 +101,14 @@ class SG_EXPORT StateSet : public Object
|
||||
|
||||
|
||||
/** Simple pairing between an attribute and its override flag.*/
|
||||
typedef std::pair<ref_ptr<StateAttribute>,StateAttribute::OverrideValue> RefAttributePair;
|
||||
/** a container to map StateAttribyte::Types to their respective RefAttributePair.*/
|
||||
typedef std::map<StateAttribute::Type,RefAttributePair> AttributeList;
|
||||
typedef std::pair<ref_ptr<StateAttribute>,StateAttribute::OverrideValue> RefAttributePair;
|
||||
|
||||
/** a container to map <StateAttribyte::Types,Member> to their respective RefAttributePair.*/
|
||||
typedef std::map<StateAttribute::TypeMemberPair,RefAttributePair> AttributeList;
|
||||
|
||||
/** Set this StateSet to contain specified attribute and override flag.*/
|
||||
void setAttribute(StateAttribute *attribute, StateAttribute::OverrideValue value=StateAttribute::OFF);
|
||||
|
||||
/** Set this StateSet to contain specified attribute and set the associated GLMode's to specified value.*/
|
||||
void setAttributeAndModes(StateAttribute *attribute, StateAttribute::GLModeValue value=StateAttribute::ON);
|
||||
|
||||
@@ -116,22 +118,22 @@ class SG_EXPORT StateSet : public Object
|
||||
void setAttributeToInherit(StateAttribute::Type type) { removeAttribute(type); }
|
||||
#endif
|
||||
/** remove attribute of specified type from StateSet.*/
|
||||
void removeAttribute(StateAttribute::Type type);
|
||||
void removeAttribute(StateAttribute::Type type, unsigned int member=0);
|
||||
|
||||
/** remove attribute from StateSet.*/
|
||||
void removeAttribute(StateAttribute *attribute);
|
||||
|
||||
/** Get specified StateAttribute for specified type.
|
||||
* Returns NULL if no type is contained within StateSet.*/
|
||||
StateAttribute* getAttribute(StateAttribute::Type type);
|
||||
StateAttribute* getAttribute(StateAttribute::Type type, unsigned int member = 0);
|
||||
|
||||
/** Get specified const StateAttribute for specified type.
|
||||
* Returns NULL if no type is contained within const StateSet.*/
|
||||
const StateAttribute* getAttribute(StateAttribute::Type type) const;
|
||||
const StateAttribute* getAttribute(StateAttribute::Type type, unsigned int member = 0) const;
|
||||
|
||||
/** Get specified RefAttributePair for specified type.
|
||||
* Returns NULL if no type is contained within StateSet.*/
|
||||
const RefAttributePair* getAttributePair(StateAttribute::Type type) const;
|
||||
const RefAttributePair* getAttributePair(StateAttribute::Type type, unsigned int member = 0) const;
|
||||
|
||||
/** return the list of all StateAttributes contained in this StateSet.*/
|
||||
inline AttributeList& getAttributeList() { return _attributeList; }
|
||||
@@ -292,9 +294,9 @@ class SG_EXPORT StateSet : public Object
|
||||
|
||||
void setAttribute(AttributeList& attributeList,StateAttribute *attribute, const StateAttribute::OverrideValue value=StateAttribute::OFF);
|
||||
|
||||
StateAttribute* getAttribute(AttributeList& attributeList,const StateAttribute::Type type);
|
||||
const StateAttribute* getAttribute(const AttributeList& attributeList,const StateAttribute::Type type) const;
|
||||
const RefAttributePair* getAttributePair(const AttributeList& attributeList,const StateAttribute::Type type) const;
|
||||
StateAttribute* getAttribute(AttributeList& attributeList,const StateAttribute::Type type, unsigned int member);
|
||||
const StateAttribute* getAttribute(const AttributeList& attributeList,const StateAttribute::Type type, unsigned int member) const;
|
||||
const RefAttributePair* getAttributePair(const AttributeList& attributeList,const StateAttribute::Type type, unsigned int member) const;
|
||||
|
||||
int _renderingHint;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user