OpenSceneGraph 3.6.5
StateAttribute
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#ifndef OSG_STATEATTRIBUTE
15#define OSG_STATEATTRIBUTE 1
16
17#include <osg/Export>
18#include <osg/Object>
19#include <osg/Callback>
20#include <osg/Shader>
21#include <osg/GL>
22
23#include <typeinfo>
24#include <utility>
25#include <vector>
26
27// define for the GL_EXT_secondary_color extension, GL_COLOR_SUM is OpenGL
28// mode to be used to enable and disable the second color.
29#ifndef GL_COLOR_SUM
30#define GL_COLOR_SUM 0x8458
31#endif
32
33namespace osg {
34
35
36// forward declare NodeVisitor, State & StateSet
37class NodeVisitor;
38class State;
39class ShaderComposer;
40class StateSet;
41class Texture;
42
48#define META_StateAttribute(library,name,type) \
49 virtual osg::Object* cloneType() const { return new name(); } \
50 virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new name (*this,copyop); } \
51 virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const name *>(obj)!=NULL; } \
52 virtual const char* libraryName() const { return #library; } \
53 virtual const char* className() const { return #name; } \
54 virtual Type getType() const { return type; }
55
57#define COMPARE_StateAttribute_Types(TYPE,rhs_attribute) \
58 if (this==&rhs_attribute) return 0;\
59 const std::type_info* type_lhs = &typeid(*this);\
60 const std::type_info* type_rhs = &typeid(rhs_attribute);\
61 if (type_lhs->before(*type_rhs)) return -1;\
62 if (*type_lhs != *type_rhs) return 1;\
63 const TYPE& rhs = static_cast<const TYPE&>(rhs_attribute);
64
65
69#define COMPARE_StateAttribute_Parameter(parameter) \
70 if (parameter<rhs.parameter) return -1; \
71 if (rhs.parameter<parameter) return 1;
72
73
77{
78 public :
79
81 typedef GLenum GLMode;
85 typedef unsigned int GLModeValue;
89 typedef unsigned int OverrideValue;
90
98 enum Values
99 {
101 OFF = 0x0,
103 ON = 0x1,
105 OVERRIDE = 0x2,
110 };
111
113 // typedef unsigned int Type;
114
216
218 typedef std::pair<Type,unsigned int> TypeMemberPair;
219
221
223 Object(sa,copyop),
225 _updateCallback(copyop(sa._updateCallback.get())),
226 _eventCallback(copyop(sa._eventCallback.get()))
227 {}
228
229
232 virtual Object* cloneType() const = 0;
233
236 virtual Object* clone(const CopyOp&) const = 0;
237
239 virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const StateAttribute*>(obj)!=NULL; }
240
242 virtual const char* libraryName() const { return "osg"; }
243
245 virtual const char* className() const { return "StateAttribute"; }
246
247
250 virtual StateAttribute* asStateAttribute() { return this; }
251
254 virtual const StateAttribute* asStateAttribute() const { return this; }
255
257 virtual Texture* asTexture() { return 0; }
258
260 virtual const Texture* asTexture() const { return 0; }
261
262
264 virtual Type getType() const = 0;
265
267 virtual unsigned int getMember() const { return 0; }
268
271
273 virtual bool isTextureAttribute() const { return false; }
274
276 virtual int compare(const StateAttribute& sa) const = 0;
277
278 bool operator < (const StateAttribute& rhs) const { return compare(rhs)<0; }
279 bool operator == (const StateAttribute& rhs) const { return compare(rhs)==0; }
280 bool operator != (const StateAttribute& rhs) const { return compare(rhs)!=0; }
281
282
284 typedef std::vector<StateSet*> ParentList;
285
287 inline const ParentList& getParents() const { return _parents; }
288
289 inline StateSet* getParent(unsigned int i) { return _parents[i]; }
295 inline const StateSet* getParent(unsigned int i) const { return _parents[i]; }
296
301 inline unsigned int getNumParents() const { return static_cast<unsigned int>(_parents.size()); }
302
305 const ShaderComponent* getShaderComponent() const { return _shaderComponent.get(); }
306
308 {
309 virtual ~ModeUsage() {}
310 virtual void usesMode(GLMode mode) = 0;
311 virtual void usesTextureMode(GLMode mode) = 0;
312 };
313
315 virtual bool getModeUsage(ModeUsage&) const
316 {
317 // default to no GLMode's associated with use of the StateAttribute.
318 return false;
319 }
320
325 {
326 // default to no black listed GLMode's associated with use of the StateAttribute.
327 return true;
328 }
329
330 // provide callback for backwards compatibility.
332
335
338
341
342
345
348
351
352
358 virtual void apply(State&) const {}
359
361 virtual void compileGLObjects(State&) const {}
362
364 virtual void resizeGLObjectBuffers(unsigned int /*maxSize*/) {}
365
369 virtual void releaseGLObjects(State* =0) const {}
370
371
372 protected:
373
374 virtual ~StateAttribute() {}
375
378
380 friend class osg::StateSet;
381
394
395
397
400};
401
402
403}
404#endif
The core osg library provides the basic scene graph classes such as Nodes, State and Drawables,...
Definition AlphaFunc:19
T * get(unsigned int contextID)
Definition ContextData:152
Deprecated.
Definition Callback:246
Copy Op(erator) used to control whether shallow or deep copy is used during copy construction and clo...
Definition CopyOp:41
@ SHALLOW_COPY
Definition CopyOp:47
Object()
Construct an object.
Definition Object:69
Smart pointer for handling referenced counted objects.
Definition ref_ptr:32
Definition Shader:318
Encapsulates the current applied OpenGL modes, attributes and vertex arrays settings,...
Definition State:80
Base class for state attributes.
Definition StateAttribute:77
GLenum GLMode
GLMode is the value used in glEnable/glDisable(mode)
Definition StateAttribute:81
Values
list values which can be used to set either GLModeValues or OverrideValues.
Definition StateAttribute:99
@ INHERIT
means that GLMode or StateAttribute should be inherited from above.
Definition StateAttribute:109
@ OVERRIDE
Overriding of GLMode's or StateAttributes is enabled, so that state below it is overridden.
Definition StateAttribute:105
@ OFF
means that associated GLMode and Override is disabled.
Definition StateAttribute:101
@ PROTECTED
Protecting of GLMode's or StateAttributes is enabled, so that state from above cannot override this a...
Definition StateAttribute:107
@ ON
means that associated GLMode is enabled and Override is disabled.
Definition StateAttribute:103
ShaderComponent * getShaderComponent()
Definition StateAttribute:304
virtual int compare(const StateAttribute &sa) const =0
Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.
ref_ptr< StateAttributeCallback > _eventCallback
Definition StateAttribute:399
void removeParent(osg::StateSet *object)
const StateSet * getParent(unsigned int i) const
Get a single const parent of this StateAttribute.
Definition StateAttribute:295
virtual void compileGLObjects(State &) const
Default to nothing to compile - all state is applied immediately.
Definition StateAttribute:361
TypeMemberPair getTypeMemberPair() const
Return the TypeMemberPair that uniquely identifies this type member.
Definition StateAttribute:270
unsigned int GLModeValue
GLModeValue is used to specify whether a mode is enabled (ON) or disabled (OFF).
Definition StateAttribute:85
void setEventCallback(StateAttributeCallback *ec)
Set the EventCallback which allows users to attach customize the updating of an object during the Eve...
virtual Type getType() const =0
Return the Type identifier of the attribute's class type.
StateSet * getParent(unsigned int i)
Definition StateAttribute:289
unsigned int getNumParents() const
Get the number of parents of this StateAttribute.
Definition StateAttribute:301
virtual void resizeGLObjectBuffers(unsigned int)
Resize any per context GLObject buffers to specified size.
Definition StateAttribute:364
virtual bool isTextureAttribute() const
Return true if StateAttribute is a type which controls texturing and needs to be issued w....
Definition StateAttribute:273
const StateAttributeCallback * getUpdateCallback() const
Get the const UpdateCallback.
Definition StateAttribute:340
virtual Object * clone(const CopyOp &) const =0
Clone an attribute, with Object* return type.
virtual void apply(State &) const
apply the OpenGL state attributes.
Definition StateAttribute:358
ref_ptr< ShaderComponent > _shaderComponent
Definition StateAttribute:396
const ShaderComponent * getShaderComponent() const
Definition StateAttribute:305
Type
Type identifier to differentiate between different state types.
Definition StateAttribute:124
@ TEXGEN
Definition StateAttribute:146
@ ATOMICCOUNTERBUFFERBINDING
Definition StateAttribute:195
@ BLENDEQUATION
Definition StateAttribute:150
@ LIGHT
Definition StateAttribute:137
@ FRONTFACE
Definition StateAttribute:135
@ DEPTH
Definition StateAttribute:154
@ MATERIAL
Definition StateAttribute:129
@ FRAGMENTPROGRAM
Definition StateAttribute:162
@ POLYGONMODE
Definition StateAttribute:127
@ SHADERSTORAGEBUFFERBINDING
Definition StateAttribute:203
@ LINEWIDTH
Definition StateAttribute:140
@ VERTEX_ATTRIB_DIVISOR
Definition StateAttribute:201
@ BLENDCOLOR
Definition StateAttribute:157
@ TEXTURE
Definition StateAttribute:125
@ FRAME_BUFFER_OBJECT
Definition StateAttribute:199
@ OSGNV_PARAMETER_BLOCK
osgNV namespace
Definition StateAttribute:176
@ PATCH_PARAMETER
Definition StateAttribute:197
@ POLYGONOFFSET
Definition StateAttribute:128
@ MULTISAMPLE
Definition StateAttribute:158
@ SCISSOR
Definition StateAttribute:156
@ DEPTHRANGEINDEXED
Definition StateAttribute:208
@ ANTIALIAS
Definition StateAttribute:131
@ POLYGONSTIPPLE
Definition StateAttribute:142
@ FOG
Definition StateAttribute:134
@ CULLFACE
Definition StateAttribute:133
@ BLENDFUNC
Definition StateAttribute:149
@ UNIFORMBUFFERBINDING
Definition StateAttribute:192
@ VALIDATOR
osgFX namespace
Definition StateAttribute:172
@ TEXENV
Definition StateAttribute:144
@ VERTEXPROGRAM
Definition StateAttribute:161
@ OSGNVEXT_TEXTURE_SHADER
Definition StateAttribute:179
@ CLIPCONTROL
Definition StateAttribute:169
@ CAPABILITY
Definition StateAttribute:214
@ STENCIL
Definition StateAttribute:152
@ HINT
Definition StateAttribute:166
@ OSGNVCG_PROGRAM
osgNVCg namespace
Definition StateAttribute:184
@ SAMPLEMASKI
Definition StateAttribute:167
@ TRANSFORMFEEDBACKBUFFERBINDING
Definition StateAttribute:193
@ POINT
Definition StateAttribute:139
@ CLAMPCOLOR
Definition StateAttribute:165
@ COLORMATRIX
Definition StateAttribute:160
@ COLORTABLE
Definition StateAttribute:132
@ TEXENVFILTER
Definition StateAttribute:145
@ TEXMAT
Definition StateAttribute:147
@ SCISSORINDEXED
Definition StateAttribute:209
@ OSGNVSLANG_PROGRAM
Definition StateAttribute:187
@ LOGICOP
Definition StateAttribute:151
@ OSGNVEXT_REGISTER_COMBINERS
Definition StateAttribute:181
@ VIEWPORT
Definition StateAttribute:155
@ OSGNVEXT_VERTEX_PROGRAM
Definition StateAttribute:180
@ PRIMITIVERESTARTINDEX
Definition StateAttribute:168
@ CLIPPLANE
Definition StateAttribute:159
@ COLORMASK
Definition StateAttribute:153
@ POINTSPRITE
Definition StateAttribute:163
@ VIEWMATRIXEXTRACTOR
Definition StateAttribute:173
@ LIGHTMODEL
Definition StateAttribute:148
@ VIEWPORTINDEXED
Definition StateAttribute:207
@ INDIRECTDRAWBUFFERBINDING
Definition StateAttribute:205
@ ALPHAFUNC
Definition StateAttribute:130
@ LINESTIPPLE
Definition StateAttribute:141
@ BINDIMAGETEXTURE
Definition StateAttribute:211
@ SAMPLER
Definition StateAttribute:212
@ OSGNVPARSE_PROGRAM_PARSER
Definition StateAttribute:190
@ PROGRAM
Definition StateAttribute:164
@ SHADEMODEL
Definition StateAttribute:143
ParentList _parents
Definition StateAttribute:379
virtual const char * className() const
Return the name of the attribute's class type.
Definition StateAttribute:245
const ParentList & getParents() const
Get the parent list of this StateAttribute.
Definition StateAttribute:287
ref_ptr< StateAttributeCallback > _updateCallback
Definition StateAttribute:398
virtual StateAttribute * asStateAttribute()
Convert 'this' into a StateAttribute pointer if Object is a StateAttribute, otherwise return 0.
Definition StateAttribute:250
virtual const char * libraryName() const
Return the name of the attribute's library.
Definition StateAttribute:242
friend class osg::StateSet
Definition StateAttribute:380
osg::StateAttributeCallback Callback
Definition StateAttribute:331
std::pair< Type, unsigned int > TypeMemberPair
Simple pairing between an attribute type and the member within that attribute type group.
Definition StateAttribute:218
StateAttribute(const StateAttribute &sa, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
Definition StateAttribute:222
StateAttributeCallback * getEventCallback()
Get the non const EventCallback.
Definition StateAttribute:347
const StateAttributeCallback * getEventCallback() const
Get the const EventCallback.
Definition StateAttribute:350
virtual bool checkValidityOfAssociatedModes(osg::State &) const
Check the modes associated with this StateAttribute are supported by current OpenGL drivers,...
Definition StateAttribute:324
virtual bool isSameKindAs(const Object *obj) const
Return true if this and obj are of the same kind of object.
Definition StateAttribute:239
void setShaderComponent(ShaderComponent *sc)
Definition StateAttribute:303
std::vector< StateSet * > ParentList
A vector of osg::StateSet pointers which is used to store the parent(s) of this StateAttribute.
Definition StateAttribute:284
virtual bool getModeUsage(ModeUsage &) const
Return the modes associated with this StateAttribute.
Definition StateAttribute:315
void setUpdateCallback(StateAttributeCallback *uc)
Set the UpdateCallback which allows users to attach customize the updating of an object during the up...
virtual Texture * asTexture()
Fast alternative to dynamic_cast<> for determining if state attribute is a Texture.
Definition StateAttribute:257
virtual Object * cloneType() const =0
Clone the type of an attribute, with Object* return type.
StateAttributeCallback * getUpdateCallback()
Get the non const UpdateCallback.
Definition StateAttribute:337
unsigned int OverrideValue
Override is used to specify the override behavior of StateAttributes from parent to children.
Definition StateAttribute:89
void addParent(osg::StateSet *object)
virtual ~StateAttribute()
Definition StateAttribute:374
virtual void releaseGLObjects(State *=0) const
Release OpenGL objects in specified graphics context if State object is passed, otherwise release Ope...
Definition StateAttribute:369
virtual const StateAttribute * asStateAttribute() const
convert 'const this' into a const StateAttribute pointer if Object is a StateAttribute,...
Definition StateAttribute:254
virtual unsigned int getMember() const
Return the member identifier within the attribute's class type.
Definition StateAttribute:267
virtual const Texture * asTexture() const
Fast alternative to dynamic_cast<> for determining if state attribute is a Texture.
Definition StateAttribute:260
Definition StateAttribute:308
virtual ~ModeUsage()
Definition StateAttribute:309
virtual void usesTextureMode(GLMode mode)=0
virtual void usesMode(GLMode mode)=0
ref_ptr< StateAttribute > attribute
Definition StateAttribute:391
~ReassignToParents()
Destructor then reassigns the attribute to all of the parents.
ParentList parents
Definition StateAttribute:392
ReassignToParents(osg::StateAttribute *att)
Constructor caches and then removes attribute for all of it's parents.
Stores a set of modes and attributes which represent a set of OpenGL state.
Definition StateSet:46
Texture pure virtual base class that encapsulates OpenGL texture functionality common to the various ...
Definition Texture:422
#define NULL
Definition Export:55
#define OSG_EXPORT
Definition Export:39

osg logo
Generated at Sun Jul 20 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.