OSG笔记:父子节点间状态(osg::StateAttribute)的继承、覆盖、保护

本文主要介绍osg::StateAttribute类中的枚举值,包括OFF、ON、OVERRIDE、PROTECTED、INHERIT,阐述了各枚举值的含义,如OFF关闭指定状态,OVERRIDE会覆盖子节点状态等。还指出可通过运算符 | 组合枚举值,节点对自身状态有自主权。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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时)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值