//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield //Distributed under the terms of the GNU Library General Public License (LGPL) //as published by the Free Software Foundation. #ifndef OSG_STATEATTRIBUTE #define OSG_STATEATTRIBUTE 1 #include #include #include #include #include namespace osg { // forward declare State & StateSet class State; class StateSet; /** 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(library,name,type) \ virtual osg::Object* cloneType() const { return osgNew name(); } \ virtual osg::Object* clone(const osg::CopyOp& copyop) const { return osgNew name (*this,copyop); } \ virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast(obj)!=NULL; } \ virtual const char* libraryName() const { return #library; } \ 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(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(obj)!=NULL; } /** return the name of the attribute's library.*/ virtual const char* libraryName() const { return "osg"; } /** return the name of the attribute's class type.*/ virtual const char* className() const { return "StateAttribute"; } /** return the Type identifier of the attribute's class type.*/ virtual const Type getType() const = 0; /** 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; } /** 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; } /** return the modes associated with this StateSet*/ virtual void getAssociatedModes(std::vector& /*modes*/) const { // default to no GLMode's associated with use of the StateAttribute. } /** 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