openscenegraph
StateSet
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 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_STATESET
15#define OSG_STATESET 1
16
17#include <osg/Object>
18#include <osg/StateAttribute>
19#include <osg/ref_ptr>
20#include <osg/Uniform>
21
22#include <map>
23#include <vector>
24#include <string>
25
26#ifndef GL_RESCALE_NORMAL
27// allow compilation against GL1.1 headers.
28#define GL_RESCALE_NORMAL 0x803A
29#endif
30
31namespace osg {
32
33// forward declare for the purposes of the UpdateCallback.
34class NodeVisitor;
35
36/** Stores a set of modes and attributes which represent a set of OpenGL state.
37 * Notice that a \c StateSet contains just a subset of the whole OpenGL state.
38 * <p>In OSG, each \c Drawable and each \c Node has a reference to a
39 * \c StateSet. These <tt>StateSet</tt>s can be shared between
40 * different <tt>Drawable</tt>s and <tt>Node</tt>s (that is, several
41 * <tt>Drawable</tt>s and <tt>Node</tt>s can reference the same \c StateSet).
42 * Indeed, this practice is recommended whenever possible,
43 * as this minimizes expensive state changes in the graphics pipeline.
44*/
45class OSG_EXPORT StateSet : public Object
46{
47 public :
48
49
50 StateSet();
51 StateSet(const StateSet&,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
52
53 virtual Object* cloneType() const { return new StateSet(); }
54 virtual Object* clone(const CopyOp& copyop) const { return new StateSet(*this,copyop); }
55 virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const StateSet*>(obj)!=NULL; }
56 virtual const char* libraryName() const { return "osg"; }
57 virtual const char* className() const { return "StateSet"; }
58
59 /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
60 int compare(const StateSet& rhs,bool compareAttributeContents=false) const;
61
62 bool operator < (const StateSet& rhs) const { return compare(rhs)<0; }
63 bool operator == (const StateSet& rhs) const { return compare(rhs)==0; }
64 bool operator != (const StateSet& rhs) const { return compare(rhs)!=0; }
65
66 /** Convert 'this' into a StateSet pointer if Object is a StateSet, otherwise return 0.
67 * Equivalent to dynamic_cast<StateSet*>(this).*/
68 virtual StateSet* asStateSet() { return this; }
69
70 /** convert 'const this' into a const StateSet pointer if Object is a StateSet, otherwise return 0.
71 * Equivalent to dynamic_cast<const StateSet*>(this).*/
72 virtual const StateSet* asStateSet() const { return this; }
73
74
75 /** 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.*/
76 typedef std::vector<Node*> ParentList;
77
78 /** Get the parent list of this StateSet. */
79 inline const ParentList& getParents() const { return _parents; }
80
81 /** Get the a copy of parent list of node. A copy is returned to
82 * prevent modification of the parent list.*/
83 inline ParentList getParents() { return _parents; }
84
85 inline Node* getParent(unsigned int i) { return _parents[i]; }
86 /**
87 * Get a single const parent of this StateSet.
88 * @param i index of the parent to get.
89 * @return the parent i.
90 */
91 inline const Node* getParent(unsigned int i) const { return _parents[i]; }
92
93 /**
94 * Get the number of parents of this StateSet.
95 * @return the number of parents of this StateSet.
96 */
97 inline unsigned int getNumParents() const { return static_cast<unsigned int>(_parents.size()); }
98
99
100 /** Compute the DataVariance based on an assessment of callback etc.*/
101 virtual void computeDataVariance();
102
103
104 /** Set all the modes to on or off so that it defines a
105 complete state, typically used for a default global state.*/
106 void setGlobalDefaults();
107
108 /** Clear the StateSet of all modes and attributes.*/
109 void clear();
110
111 /** Merge this \c StateSet with the \c StateSet passed as parameter.
112 * Every mode and attribute in this \c StateSet that is marked with
113 * \c StateAttribute::OVERRIDE is replaced with the
114 * equivalent mode or attribute from \c rhs.
115 */
116 void merge(const StateSet& rhs);
117
118 /** a container to map GLModes to their respective GLModeValues.*/
119 typedef std::map<StateAttribute::GLMode,StateAttribute::GLModeValue> ModeList;
120
121 /** Set this \c StateSet to contain the specified \c GLMode with a given
122 * value.
123 * @note Don't use this method to set modes related to textures. For this
124 * purpose, use \c setTextureMode(), that accepts an extra parameter
125 * specifying which texture unit shall be affected by the call.
126 */
127 void setMode(StateAttribute::GLMode mode, StateAttribute::GLModeValue value);
128
129 /** Remove \c mode from this \c StateSet.
130 * @note Don't use this method to remove modes related to textures. For
131 * this purpose, use \c removeTextureMode(), that accepts an extra
132 * parameter specifying which texture unit shall be affected by
133 * the call.
134 */
135 void removeMode(StateAttribute::GLMode mode);
136
137 /** Get the value for a given \c GLMode.
138 * @param mode The \c GLMode whose value is desired.
139 * @return If \c mode is contained within this \c StateSet, returns the
140 * value associated with it. Otherwise, returns
141 * \c StateAttribute::INHERIT.
142 * @note Don't use this method to get the value of modes related to
143 * textures. For this purpose, use \c removeTextureMode(), that
144 * accepts an extra parameter specifying which texture unit shall
145 * be affected by the call.
146 */
147 StateAttribute::GLModeValue getMode(StateAttribute::GLMode mode) const;
148
149 /** Set the list of all <tt>GLMode</tt>s contained in this \c StateSet.*/
150 inline void setModeList(ModeList& ml) { _modeList=ml; }
151
152 /** Return the list of all <tt>GLMode</tt>s contained in this \c StateSet.*/
153 inline ModeList& getModeList() { return _modeList; }
154
155 /** Return the \c const list of all <tt>GLMode</tt>s contained in this
156 * <tt>const StateSet</tt>.
157 */
158 inline const ModeList& getModeList() const { return _modeList; }
159
160
161
162 /** Simple pairing between an attribute and its override flag.*/
163 typedef std::pair<ref_ptr<StateAttribute>,StateAttribute::OverrideValue> RefAttributePair;
164
165 /** a container to map <StateAttribyte::Types,Member> to their respective RefAttributePair.*/
166 typedef std::map<StateAttribute::TypeMemberPair,RefAttributePair> AttributeList;
167
168 /** Set this StateSet to contain specified attribute and override flag.*/
169 void setAttribute(StateAttribute *attribute, StateAttribute::OverrideValue value=StateAttribute::OFF);
170
171 template<class T> void setAttribute(const ref_ptr<T>& attribute, StateAttribute::OverrideValue value=StateAttribute::OFF) { setAttribute(attribute.get(), value); }
172
173 /** Set this StateSet to contain specified attribute and set the associated GLMode's to specified value.*/
174 void setAttributeAndModes(StateAttribute *attribute, StateAttribute::GLModeValue value=StateAttribute::ON);
175
176 template<class T> void setAttributeAndModes(const ref_ptr<T>& attribute, StateAttribute::GLModeValue value=StateAttribute::ON) { setAttributeAndModes(attribute.get(), value); }
177
178 /** remove attribute of specified type from StateSet.*/
179 void removeAttribute(StateAttribute::Type type, unsigned int member=0);
180
181 /** remove attribute from StateSet.*/
182 void removeAttribute(StateAttribute *attribute);
183
184 template<class T> void removeAttribute(const ref_ptr<T>& attribute) { removeAttribute(attribute.get()); }
185
186 /** Get specified StateAttribute for specified type.
187 * Returns NULL if no type is contained within StateSet.*/
188 StateAttribute* getAttribute(StateAttribute::Type type, unsigned int member = 0);
189
190 /** Get specified const StateAttribute for specified type.
191 * Returns NULL if no type is contained within const StateSet.*/
192 const StateAttribute* getAttribute(StateAttribute::Type type, unsigned int member = 0) const;
193
194 /** Get specified RefAttributePair for specified type.
195 * Returns NULL if no type is contained within StateSet.*/
196 RefAttributePair* getAttributePair(StateAttribute::Type type, unsigned int member = 0);
197
198 /** Get specified RefAttributePair for specified type.
199 * Returns NULL if no type is contained within StateSet.*/
200 const RefAttributePair* getAttributePair(StateAttribute::Type type, unsigned int member = 0) const;
201
202 /** set the list of all StateAttributes contained in this StateSet.*/
203 inline void setAttributeList(AttributeList& al) { _attributeList=al; }
204
205 /** return the list of all StateAttributes contained in this StateSet.*/
206 inline AttributeList& getAttributeList() { return _attributeList; }
207
208 /** return the const list of all StateAttributes contained in this const StateSet.*/
209 inline const AttributeList& getAttributeList() const { return _attributeList; }
210
211
212
213 typedef std::vector<ModeList> TextureModeList;
214
215 /** Set this \c StateSet to contain specified \c GLMode with a given
216 * value.
217 * @param unit The texture unit to be affected (used with
218 * multi-texturing).
219 * @param mode The OpenGL mode to be added to the \c StateSet.
220 * @param value The value to be assigned to \c mode.
221 */
222 void setTextureMode(unsigned int unit,StateAttribute::GLMode mode, StateAttribute::GLModeValue value);
223
224 /** Remove texture mode from StateSet.*/
225 void removeTextureMode(unsigned int unit,StateAttribute::GLMode mode);
226
227 /** Get specified GLModeValue for specified GLMode.
228 * returns INHERIT if no GLModeValue is contained within StateSet.*/
229 StateAttribute::GLModeValue getTextureMode(unsigned int unit,StateAttribute::GLMode mode) const;
230
231 /** set the list of all Texture related GLModes contained in this StateSet.*/
232 inline void setTextureModeList(TextureModeList& tml) { _textureModeList=tml; }
233
234 /** return the list of all Texture related GLModes contained in this StateSet.*/
235 inline TextureModeList& getTextureModeList() { return _textureModeList; }
236
237 /** return the const list of all Texture related GLModes contained in this const StateSet.*/
238 inline const TextureModeList& getTextureModeList() const { return _textureModeList; }
239
240 /** Return the number texture units active in the TextureModeList.*/
241 inline unsigned int getNumTextureModeLists() const { return static_cast<unsigned int>(_textureModeList.size()); }
242
243 typedef std::vector<AttributeList> TextureAttributeList;
244
245 /** Set this StateSet to contain specified attribute and override flag.*/
246 void setTextureAttribute(unsigned int unit,StateAttribute *attribute, StateAttribute::OverrideValue value=StateAttribute::OFF);
247
248 template<class T> void setTextureAttribute(unsigned int unit, const ref_ptr<T>& attribute, StateAttribute::OverrideValue value=StateAttribute::OFF) { setTextureAttribute( unit, attribute.get(), value); }
249
250 /** Set this StateSet to contain specified attribute and set the associated GLMode's to specified value.*/
251 void setTextureAttributeAndModes(unsigned int unit,StateAttribute *attribute, StateAttribute::GLModeValue value=StateAttribute::ON);
252
253 template<class T> void setTextureAttributeAndModes(unsigned int unit, const ref_ptr<T>& attribute, StateAttribute::OverrideValue value=StateAttribute::ON) { setTextureAttributeAndModes( unit, attribute.get(), value); }
254
255 /** remove texture attribute of specified type from StateSet.*/
256 void removeTextureAttribute(unsigned int unit, StateAttribute::Type type);
257
258 /** remove texture attribute from StateSet.*/
259 void removeTextureAttribute(unsigned int unit, StateAttribute *attribute);
260
261 template<class T> void removeTextureAttribute(unsigned int unit, const ref_ptr<T>& attribute) { removeTextureAttribute(unit, attribute.get()); }
262
263 /** Get specified Texture related StateAttribute for specified type.
264 * Returns NULL if no type is contained within StateSet.*/
265 StateAttribute* getTextureAttribute(unsigned int unit, StateAttribute::Type type);
266
267 /** Get specified Texture related const StateAttribute for specified type.
268 * Returns NULL if no type is contained within const StateSet.*/
269 const StateAttribute* getTextureAttribute(unsigned int unit, StateAttribute::Type type) const;
270
271 /** Get specified Texture related RefAttributePair for specified type.
272 * Returns NULL if no type is contained within StateSet.*/
273 RefAttributePair* getTextureAttributePair(unsigned int unit, StateAttribute::Type type);
274
275 /** Get specified Texture related RefAttributePair for specified type.
276 * Returns NULL if no type is contained within StateSet.*/
277 const RefAttributePair* getTextureAttributePair(unsigned int unit, StateAttribute::Type type) const;
278
279 /** Set the list of all Texture related StateAttributes contained in this StateSet.*/
280 inline void setTextureAttributeList(TextureAttributeList& tal) { _textureAttributeList=tal; }
281
282 /** Return the list of all Texture related StateAttributes contained in this StateSet.*/
283 inline TextureAttributeList& getTextureAttributeList() { return _textureAttributeList; }
284
285 /** Return the const list of all Texture related StateAttributes contained in this const StateSet.*/
286 inline const TextureAttributeList& getTextureAttributeList() const { return _textureAttributeList; }
287
288 /** Return the number of texture units active in the TextureAttributeList.*/
289 inline unsigned int getNumTextureAttributeLists() const { return static_cast<unsigned int>(_textureAttributeList.size()); }
290
291
292 void setAssociatedModes(const StateAttribute* attribute, StateAttribute::GLModeValue value);
293 void removeAssociatedModes(const StateAttribute* attribute);
294
295 void setAssociatedTextureModes(unsigned int unit, const StateAttribute* attribute, StateAttribute::GLModeValue value);
296 void removeAssociatedTextureModes(unsigned int unit, const StateAttribute* attribute);
297
298
299
300
301 /** Simple pairing between a Uniform and its override flag.*/
302 typedef std::pair<ref_ptr<Uniform>,StateAttribute::OverrideValue> RefUniformPair;
303
304 /** a container to map Uniform name to its respective RefUniformPair.*/
305 typedef std::map<std::string,RefUniformPair> UniformList;
306
307 /** Set this StateSet to contain specified uniform and override flag.*/
308 void addUniform(Uniform* uniform, StateAttribute::OverrideValue value=StateAttribute::ON);
309
310 template<class T> void addUniform(const ref_ptr<T>& uniform, StateAttribute::OverrideValue value=StateAttribute::ON) { addUniform( uniform.get(), value); }
311
312 /** remove uniform of specified name from StateSet.*/
313 void removeUniform(const std::string& name);
314
315 /** remove Uniform from StateSet.*/
316 void removeUniform(Uniform* uniform);
317
318 template<class T> void removeUniform(const ref_ptr<T>& uniform) { removeUniform(uniform.get()); }
319
320 /** Get Uniform for specified name.
321 * Returns NULL if no matching Uniform is contained within StateSet.*/
322 Uniform* getUniform(const std::string& name);
323
324 /** Get Uniform for specified name, if one is not available create it, add it to this StateSet and return a pointer to it.*/
325 Uniform* getOrCreateUniform(const std::string& name, Uniform::Type type, unsigned int numElements=1);
326
327 /** Get const Uniform for specified name.
328 * Returns NULL if no matching Uniform is contained within StateSet.*/
329 const Uniform* getUniform(const std::string& name) const;
330
331 /** Get specified RefUniformPair for specified Uniform name.
332 * Returns NULL if no Uniform is contained within StateSet.*/
333 const RefUniformPair* getUniformPair(const std::string& name) const;
334
335 /** set the list of all Uniforms contained in this StateSet.*/
336 inline void setUniformList(UniformList& al) { _uniformList=al; }
337
338 /** return the list of all Uniforms contained in this StateSet.*/
339 inline UniformList& getUniformList() { return _uniformList; }
340
341 /** return the const list of all Uniforms contained in this const StateSet.*/
342 inline const UniformList& getUniformList() const { return _uniformList; }
343
344
345 typedef std::pair<std::string, StateAttribute::OverrideValue> DefinePair;
346 typedef std::map<std::string, DefinePair> DefineList;
347
348 /** Added define pass on to shaders that use utilize that define, as specified by the GLSL \#pragma import_defines(..) and \#pragma requires(..). */
349 void setDefine(const std::string& defineName, StateAttribute::OverrideValue value=StateAttribute::ON);
350
351 /** 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(..). */
352 void setDefine(const std::string& defineName, const std::string& defineValue, StateAttribute::OverrideValue value=StateAttribute::ON);
353
354 DefinePair* getDefinePair(const std::string& defineName) { DefineList::iterator itr = _defineList.find(defineName); return (itr!=_defineList.end()) ? &(itr->second) : 0; }
355 const DefinePair* getDefinePair(const std::string& defineName) const { DefineList::const_iterator itr = _defineList.find(defineName); return (itr!=_defineList.end()) ? &(itr->second) : 0; }
356
357
358 /** Remove define*/
359 void removeDefine(const std::string& defineName);
360
361
362 /** Set the list of defines to pass on to shaders.*/
363 void setDefineList(const DefineList& dl) { _defineList = dl; }
364
365 /** Get the list of defines to pass on to shaders.*/
366 DefineList& getDefineList() { return _defineList; }
367
368 /** Get the const list of defines to pass on to shaders.*/
369 const DefineList& getDefineList() const { return _defineList; }
370
371
372
373 enum RenderingHint
374 {
375 DEFAULT_BIN = 0,
376 OPAQUE_BIN = 1,
377 TRANSPARENT_BIN = 2
378 };
379
380 /** Set the \c RenderingHint of this \c StateSet. \c RenderingHint is
381 * used by the renderer to determine which draw bin to drop associated
382 * <tt>osg::Drawable</tt>s in. Typically, users will set this to either
383 * \c StateSet::OPAQUE_BIN or \c StateSet::TRANSPARENT_BIN.
384 * <tt>Drawable</tt>s in the opaque bin are sorted by their
385 * \c StateSet, so that the number of expensive changes in the OpenGL
386 * state is minimized. <tt>Drawable</tt>s in the transparent bin are
387 * sorted by depth, so that objects farther from the viewer are
388 * rendered first (and hence alpha blending works nicely for
389 * translucent objects).
390 */
391 void setRenderingHint(int hint);
392
393 /** Get the \c RenderingHint of this \c StateSet.*/
394 inline int getRenderingHint() const { return _renderingHint; }
395
396 enum RenderBinMode
397 {
398 INHERIT_RENDERBIN_DETAILS =0,
399 USE_RENDERBIN_DETAILS =1,
400 OVERRIDE_RENDERBIN_DETAILS =2,
401 PROTECTED_RENDERBIN_DETAILS =4,
402 OVERRIDE_PROTECTED_RENDERBIN_DETAILS = OVERRIDE_RENDERBIN_DETAILS|PROTECTED_RENDERBIN_DETAILS
403 };
404
405 /** Set the render bin details.*/
406 void setRenderBinDetails(int binNum,const std::string& binName,RenderBinMode mode=USE_RENDERBIN_DETAILS);
407
408 /** Set the render bin details to inherit.*/
409 void setRenderBinToInherit();
410
411 /** Get whether the render bin details are set and should be used.*/
412 inline bool useRenderBinDetails() const { return _binMode!=INHERIT_RENDERBIN_DETAILS; }
413
414 /** Set the render bin mode.*/
415 inline void setRenderBinMode(RenderBinMode mode) { _binMode=mode; }
416
417 /** Get the render bin mode.*/
418 inline RenderBinMode getRenderBinMode() const { return _binMode; }
419
420 /** Set the render bin number.*/
421 inline void setBinNumber(int num) { _binNum=num; }
422
423 /** Get the render bin number.*/
424 inline int getBinNumber() const { return _binNum; }
425
426 /** Set the render bin name.*/
427 inline void setBinName(const std::string& name) { _binName=name; }
428
429 /** Get the render bin name.*/
430 inline const std::string& getBinName() const { return _binName; }
431
432 /** By default render bins will be nested within each other dependent
433 * upon where they are set in the scene graph. This can be problematic
434 * if a transparent render bin is attached to an opaque render bin
435 * which is attached to another transparent render bin as these render
436 * bins will be sorted separately, giving the wrong draw ordering for
437 * back-to-front transparency. Therefore, to prevent render bins being
438 * nested, call setNestRenderBins(false). */
439 inline void setNestRenderBins(bool val) { _nestRenderBins = val; }
440
441 /** Get whether associated RenderBin should be nested within parents RenderBin.*/
442 inline bool getNestRenderBins() const { return _nestRenderBins; }
443
444
445 struct OSG_EXPORT Callback : public virtual osg::Callback
446 {
447 Callback() {}
448
449 Callback(const Callback& org,const CopyOp& copyop):
450 osg::Object(org, copyop),
451 osg::Callback(org, copyop) {}
452
453 META_Object(osg,Callback);
454
455 /** override Callback::run() entry point to adapt to StateAttributeCallback::run(..) method.*/
456 virtual bool run(osg::Object* object, osg::Object* data);
457
458 /** do customized callback code.*/
459 virtual void operator() (StateSet*, NodeVisitor*) {}
460 };
461
462 /** Set the Update Callback which allows users to attach customize the updating of an object during the update traversal.*/
463 void setUpdateCallback(Callback* ac);
464
465 template<class T> void setUpdateCallback(const ref_ptr<T>& ac) { setUpdateCallback(ac.get()); }
466
467 /** Get the non const Update Callback.*/
468 Callback* getUpdateCallback() { return _updateCallback.get(); }
469
470 /** Get the const Update Callback.*/
471 const Callback* getUpdateCallback() const { return _updateCallback.get(); }
472
473 /** Return whether this StateSet has update callbacks associated with it, and therefore must be traversed.*/
474 bool requiresUpdateTraversal() const { return _updateCallback.valid() || getNumChildrenRequiringUpdateTraversal()!=0; }
475
476 /** Get the number of Objects of this StateSet which require Update traversal,
477 * since they have an Update Callback attached to them or their children.*/
478 inline unsigned int getNumChildrenRequiringUpdateTraversal() const { return _numChildrenRequiringUpdateTraversal; }
479
480 /** Run the update callbacks attached directly to this StateSet or to its children.*/
481 void runUpdateCallbacks(osg::NodeVisitor* nv);
482
483
484 /** Set the Event Callback which allows users to attach customize the updating of an object during the event traversal.*/
485 void setEventCallback(Callback* ac);
486
487 template<class T> void setEventCallback(const ref_ptr<T>& ec) { setEventCallback(ec.get()); }
488
489 /** Get the non const Event Callback.*/
490 Callback* getEventCallback() { return _eventCallback.get(); }
491
492 /** Get the const Event Callback.*/
493 const Callback* getEventCallback() const { return _eventCallback.get(); }
494
495 /** Return whether this StateSet has event callbacks associated with it, and therefore must be traversed.*/
496 bool requiresEventTraversal() const { return _eventCallback.valid() || getNumChildrenRequiringEventTraversal()!=0; }
497
498 /** Get the number of Objects of this StateSet which require Event traversal,
499 * since they have an Eevnt Callback attached to them or their children.*/
500 inline unsigned int getNumChildrenRequiringEventTraversal() const { return _numChildrenRequiringEventTraversal; }
501
502 /** Run the event callbacks attached directly to this StateSet or to its children.*/
503 void runEventCallbacks(osg::NodeVisitor* nv);
504
505 /** Check the modes associated with this StateSet are supported by current OpenGL drivers,
506 * and if not set the associated mode in osg::State to be black listed/invalid.
507 * Return true if all associated modes are valid.*/
508 bool checkValidityOfAssociatedModes(State& state) const;
509
510 /** Set whether to use a mutex to ensure ref() and unref() are thread safe.*/
511 virtual void setThreadSafeRefUnref(bool threadSafe);
512
513 /** call compile on all StateAttributes contained within this StateSet.*/
514 void compileGLObjects(State& state) const;
515
516 /** Resize any per context GLObject buffers to specified size. */
517 virtual void resizeGLObjectBuffers(unsigned int maxSize);
518
519 /** call release on all StateAttributes contained within this StateSet.*/
520 virtual void releaseGLObjects(State* state=0) const;
521
522 protected :
523
524
525 virtual ~StateSet();
526
527 StateSet& operator = (const StateSet&) { return *this; }
528
529 void addParent(osg::Node* object);
530 void removeParent(osg::Node* object);
531
532 ParentList _parents;
533 friend class osg::Node;
534 friend class osg::Drawable;
535 friend class osg::Uniform;
536 friend class osg::StateAttribute;
537
538 ModeList _modeList;
539 AttributeList _attributeList;
540
541 TextureModeList _textureModeList;
542 TextureAttributeList _textureAttributeList;
543
544 UniformList _uniformList;
545 DefineList _defineList;
546
547 inline ModeList& getOrCreateTextureModeList(unsigned int unit)
548 {
549 if (unit>=_textureModeList.size()) _textureModeList.resize(unit+1);
550 return _textureModeList[unit];
551 }
552
553 inline AttributeList& getOrCreateTextureAttributeList(unsigned int unit)
554 {
555 if (unit>=_textureAttributeList.size()) _textureAttributeList.resize(unit+1);
556 return _textureAttributeList[unit];
557 }
558
559 int compareModes(const ModeList& lhs, const ModeList& rhs);
560 int compareAttributePtrs(const AttributeList& lhs, const AttributeList& rhs);
561 int compareAttributeContents(const AttributeList& lhs, const AttributeList& rhs);
562
563 void setMode(ModeList& modeList,StateAttribute::GLMode mode, StateAttribute::GLModeValue value);
564 void setModeToInherit(ModeList& modeList, StateAttribute::GLMode mode);
565 StateAttribute::GLModeValue getMode(const ModeList& modeList, StateAttribute::GLMode mode) const;
566
567 void setAttribute(AttributeList& attributeList,StateAttribute *attribute, StateAttribute::OverrideValue value=StateAttribute::OFF);
568
569 StateAttribute* getAttribute(AttributeList& attributeList, StateAttribute::Type type, unsigned int member);
570 const StateAttribute* getAttribute(const AttributeList& attributeList, StateAttribute::Type type, unsigned int member) const;
571
572 RefAttributePair* getAttributePair(AttributeList& attributeList, StateAttribute::Type type, unsigned int member);
573 const RefAttributePair* getAttributePair(const AttributeList& attributeList, StateAttribute::Type type, unsigned int member) const;
574
575 int _renderingHint;
576
577 RenderBinMode _binMode;
578 int _binNum;
579 std::string _binName;
580 bool _nestRenderBins;
581
582 ref_ptr<Callback> _updateCallback;
583 unsigned int _numChildrenRequiringUpdateTraversal;
584 void setNumChildrenRequiringUpdateTraversal(unsigned int num);
585
586 ref_ptr<Callback> _eventCallback;
587 unsigned int _numChildrenRequiringEventTraversal;
588 void setNumChildrenRequiringEventTraversal(unsigned int num);
589
590};
591
592extern OSG_EXPORT bool isTextureMode(StateAttribute::GLMode mode);
593
594}
595
596#endif