2012-03-22 01:36:20 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
2012-03-22 01:36:20 +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.
|
2012-03-22 01:36:20 +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
|
2012-03-22 01:36:20 +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_STATEATTRIBUTE
|
|
|
|
#define OSG_STATEATTRIBUTE 1
|
|
|
|
|
2002-04-17 19:36:38 +08:00
|
|
|
#include <osg/Export>
|
2001-09-20 05:19:47 +08:00
|
|
|
#include <osg/Object>
|
2014-06-06 00:26:13 +08:00
|
|
|
#include <osg/Callback>
|
2010-07-02 20:04:20 +08:00
|
|
|
#include <osg/Shader>
|
2001-09-20 05:19:47 +08:00
|
|
|
#include <osg/GL>
|
|
|
|
|
2001-09-22 10:42:08 +08:00
|
|
|
#include <typeinfo>
|
2004-10-13 19:15:50 +08:00
|
|
|
#include <utility>
|
2005-04-25 05:04:54 +08:00
|
|
|
#include <vector>
|
2001-09-22 10:42:08 +08:00
|
|
|
|
2005-01-08 03:00:40 +08:00
|
|
|
// 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
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
namespace osg {
|
|
|
|
|
2004-08-03 19:01:39 +08:00
|
|
|
|
2005-04-23 06:45:39 +08:00
|
|
|
// forward declare NodeVisitor, State & StateSet
|
|
|
|
class NodeVisitor;
|
2001-09-20 05:19:47 +08:00
|
|
|
class State;
|
2010-06-25 01:15:27 +08:00
|
|
|
class ShaderComposer;
|
2001-09-20 05:19:47 +08:00
|
|
|
class StateSet;
|
2008-07-22 20:28:46 +08:00
|
|
|
class Texture;
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2001-09-22 10:42:08 +08:00
|
|
|
/** META_StateAttribute macro define the standard clone, isSameKindAs,
|
|
|
|
* className and getType methods.
|
2012-03-22 01:36:20 +08:00
|
|
|
* Use when subclassing from Object to make it more convenient to define
|
|
|
|
* the standard pure virtual methods which are required for all Object
|
2001-09-22 10:42:08 +08:00
|
|
|
* subclasses.*/
|
2002-06-06 21:25:36 +08:00
|
|
|
#define META_StateAttribute(library,name,type) \
|
2002-12-16 21:40:58 +08:00
|
|
|
virtual osg::Object* cloneType() const { return new name(); } \
|
|
|
|
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new name (*this,copyop); } \
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const name *>(obj)!=NULL; } \
|
2002-06-06 21:25:36 +08:00
|
|
|
virtual const char* libraryName() const { return #library; } \
|
2001-09-22 10:42:08 +08:00
|
|
|
virtual const char* className() const { return #name; } \
|
2002-09-02 20:31:35 +08:00
|
|
|
virtual Type getType() const { return type; }
|
2001-09-22 10:42:08 +08:00
|
|
|
|
2004-09-03 03:10:33 +08:00
|
|
|
/** COMPARE_StateAttribute_Types macro is a helper for implementing the StateAtribute::compare(..) method.*/
|
2001-09-22 10:42:08 +08:00
|
|
|
#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);
|
|
|
|
|
|
|
|
|
|
|
|
/** COMPARE_StateAttribute_Parameter macro is a helper for implementing the StatateAtribute::compare(..) method.
|
2004-09-03 03:10:33 +08:00
|
|
|
* Macro assumes that variable rhs has been correctly defined by preceding code
|
2001-09-22 10:42:08 +08:00
|
|
|
* macro.*/
|
|
|
|
#define COMPARE_StateAttribute_Parameter(parameter) \
|
|
|
|
if (parameter<rhs.parameter) return -1; \
|
|
|
|
if (rhs.parameter<parameter) return 1;
|
|
|
|
|
2002-08-29 22:29:49 +08:00
|
|
|
|
2004-09-03 03:10:33 +08:00
|
|
|
/** Base class for state attributes.
|
2012-03-22 01:36:20 +08:00
|
|
|
*/
|
2005-04-12 01:14:17 +08:00
|
|
|
class OSG_EXPORT StateAttribute : public Object
|
2001-09-20 05:19:47 +08:00
|
|
|
{
|
|
|
|
public :
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
/** GLMode is the value used in glEnable/glDisable(mode) */
|
|
|
|
typedef GLenum GLMode;
|
2004-09-03 03:10:33 +08:00
|
|
|
/** GLModeValue is used to specify whether a mode is enabled (ON) or disabled (OFF).
|
2012-03-22 01:36:20 +08:00
|
|
|
* GLMoveValue is also used to specify the override behavior of modes from parent to children.
|
2001-09-20 05:19:47 +08:00
|
|
|
* See enum Value description for more details.*/
|
|
|
|
typedef unsigned int GLModeValue;
|
2004-09-03 03:10:33 +08:00
|
|
|
/** Override is used to specify the override behavior of StateAttributes
|
2012-03-22 01:36:20 +08:00
|
|
|
* from parent to children.
|
2001-09-20 05:19:47 +08:00
|
|
|
* See enum Value description for more details.*/
|
2003-09-17 20:04:48 +08:00
|
|
|
typedef unsigned int OverrideValue;
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2004-09-03 03:10:33 +08:00
|
|
|
/** list values which can be used to set either GLModeValues or OverrideValues.
|
2012-03-22 01:36:20 +08:00
|
|
|
* When using in conjunction with GLModeValues, all Values have meaning.
|
|
|
|
* When using in conjunction with StateAttribute OverrideValue only
|
2004-09-03 03:10:33 +08:00
|
|
|
* OFF,OVERRIDE and INHERIT are meaningful.
|
2012-03-22 01:36:20 +08:00
|
|
|
* However, they are useful when using GLModeValue
|
2001-09-20 05:19:47 +08:00
|
|
|
* and OverrideValue in conjunction with each other as when using
|
|
|
|
* StateSet::setAttributeAndModes(..).*/
|
|
|
|
enum Values
|
|
|
|
{
|
|
|
|
/** means that associated GLMode and Override is disabled.*/
|
|
|
|
OFF = 0x0,
|
|
|
|
/** means that associated GLMode is enabled and Override is disabled.*/
|
|
|
|
ON = 0x1,
|
2004-09-03 03:10:33 +08:00
|
|
|
/** Overriding of GLMode's or StateAttributes is enabled, so that state below it is overridden.*/
|
2001-09-20 05:19:47 +08:00
|
|
|
OVERRIDE = 0x2,
|
2004-09-03 03:10:33 +08:00
|
|
|
/** Protecting of GLMode's or StateAttributes is enabled, so that state from above cannot override this and below state.*/
|
2012-03-22 01:36:20 +08:00
|
|
|
PROTECTED = 0x4,
|
2004-09-03 03:10:33 +08:00
|
|
|
/** means that GLMode or StateAttribute should be inherited from above.*/
|
2002-08-05 20:40:24 +08:00
|
|
|
INHERIT = 0x8
|
2001-09-20 05:19:47 +08:00
|
|
|
};
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2001-09-22 10:42:08 +08:00
|
|
|
/** Type identifier to differentiate between different state types. */
|
2004-10-08 17:18:40 +08:00
|
|
|
// typedef unsigned int Type;
|
2001-09-22 10:42:08 +08:00
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
/** Values of StateAttribute::Type used to aid identification
|
2001-10-01 19:15:55 +08:00
|
|
|
* of different StateAttribute subclasses. Each subclass defines
|
2012-03-22 01:36:20 +08:00
|
|
|
* its own value in the virtual Type getType() method. When
|
2001-09-20 05:19:47 +08:00
|
|
|
* extending the osg's StateAttribute's simply define your
|
|
|
|
* own Type value which is unique, using the StateAttribute::Type
|
|
|
|
* enum as a guide of what values to use. If your new subclass
|
2015-06-01 21:11:49 +08:00
|
|
|
* needs to override a standard StateAttribute then simply use
|
2004-09-03 03:10:33 +08:00
|
|
|
* that type's value. */
|
2004-10-08 17:18:40 +08:00
|
|
|
enum Type
|
2001-09-20 05:19:47 +08:00
|
|
|
{
|
2002-01-17 05:22:06 +08:00
|
|
|
TEXTURE,
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2002-03-30 01:26:40 +08:00
|
|
|
POLYGONMODE,
|
|
|
|
POLYGONOFFSET,
|
2002-01-17 05:22:06 +08:00
|
|
|
MATERIAL,
|
|
|
|
ALPHAFUNC,
|
|
|
|
ANTIALIAS,
|
|
|
|
COLORTABLE,
|
|
|
|
CULLFACE,
|
|
|
|
FOG,
|
|
|
|
FRONTFACE,
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2002-01-17 05:22:06 +08:00
|
|
|
LIGHT,
|
|
|
|
|
|
|
|
POINT,
|
|
|
|
LINEWIDTH,
|
2002-02-25 04:55:45 +08:00
|
|
|
LINESTIPPLE,
|
2002-09-19 18:30:15 +08:00
|
|
|
POLYGONSTIPPLE,
|
2002-01-17 05:22:06 +08:00
|
|
|
SHADEMODEL,
|
|
|
|
TEXENV,
|
2004-10-14 03:52:39 +08:00
|
|
|
TEXENVFILTER,
|
2002-01-17 05:22:06 +08:00
|
|
|
TEXGEN,
|
|
|
|
TEXMAT,
|
2002-02-26 06:46:38 +08:00
|
|
|
LIGHTMODEL,
|
2002-07-12 22:25:10 +08:00
|
|
|
BLENDFUNC,
|
2005-03-18 17:48:09 +08:00
|
|
|
BLENDEQUATION,
|
|
|
|
LOGICOP,
|
2002-01-17 05:22:06 +08:00
|
|
|
STENCIL,
|
|
|
|
COLORMASK,
|
|
|
|
DEPTH,
|
|
|
|
VIEWPORT,
|
2005-07-22 17:31:19 +08:00
|
|
|
SCISSOR,
|
2003-09-17 20:04:48 +08:00
|
|
|
BLENDCOLOR,
|
|
|
|
MULTISAMPLE,
|
2002-01-17 05:22:06 +08:00
|
|
|
CLIPPLANE,
|
2003-01-05 04:45:53 +08:00
|
|
|
COLORMATRIX,
|
|
|
|
VERTEXPROGRAM,
|
2003-07-16 00:22:29 +08:00
|
|
|
FRAGMENTPROGRAM,
|
2004-10-08 17:18:40 +08:00
|
|
|
POINTSPRITE,
|
2005-04-15 16:35:06 +08:00
|
|
|
PROGRAM,
|
2006-06-08 23:27:18 +08:00
|
|
|
CLAMPCOLOR,
|
2007-06-04 18:47:15 +08:00
|
|
|
HINT,
|
2013-02-14 00:29:03 +08:00
|
|
|
SAMPLEMASKI,
|
From Aurelien Albert, Added support for glPrimitiveRestartIndex.
"The idea of this new OpenGL feature is :
- set RestartIndex = "n"
- draw elements strip
-> when the index is "n", the strip is "stopped" and restarted
It's very usefull for drawing tiles with a single strip and a "restart" at the end of each row.
The idea a an OSG StateAttribute is :
Usually we use to build geometry from code, because software modelers rarely support it (and 3d file formats doesn't support it) :
-RootNode <= "PrimitiveRestartIndex=0" // So now, we know that our restart index is 0 for all drawables under this node
|
- Drawable 1 : triangles => as usual
|
- Drawable 2 : triangles strip => as usual
|
- Drawable 3 : triangles strip + "GL_PRIMITIVE_RESTART" mode = ON => use the restart index
|
- Drawable 4 : triangles strip + "GL_PRIMITIVE_RESTART" mode = ON => use the restart index
|
- Drawable 5 : triangles strip => as usual
With a StateAttribute, it's easy for the developper to say "0 will be my restart index for all this object" and then activate the mode only on some nodes.
The main problem is if you set and restart index value which is not included in the vertex array (for exemple set restart index = 100 but you have only 50 vertex). There is no problem with OpenGL, but some OSG algorithms will try to access the vertex[100] and will segfault.
To solve this, I think there is two ways :
1/ add restart index in osg::PrimitiveSet and use this value in all algorithms. It's a lot of work, maybe dangerous, and it concern only a few situations : developpers who use this extension should be aware of advanced OpenGL (and OSG) data management
2/ use a StateAttribute, and choose a "correct" restart index. In my applications, I always use "0" as a restart index and duplicate the first vertex (vertex[0] = vertex[1]). So there is no difference for OpenGL and all OSG algorithms works properly.
"
2013-06-28 21:43:46 +08:00
|
|
|
PRIMITIVERESTARTINDEX,
|
2015-06-30 17:11:00 +08:00
|
|
|
CLIPCONTROL,
|
2005-04-15 16:35:06 +08:00
|
|
|
|
2004-10-08 17:18:40 +08:00
|
|
|
/// osgFX namespace
|
|
|
|
VALIDATOR,
|
|
|
|
VIEWMATRIXEXTRACTOR,
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2005-04-15 16:35:06 +08:00
|
|
|
/// osgNV namespace
|
2005-03-18 17:48:09 +08:00
|
|
|
OSGNV_PARAMETER_BLOCK,
|
|
|
|
|
2004-10-15 18:35:09 +08:00
|
|
|
// osgNVExt namespace
|
2005-03-18 17:48:09 +08:00
|
|
|
OSGNVEXT_TEXTURE_SHADER,
|
|
|
|
OSGNVEXT_VERTEX_PROGRAM,
|
|
|
|
OSGNVEXT_REGISTER_COMBINERS,
|
|
|
|
|
2005-04-15 16:35:06 +08:00
|
|
|
/// osgNVCg namespace
|
2005-03-18 17:48:09 +08:00
|
|
|
OSGNVCG_PROGRAM,
|
|
|
|
|
|
|
|
// osgNVSlang namespace
|
|
|
|
OSGNVSLANG_PROGRAM,
|
|
|
|
|
2004-10-15 18:35:09 +08:00
|
|
|
// osgNVParse
|
2010-11-30 01:43:27 +08:00
|
|
|
OSGNVPARSE_PROGRAM_PARSER,
|
|
|
|
|
|
|
|
UNIFORMBUFFERBINDING,
|
2012-03-29 17:43:12 +08:00
|
|
|
TRANSFORMFEEDBACKBUFFERBINDING,
|
|
|
|
|
2013-06-11 18:52:37 +08:00
|
|
|
ATOMICCOUNTERBUFFERBINDING,
|
2013-07-22 18:15:59 +08:00
|
|
|
|
|
|
|
PATCH_PARAMETER,
|
|
|
|
|
2014-11-24 22:54:39 +08:00
|
|
|
FRAME_BUFFER_OBJECT,
|
|
|
|
|
2014-12-04 01:31:16 +08:00
|
|
|
VERTEX_ATTRIB_DIVISOR,
|
|
|
|
|
2014-12-10 20:23:04 +08:00
|
|
|
SHADERSTORAGEBUFFERBINDING,
|
|
|
|
|
2014-12-04 01:31:16 +08:00
|
|
|
CAPABILITY = 100
|
2001-09-20 05:19:47 +08:00
|
|
|
};
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2004-10-13 19:15:50 +08:00
|
|
|
/** Simple pairing between an attribute type and the member within that attribute type group.*/
|
|
|
|
typedef std::pair<Type,unsigned int> TypeMemberPair;
|
|
|
|
|
2007-08-22 18:34:11 +08:00
|
|
|
StateAttribute();
|
2012-03-22 01:36:20 +08:00
|
|
|
|
|
|
|
StateAttribute(const StateAttribute& sa,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
2009-10-22 18:33:16 +08:00
|
|
|
Object(sa,copyop),
|
2010-07-02 20:04:20 +08:00
|
|
|
_shaderComponent(sa._shaderComponent),
|
|
|
|
_updateCallback(copyop(sa._updateCallback.get())),
|
|
|
|
_eventCallback(copyop(sa._eventCallback.get()))
|
2009-10-22 18:33:16 +08:00
|
|
|
{}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
|
|
|
|
/** Clone the type of an attribute, with Object* return type.
|
|
|
|
Must be defined by derived classes.*/
|
|
|
|
virtual Object* cloneType() const = 0;
|
2001-09-20 05:19:47 +08:00
|
|
|
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
/** Clone an attribute, with Object* return type.
|
|
|
|
Must be defined by derived classes.*/
|
2002-01-29 22:04:06 +08:00
|
|
|
virtual Object* clone(const CopyOp&) const = 0;
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2004-10-13 19:15:50 +08:00
|
|
|
/** Return true if this and obj are of the same kind of object.*/
|
2001-09-20 05:19:47 +08:00
|
|
|
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const StateAttribute*>(obj)!=NULL; }
|
|
|
|
|
2004-10-13 19:15:50 +08:00
|
|
|
/** Return the name of the attribute's library.*/
|
2002-06-06 21:25:36 +08:00
|
|
|
virtual const char* libraryName() const { return "osg"; }
|
|
|
|
|
2004-10-13 19:15:50 +08:00
|
|
|
/** Return the name of the attribute's class type.*/
|
2001-09-20 05:19:47 +08:00
|
|
|
virtual const char* className() const { return "StateAttribute"; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
|
|
|
|
2015-06-09 18:49:34 +08:00
|
|
|
/** Convert 'this' into a StateAttribute pointer if Object is a StateAttribute, otherwise return 0.
|
|
|
|
* Equivalent to dynamic_cast<StateAttribute*>(this).*/
|
|
|
|
virtual StateAttribute* asStateAttribute() { return this; }
|
|
|
|
|
|
|
|
/** convert 'const this' into a const StateAttribute pointer if Object is a StateAttribute, otherwise return 0.
|
|
|
|
* Equivalent to dynamic_cast<const StateAttribute*>(this).*/
|
|
|
|
virtual const StateAttribute* asStateAttribute() const { return this; }
|
|
|
|
|
2008-07-22 20:28:46 +08:00
|
|
|
/** Fast alternative to dynamic_cast<> for determining if state attribute is a Texture.*/
|
|
|
|
virtual Texture* asTexture() { return 0; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2008-07-22 20:28:46 +08:00
|
|
|
/** Fast alternative to dynamic_cast<> for determining if state attribute is a Texture.*/
|
|
|
|
virtual const Texture* asTexture() const { return 0; }
|
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2004-10-13 19:15:50 +08:00
|
|
|
/** Return the Type identifier of the attribute's class type.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
virtual Type getType() const = 0;
|
2001-09-22 10:42:08 +08:00
|
|
|
|
2004-10-13 19:15:50 +08:00
|
|
|
/** Return the member identifier within the attribute's class type. Used for light number/clip plane number etc.*/
|
|
|
|
virtual unsigned int getMember() const { return 0; }
|
|
|
|
|
|
|
|
/** Return the TypeMemberPair that uniquely identifies this type member.*/
|
|
|
|
inline TypeMemberPair getTypeMemberPair() const { return TypeMemberPair(getType(),getMember()); }
|
|
|
|
|
|
|
|
/** Return true if StateAttribute is a type which controls texturing and needs to be issued w.r.t to specific texture unit.*/
|
2002-07-09 17:35:42 +08:00
|
|
|
virtual bool isTextureAttribute() const { return false; }
|
2002-03-15 01:34:08 +08:00
|
|
|
|
2004-10-13 19:15:50 +08:00
|
|
|
/** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
|
2001-09-22 10:42:08 +08:00
|
|
|
virtual int compare(const StateAttribute& sa) const = 0;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2001-09-22 10:42:08 +08:00
|
|
|
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; }
|
2005-04-25 05:04:54 +08:00
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2005-04-25 05:04:54 +08:00
|
|
|
/** A vector of osg::StateSet pointers which is used to store the parent(s) of this StateAttribute.*/
|
|
|
|
typedef std::vector<StateSet*> ParentList;
|
|
|
|
|
|
|
|
/** Get the parent list of this StateAttribute. */
|
|
|
|
inline const ParentList& getParents() const { return _parents; }
|
|
|
|
|
|
|
|
inline StateSet* getParent(unsigned int i) { return _parents[i]; }
|
|
|
|
/**
|
|
|
|
* Get a single const parent of this StateAttribute.
|
|
|
|
* @param i index of the parent to get.
|
|
|
|
* @return the parent i.
|
|
|
|
*/
|
|
|
|
inline const StateSet* getParent(unsigned int i) const { return _parents[i]; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the number of parents of this StateAttribute.
|
|
|
|
* @return the number of parents of this StateAttribute.
|
|
|
|
*/
|
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
|
|
|
|
2010-07-02 20:04:20 +08:00
|
|
|
void setShaderComponent(ShaderComponent* sc) { _shaderComponent = sc; }
|
|
|
|
ShaderComponent* getShaderComponent() { return _shaderComponent.get(); }
|
|
|
|
const ShaderComponent* getShaderComponent() const { return _shaderComponent.get(); }
|
2002-07-09 17:35:42 +08:00
|
|
|
|
2004-03-03 23:38:22 +08:00
|
|
|
struct ModeUsage
|
|
|
|
{
|
2005-08-26 01:53:01 +08:00
|
|
|
virtual ~ModeUsage() {}
|
2004-03-03 23:38:22 +08:00
|
|
|
virtual void usesMode(GLMode mode) = 0;
|
|
|
|
virtual void usesTextureMode(GLMode mode) = 0;
|
|
|
|
};
|
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
/** Return the modes associated with this StateAttribute.*/
|
2004-03-03 23:38:22 +08:00
|
|
|
virtual bool getModeUsage(ModeUsage&) const
|
2001-09-20 05:19:47 +08:00
|
|
|
{
|
2001-10-01 19:15:55 +08:00
|
|
|
// default to no GLMode's associated with use of the StateAttribute.
|
2004-03-03 23:38:22 +08:00
|
|
|
return false;
|
2001-09-20 05:19:47 +08:00
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2006-02-22 22:31:13 +08:00
|
|
|
/** Check the modes associated with this StateAttribute are supported by current OpenGL drivers,
|
|
|
|
* and if not set the associated mode in osg::State to be black listed/invalid.
|
|
|
|
* Return true if all associated modes are valid.*/
|
2006-02-23 03:14:01 +08:00
|
|
|
virtual bool checkValidityOfAssociatedModes(osg::State&) const
|
2006-02-22 22:31:13 +08:00
|
|
|
{
|
|
|
|
// default to no black listed GLMode's associated with use of the StateAttribute.
|
|
|
|
return true;
|
|
|
|
}
|
2005-04-23 06:45:39 +08:00
|
|
|
|
2009-10-22 18:33:16 +08:00
|
|
|
// provide callback for backwards compatibility.
|
|
|
|
typedef osg::StateAttributeCallback Callback;
|
2005-04-23 06:45:39 +08:00
|
|
|
|
|
|
|
/** Set the UpdateCallback which allows users to attach customize the updating of an object during the update traversal.*/
|
2009-10-22 18:33:16 +08:00
|
|
|
void setUpdateCallback(StateAttributeCallback* uc);
|
2005-04-23 06:45:39 +08:00
|
|
|
|
|
|
|
/** Get the non const UpdateCallback.*/
|
2009-10-22 18:33:16 +08:00
|
|
|
StateAttributeCallback* getUpdateCallback() { return _updateCallback.get(); }
|
2005-04-23 06:45:39 +08:00
|
|
|
|
|
|
|
/** Get the const UpdateCallback.*/
|
2009-10-22 18:33:16 +08:00
|
|
|
const StateAttributeCallback* getUpdateCallback() const { return _updateCallback.get(); }
|
2005-04-23 06:45:39 +08:00
|
|
|
|
|
|
|
|
|
|
|
/** Set the EventCallback which allows users to attach customize the updating of an object during the Event traversal.*/
|
2009-10-22 18:33:16 +08:00
|
|
|
void setEventCallback(StateAttributeCallback* ec);
|
2005-04-23 06:45:39 +08:00
|
|
|
|
|
|
|
/** Get the non const EventCallback.*/
|
2009-10-22 18:33:16 +08:00
|
|
|
StateAttributeCallback* getEventCallback() { return _eventCallback.get(); }
|
2005-04-23 06:45:39 +08:00
|
|
|
|
|
|
|
/** Get the const EventCallback.*/
|
2009-10-22 18:33:16 +08:00
|
|
|
const StateAttributeCallback* getEventCallback() const { return _eventCallback.get(); }
|
2005-04-23 06:45:39 +08:00
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
|
|
|
|
/** apply the OpenGL state attributes.
|
2006-09-19 04:54:48 +08:00
|
|
|
* The render info for the current OpenGL context is passed
|
2001-09-20 05:19:47 +08:00
|
|
|
* in to allow the StateAttribute to obtain details on the
|
|
|
|
* the current context and state.
|
|
|
|
*/
|
2006-09-19 04:54:48 +08:00
|
|
|
virtual void apply(State&) const {}
|
|
|
|
|
2007-01-04 22:11:51 +08:00
|
|
|
/** Default to nothing to compile - all state is applied immediately. */
|
2004-07-20 13:37:59 +08:00
|
|
|
virtual void compileGLObjects(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*/) {}
|
|
|
|
|
|
|
|
/** Release OpenGL objects in specified graphics context if State
|
2007-12-11 01:30:18 +08:00
|
|
|
object is passed, otherwise release OpenGL objects for all graphics context if
|
2004-07-20 13:37:59 +08:00
|
|
|
State object pointer NULL.*/
|
|
|
|
virtual void releaseGLObjects(State* =0) const {}
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
protected:
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
virtual ~StateAttribute() {}
|
|
|
|
|
2005-04-25 05:04:54 +08:00
|
|
|
void addParent(osg::StateSet* object);
|
|
|
|
void removeParent(osg::StateSet* object);
|
|
|
|
|
|
|
|
ParentList _parents;
|
|
|
|
friend class osg::StateSet;
|
|
|
|
|
2010-07-02 20:04:20 +08:00
|
|
|
ref_ptr<ShaderComponent> _shaderComponent;
|
|
|
|
|
2009-10-22 18:33:16 +08:00
|
|
|
ref_ptr<StateAttributeCallback> _updateCallback;
|
|
|
|
ref_ptr<StateAttributeCallback> _eventCallback;
|
2001-09-20 05:19:47 +08:00
|
|
|
};
|
|
|
|
|
2002-02-03 20:33:41 +08:00
|
|
|
}
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
#endif
|