2001-10-04 23:12:57 +08:00
|
|
|
//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield
|
|
|
|
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
|
|
|
//as published by the Free Software Foundation.
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
#ifndef OSG_STATEATTRIBUTE
|
|
|
|
#define OSG_STATEATTRIBUTE 1
|
|
|
|
|
|
|
|
#include <osg/Object>
|
|
|
|
#include <osg/GL>
|
|
|
|
|
2001-09-22 10:42:08 +08:00
|
|
|
#include <typeinfo>
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
namespace osg {
|
|
|
|
|
|
|
|
// 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.*/
|
|
|
|
#define META_StateAttribute(name,type) \
|
|
|
|
virtual Object* clone() const { return new name (); } \
|
|
|
|
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const name *>(obj)!=NULL; } \
|
|
|
|
virtual const char* className() const { return #name; } \
|
|
|
|
virtual const Type getType() const { return type; }
|
|
|
|
|
|
|
|
/** 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;
|
|
|
|
|
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.*/
|
|
|
|
typedef unsigned int OverrideValue;
|
|
|
|
|
|
|
|
/** 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,
|
|
|
|
/** Overriding of GLMode's or StateAttributes is enabled.*/
|
|
|
|
OVERRIDE = 0x2,
|
2001-12-28 04:06:07 +08:00
|
|
|
/** Equivilant to OFF | OVERRIDE.*/
|
2001-09-20 05:19:47 +08:00
|
|
|
OVERRIDE_OFF = 0x2,
|
2001-12-28 04:06:07 +08:00
|
|
|
/** Equivilant to ON | OVERRIDE.*/
|
2001-09-20 05:19:47 +08:00
|
|
|
OVERRIDE_ON = 0x3,
|
|
|
|
/** means that GLMode or StateAttribute should in inherited from above.*/
|
|
|
|
INHERIT = 0x4
|
|
|
|
};
|
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
|
|
|
{
|
2001-10-04 22:10:20 +08:00
|
|
|
TEXTURE =0,
|
2001-12-19 08:38:23 +08:00
|
|
|
TEXTURE_0 =TEXTURE,
|
|
|
|
TEXTURE_1 =TEXTURE_0+1,
|
|
|
|
TEXTURE_2 =TEXTURE_1+2,
|
|
|
|
TEXTURE_3 =TEXTURE_2+3,
|
|
|
|
|
|
|
|
MATERIAL =TEXTURE_3+1,
|
|
|
|
ALPHAFUNC =MATERIAL+1,
|
|
|
|
ANTIALIAS =ALPHAFUNC+1,
|
|
|
|
COLORTABLE =ANTIALIAS+1,
|
|
|
|
CULLFACE =COLORTABLE+1,
|
|
|
|
FOG =CULLFACE+1,
|
|
|
|
FRONTFACE =FOG+1,
|
|
|
|
|
|
|
|
LIGHT =FRONTFACE+1,
|
|
|
|
LIGHT_0 =LIGHT,
|
2001-09-22 10:42:08 +08:00
|
|
|
LIGHT_1 =LIGHT+1,
|
2001-12-19 08:38:23 +08:00
|
|
|
LIGHT_2 =LIGHT+1,
|
|
|
|
LIGHT_3 =LIGHT+1,
|
|
|
|
LIGHT_4 =LIGHT+1,
|
|
|
|
LIGHT_5 =LIGHT+1,
|
|
|
|
LIGHT_6 =LIGHT+1,
|
|
|
|
LIGHT_7 =LIGHT+1,
|
2001-12-21 04:48:46 +08:00
|
|
|
|
|
|
|
POINT =LIGHT_7+1,
|
|
|
|
LINEWIDTH =POINT+1,
|
2002-01-05 01:35:54 +08:00
|
|
|
SHADEMODEL =LINEWIDTH+1,
|
|
|
|
POLYGONMODE =SHADEMODEL+1,
|
2001-12-19 08:38:23 +08:00
|
|
|
POLYGONOFFSET =POLYGONMODE+1,
|
|
|
|
TEXENV =POLYGONOFFSET+1,
|
|
|
|
TEXGEN =TEXENV+1,
|
|
|
|
TEXMAT =TEXGEN+1,
|
|
|
|
TRANSPARENCY =TEXMAT+1,
|
|
|
|
STENCIL =TRANSPARENCY+1,
|
|
|
|
COLORMASK =STENCIL+1,
|
|
|
|
DEPTH =COLORMASK+1,
|
|
|
|
VIEWPORT =DEPTH+1,
|
|
|
|
|
|
|
|
CLIPPLANE =VIEWPORT+1,
|
|
|
|
CLIPPLANE_0 =CLIPPLANE,
|
|
|
|
CLIPPLANE_1 =CLIPPLANE_0+1,
|
|
|
|
CLIPPLANE_2 =CLIPPLANE_1+1,
|
|
|
|
CLIPPLANE_3 =CLIPPLANE_2+1,
|
|
|
|
CLIPPLANE_4 =CLIPPLANE_3+1,
|
|
|
|
CLIPPLANE_5 =CLIPPLANE_4+1,
|
|
|
|
|
|
|
|
COLORMATRIX =CLIPPLANE_5+1
|
2001-09-20 05:19:47 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
StateAttribute() {}
|
|
|
|
|
|
|
|
/** return a shallow copy of a node, with Object* return type.*/
|
|
|
|
virtual Object* clone() const = 0;
|
|
|
|
|
|
|
|
/** 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; }
|
|
|
|
|
|
|
|
/** 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.*/
|
2001-09-20 05:19:47 +08:00
|
|
|
virtual const Type getType() const = 0;
|
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
|
|
|
|
|
|
|
virtual void setStateSetModes(StateSet&,const GLModeValue) const
|
|
|
|
{
|
2001-10-01 19:15:55 +08:00
|
|
|
// default to no GLMode's associated with use of the StateAttribute.
|
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.
|
|
|
|
*/
|
|
|
|
virtual void apply(State&) const = 0 ;
|
|
|
|
|
|
|
|
/** default to nothing to compile - all state is applied immediately. */
|
|
|
|
virtual void compile(State&) const {};
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual ~StateAttribute() {}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|