#ifndef OSG_GEOSTATE #define OSG_GEOSTATE 1 #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace osg { class Input; class Output; /** Encapsulates OpenGL state modes and attributes. Used to specificy textures etc of osg::GeoSet's which hold references to a single osg::GeoState. GeoState can be shared between GeoSet's and is recommend if possible as it minimize expensive state changes in the graphics pipeline. */ class SG_EXPORT GeoState : public Object { public : enum AttributeType { ANTIALIAS, FACE_CULL, FOG, LIGHTING, MATERIAL, POINT, POLYGON_OFFSET, TEXENV, TEXGEN, TEXMAT, TEXTURE, TRANSPARENCY, WIREFRAME, ALPHAFUNC }; enum AttributeMode { INHERIT, OFF, ON, OVERRIDE_OFF, OVERRIDE_ON, }; GeoState(); static GeoState* instance(); virtual Object* clone() const { return new GeoState(); } virtual bool isSameKindAs(Object* obj) { return dynamic_cast(obj)!=NULL; } const char* className() const { return "GeoState"; } /** set all the modes to on or off so that it defines a complete state, typically used for a default global state.*/ void setGlobalDefaults(); /** set all the modes to inherit, typically used to signifiy nodes which inherit all of their modes for the global state.*/ void setAllToInherit(); void setMode(AttributeType type, AttributeMode mode); AttributeMode getMode(AttributeType type) const; void setAttribute(AttributeType type, Object *attribute); Object* getAttribute(AttributeType type) const; bool isTransparent() { return _transparencing==ON; } void apply(); void apply(GeoState* global,GeoState* prev); bool check(); static AttributeMode combineMode(const AttributeMode g,const AttributeMode p,const AttributeMode c) { AttributeMode gp = mergeMode(g,p); AttributeMode gc = mergeMode(g,c); if (gc==gp) return INHERIT; else return gc; } static AttributeMode mergeMode(const AttributeMode lhs,const AttributeMode rhs) { AttributeMode mode; if (rhs==INHERIT || lhs==OVERRIDE_OFF || lhs==OVERRIDE_ON) mode = lhs; else mode = rhs; if (mode==OVERRIDE_OFF) return OFF; else if (mode==OVERRIDE_OFF) return ON; return mode; } protected : virtual ~GeoState(); GeoState(const GeoState&):Object() {} GeoState& operator = (const GeoState&) { return *this; } virtual bool readLocalData(Input& fr); virtual bool writeLocalData(Output& fw); bool matchModeStr(const char* str, AttributeMode& mode); const char* getModeStr(AttributeMode flag); // Modes AttributeMode _transparencing; AttributeMode _face_culling; AttributeMode _lighting; AttributeMode _texturing; AttributeMode _fogging; AttributeMode _texgening; AttributeMode _antialiasing; AttributeMode _colortable; AttributeMode _pointSmoothing; AttributeMode _polygonOffsetting; AttributeMode _alphaTesting; // Attributes ref_ptr _texture; ref_ptr _texgen; ref_ptr _material; ref_ptr _texenv; ref_ptr _transparency; ref_ptr _texmat; ref_ptr _fog; ref_ptr _point; ref_ptr _polygonOffset; ref_ptr _cullFace; ref_ptr _alphaFunc; }; }; #endif