2008-06-19 19:09:20 +08:00
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield
2003-01-22 00:45:36 +08:00
*
2005-02-02 23:08:55 +08:00
* 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
2003-01-22 00:45:36 +08:00
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
2005-02-02 23:08:55 +08:00
*
2003-01-22 00:45:36 +08:00
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
2005-02-02 23:08:55 +08:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2003-01-22 00:45:36 +08:00
* 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>
2005-03-12 04:29:21 +08:00
#include <osg/Uniform>
2001-09-20 05:19:47 +08:00
#include <map>
#include <vector>
#include <string>
2004-05-19 17:17:36 +08:00
#ifndef GL_RESCALE_NORMAL
// allow compilation against GL1.1 headers.
#define GL_RESCALE_NORMAL 0x803A
#endif
2001-09-20 05:19:47 +08:00
namespace osg {
2005-04-23 06:45:39 +08:00
// forward declare for the purposes of the UpdateCallback.
class NodeVisitor;
2007-12-11 01:30:18 +08:00
/** Stores a set of modes and attributes which represent a set of OpenGL state.
2005-02-02 23:08:55 +08:00
* Notice that a \c StateSet contains just a subset of the whole OpenGL state.
* <p>In OSG, each \c Drawable and each \c Node has a reference to a
* \c StateSet. These <tt>StateSet</tt>s can be shared between
* different <tt>Drawable</tt>s and <tt>Node</tt>s (that is, several
* <tt>Drawable</tt>s and <tt>Node</tt>s can reference the same \c StateSet).
* Indeed, this practice is recommended whenever possible,
* as this minimizes expensive state changes in the graphics pipeline.
2001-09-20 05:19:47 +08:00
*/
2005-04-12 01:14:17 +08:00
class OSG_EXPORT StateSet : public Object
2001-09-20 05:19:47 +08:00
{
public :
2005-02-02 23:08:55 +08:00
2001-09-20 05:19:47 +08:00
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;
2005-02-02 23:08:55 +08:00
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; }
2016-01-19 04:05:20 +08:00
/** Convert 'this' into a StateSet pointer if Object is a StateSet, otherwise return 0.
* Equivalent to dynamic_cast<StateSet*>(this).*/
virtual StateSet* asStateSet() { return this; }
/** convert 'const this' into a const StateSet pointer if Object is a StateSet, otherwise return 0.
* Equivalent to dynamic_cast<const StateSet*>(this).*/
virtual const StateSet* asStateSet() const { return this; }
2005-04-25 05:04:54 +08:00
/** A vector of osg::Object pointers which is used to store the parent(s) of this Stateset, the parents could be osg::Node or osg::Drawable.*/
2014-08-25 21:43:11 +08:00
typedef std::vector<Node*> ParentList;
2005-04-25 05:04:54 +08:00
/** Get the parent list of this StateSet. */
inline const ParentList& getParents() const { return _parents; }
2012-03-22 01:36:20 +08:00
/** Get the a copy of parent list of node. A copy is returned to
2005-04-25 05:04:54 +08:00
* prevent modification of the parent list.*/
inline ParentList getParents() { return _parents; }
2014-08-25 21:43:11 +08:00
inline Node* getParent(unsigned int i) { return _parents[i]; }
2005-04-25 05:04:54 +08:00
/**
* Get a single const parent of this StateSet.
* @param i index of the parent to get.
* @return the parent i.
*/
2014-08-25 21:43:11 +08:00
inline const Node* getParent(unsigned int i) const { return _parents[i]; }
2005-04-25 05:04:54 +08:00
/**
* Get the number of parents of this StateSet.
* @return the number of parents of this StateSet.
*/
2009-01-30 18:55:28 +08:00
inline unsigned int getNumParents() const { return static_cast<unsigned int>(_parents.size()); }
2005-04-25 05:04:54 +08:00
2007-12-11 01:30:18 +08:00
/** Compute the DataVariance based on an assessment of callback etc.*/
2007-02-14 19:24:42 +08:00
virtual void computeDataVariance();
2005-02-02 23:08:55 +08:00
/** Set all the modes to on or off so that it defines a
2001-09-20 05:19:47 +08:00
complete state, typically used for a default global state.*/
void setGlobalDefaults();
2004-10-07 17:40:03 +08:00
/** Clear the StateSet of all modes and attributes.*/
void clear();
2005-02-02 23:08:55 +08:00
/** Merge this \c StateSet with the \c StateSet passed as parameter.
* Every mode and attribute in this \c StateSet that is marked with
* \c StateAttribute::OVERRIDE is replaced with the
* equivalent mode or attribute from \c rhs.
*/
2001-10-14 17:58:49 +08:00
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;
2005-02-02 23:08:55 +08:00
/** Set this \c StateSet to contain the specified \c GLMode with a given
* value.
* @note Don't use this method to set modes related to textures. For this
* purpose, use \c setTextureMode(), that accepts an extra parameter
* specifying which texture unit shall be affected by the call.
*/
2002-09-02 20:31:35 +08:00
void setMode(StateAttribute::GLMode mode, StateAttribute::GLModeValue value);
2005-02-02 23:08:55 +08:00
/** Remove \c mode from this \c StateSet.
* @note Don't use this method to remove modes related to textures. For
* this purpose, use \c removeTextureMode(), that accepts an extra
* parameter specifying which texture unit shall be affected by
* the call.
*/
2004-10-07 17:40:03 +08:00
void removeMode(StateAttribute::GLMode mode);
2001-09-20 05:19:47 +08:00
2005-02-02 23:08:55 +08:00
/** Get the value for a given \c GLMode.
* @param mode The \c GLMode whose value is desired.
* @return If \c mode is contained within this \c StateSet, returns the
* value associated with it. Otherwise, returns
* \c StateAttribute::INHERIT.
* @note Don't use this method to get the value of modes related to
* textures. For this purpose, use \c removeTextureMode(), that
* accepts an extra parameter specifying which texture unit shall
* be affected by the call.
*/
2002-09-02 20:31:35 +08:00
StateAttribute::GLModeValue getMode(StateAttribute::GLMode mode) const;
2001-09-20 05:19:47 +08:00
2005-02-02 23:08:55 +08:00
/** Set the list of all <tt>GLMode</tt>s contained in this \c StateSet.*/
2004-12-17 09:06:33 +08:00
inline void setModeList(ModeList& ml) { _modeList=ml; }
2005-02-02 23:08:55 +08:00
/** Return the list of all <tt>GLMode</tt>s contained in this \c StateSet.*/
2001-09-20 05:19:47 +08:00
inline ModeList& getModeList() { return _modeList; }
2005-02-02 23:08:55 +08:00
/** Return the \c const list of all <tt>GLMode</tt>s contained in this
* <tt>const StateSet</tt>.
*/
2001-09-20 05:19:47 +08:00
inline const ModeList& getModeList() const { return _modeList; }
2002-07-07 22:40:41 +08:00
2004-10-07 17:40:03 +08:00
/** Simple pairing between an attribute and its override flag.*/
2004-10-13 19:15:50 +08:00
typedef std::pair<ref_ptr<StateAttribute>,StateAttribute::OverrideValue> RefAttributePair;
2005-02-02 23:08:55 +08:00
2004-10-13 19:15:50 +08:00
/** a container to map <StateAttribyte::Types,Member> to their respective RefAttributePair.*/
typedef std::map<StateAttribute::TypeMemberPair,RefAttributePair> AttributeList;
2001-09-20 05:19:47 +08:00
2004-10-07 17:40:03 +08:00
/** 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);
2004-10-13 19:15:50 +08:00
2015-10-22 21:42:19 +08:00
template<class T> void setAttribute(const ref_ptr<T>& attribute, StateAttribute::OverrideValue value=StateAttribute::OFF) { setAttribute(attribute.get(), value); }
2004-10-07 17:40:03 +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);
2004-10-07 17:40:03 +08:00
2016-01-18 21:10:14 +08:00
template<class T> void setAttributeAndModes(const ref_ptr<T>& attribute, StateAttribute::GLModeValue value=StateAttribute::ON) { setAttributeAndModes(attribute.get(), value); }
2015-10-22 21:42:19 +08:00
2004-10-07 17:40:03 +08:00
/** remove attribute of specified type from StateSet.*/
2004-10-13 19:15:50 +08:00
void removeAttribute(StateAttribute::Type type, unsigned int member=0);
2001-09-20 05:19:47 +08:00
2004-10-07 17:40:03 +08:00
/** remove attribute from StateSet.*/
void removeAttribute(StateAttribute *attribute);
2015-10-22 21:42:19 +08:00
template<class T> void removeAttribute(const ref_ptr<T>& attribute) { removeAttribute(attribute.get()); }
2004-10-07 17:40:03 +08:00
/** Get specified StateAttribute for specified type.
2004-09-14 01:19:05 +08:00
* Returns NULL if no type is contained within StateSet.*/
2004-10-13 19:15:50 +08:00
StateAttribute* getAttribute(StateAttribute::Type type, unsigned int member = 0);
2001-09-29 00:56:19 +08:00
2004-10-07 17:40:03 +08:00
/** Get specified const StateAttribute for specified type.
2004-09-14 01:19:05 +08:00
* Returns NULL if no type is contained within const StateSet.*/
2004-10-13 19:15:50 +08:00
const StateAttribute* getAttribute(StateAttribute::Type type, unsigned int member = 0) const;
2001-09-20 05:19:47 +08:00
2004-10-07 17:40:03 +08:00
/** Get specified RefAttributePair for specified type.
2004-09-14 01:19:05 +08:00
* Returns NULL if no type is contained within StateSet.*/
2004-10-13 19:15:50 +08:00
const RefAttributePair* getAttributePair(StateAttribute::Type type, unsigned int member = 0) const;
2005-02-02 23:08:55 +08:00
2004-12-17 09:06:33 +08:00
/** set the list of all StateAttributes contained in this StateSet.*/
inline void setAttributeList(AttributeList& al) { _attributeList=al; }
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;
2005-02-02 23:08:55 +08:00
/** Set this \c StateSet to contain specified \c GLMode with a given
* value.
* @param unit The texture unit to be affected (used with
* multi-texturing).
* @param mode The OpenGL mode to be added to the \c StateSet.
* @param value The value to be assigned to \c mode.
*/
2002-09-02 20:31:35 +08:00
void setTextureMode(unsigned int unit,StateAttribute::GLMode mode, StateAttribute::GLModeValue value);
2004-10-07 17:40:03 +08:00
/** Remove texture mode from StateSet.*/
void removeTextureMode(unsigned int unit,StateAttribute::GLMode mode);
2002-07-07 22:40:41 +08:00
2004-10-07 17:40:03 +08:00
/** Get specified GLModeValue for specified GLMode.
2002-07-07 22:40:41 +08:00
* 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
2004-12-17 09:06:33 +08:00
/** set the list of all Texture related GLModes contained in this StateSet.*/
inline void setTextureModeList(TextureModeList& tml) { _textureModeList=tml; }
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; }
2011-01-17 17:10:14 +08:00
/** Return the number texture units active in the TextureModeList.*/
2013-05-15 00:12:21 +08:00
inline unsigned int getNumTextureModeLists() const { return static_cast<unsigned int>(_textureModeList.size()); }
2002-07-07 22:40:41 +08:00
typedef std::vector<AttributeList> TextureAttributeList;
2004-10-07 17:40:03 +08:00
/** 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);
2015-10-22 21:42:19 +08:00
template<class T> void setTextureAttribute(unsigned int unit, const ref_ptr<T>& attribute, StateAttribute::OverrideValue value=StateAttribute::OFF) { setTextureAttribute( unit, attribute.get(), value); }
2004-10-07 17:40:03 +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);
2004-10-07 17:40:03 +08:00
2016-03-30 03:24:05 +08:00
template<class T> void setTextureAttributeAndModes(unsigned int unit, const ref_ptr<T>& attribute, StateAttribute::OverrideValue value=StateAttribute::ON) { setTextureAttributeAndModes( unit, attribute.get(), value); }
2015-10-22 21:42:19 +08:00
2004-10-07 17:40:03 +08:00
/** remove texture attribute of specified type from StateSet.*/
void removeTextureAttribute(unsigned int unit, StateAttribute::Type type);
/** remove texture attribute from StateSet.*/
void removeTextureAttribute(unsigned int unit, StateAttribute *attribute);
2002-07-07 22:40:41 +08:00
2015-10-22 21:42:19 +08:00
template<class T> void removeTextureAttribute(unsigned int unit, const ref_ptr<T>& attribute) { removeTextureAttribute(unit, attribute.get()); }
2004-10-07 17:40:03 +08:00
/** Get specified Texture related StateAttribute for specified type.
2004-09-03 03:10:33 +08:00
* 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
2004-10-07 17:40:03 +08:00
/** Get specified Texture related const StateAttribute for specified type.
2004-09-03 03:10:33 +08:00
* 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
2004-10-07 17:40:03 +08:00
/** Get specified Texture related RefAttributePair for specified type.
2004-09-14 01:19:05 +08:00
* 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;
2005-02-02 23:08:55 +08:00
2004-12-17 09:06:33 +08:00
/** Set the list of all Texture related StateAttributes contained in this StateSet.*/
inline void setTextureAttributeList(TextureAttributeList& tal) { _textureAttributeList=tal; }
2004-09-14 01:19:05 +08:00
/** Return the list of all Texture related StateAttributes contained in this StateSet.*/
2002-07-07 22:40:41 +08:00
inline TextureAttributeList& getTextureAttributeList() { return _textureAttributeList; }
2004-09-14 01:19:05 +08:00
/** Return the const list of all Texture related StateAttributes contained in this const StateSet.*/
2002-07-07 22:40:41 +08:00
inline const TextureAttributeList& getTextureAttributeList() const { return _textureAttributeList; }
2011-01-17 17:10:14 +08:00
/** Return the number of texture units active in the TextureAttributeList.*/
2013-05-15 00:12:21 +08:00
inline unsigned int getNumTextureAttributeLists() const { return static_cast<unsigned int>(_textureAttributeList.size()); }
2011-01-17 17:10:14 +08:00
2002-07-07 22:40:41 +08:00
2002-09-02 20:31:35 +08:00
void setAssociatedModes(const StateAttribute* attribute, StateAttribute::GLModeValue value);
2007-12-11 19:42:02 +08:00
void removeAssociatedModes(const StateAttribute* attribute);
2005-02-02 23:08:55 +08:00
2002-09-02 20:31:35 +08:00
void setAssociatedTextureModes(unsigned int unit,const StateAttribute* attribute, StateAttribute::GLModeValue value);
2007-12-11 19:42:02 +08:00
void removeAssociatedTextureModes(unsigned int unit,const StateAttribute* attribute);
2002-07-07 22:40:41 +08:00
2005-03-12 04:29:21 +08:00
2005-03-24 17:37:45 +08:00
/** Simple pairing between a Uniform and its override flag.*/
2005-03-12 04:29:21 +08:00
typedef std::pair<ref_ptr<Uniform>,StateAttribute::OverrideValue> RefUniformPair;
2005-03-24 17:37:45 +08:00
/** a container to map Uniform name to its respective RefUniformPair.*/
2005-03-12 04:29:21 +08:00
typedef std::map<std::string,RefUniformPair> UniformList;
/** Set this StateSet to contain specified uniform and override flag.*/
2005-03-24 17:37:45 +08:00
void addUniform(Uniform* uniform, StateAttribute::OverrideValue value=StateAttribute::ON);
2012-03-22 01:36:20 +08:00
2015-10-22 21:42:19 +08:00
template<class T> void addUniform(const ref_ptr<T>& uniform, StateAttribute::OverrideValue value=StateAttribute::ON) { addUniform( uniform.get(), value); }
2005-03-12 04:29:21 +08:00
/** remove uniform of specified name from StateSet.*/
void removeUniform(const std::string& name);
2005-03-24 17:37:45 +08:00
/** remove Uniform from StateSet.*/
void removeUniform(Uniform* uniform);
2005-03-12 04:29:21 +08:00
2015-10-22 21:42:19 +08:00
template<class T> void removeUniform(const ref_ptr<T>& uniform) { removeUniform(uniform.get()); }
2005-03-12 04:29:21 +08:00
/** Get Uniform for specified name.
2005-03-24 17:37:45 +08:00
* Returns NULL if no matching Uniform is contained within StateSet.*/
2005-03-12 04:29:21 +08:00
Uniform* getUniform(const std::string& name);
2005-05-05 20:30:54 +08:00
/** Get Uniform for specified name, if one is not available create it, add it to this StateSet and return a pointer to it.*/
2006-05-17 05:20:36 +08:00
Uniform* getOrCreateUniform(const std::string& name, Uniform::Type type, unsigned int numElements=1);
2005-05-05 20:30:54 +08:00
2005-03-12 04:29:21 +08:00
/** Get const Uniform for specified name.
2005-03-24 17:37:45 +08:00
* Returns NULL if no matching Uniform is contained within StateSet.*/
2005-03-12 04:29:21 +08:00
const Uniform* getUniform(const std::string& name) const;
2005-03-24 17:37:45 +08:00
/** Get specified RefUniformPair for specified Uniform name.
* Returns NULL if no Uniform is contained within StateSet.*/
2005-03-12 04:29:21 +08:00
const RefUniformPair* getUniformPair(const std::string& name) const;
/** set the list of all Uniforms contained in this StateSet.*/
inline void setUniformList(UniformList& al) { _uniformList=al; }
/** return the list of all Uniforms contained in this StateSet.*/
inline UniformList& getUniformList() { return _uniformList; }
/** return the const list of all Uniforms contained in this const StateSet.*/
inline const UniformList& getUniformList() const { return _uniformList; }
2015-02-11 01:04:02 +08:00
typedef std::pair<std::string, StateAttribute::OverrideValue> DefinePair;
typedef std::map<std::string, DefinePair> DefineList;
2016-06-01 21:20:14 +08:00
/** Added define pass on to shaders that use utilize that define, as specified by the GLSL \#pragma import_defines(..) and \#pragma requires(..). */
2015-02-11 01:04:02 +08:00
void setDefine(const std::string& defineName, StateAttribute::OverrideValue value=StateAttribute::ON);
2016-06-01 21:20:14 +08:00
/** Added define with value to pass on to shaders that use utilize that define, as specified by the GLSL \#pragma import_defines(..) and \#pragma requires(..). */
2015-02-11 01:04:02 +08:00
void setDefine(const std::string& defineName, const std::string& defineValue, StateAttribute::OverrideValue value=StateAttribute::ON);
DefinePair* getDefinePair(const std::string& defineName) { DefineList::iterator itr = _defineList.find(defineName); return (itr!=_defineList.end()) ? &(itr->second) : 0; }
const DefinePair* getDefinePair(const std::string& defineName) const { DefineList::const_iterator itr = _defineList.find(defineName); return (itr!=_defineList.end()) ? &(itr->second) : 0; }
/** Remove define*/
void removeDefine(const std::string& defineName);
/** Set the list of defines to pass on to shaders.*/
2015-02-20 23:02:43 +08:00
void setDefineList(const DefineList& dl) { _defineList = dl; }
2015-02-11 01:04:02 +08:00
/** Get the list of defines to pass on to shaders.*/
DefineList& getDefineList() { return _defineList; }
/** Get the const list of defines to pass on to shaders.*/
const DefineList& getDefineList() const { return _defineList; }
2001-09-20 05:19:47 +08:00
enum RenderingHint
{
DEFAULT_BIN = 0,
OPAQUE_BIN = 1,
TRANSPARENT_BIN = 2
};
2005-02-02 23:08:55 +08:00
/** Set the \c RenderingHint of this \c StateSet. \c RenderingHint is
* used by the renderer to determine which draw bin to drop associated
* <tt>osg::Drawable</tt>s in. Typically, users will set this to either
* \c StateSet::OPAQUE_BIN or \c StateSet::TRANSPARENT_BIN.
* <tt>Drawable</tt>s in the opaque bin are sorted by their
* \c StateSet, so that the number of expensive changes in the OpenGL
* state is minimized. <tt>Drawable</tt>s in the transparent bin are
* sorted by depth, so that objects farther from the viewer are
* rendered first (and hence alpha blending works nicely for
* translucent objects).
*/
2002-09-02 20:31:35 +08:00
void setRenderingHint(int hint);
2001-09-20 05:19:47 +08:00
2005-02-02 23:08:55 +08:00
/** Get the \c RenderingHint of this \c 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
{
2014-07-30 20:47:16 +08:00
INHERIT_RENDERBIN_DETAILS =0,
USE_RENDERBIN_DETAILS =1,
OVERRIDE_RENDERBIN_DETAILS =2,
PROTECTED_RENDERBIN_DETAILS =4,
OVERRIDE_PROTECTED_RENDERBIN_DETAILS = OVERRIDE_RENDERBIN_DETAILS|PROTECTED_RENDERBIN_DETAILS
2001-09-20 05:19:47 +08:00
};
2004-10-07 17:40:03 +08:00
/** 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);
2005-02-02 23:08:55 +08:00
2004-10-07 17:40:03 +08:00
/** Set the render bin details to inherit.*/
2002-09-20 22:51:59 +08:00
void setRenderBinToInherit();
2005-02-02 23:08:55 +08:00
2004-12-17 09:06:33 +08:00
/** Get whether the render bin details are set and should be used.*/
inline bool useRenderBinDetails() const { return _binMode!=INHERIT_RENDERBIN_DETAILS; }
/** Set the render bin mode.*/
inline void setRenderBinMode(RenderBinMode mode) { _binMode=mode; }
2004-10-07 17:40:03 +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
2004-12-17 09:06:33 +08:00
/** Set the render bin number.*/
inline void setBinNumber(int num) { _binNum=num; }
2001-09-20 05:19:47 +08:00
2004-10-07 17:40:03 +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
2004-12-17 09:06:33 +08:00
/** Set the render bin name.*/
inline void setBinName(const std::string& name) { _binName=name; }
2004-10-07 17:40:03 +08:00
/** Get the render bin name.*/
2001-09-20 05:19:47 +08:00
inline const std::string& getBinName() const { return _binName; }
2008-06-19 19:09:20 +08:00
/** By default render bins will be nested within each other dependent
* upon where they are set in the scene graph. This can be problematic
* if a transparent render bin is attached to an opaque render bin
* which is attached to another transparent render bin as these render
* bins will be sorted separately, giving the wrong draw ordering for
* back-to-front transparency. Therefore, to prevent render bins being
* nested, call setNestRenderBins(false). */
inline void setNestRenderBins(bool val) { _nestRenderBins = val; }
/** Get whether associated RenderBin should be nested within parents RenderBin.*/
inline bool getNestRenderBins() const { return _nestRenderBins; }
2005-02-02 23:08:55 +08:00
2014-06-06 17:01:25 +08:00
struct OSG_EXPORT Callback : public virtual osg::Callback
2005-04-23 06:45:39 +08:00
{
Callback() {}
2016-08-29 16:41:40 +08:00
Callback(const Callback& org,const CopyOp& copyop):
osg::Object(org, copyop),
osg::Callback(org, copyop) {}
2005-04-23 06:45:39 +08:00
META_Object(osg,Callback);
2014-06-06 00:26:13 +08:00
/** override Callback::run() entry point to adapt to StateAttributeCallback::run(..) method.*/
virtual bool run(osg::Object* object, osg::Object* data);
2005-04-23 06:45:39 +08:00
/** do customized callback code.*/
2005-04-25 19:05:02 +08:00
virtual void operator() (StateSet*, NodeVisitor*) {}
2005-04-23 06:45:39 +08:00
};
/** Set the Update Callback which allows users to attach customize the updating of an object during the update traversal.*/
void setUpdateCallback(Callback* ac);
2015-10-22 21:42:19 +08:00
template<class T> void setUpdateCallback(const ref_ptr<T>& ac) { setUpdateCallback(ac.get()); }
2005-04-23 06:45:39 +08:00
/** Get the non const Update Callback.*/
Callback* getUpdateCallback() { return _updateCallback.get(); }
/** Get the const Update Callback.*/
const Callback* getUpdateCallback() const { return _updateCallback.get(); }
2005-04-25 19:05:02 +08:00
/** Return whether this StateSet has update callbacks associated with it, and therefore must be traversed.*/
bool requiresUpdateTraversal() const { return _updateCallback.valid() || getNumChildrenRequiringUpdateTraversal()!=0; }
2005-04-23 06:45:39 +08:00
/** Get the number of Objects of this StateSet which require Update traversal,
* since they have an Update Callback attached to them or their children.*/
2005-04-25 19:05:02 +08:00
inline unsigned int getNumChildrenRequiringUpdateTraversal() const { return _numChildrenRequiringUpdateTraversal; }
2012-03-22 01:36:20 +08:00
2005-04-25 19:05:02 +08:00
/** Run the update callbacks attached directly to this StateSet or to its children.*/
void runUpdateCallbacks(osg::NodeVisitor* nv);
2005-04-23 06:45:39 +08:00
/** Set the Event Callback which allows users to attach customize the updating of an object during the event traversal.*/
void setEventCallback(Callback* ac);
2015-10-22 21:42:19 +08:00
template<class T> void setEventCallback(const ref_ptr<T>& ec) { setEventCallback(ec.get()); }
2005-04-23 06:45:39 +08:00
/** Get the non const Event Callback.*/
Callback* getEventCallback() { return _eventCallback.get(); }
/** Get the const Event Callback.*/
const Callback* getEventCallback() const { return _eventCallback.get(); }
2005-04-25 19:05:02 +08:00
/** Return whether this StateSet has event callbacks associated with it, and therefore must be traversed.*/
bool requiresEventTraversal() const { return _eventCallback.valid() || getNumChildrenRequiringEventTraversal()!=0; }
2005-04-23 06:45:39 +08:00
/** Get the number of Objects of this StateSet which require Event traversal,
* since they have an Eevnt Callback attached to them or their children.*/
2005-04-25 19:05:02 +08:00
inline unsigned int getNumChildrenRequiringEventTraversal() const { return _numChildrenRequiringEventTraversal; }
2012-03-22 01:36:20 +08:00
2005-04-25 19:05:02 +08:00
/** Run the event callbacks attached directly to this StateSet or to its children.*/
void runEventCallbacks(osg::NodeVisitor* nv);
2005-04-23 06:45:39 +08:00
2006-02-22 22:31:13 +08:00
/** Check the modes associated with this StateSet are supported by current OpenGL drivers,
* and if not set the associated mode in osg::State to be black listed/invalid.
2006-02-22 22:35:06 +08:00
* Return true if all associated modes are valid.*/
2006-02-23 03:14:01 +08:00
bool checkValidityOfAssociatedModes(State& state) const;
2005-04-23 06:45:39 +08:00
2007-01-05 00:49:58 +08:00
/** Set whether to use a mutex to ensure ref() and unref() are thread safe.*/
virtual void setThreadSafeRefUnref(bool threadSafe);
2001-09-20 05:19:47 +08:00
/** call compile on all StateAttributes contained within this StateSet.*/
2004-07-20 13:37:59 +08:00
void compileGLObjects(State& state) const;
2007-01-04 22:11:51 +08:00
/** Resize any per context GLObject buffers to specified size. */
virtual void resizeGLObjectBuffers(unsigned int maxSize);
2004-07-20 13:37:59 +08:00
/** call release on all StateAttributes contained within this StateSet.*/
virtual void releaseGLObjects(State* state=0) const;
2001-09-20 05:19:47 +08:00
protected :
virtual ~StateSet();
StateSet& operator = (const StateSet&) { return *this; }
2005-02-02 23:08:55 +08:00
2014-08-25 21:43:11 +08:00
void addParent(osg::Node* object);
void removeParent(osg::Node* object);
2005-04-25 05:04:54 +08:00
ParentList _parents;
friend class osg::Node;
friend class osg::Drawable;
2005-04-25 21:37:12 +08:00
friend class osg::Uniform;
friend class osg::StateAttribute;
2012-03-22 01:36:20 +08:00
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;
2005-02-02 23:08:55 +08:00
2005-03-12 04:29:21 +08:00
UniformList _uniformList;
2015-02-11 01:04:02 +08:00
DefineList _defineList;
2005-03-12 04:29:21 +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];
}
2005-02-02 23:08:55 +08:00
2002-07-07 22:40:41 +08:00
inline AttributeList& getOrCreateTextureAttributeList(unsigned int unit)
{
if (unit>=_textureAttributeList.size()) _textureAttributeList.resize(unit+1);
return _textureAttributeList[unit];
}
2005-02-02 23:08:55 +08:00
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;
2002-07-09 17:35:42 +08:00
void setAttribute(AttributeList& attributeList,StateAttribute *attribute, const StateAttribute::OverrideValue value=StateAttribute::OFF);
2004-10-13 19:15:50 +08:00
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;
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;
2008-06-19 19:09:20 +08:00
bool _nestRenderBins;
2012-03-22 01:36:20 +08:00
2005-04-25 19:05:02 +08:00
ref_ptr<Callback> _updateCallback;
unsigned int _numChildrenRequiringUpdateTraversal;
void setNumChildrenRequiringUpdateTraversal(unsigned int num);
2005-04-23 06:45:39 +08:00
2005-04-25 19:05:02 +08:00
ref_ptr<Callback> _eventCallback;
unsigned int _numChildrenRequiringEventTraversal;
void setNumChildrenRequiringEventTraversal(unsigned int num);
2001-09-20 05:19:47 +08:00
};
2006-09-21 18:01:27 +08:00
extern OSG_EXPORT bool isTextureMode(StateAttribute::GLMode mode);
2002-02-03 20:33:41 +08:00
}
2001-09-20 05:19:47 +08:00
#endif