2003-01-22 00:45:36 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2001-10-04 23:12:57 +08:00
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
#ifndef OSG_STATESET
|
|
|
|
#define OSG_STATESET 1
|
|
|
|
|
|
|
|
#include <osg/Object>
|
|
|
|
#include <osg/StateAttribute>
|
|
|
|
#include <osg/ref_ptr>
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace osg {
|
|
|
|
|
|
|
|
/**
|
|
|
|
Encapsulates OpenGL state modes and attributes.
|
2001-10-01 19:15:55 +08:00
|
|
|
Used to specific textures etc of osg::Drawable's which hold references
|
2001-09-20 05:19:47 +08:00
|
|
|
to a single osg::StateSet. StateSet can be shared between Drawable's
|
|
|
|
and is recommend if possible as it minimize expensive state changes
|
|
|
|
in the graphics pipeline.
|
|
|
|
*/
|
|
|
|
class SG_EXPORT StateSet : public Object
|
|
|
|
{
|
|
|
|
public :
|
|
|
|
|
|
|
|
|
|
|
|
StateSet();
|
2002-01-29 22:04:06 +08:00
|
|
|
StateSet(const StateSet&,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
2001-10-23 06:02:47 +08:00
|
|
|
|
2002-12-16 21:40:58 +08:00
|
|
|
virtual Object* cloneType() const { return new StateSet(); }
|
|
|
|
virtual Object* clone(const CopyOp& copyop) const { return new StateSet(*this,copyop); }
|
2001-09-20 05:19:47 +08:00
|
|
|
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const StateSet*>(obj)!=NULL; }
|
2002-06-06 21:25:36 +08:00
|
|
|
virtual const char* libraryName() const { return "osg"; }
|
2001-09-20 05:19:47 +08:00
|
|
|
virtual const char* className() const { return "StateSet"; }
|
|
|
|
|
2001-10-02 07:02:14 +08:00
|
|
|
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
|
2001-11-01 04:04:32 +08:00
|
|
|
int compare(const StateSet& rhs,bool compareAttributeContents=false) const;
|
2001-10-02 07:02:14 +08:00
|
|
|
|
|
|
|
bool operator < (const StateSet& rhs) const { return compare(rhs)<0; }
|
|
|
|
bool operator == (const StateSet& rhs) const { return compare(rhs)==0; }
|
|
|
|
bool operator != (const StateSet& rhs) const { return compare(rhs)!=0; }
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
/** set all the modes to on or off so that it defines a
|
|
|
|
complete state, typically used for a default global state.*/
|
|
|
|
void setGlobalDefaults();
|
|
|
|
|
2001-10-01 19:15:55 +08:00
|
|
|
/** set all the modes to inherit, typically used to signify
|
2001-09-20 05:19:47 +08:00
|
|
|
nodes which inherit all of their modes for the global state.*/
|
|
|
|
void setAllToInherit();
|
2001-10-14 17:58:49 +08:00
|
|
|
|
2002-03-15 01:34:08 +08:00
|
|
|
/** merge this stateset with stateset rhs, this overrides
|
2001-10-14 17:58:49 +08:00
|
|
|
* the rhs if OVERRIDE is specified, otherwise rhs takes precedence.*/
|
|
|
|
void merge(const StateSet& rhs);
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
/** a container to map GLModes to their respective GLModeValues.*/
|
|
|
|
typedef std::map<StateAttribute::GLMode,StateAttribute::GLModeValue> ModeList;
|
|
|
|
|
|
|
|
/** set this StateSet to contain specified GLMode and value.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
void setMode(StateAttribute::GLMode mode, StateAttribute::GLModeValue value);
|
2001-09-20 05:19:47 +08:00
|
|
|
/** set this StateSet to inherit specified GLMode type from parents.
|
|
|
|
* has the effect of deleting any GlMode of specified type from StateSet.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
void setModeToInherit(StateAttribute::GLMode mode);
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
/** get specified GLModeValue for specified GLMode.
|
|
|
|
* returns INHERIT if no GLModeValue is contained within StateSet.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
StateAttribute::GLModeValue getMode(StateAttribute::GLMode mode) const;
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
/** return the list of all GLModes contained in this StateSet.*/
|
|
|
|
inline ModeList& getModeList() { return _modeList; }
|
|
|
|
|
|
|
|
/** return the const list of all GLModes contained in this const StateSet.*/
|
|
|
|
inline const ModeList& getModeList() const { return _modeList; }
|
|
|
|
|
|
|
|
|
2002-07-07 22:40:41 +08:00
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
/** 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;
|
|
|
|
|
|
|
|
/** set this StateSet to contain specified attribute and override flag.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
void setAttribute(StateAttribute *attribute, StateAttribute::OverrideValue value=StateAttribute::OFF);
|
2001-10-01 19:15:55 +08:00
|
|
|
/** set this StateSet to contain specified attribute and set the associated GLMode's to specified value.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
void setAttributeAndModes(StateAttribute *attribute, StateAttribute::GLModeValue value=StateAttribute::ON);
|
2001-09-20 05:19:47 +08:00
|
|
|
/** set this StateSet to inherit specified attribute type from parents.
|
|
|
|
* has the effect of deleting any state attributes of specified type from StateSet.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
void setAttributeToInherit(StateAttribute::Type type);
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
/** get specified StateAttribute for specified type.
|
|
|
|
* returns NULL if no type is contained within StateSet.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
StateAttribute* getAttribute(StateAttribute::Type type);
|
2001-09-29 00:56:19 +08:00
|
|
|
|
|
|
|
/** get specified const StateAttribute for specified type.
|
|
|
|
* returns NULL if no type is contained within const StateSet.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
const StateAttribute* getAttribute(StateAttribute::Type type) const;
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
/** get specified RefAttributePair for specified type.
|
|
|
|
* returns NULL if no type is contained within StateSet.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
const RefAttributePair* getAttributePair(StateAttribute::Type type) const;
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
/** return the list of all StateAttributes contained in this StateSet.*/
|
|
|
|
inline AttributeList& getAttributeList() { return _attributeList; }
|
|
|
|
|
|
|
|
/** return the const list of all StateAttributes contained in this const StateSet.*/
|
|
|
|
inline const AttributeList& getAttributeList() const { return _attributeList; }
|
|
|
|
|
2002-07-07 22:40:41 +08:00
|
|
|
|
|
|
|
|
|
|
|
typedef std::vector<ModeList> TextureModeList;
|
|
|
|
|
|
|
|
/** set this StateSet to contain specified GLMode and value.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
void setTextureMode(unsigned int unit,StateAttribute::GLMode mode, StateAttribute::GLModeValue value);
|
2002-07-07 22:40:41 +08:00
|
|
|
/** set this StateSet to inherit specified GLMode type from parents.
|
|
|
|
* has the effect of deleting any GlMode of specified type from StateSet.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
void setTextureModeToInherit(unsigned int unit,StateAttribute::GLMode mode);
|
2002-07-07 22:40:41 +08:00
|
|
|
|
|
|
|
/** get specified GLModeValue for specified GLMode.
|
|
|
|
* returns INHERIT if no GLModeValue is contained within StateSet.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
StateAttribute::GLModeValue getTextureMode(unsigned int unit,StateAttribute::GLMode mode) const;
|
2002-07-07 22:40:41 +08:00
|
|
|
|
|
|
|
/** return the list of all Texture related GLModes contained in this StateSet.*/
|
|
|
|
inline TextureModeList& getTextureModeList() { return _textureModeList; }
|
|
|
|
|
|
|
|
/** return the const list of all Texture related GLModes contained in this const StateSet.*/
|
|
|
|
inline const TextureModeList& getTextureModeList() const { return _textureModeList; }
|
|
|
|
|
|
|
|
|
|
|
|
typedef std::vector<AttributeList> TextureAttributeList;
|
|
|
|
|
|
|
|
/** set this StateSet to contain specified attribute and override flag.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
void setTextureAttribute(unsigned int unit,StateAttribute *attribute, StateAttribute::OverrideValue value=StateAttribute::OFF);
|
2002-07-07 22:40:41 +08:00
|
|
|
/** set this StateSet to contain specified attribute and set the associated GLMode's to specified value.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
void setTextureAttributeAndModes(unsigned int unit,StateAttribute *attribute, StateAttribute::GLModeValue value=StateAttribute::ON);
|
2002-07-07 22:40:41 +08:00
|
|
|
/** set this StateSet to inherit specified attribute type from parents.
|
|
|
|
* has the effect of deleting any state attributes of specified type from StateSet.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
void setTextureAttributeToInherit(unsigned int unit,StateAttribute::Type type);
|
2002-07-07 22:40:41 +08:00
|
|
|
|
|
|
|
/** get specified Texture related StateAttribute for specified type.
|
|
|
|
* returns NULL if no type is contained within StateSet.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
StateAttribute* getTextureAttribute(unsigned int unit,StateAttribute::Type type);
|
2002-07-07 22:40:41 +08:00
|
|
|
|
|
|
|
/** get specified Texture related const StateAttribute for specified type.
|
|
|
|
* returns NULL if no type is contained within const StateSet.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
const StateAttribute* getTextureAttribute(unsigned int unit,StateAttribute::Type type) const;
|
2002-07-07 22:40:41 +08:00
|
|
|
|
|
|
|
/** get specified Texture related RefAttributePair for specified type.
|
|
|
|
* returns NULL if no type is contained within StateSet.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
const RefAttributePair* getTextureAttributePair(unsigned int unit,StateAttribute::Type type) const;
|
2002-07-07 22:40:41 +08:00
|
|
|
|
|
|
|
/** return the list of all Texture related StateAttributes contained in this StateSet.*/
|
|
|
|
inline TextureAttributeList& getTextureAttributeList() { return _textureAttributeList; }
|
|
|
|
|
|
|
|
/** return the const list of all Texture related StateAttributes contained in this const StateSet.*/
|
|
|
|
inline const TextureAttributeList& getTextureAttributeList() const { return _textureAttributeList; }
|
|
|
|
|
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
void setAssociatedModes(const StateAttribute* attribute, StateAttribute::GLModeValue value);
|
2002-07-09 17:35:42 +08:00
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
void setAssociatedTextureModes(unsigned int unit,const StateAttribute* attribute, StateAttribute::GLModeValue value);
|
2002-07-07 22:40:41 +08:00
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
enum RenderingHint
|
|
|
|
{
|
|
|
|
DEFAULT_BIN = 0,
|
|
|
|
OPAQUE_BIN = 1,
|
|
|
|
TRANSPARENT_BIN = 2
|
|
|
|
};
|
|
|
|
|
|
|
|
/** set the RenderingHint of the StateSet.
|
|
|
|
* RenderingHint is used by osgUtil::Renderer to determine which
|
|
|
|
* draw bin to drop associated osg::Drawables in. For opaque
|
|
|
|
* objects OPAQUE_BIN would typical used, which TRANSPARENT_BIN
|
|
|
|
* should be used for objects which need to be depth sorted.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
void setRenderingHint(int hint);
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
/** get the RenderingHint of the StateSet.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
inline int getRenderingHint() const { return _renderingHint; }
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
enum RenderBinMode
|
|
|
|
{
|
|
|
|
INHERIT_RENDERBIN_DETAILS,
|
|
|
|
USE_RENDERBIN_DETAILS,
|
|
|
|
OVERRIDE_RENDERBIN_DETAILS,
|
|
|
|
ENCLOSE_RENDERBIN_DETAILS
|
|
|
|
};
|
|
|
|
|
|
|
|
/** set the render bin details.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
void setRenderBinDetails(int binNum,const std::string& binName,RenderBinMode mode=USE_RENDERBIN_DETAILS);
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
/** set the render bin details to inherit.*/
|
2002-09-20 22:51:59 +08:00
|
|
|
void setRenderBinToInherit();
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
/** get the render bin mode.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
inline RenderBinMode getRenderBinMode() const { return _binMode; }
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
/** get whether the render bin details are set and should be used.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
inline bool useRenderBinDetails() const { return _binMode!=INHERIT_RENDERBIN_DETAILS; }
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
/** get the render bin number.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
inline int getBinNumber() const { return _binNum; }
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
/** get the render bin name.*/
|
|
|
|
inline const std::string& getBinName() const { return _binName; }
|
|
|
|
|
|
|
|
|
|
|
|
/** call compile on all StateAttributes contained within this StateSet.*/
|
|
|
|
void compile(State& state) const;
|
|
|
|
|
|
|
|
protected :
|
|
|
|
|
|
|
|
|
|
|
|
virtual ~StateSet();
|
|
|
|
|
|
|
|
StateSet& operator = (const StateSet&) { return *this; }
|
2002-07-07 22:40:41 +08:00
|
|
|
|
|
|
|
ModeList _modeList;
|
|
|
|
AttributeList _attributeList;
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2002-07-07 22:40:41 +08:00
|
|
|
TextureModeList _textureModeList;
|
|
|
|
TextureAttributeList _textureAttributeList;
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2002-07-07 22:40:41 +08:00
|
|
|
inline ModeList& getOrCreateTextureModeList(unsigned int unit)
|
|
|
|
{
|
|
|
|
if (unit>=_textureModeList.size()) _textureModeList.resize(unit+1);
|
|
|
|
return _textureModeList[unit];
|
|
|
|
}
|
|
|
|
|
|
|
|
inline AttributeList& getOrCreateTextureAttributeList(unsigned int unit)
|
|
|
|
{
|
|
|
|
if (unit>=_textureAttributeList.size()) _textureAttributeList.resize(unit+1);
|
|
|
|
return _textureAttributeList[unit];
|
|
|
|
}
|
2002-07-09 17:35:42 +08:00
|
|
|
|
|
|
|
int compareModes(const ModeList& lhs,const ModeList& rhs);
|
|
|
|
int compareAttributePtrs(const AttributeList& lhs,const AttributeList& rhs);
|
|
|
|
int compareAttributeContents(const AttributeList& lhs,const AttributeList& rhs);
|
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
void setMode(ModeList& modeList,StateAttribute::GLMode mode, StateAttribute::GLModeValue value);
|
|
|
|
void setModeToInherit(ModeList& modeList,StateAttribute::GLMode mode);
|
|
|
|
StateAttribute::GLModeValue getMode(const ModeList& modeList,StateAttribute::GLMode mode) const;
|
|
|
|
void setAssociatedModes(ModeList& modeList,const StateAttribute* attribute, StateAttribute::GLModeValue value);
|
2002-07-09 17:35:42 +08:00
|
|
|
|
|
|
|
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;
|
2002-07-07 22:40:41 +08:00
|
|
|
|
|
|
|
int _renderingHint;
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2002-07-07 22:40:41 +08:00
|
|
|
RenderBinMode _binMode;
|
|
|
|
int _binNum;
|
|
|
|
std::string _binName;
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2002-02-03 20:33:41 +08:00
|
|
|
}
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
#endif
|