StateAttribute
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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.
*/
#ifndef OSG_STATEATTRIBUTE
#define OSG_STATEATTRIBUTE 1
#include <osg/Export>
#include <osg/Object>
#include <osg/Callback>
#include <osg/Shader>
#include <osg/GL>
#include <typeinfo>
#include <utility>
#include <vector>
// define for the GL_EXT_secondary_color extension, GL_COLOR_SUM is OpenGL
// mode to be used to enable and disable the second color.
#ifndef GL_COLOR_SUM
#define GL_COLOR_SUM 0x8458
#endif
namespace osg {
// forward declare NodeVisitor, State & StateSet
class NodeVisitor;
class State;
class ShaderComposer;
class StateSet;
class Texture;
#define META_StateAttribute(library,name,type) \
virtual osg::Object* cloneType() const { return new name(); } \
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new name (*this,copyop); } \
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const name *>(obj)!=NULL; } \
virtual const char* libraryName() const { return #library; } \
virtual const char* className() const { return #name; } \
virtual Type getType() const { return type; }
#define COMPARE_StateAttribute_Types(TYPE,rhs_attribute) \
if (this==&rhs_attribute) return 0;\
const std::type_info* type_lhs = &typeid(*this);\
const std::type_info* type_rhs = &typeid(rhs_attribute);\
if (type_lhs->before(*type_rhs)) return -1;\
if (*type_lhs != *type_rhs) return 1;\
const TYPE& rhs = static_cast<const TYPE&>(rhs_attribute);
#define COMPARE_StateAttribute_Parameter(parameter) \
if (parameter<rhs.parameter) return -1; \
if (rhs.parameter<parameter) return 1;
class OSG_EXPORT StateAttribute : public Object
{
public :
typedef GLenum GLMode;
typedef unsigned int GLModeValue;
typedef unsigned int OverrideValue;
enum Values
{
OFF = 0x0,
ON = 0x1,
OVERRIDE = 0x2,
PROTECTED = 0x4,
INHERIT = 0x8
};
// typedef unsigned int Type;
enum Type
{
TEXTURE,
POLYGONMODE,
POLYGONOFFSET,
MATERIAL,
ALPHAFUNC,
ANTIALIAS,
COLORTABLE,
CULLFACE,
FOG,
FRONTFACE,
LIGHT,
POINT,
LINEWIDTH,
LINESTIPPLE,
POLYGONSTIPPLE,
SHADEMODEL,
TEXENV,
TEXENVFILTER,
TEXGEN,
TEXMAT,
LIGHTMODEL,
BLENDFUNC,
BLENDEQUATION,
LOGICOP,
STENCIL,
COLORMASK,
DEPTH,
VIEWPORT,
SCISSOR,
BLENDCOLOR,
MULTISAMPLE,
CLIPPLANE,
COLORMATRIX,
VERTEXPROGRAM,
FRAGMENTPROGRAM,
POINTSPRITE,
PROGRAM,
CLAMPCOLOR,
HINT,
SAMPLEMASKI,
PRIMITIVERESTARTINDEX,
CLIPCONTROL,
VALIDATOR,
VIEWMATRIXEXTRACTOR,
OSGNV_PARAMETER_BLOCK,
// osgNVExt namespace
OSGNVEXT_TEXTURE_SHADER,
OSGNVEXT_VERTEX_PROGRAM,
OSGNVEXT_REGISTER_COMBINERS,
OSGNVCG_PROGRAM,
// osgNVSlang namespace
OSGNVSLANG_PROGRAM,
// osgNVParse
OSGNVPARSE_PROGRAM_PARSER,
UNIFORMBUFFERBINDING,
TRANSFORMFEEDBACKBUFFERBINDING,
ATOMICCOUNTERBUFFERBINDING,
PATCH_PARAMETER,
FRAME_BUFFER_OBJECT,
VERTEX_ATTRIB_DIVISOR,
SHADERSTORAGEBUFFERBINDING,
INDIRECTDRAWBUFFERBINDING,
VIEWPORTINDEXED,
DEPTHRANGEINDEXED,
SCISSORINDEXED,
BINDIMAGETEXTURE,
SAMPLER,
CAPABILITY = 100
};
typedef std::pair<Type,unsigned int> TypeMemberPair;
StateAttribute();
StateAttribute(const StateAttribute& sa,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
Object(sa,copyop),
_shaderComponent(sa._shaderComponent),
_updateCallback(copyop(sa._updateCallback.get())),
_eventCallback(copyop(sa._eventCallback.get()))
{}
virtual Object* cloneType() const = 0;
virtual Object* clone(const CopyOp&) const = 0;
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const StateAttribute*>(obj)!=NULL; }
virtual const char* libraryName() const { return "osg"; }
virtual const char* className() const { return "StateAttribute"; }
virtual StateAttribute* asStateAttribute() { return this; }
virtual const StateAttribute* asStateAttribute() const { return this; }
virtual Texture* asTexture() { return 0; }
virtual const Texture* asTexture() const { return 0; }
virtual Type getType() const = 0;
virtual unsigned int getMember() const { return 0; }
inline TypeMemberPair getTypeMemberPair() const { return TypeMemberPair(getType(),getMember()); }
virtual bool isTextureAttribute() const { return false; }
virtual int compare(const StateAttribute& sa) const = 0;
bool operator < (const StateAttribute& rhs) const { return compare(rhs)<0; }
bool operator == (const StateAttribute& rhs) const { return compare(rhs)==0; }
bool operator != (const StateAttribute& rhs) const { return compare(rhs)!=0; }
typedef std::vector<StateSet*> ParentList;
inline const ParentList& getParents() const { return _parents; }
inline StateSet* getParent(unsigned int i) { return _parents[i]; }
inline const StateSet* getParent(unsigned int i) const { return _parents[i]; }
inline unsigned int getNumParents() const { return static_cast<unsigned int>(_parents.size()); }
void setShaderComponent(ShaderComponent* sc) { _shaderComponent = sc; }
ShaderComponent* getShaderComponent() { return _shaderComponent.get(); }
const ShaderComponent* getShaderComponent() const { return _shaderComponent.get(); }
struct ModeUsage
{
virtual ~ModeUsage() {}
virtual void usesMode(GLMode mode) = 0;
virtual void usesTextureMode(GLMode mode) = 0;
};
virtual bool getModeUsage(ModeUsage&) const
{
// default to no GLMode's associated with use of the StateAttribute.
return false;
}
virtual bool checkValidityOfAssociatedModes(osg::State&) const
{
// default to no black listed GLMode's associated with use of the StateAttribute.
return true;
}
// provide callback for backwards compatibility.
typedef osg::StateAttributeCallback Callback;
void setUpdateCallback(StateAttributeCallback* uc);
StateAttributeCallback* getUpdateCallback() { return _updateCallback.get(); }
const StateAttributeCallback* getUpdateCallback() const { return _updateCallback.get(); }
void setEventCallback(StateAttributeCallback* ec);
StateAttributeCallback* getEventCallback() { return _eventCallback.get(); }
const StateAttributeCallback* getEventCallback() const { return _eventCallback.get(); }
virtual void apply(State&) const {}
virtual void compileGLObjects(State&) const {}
virtual void resizeGLObjectBuffers(unsigned int /*maxSize*/) {}
virtual void releaseGLObjects(State* =0) const {}
protected:
virtual ~StateAttribute() {}
void addParent(osg::StateSet* object);
void removeParent(osg::StateSet* object);
ParentList _parents;
friend class osg::StateSet;
struct ReassignToParents
{
ReassignToParents(osg::StateAttribute* att);
~ReassignToParents();
ref_ptr<StateAttribute> attribute;
ParentList parents;
};
ref_ptr<ShaderComponent> _shaderComponent;
ref_ptr<StateAttributeCallback> _updateCallback;
ref_ptr<StateAttributeCallback> _eventCallback;
};
}
#endif
Callback
Object
Shader
osg::CopyOp
Definition CopyOp:41
osg::CopyOp::SHALLOW_COPY
@ SHALLOW_COPY
Definition CopyOp:47
osg::Object::Object
Object()
Definition Object:69
osg::ShaderComponent
Definition Shader:318
osg::StateAttributeCallback
Definition Callback:246
osg::StateAttribute
Definition StateAttribute:77
osg::StateAttribute::GLMode
GLenum GLMode
Definition StateAttribute:81
osg::StateAttribute::Values
Values
Definition StateAttribute:99
osg::StateAttribute::INHERIT
@ INHERIT
Definition StateAttribute:109
osg::StateAttribute::OVERRIDE
@ OVERRIDE
Definition StateAttribute:105
osg::StateAttribute::OFF
@ OFF
Definition StateAttribute:101
osg::StateAttribute::PROTECTED
@ PROTECTED
Definition StateAttribute:107
osg::StateAttribute::ON
@ ON
Definition StateAttribute:103
osg::StateAttribute::getShaderComponent
ShaderComponent * getShaderComponent()
Definition StateAttribute:304
osg::StateAttribute::compare
virtual int compare(const StateAttribute &sa) const =0
osg::StateAttribute::_eventCallback
ref_ptr< StateAttributeCallback > _eventCallback
Definition StateAttribute:399
osg::StateAttribute::StateAttribute
StateAttribute()
osg::StateAttribute::removeParent
void removeParent(osg::StateSet *object)
osg::StateAttribute::getParent
const StateSet * getParent(unsigned int i) const
Definition StateAttribute:295
osg::StateAttribute::compileGLObjects
virtual void compileGLObjects(State &) const
Definition StateAttribute:361
osg::StateAttribute::getTypeMemberPair
TypeMemberPair getTypeMemberPair() const
Definition StateAttribute:270
osg::StateAttribute::GLModeValue
unsigned int GLModeValue
Definition StateAttribute:85
osg::StateAttribute::setEventCallback
void setEventCallback(StateAttributeCallback *ec)
osg::StateAttribute::getType
virtual Type getType() const =0
osg::StateAttribute::getParent
StateSet * getParent(unsigned int i)
Definition StateAttribute:289
osg::StateAttribute::getNumParents
unsigned int getNumParents() const
Definition StateAttribute:301
osg::StateAttribute::resizeGLObjectBuffers
virtual void resizeGLObjectBuffers(unsigned int)
Definition StateAttribute:364
osg::StateAttribute::isTextureAttribute
virtual bool isTextureAttribute() const
Definition StateAttribute:273
osg::StateAttribute::getUpdateCallback
const StateAttributeCallback * getUpdateCallback() const
Definition StateAttribute:340
osg::StateAttribute::clone
virtual Object * clone(const CopyOp &) const =0
osg::StateAttribute::apply
virtual void apply(State &) const
Definition StateAttribute:358
osg::StateAttribute::_shaderComponent
ref_ptr< ShaderComponent > _shaderComponent
Definition StateAttribute:396
osg::StateAttribute::getShaderComponent
const ShaderComponent * getShaderComponent() const
Definition StateAttribute:305
osg::StateAttribute::Type
Type
Definition StateAttribute:124
osg::StateAttribute::TEXGEN
@ TEXGEN
Definition StateAttribute:146
osg::StateAttribute::ATOMICCOUNTERBUFFERBINDING
@ ATOMICCOUNTERBUFFERBINDING
Definition StateAttribute:195
osg::StateAttribute::BLENDEQUATION
@ BLENDEQUATION
Definition StateAttribute:150
osg::StateAttribute::LIGHT
@ LIGHT
Definition StateAttribute:137
osg::StateAttribute::FRONTFACE
@ FRONTFACE
Definition StateAttribute:135
osg::StateAttribute::DEPTH
@ DEPTH
Definition StateAttribute:154
osg::StateAttribute::MATERIAL
@ MATERIAL
Definition StateAttribute:129
osg::StateAttribute::FRAGMENTPROGRAM
@ FRAGMENTPROGRAM
Definition StateAttribute:162
osg::StateAttribute::POLYGONMODE
@ POLYGONMODE
Definition StateAttribute:127
osg::StateAttribute::SHADERSTORAGEBUFFERBINDING
@ SHADERSTORAGEBUFFERBINDING
Definition StateAttribute:203
osg::StateAttribute::LINEWIDTH
@ LINEWIDTH
Definition StateAttribute:140
osg::StateAttribute::VERTEX_ATTRIB_DIVISOR
@ VERTEX_ATTRIB_DIVISOR
Definition StateAttribute:201
osg::StateAttribute::BLENDCOLOR
@ BLENDCOLOR
Definition StateAttribute:157
osg::StateAttribute::TEXTURE
@ TEXTURE
Definition StateAttribute:125
osg::StateAttribute::FRAME_BUFFER_OBJECT
@ FRAME_BUFFER_OBJECT
Definition StateAttribute:199
osg::StateAttribute::OSGNV_PARAMETER_BLOCK
@ OSGNV_PARAMETER_BLOCK
osgNV namespace
Definition StateAttribute:176
osg::StateAttribute::PATCH_PARAMETER
@ PATCH_PARAMETER
Definition StateAttribute:197
osg::StateAttribute::POLYGONOFFSET
@ POLYGONOFFSET
Definition StateAttribute:128
osg::StateAttribute::MULTISAMPLE
@ MULTISAMPLE
Definition StateAttribute:158
osg::StateAttribute::SCISSOR
@ SCISSOR
Definition StateAttribute:156
osg::StateAttribute::DEPTHRANGEINDEXED
@ DEPTHRANGEINDEXED
Definition StateAttribute:208
osg::StateAttribute::ANTIALIAS
@ ANTIALIAS
Definition StateAttribute:131
osg::StateAttribute::POLYGONSTIPPLE
@ POLYGONSTIPPLE
Definition StateAttribute:142
osg::StateAttribute::FOG
@ FOG
Definition StateAttribute:134
osg::StateAttribute::CULLFACE
@ CULLFACE
Definition StateAttribute:133
osg::StateAttribute::BLENDFUNC
@ BLENDFUNC
Definition StateAttribute:149
osg::StateAttribute::UNIFORMBUFFERBINDING
@ UNIFORMBUFFERBINDING
Definition StateAttribute:192
osg::StateAttribute::VALIDATOR
@ VALIDATOR
osgFX namespace
Definition StateAttribute:172
osg::StateAttribute::TEXENV
@ TEXENV
Definition StateAttribute:144
osg::StateAttribute::VERTEXPROGRAM
@ VERTEXPROGRAM
Definition StateAttribute:161
osg::StateAttribute::OSGNVEXT_TEXTURE_SHADER
@ OSGNVEXT_TEXTURE_SHADER
Definition StateAttribute:179
osg::StateAttribute::CLIPCONTROL
@ CLIPCONTROL
Definition StateAttribute:169
osg::StateAttribute::CAPABILITY
@ CAPABILITY
Definition StateAttribute:214
osg::StateAttribute::STENCIL
@ STENCIL
Definition StateAttribute:152
osg::StateAttribute::HINT
@ HINT
Definition StateAttribute:166
osg::StateAttribute::OSGNVCG_PROGRAM
@ OSGNVCG_PROGRAM
osgNVCg namespace
Definition StateAttribute:184
osg::StateAttribute::SAMPLEMASKI
@ SAMPLEMASKI
Definition StateAttribute:167
osg::StateAttribute::TRANSFORMFEEDBACKBUFFERBINDING
@ TRANSFORMFEEDBACKBUFFERBINDING
Definition StateAttribute:193
osg::StateAttribute::POINT
@ POINT
Definition StateAttribute:139
osg::StateAttribute::CLAMPCOLOR
@ CLAMPCOLOR
Definition StateAttribute:165
osg::StateAttribute::COLORMATRIX
@ COLORMATRIX
Definition StateAttribute:160
osg::StateAttribute::COLORTABLE
@ COLORTABLE
Definition StateAttribute:132
osg::StateAttribute::TEXENVFILTER
@ TEXENVFILTER
Definition StateAttribute:145
osg::StateAttribute::TEXMAT
@ TEXMAT
Definition StateAttribute:147
osg::StateAttribute::SCISSORINDEXED
@ SCISSORINDEXED
Definition StateAttribute:209
osg::StateAttribute::OSGNVSLANG_PROGRAM
@ OSGNVSLANG_PROGRAM
Definition StateAttribute:187
osg::StateAttribute::LOGICOP
@ LOGICOP
Definition StateAttribute:151
osg::StateAttribute::OSGNVEXT_REGISTER_COMBINERS
@ OSGNVEXT_REGISTER_COMBINERS
Definition StateAttribute:181
osg::StateAttribute::VIEWPORT
@ VIEWPORT
Definition StateAttribute:155
osg::StateAttribute::OSGNVEXT_VERTEX_PROGRAM
@ OSGNVEXT_VERTEX_PROGRAM
Definition StateAttribute:180
osg::StateAttribute::PRIMITIVERESTARTINDEX
@ PRIMITIVERESTARTINDEX
Definition StateAttribute:168
osg::StateAttribute::CLIPPLANE
@ CLIPPLANE
Definition StateAttribute:159
osg::StateAttribute::COLORMASK
@ COLORMASK
Definition StateAttribute:153
osg::StateAttribute::POINTSPRITE
@ POINTSPRITE
Definition StateAttribute:163
osg::StateAttribute::VIEWMATRIXEXTRACTOR
@ VIEWMATRIXEXTRACTOR
Definition StateAttribute:173
osg::StateAttribute::LIGHTMODEL
@ LIGHTMODEL
Definition StateAttribute:148
osg::StateAttribute::VIEWPORTINDEXED
@ VIEWPORTINDEXED
Definition StateAttribute:207
osg::StateAttribute::INDIRECTDRAWBUFFERBINDING
@ INDIRECTDRAWBUFFERBINDING
Definition StateAttribute:205
osg::StateAttribute::ALPHAFUNC
@ ALPHAFUNC
Definition StateAttribute:130
osg::StateAttribute::LINESTIPPLE
@ LINESTIPPLE
Definition StateAttribute:141
osg::StateAttribute::BINDIMAGETEXTURE
@ BINDIMAGETEXTURE
Definition StateAttribute:211
osg::StateAttribute::SAMPLER
@ SAMPLER
Definition StateAttribute:212
osg::StateAttribute::OSGNVPARSE_PROGRAM_PARSER
@ OSGNVPARSE_PROGRAM_PARSER
Definition StateAttribute:190
osg::StateAttribute::PROGRAM
@ PROGRAM
Definition StateAttribute:164
osg::StateAttribute::SHADEMODEL
@ SHADEMODEL
Definition StateAttribute:143
osg::StateAttribute::_parents
ParentList _parents
Definition StateAttribute:379
osg::StateAttribute::className
virtual const char * className() const
Definition StateAttribute:245
osg::StateAttribute::getParents
const ParentList & getParents() const
Definition StateAttribute:287
osg::StateAttribute::_updateCallback
ref_ptr< StateAttributeCallback > _updateCallback
Definition StateAttribute:398
osg::StateAttribute::asStateAttribute
virtual StateAttribute * asStateAttribute()
Definition StateAttribute:250
osg::StateAttribute::libraryName
virtual const char * libraryName() const
Definition StateAttribute:242
osg::StateAttribute::StateSet
friend class osg::StateSet
Definition StateAttribute:380
osg::StateAttribute::Callback
osg::StateAttributeCallback Callback
Definition StateAttribute:331
osg::StateAttribute::TypeMemberPair
std::pair< Type, unsigned int > TypeMemberPair
Definition StateAttribute:218
osg::StateAttribute::StateAttribute
StateAttribute(const StateAttribute &sa, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
Definition StateAttribute:222
osg::StateAttribute::getEventCallback
StateAttributeCallback * getEventCallback()
Definition StateAttribute:347
osg::StateAttribute::getEventCallback
const StateAttributeCallback * getEventCallback() const
Definition StateAttribute:350
osg::StateAttribute::checkValidityOfAssociatedModes
virtual bool checkValidityOfAssociatedModes(osg::State &) const
Definition StateAttribute:324
osg::StateAttribute::isSameKindAs
virtual bool isSameKindAs(const Object *obj) const
Definition StateAttribute:239
osg::StateAttribute::setShaderComponent
void setShaderComponent(ShaderComponent *sc)
Definition StateAttribute:303
osg::StateAttribute::ParentList
std::vector< StateSet * > ParentList
Definition StateAttribute:284
osg::StateAttribute::getModeUsage
virtual bool getModeUsage(ModeUsage &) const
Definition StateAttribute:315
osg::StateAttribute::setUpdateCallback
void setUpdateCallback(StateAttributeCallback *uc)
osg::StateAttribute::asTexture
virtual Texture * asTexture()
Definition StateAttribute:257
osg::StateAttribute::cloneType
virtual Object * cloneType() const =0
osg::StateAttribute::getUpdateCallback
StateAttributeCallback * getUpdateCallback()
Definition StateAttribute:337
osg::StateAttribute::OverrideValue
unsigned int OverrideValue
Definition StateAttribute:89
osg::StateAttribute::addParent
void addParent(osg::StateSet *object)
osg::StateAttribute::~StateAttribute
virtual ~StateAttribute()
Definition StateAttribute:374
osg::StateAttribute::releaseGLObjects
virtual void releaseGLObjects(State *=0) const
Definition StateAttribute:369
osg::StateAttribute::asStateAttribute
virtual const StateAttribute * asStateAttribute() const
Definition StateAttribute:254
osg::StateAttribute::getMember
virtual unsigned int getMember() const
Definition StateAttribute:267
osg::StateAttribute::asTexture
virtual const Texture * asTexture() const
Definition StateAttribute:260
osg::StateSet
Definition StateSet:46
osg::State
Definition State:80
osg::Texture
Definition Texture:422
osg::ref_ptr
Definition ref_ptr:32
osg
Definition AlphaFunc:19
osg::get
T * get(unsigned int contextID)
Definition ContextData:152
Export
NULL
#define NULL
Definition osg/Export:55
OSG_EXPORT
#define OSG_EXPORT
Definition osg/Export:39
osg::StateAttribute::ModeUsage
Definition StateAttribute:308
osg::StateAttribute::ModeUsage::~ModeUsage
virtual ~ModeUsage()
Definition StateAttribute:309
osg::StateAttribute::ModeUsage::usesTextureMode
virtual void usesTextureMode(GLMode mode)=0
osg::StateAttribute::ModeUsage::usesMode
virtual void usesMode(GLMode mode)=0
osg::StateAttribute::ReassignToParents::attribute
ref_ptr< StateAttribute > attribute
Definition StateAttribute:391
osg::StateAttribute::ReassignToParents::~ReassignToParents
~ReassignToParents()
osg::StateAttribute::ReassignToParents::parents
ParentList parents
Definition StateAttribute:392
osg::StateAttribute::ReassignToParents::ReassignToParents
ReassignToParents(osg::StateAttribute *att)