2003-01-22 00:45:36 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 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.
|
|
|
|
*/
|
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>
|
|
|
|
#include <osg/GL>
|
|
|
|
|
2001-09-22 10:42:08 +08:00
|
|
|
#include <typeinfo>
|
|
|
|
|
2004-08-03 19:01:39 +08:00
|
|
|
// #define THREAD_SAFE_GLOBJECT_DELETE_LISTS 1
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
namespace osg {
|
|
|
|
|
2004-08-03 19:01:39 +08:00
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
// forward declare State & StateSet
|
|
|
|
class State;
|
|
|
|
class StateSet;
|
|
|
|
|
2001-09-22 10:42:08 +08:00
|
|
|
/** META_StateAttribute macro define the standard clone, isSameKindAs,
|
|
|
|
* className and getType methods.
|
|
|
|
* Use when subclassing from Object to make it more convinient to define
|
|
|
|
* the standard pure virtual methods which are required for all Object
|
|
|
|
* 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
|
|
|
|
|
|
|
/** COMPARE_StateAttribute_Types macro is a helper for implementing the StatateAtribute::compare(..) method.*/
|
|
|
|
#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.
|
|
|
|
* Macro assumes that variable rhs has been corrected defined by code preceesing
|
|
|
|
* 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
|
|
|
|
|
|
|
// define for the GL_EXT_secondary_color extension, GL_COLOR_SUM is OpenGL
|
|
|
|
// mode to be used to enable and disable the off the second color.
|
|
|
|
#ifndef GL_COLOR_SUM
|
|
|
|
#define GL_COLOR_SUM 0x8458
|
|
|
|
#endif
|
|
|
|
|
2001-10-01 19:15:55 +08:00
|
|
|
/** Base class for state attribuets.
|
2001-09-20 05:19:47 +08:00
|
|
|
*/
|
|
|
|
class SG_EXPORT StateAttribute : public Object
|
|
|
|
{
|
|
|
|
public :
|
|
|
|
|
|
|
|
/** GLMode is the value used in glEnable/glDisable(mode) */
|
|
|
|
typedef GLenum GLMode;
|
|
|
|
/** GLModeValue is used to specified whether an mode is enabled (ON) or disabled (OFF).
|
2001-10-01 19:15:55 +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;
|
|
|
|
/** Override is used to specified the override behavior of StateAttributes
|
|
|
|
* from from parent to children.
|
|
|
|
* 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
|
|
|
|
|
|
|
/** list values which can be used in to set either GLModeValues
|
2001-10-01 19:15:55 +08:00
|
|
|
* or OverrideValues. When using in conjunction with GLModeValues
|
2001-09-20 05:19:47 +08:00
|
|
|
* all Values have meaning. When using in conjection with
|
|
|
|
* StateAttribute OverrideValue only OFF,OVERRIDE and INHERIT
|
|
|
|
* are meaningful. However, they are useful when using GLModeValue
|
|
|
|
* 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,
|
2002-08-05 20:40:24 +08:00
|
|
|
/** Overriding of GLMode's or StateAttributes is enabled, so that state below it is overriden.*/
|
2001-09-20 05:19:47 +08:00
|
|
|
OVERRIDE = 0x2,
|
2002-08-05 20:40:24 +08:00
|
|
|
/** Protecting of GLMode's os StateAttributes is enabled, so that state from above connot override this and below state.*/
|
|
|
|
PROTECTED = 0x4,
|
2001-09-20 05:19:47 +08:00
|
|
|
/** means that GLMode or StateAttribute should in inherited from above.*/
|
2002-08-05 20:40:24 +08:00
|
|
|
INHERIT = 0x8
|
2001-09-20 05:19:47 +08:00
|
|
|
};
|
2001-12-28 04:06:07 +08:00
|
|
|
|
2001-09-22 10:42:08 +08:00
|
|
|
/** Type identifier to differentiate between different state types. */
|
|
|
|
typedef unsigned int Type;
|
|
|
|
|
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
|
2001-09-20 05:19:47 +08:00
|
|
|
* it own value in the virtual Type getType() method. When
|
|
|
|
* 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
|
|
|
|
* needs to override a standard StateAttriubte then simple use
|
|
|
|
* that types value. */
|
2001-09-22 10:42:08 +08:00
|
|
|
enum Types
|
2001-09-20 05:19:47 +08:00
|
|
|
{
|
2002-01-17 05:22:06 +08:00
|
|
|
TEXTURE,
|
2001-12-19 08:38:23 +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,
|
2001-12-19 08:38:23 +08:00
|
|
|
|
2002-01-17 05:22:06 +08:00
|
|
|
LIGHT,
|
2001-12-19 08:38:23 +08:00
|
|
|
LIGHT_0 =LIGHT,
|
2002-01-17 05:22:06 +08:00
|
|
|
LIGHT_1,
|
|
|
|
LIGHT_2,
|
|
|
|
LIGHT_3,
|
|
|
|
LIGHT_4,
|
|
|
|
LIGHT_5,
|
|
|
|
LIGHT_6,
|
|
|
|
LIGHT_7,
|
|
|
|
|
|
|
|
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,
|
|
|
|
TEXGEN,
|
|
|
|
TEXMAT,
|
2002-02-26 06:46:38 +08:00
|
|
|
LIGHTMODEL,
|
2002-07-12 22:25:10 +08:00
|
|
|
BLENDFUNC,
|
2002-01-17 05:22:06 +08:00
|
|
|
STENCIL,
|
|
|
|
COLORMASK,
|
|
|
|
DEPTH,
|
|
|
|
VIEWPORT,
|
2003-09-17 20:04:48 +08:00
|
|
|
BLENDCOLOR,
|
|
|
|
MULTISAMPLE,
|
|
|
|
|
2001-12-19 08:38:23 +08:00
|
|
|
|
2002-01-17 05:22:06 +08:00
|
|
|
CLIPPLANE,
|
2001-12-19 08:38:23 +08:00
|
|
|
CLIPPLANE_0 =CLIPPLANE,
|
2002-01-17 05:22:06 +08:00
|
|
|
CLIPPLANE_1,
|
|
|
|
CLIPPLANE_2,
|
|
|
|
CLIPPLANE_3,
|
|
|
|
CLIPPLANE_4,
|
|
|
|
CLIPPLANE_5,
|
2001-12-19 08:38:23 +08:00
|
|
|
|
2003-01-05 04:45:53 +08:00
|
|
|
COLORMATRIX,
|
|
|
|
|
|
|
|
VERTEXPROGRAM,
|
2003-07-16 00:22:29 +08:00
|
|
|
FRAGMENTPROGRAM,
|
|
|
|
|
|
|
|
PROGRAMOBJECT // utilised in osgGL2/ProgramObject
|
2001-09-20 05:19:47 +08:00
|
|
|
};
|
|
|
|
|
2002-03-15 01:34:08 +08:00
|
|
|
|
Added DataVariance enum and set/get fields to osg::Object to help identify
which objects have values that vary over the lifetime of the object (DYNAMIC)
and ones that do not vary (STATIC). Removed the equivalent code in
osg::Transform, StateSet and StateAttribute, as these are now encompassed
by the new DataVariance field.
Removed MatrixMode enum from Matrix, and associated fields/parameters from
osg::Transfrom and osg::NodeVisitor, since MatrixMode was not providing
any useful functionality, but made the interface more complex (MatrixMode
was an experimental API)
Added ReferenceFrame field to osg::Transform which allows users to specify
transforms that are relative to their parents (the default, and previous behavior)
or absolute reference frame, which can be used for HUD's, camera relative
light sources etc etc. Note, the view frustum culling for absolute Transform
are disabled, and all their parents up to the root are also automatically
have view frustum culling disabled. However, once passed an absolute Transform
node culling will return to its default state of on, so you can still cull
underneath an absolute transform, its only the culling above which is disabled.
2002-04-12 07:20:23 +08:00
|
|
|
StateAttribute() { setDataVariance(STATIC); }
|
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
|
|
|
|
2002-01-29 22:04:06 +08:00
|
|
|
StateAttribute(const StateAttribute& sa,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
Added DataVariance enum and set/get fields to osg::Object to help identify
which objects have values that vary over the lifetime of the object (DYNAMIC)
and ones that do not vary (STATIC). Removed the equivalent code in
osg::Transform, StateSet and StateAttribute, as these are now encompassed
by the new DataVariance field.
Removed MatrixMode enum from Matrix, and associated fields/parameters from
osg::Transfrom and osg::NodeVisitor, since MatrixMode was not providing
any useful functionality, but made the interface more complex (MatrixMode
was an experimental API)
Added ReferenceFrame field to osg::Transform which allows users to specify
transforms that are relative to their parents (the default, and previous behavior)
or absolute reference frame, which can be used for HUD's, camera relative
light sources etc etc. Note, the view frustum culling for absolute Transform
are disabled, and all their parents up to the root are also automatically
have view frustum culling disabled. However, once passed an absolute Transform
node culling will return to its default state of on, so you can still cull
underneath an absolute transform, its only the culling above which is disabled.
2002-04-12 07:20:23 +08:00
|
|
|
Object(sa,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
|
|
|
|
|
|
|
|
|
|
|
/** 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
|
|
|
|
|
|
|
/** return true if this and obj are of the same kind of object.*/
|
|
|
|
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const StateAttribute*>(obj)!=NULL; }
|
|
|
|
|
2002-06-06 21:25:36 +08:00
|
|
|
/** return the name of the attribute's library.*/
|
|
|
|
virtual const char* libraryName() const { return "osg"; }
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
/** return the name of the attribute's class type.*/
|
|
|
|
virtual const char* className() const { return "StateAttribute"; }
|
|
|
|
|
2001-10-01 19:15:55 +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
|
|
|
|
2002-07-09 17:35:42 +08:00
|
|
|
/** return true if StateAttribute is a type which controls texturing and needs to be issued w.r.t to specific texture unit.*/
|
|
|
|
virtual bool isTextureAttribute() const { return false; }
|
2002-03-15 01:34:08 +08:00
|
|
|
|
2001-09-22 10:42:08 +08:00
|
|
|
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
|
|
|
|
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; }
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2002-07-09 17:35:42 +08:00
|
|
|
|
2004-03-03 23:38:22 +08:00
|
|
|
struct ModeUsage
|
|
|
|
{
|
|
|
|
virtual void usesMode(GLMode mode) = 0;
|
|
|
|
virtual void usesTextureMode(GLMode mode) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** return the modes associated with this StateAttribute.*/
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/** apply the OpenGL state attributes.
|
|
|
|
* The global state for the current OpenGL context is passed
|
|
|
|
* in to allow the StateAttribute to obtain details on the
|
|
|
|
* the current context and state.
|
|
|
|
*/
|
2003-04-11 03:32:32 +08:00
|
|
|
virtual void apply(State&) const = 0;
|
2001-09-20 05:19:47 +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 {}
|
|
|
|
|
|
|
|
/** release an OpenGL objects in specified graphics context if State
|
|
|
|
object is passed, otherwise release OpenGL objexts for all graphics context if
|
|
|
|
State object pointer NULL.*/
|
|
|
|
virtual void releaseGLObjects(State* =0) const {}
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual ~StateAttribute() {}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2002-02-03 20:33:41 +08:00
|
|
|
}
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
#endif
|