osg::StateAttribute类中有如下枚举

/** list values which can be used to set either GLModeValues or OverrideValues.
* When using in conjunction with GLModeValues, all Values have meaning.
* When using in conjunction 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, so that state below it is overridden.*/
OVERRIDE = 0x2,
/** Protecting of GLMode's or StateAttributes is enabled, so that state from above cannot override this and below state.*/
PROTECTED = 0x4,
/** means that GLMode or StateAttribute should be inherited from above.*/
INHERIT = 0x8
};

对枚举值的理解

  • osg::StateAttribute::OFF
    关闭指定状态
  • osg::StateAttribute::ON
    打开指定状态,此处不会覆盖子节点及子孙节点状态
  • osg::StateAttribute::OVERRIDE
    会覆盖子节点及子孙节点的状态,即使子节点或子孙节点对此状态设置了关闭,也一样会被覆盖到。除非它们使用osg::StateAttribute::PROTECTED设置了对自己状态的保护
  • osg::StateAttribute::PROTECTED
    此节点对自己的状态有保护作用,不会受父节点或祖先节点状态的覆盖。
  • osg::StateAttribute::INHERIT
    继承父节点或祖先节点的状态。若祖先节点没有设置状态的OVERRIDE,此节点又想继承的话,就可设置INHERIT枚举值。

总结

  1. 可通过运行符 | 来组合这些枚举值
  2. 节点对自身状态有绝对的自主权。
  • 通过osg::StateAttribute::INHERT,可以自己选择继承上层节点的状态(如:在上层节点没有设置自己状态OVERRIDE时)
  • 通过osg::StateAttribute::PROTECTED, 可以自己选择自己的状态是否能被上层节点的状态覆盖(如:上层节点设置自己状态为OVERRIDE时)
  • 通过osg::StateAttribute::OVERRIDE,可以允许自己的状态覆盖下层节点的状态(在下层节点没有设置PROTECTED时)