Changeset 13041 for OpenSceneGraph/trunk/src/osg/StateSet.cpp
- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/src/osg/StateSet.cpp (modified) (61 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osg/StateSet.cpp
r11472 r13041 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield 2 2 * 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 39 39 using namespace osg; 40 40 41 // local class to help porting from OSG0.8.x to 0.9.x 41 // local class to help porting from OSG0.8.x to 0.9.x 42 42 class TextureGLModeSet 43 43 { … … 61 61 _textureModeSet.insert(GL_TEXTURE_GEN_T); 62 62 } 63 63 64 64 bool isTextureMode(StateAttribute::GLMode mode) const 65 65 { … … 70 70 71 71 std::set<StateAttribute::GLMode> _textureModeSet; 72 72 73 73 }; 74 74 … … 89 89 { 90 90 _renderingHint = DEFAULT_BIN; 91 91 92 92 _numChildrenRequiringUpdateTraversal = 0; 93 93 _numChildrenRequiringEventTraversal = 0; … … 114 114 } 115 115 } 116 116 117 117 // copy texture related modes. 118 118 _textureModeList = rhs._textureModeList; 119 119 120 120 // set up the size of the texture attribute list. 121 121 _textureAttributeList.resize(rhs._textureAttributeList.size()); 122 122 123 123 // copy the contents across. 124 124 for(unsigned int i=0;i<rhs._textureAttributeList.size();++i) 125 125 { 126 126 127 127 AttributeList& lhs_attributeList = _textureAttributeList[i]; 128 128 const AttributeList& rhs_attributeList = rhs._textureAttributeList[i]; … … 156 156 } 157 157 } 158 158 159 159 _renderingHint = rhs._renderingHint; 160 160 … … 192 192 ++itr) 193 193 { 194 if (itr->second.first->getDataVariance()==UNSPECIFIED && 194 if (itr->second.first->getDataVariance()==UNSPECIFIED && 195 195 (itr->second.first->getUpdateCallback() || itr->second.first->getEventCallback())) 196 196 { … … 209 209 ++itr) 210 210 { 211 if (itr->second.first->getDataVariance()==UNSPECIFIED && 211 if (itr->second.first->getDataVariance()==UNSPECIFIED && 212 212 (itr->second.first->getUpdateCallback() || itr->second.first->getEventCallback())) 213 213 { … … 225 225 ++uitr) 226 226 { 227 if (uitr->second.first->getDataVariance()==UNSPECIFIED && 227 if (uitr->second.first->getDataVariance()==UNSPECIFIED && 228 228 (uitr->second.first->getUpdateCallback() || uitr->second.first->getEventCallback())) 229 229 { … … 274 274 if (_textureAttributeList.size()<rhs._textureAttributeList.size()) return -1; 275 275 if (_textureAttributeList.size()>rhs._textureAttributeList.size()) return 1; 276 276 277 277 for(unsigned int ai=0;ai<_textureAttributeList.size();++ai) 278 278 { … … 325 325 } 326 326 327 327 328 328 // now check the rest of the non texture attributes 329 329 if (compareAttributeContents) … … 371 371 else if (rhs_attr_itr == rhs._attributeList.end()) return 1; 372 372 } 373 374 // we've got here so attributes must be equal... 373 374 // we've got here so attributes must be equal... 375 375 376 376 … … 440 440 if (rhs_uniform_itr!=rhs._uniformList.end()) return -1; 441 441 } 442 else if (rhs_uniform_itr == rhs._uniformList.end()) return 1; 442 else if (rhs_uniform_itr == rhs._uniformList.end()) return 1; 443 443 444 444 // check render bin details 445 445 446 446 if ( _binMode < rhs._binMode ) return -1; 447 447 else if ( _binMode > rhs._binMode ) return 1; 448 448 449 449 if ( _binMode != INHERIT_RENDERBIN_DETAILS ) 450 450 { … … 527 527 528 528 void StateSet::setGlobalDefaults() 529 { 529 { 530 530 _renderingHint = DEFAULT_BIN; 531 531 … … 543 543 material->setColorMode(Material::AMBIENT_AND_DIFFUSE); 544 544 setAttributeAndModes(material,StateAttribute::ON); 545 545 546 546 #endif 547 547 } … … 562 562 itr->second.first->removeParent(this); 563 563 } 564 564 565 565 _modeList.clear(); 566 566 _attributeList.clear(); 567 567 568 568 569 569 // remove self from as texture attributes parent … … 596 596 void StateSet::merge(const StateSet& rhs) 597 597 { 598 // merge the modes of rhs into this, 598 // merge the modes of rhs into this, 599 599 // this overrides rhs if OVERRIDE defined in this. 600 600 for(ModeList::const_iterator rhs_mitr = rhs._modeList.begin(); … … 605 605 if (lhs_mitr!=_modeList.end()) 606 606 { 607 // take the rhs mode unless the lhs is override and the rhs is not protected 607 // take the rhs mode unless the lhs is override and the rhs is not protected 608 608 if (!(lhs_mitr->second & StateAttribute::OVERRIDE ) || 609 (rhs_mitr->second & StateAttribute::PROTECTED)) 609 (rhs_mitr->second & StateAttribute::PROTECTED)) 610 610 { 611 611 // override isn't on in rhs, so override it with incoming … … 621 621 } 622 622 623 // merge the attributes of rhs into this, 623 // merge the attributes of rhs into this, 624 624 // this overrides rhs if OVERRIDE defined in this. 625 625 for(AttributeList::const_iterator rhs_aitr = rhs._attributeList.begin(); … … 630 630 if (lhs_aitr!=_attributeList.end()) 631 631 { 632 // take the rhs attribute unless the lhs is override and the rhs is not protected 632 // take the rhs attribute unless the lhs is override and the rhs is not protected 633 633 if (!(lhs_aitr->second.second & StateAttribute::OVERRIDE) || 634 634 (rhs_aitr->second.second & StateAttribute::PROTECTED)) … … 668 668 ModeList& lhs_modeList = _textureModeList[mi]; 669 669 const ModeList& rhs_modeList = rhs._textureModeList[mi]; 670 // merge the modes of rhs into this, 670 // merge the modes of rhs into this, 671 671 // this overrides rhs if OVERRIDE defined in this. 672 672 for(ModeList::const_iterator rhs_mitr = rhs_modeList.begin(); … … 677 677 if (lhs_mitr!=lhs_modeList.end()) 678 678 { 679 // take the rhs mode unless the lhs is override and the rhs is not protected 679 // take the rhs mode unless the lhs is override and the rhs is not protected 680 680 if (!(lhs_mitr->second & StateAttribute::OVERRIDE) || 681 (rhs_mitr->second & StateAttribute::PROTECTED)) 681 (rhs_mitr->second & StateAttribute::PROTECTED)) 682 682 { 683 683 // override isn't on in rhs, so override it with incoming … … 693 693 } 694 694 } 695 695 696 696 if (_textureAttributeList.size()<rhs._textureAttributeList.size()) _textureAttributeList.resize(rhs._textureAttributeList.size()); 697 697 for(unsigned int ai=0;ai<rhs._textureAttributeList.size();++ai) … … 699 699 AttributeList& lhs_attributeList = _textureAttributeList[ai]; 700 700 const AttributeList& rhs_attributeList = rhs._textureAttributeList[ai]; 701 702 // merge the attributes of rhs into this, 701 702 // merge the attributes of rhs into this, 703 703 // this overrides rhs if OVERRIDE defined in this. 704 704 for(AttributeList::const_iterator rhs_aitr = rhs_attributeList.begin(); … … 709 709 if (lhs_aitr!=lhs_attributeList.end()) 710 710 { 711 // take the rhs attribute unless the lhs is override and the rhs is not protected 711 // take the rhs attribute unless the lhs is override and the rhs is not protected 712 712 if (!(lhs_aitr->second.second & StateAttribute::OVERRIDE) || 713 (rhs_aitr->second.second & StateAttribute::PROTECTED)) 713 (rhs_aitr->second.second & StateAttribute::PROTECTED)) 714 714 { 715 715 // override isn't on in rhs, so override it with incoming 716 716 // value. 717 717 718 718 if (lhs_aitr->second.first!=rhs_aitr->second.first) 719 719 { … … 736 736 } 737 737 738 // merge the uniforms of rhs into this, 738 // merge the uniforms of rhs into this, 739 739 // this overrides rhs if OVERRIDE defined in this. 740 740 for(UniformList::const_iterator rhs_uitr = rhs._uniformList.begin(); … … 745 745 if (lhs_uitr!=_uniformList.end()) 746 746 { 747 // take the rhs uniform unless the lhs is override and the rhs is not protected 747 // take the rhs uniform unless the lhs is override and the rhs is not protected 748 748 if (!(lhs_uitr->second.second & StateAttribute::OVERRIDE) || 749 (rhs_uitr->second.second & StateAttribute::PROTECTED)) 749 (rhs_uitr->second.second & StateAttribute::PROTECTED)) 750 750 { 751 751 // override isn't on in rhs, so override it with incoming … … 861 861 setTextureAttribute(0,attribute,value); 862 862 } 863 } 863 } 864 864 } 865 865 … … 873 873 { 874 874 removeAttribute(attribute->getType()); 875 } 875 } 876 876 else 877 877 { … … 896 896 if (itr!=_attributeList.end()) 897 897 { 898 if (itr->second.first->getUpdateCallback()) 898 if (itr->second.first->getUpdateCallback()) 899 899 { 900 900 setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()-1); 901 901 } 902 902 903 if (itr->second.first->getEventCallback()) 903 if (itr->second.first->getEventCallback()) 904 904 { 905 905 setNumChildrenRequiringEventTraversal(getNumChildrenRequiringEventTraversal()-1); … … 915 915 { 916 916 if (!attribute) return; 917 917 918 918 AttributeList::iterator itr = _attributeList.find(attribute->getTypeMemberPair()); 919 919 if (itr!=_attributeList.end()) 920 920 { 921 921 if (itr->second.first != attribute) return; 922 923 if (itr->second.first->getUpdateCallback()) 922 923 if (itr->second.first->getUpdateCallback()) 924 924 { 925 925 setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()-1); 926 926 } 927 927 928 if (itr->second.first->getEventCallback()) 928 if (itr->second.first->getEventCallback()) 929 929 { 930 930 setNumChildrenRequiringEventTraversal(getNumChildrenRequiringEventTraversal()-1); … … 959 959 int delta_update = 0; 960 960 int delta_event = 0; 961 961 962 962 UniformList::iterator itr=_uniformList.find(uniform->getName()); 963 963 if (itr==_uniformList.end()) … … 967 967 up.first = uniform; 968 968 up.second = value&(StateAttribute::OVERRIDE|StateAttribute::PROTECTED); 969 969 970 970 uniform->addParent(this); 971 972 if (uniform->getUpdateCallback()) 971 972 if (uniform->getUpdateCallback()) 973 973 { 974 974 delta_update = 1; 975 975 } 976 976 977 if (uniform->getEventCallback()) 977 if (uniform->getEventCallback()) 978 978 { 979 979 delta_event = 1; … … 992 992 if (itr->second.first->getUpdateCallback()) --delta_update; 993 993 if (itr->second.first->getEventCallback()) --delta_event; 994 994 995 995 uniform->addParent(this); 996 996 itr->second.first = uniform; … … 1002 1002 } 1003 1003 1004 if (delta_update!=0) 1004 if (delta_update!=0) 1005 1005 { 1006 1006 setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()+delta_update); 1007 1007 } 1008 1008 1009 if (delta_event!=0) 1009 if (delta_event!=0) 1010 1010 { 1011 1011 setNumChildrenRequiringEventTraversal(getNumChildrenRequiringEventTraversal()+delta_event); … … 1020 1020 if (itr!=_uniformList.end()) 1021 1021 { 1022 if (itr->second.first->getUpdateCallback()) 1022 if (itr->second.first->getUpdateCallback()) 1023 1023 { 1024 1024 setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()-1); 1025 1025 } 1026 1026 1027 if (itr->second.first->getEventCallback()) 1027 if (itr->second.first->getEventCallback()) 1028 1028 { 1029 1029 setNumChildrenRequiringEventTraversal(getNumChildrenRequiringEventTraversal()-1); … … 1039 1039 { 1040 1040 if (!uniform) return; 1041 1041 1042 1042 UniformList::iterator itr = _uniformList.find(uniform->getName()); 1043 1043 if (itr!=_uniformList.end()) … … 1045 1045 if (itr->second.first != uniform) return; 1046 1046 1047 if (itr->second.first->getUpdateCallback()) 1047 if (itr->second.first->getUpdateCallback()) 1048 1048 { 1049 1049 setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()-1); 1050 1050 } 1051 1051 1052 if (itr->second.first->getEventCallback()) 1052 if (itr->second.first->getEventCallback()) 1053 1053 { 1054 1054 setNumChildrenRequiringEventTraversal(getNumChildrenRequiringEventTraversal()-1); … … 1071 1071 // for look for an appropriate uniform. 1072 1072 UniformList::iterator itr = _uniformList.find(name); 1073 if (itr!=_uniformList.end() && 1073 if (itr!=_uniformList.end() && 1074 1074 itr->second.first->getType()==type) 1075 1075 { … … 1078 1078 1079 1079 // no uniform found matching name so create it.. 1080 1080 1081 1081 Uniform* uniform = new Uniform(type,name,numElements); 1082 1082 addUniform(uniform); 1083 1083 1084 1084 return uniform; 1085 1085 } … … 1174 1174 if (attribute) 1175 1175 { 1176 1176 1177 1177 if (attribute->isTextureAttribute()) 1178 1178 { … … 1210 1210 } 1211 1211 1212 if (itr->second.first->getUpdateCallback()) 1212 if (itr->second.first->getUpdateCallback()) 1213 1213 { 1214 1214 setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()-1); 1215 1215 } 1216 1216 1217 if (itr->second.first->getEventCallback()) 1217 if (itr->second.first->getEventCallback()) 1218 1218 { 1219 1219 setNumChildrenRequiringEventTraversal(getNumChildrenRequiringEventTraversal()-1); … … 1239 1239 setAssociatedTextureModes(unit,itr->second.first.get(),StateAttribute::INHERIT); 1240 1240 1241 if (itr->second.first->getUpdateCallback()) 1241 if (itr->second.first->getUpdateCallback()) 1242 1242 { 1243 1243 setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()-1); 1244 1244 } 1245 1245 1246 if (itr->second.first->getEventCallback()) 1246 if (itr->second.first->getEventCallback()) 1247 1247 { 1248 1248 setNumChildrenRequiringEventTraversal(getNumChildrenRequiringEventTraversal()-1); … … 1475 1475 _value(value), 1476 1476 _unit(unit) {} 1477 1477 1478 1478 virtual ~SetAssociateModesHelper() {} 1479 1479 1480 1480 virtual void usesMode(StateAttribute::GLMode mode) 1481 1481 { 1482 1482 _stateset->setMode(mode,_value); 1483 1483 } 1484 1484 1485 1485 virtual void usesTextureMode(StateAttribute::GLMode mode) 1486 1486 { 1487 1487 _stateset->setTextureMode(_unit,mode,_value); 1488 1488 } 1489 1490 1491 1489 1490 1491 1492 1492 StateSet* _stateset; 1493 1493 StateAttribute::GLModeValue _value; … … 1501 1501 _stateset(stateset), 1502 1502 _unit(unit) {} 1503 1503 1504 1504 virtual ~RemoveAssociateModesHelper() {} 1505 1505 1506 1506 virtual void usesMode(StateAttribute::GLMode mode) 1507 1507 { 1508 1508 _stateset->removeMode(mode); 1509 1509 } 1510 1510 1511 1511 virtual void usesTextureMode(StateAttribute::GLMode mode) 1512 1512 { 1513 1513 _stateset->removeTextureMode(_unit, mode); 1514 1514 } 1515 1516 1517 1515 1516 1517 1518 1518 StateSet* _stateset; 1519 1519 unsigned int _unit; … … 1550 1550 int delta_update = 0; 1551 1551 int delta_event = 0; 1552 1552 1553 1553 AttributeList::iterator itr=attributeList.find(attribute->getTypeMemberPair()); 1554 1554 if (itr==attributeList.end()) … … 1557 1557 attributeList[attribute->getTypeMemberPair()] = RefAttributePair(attribute,value&(StateAttribute::OVERRIDE|StateAttribute::PROTECTED)); 1558 1558 attribute->addParent(this); 1559 1560 if (attribute->getUpdateCallback()) 1559 1560 if (attribute->getUpdateCallback()) 1561 1561 { 1562 1562 delta_update = 1; 1563 1563 } 1564 1564 1565 if (attribute->getEventCallback()) 1565 if (attribute->getEventCallback()) 1566 1566 { 1567 1567 delta_event = 1; … … 1590 1590 } 1591 1591 1592 if (delta_update!=0) 1592 if (delta_update!=0) 1593 1593 { 1594 1594 setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()+delta_update); 1595 1595 } 1596 1596 1597 if (delta_event!=0) 1597 if (delta_event!=0) 1598 1598 { 1599 1599 setNumChildrenRequiringEventTraversal(getNumChildrenRequiringEventTraversal()+delta_event); … … 1644 1644 1645 1645 if (_updateCallback==ac) return; 1646 1646 1647 1647 int delta = 0; 1648 1648 if (_updateCallback.valid()) --delta; … … 1650 1650 1651 1651 _updateCallback = ac; 1652 1652 1653 1653 if (delta!=0 && _numChildrenRequiringUpdateTraversal==0) 1654 1654 { … … 1662 1662 1663 1663 osg::Drawable* drawable = dynamic_cast<osg::Drawable*>(*itr); 1664 if (drawable) 1664 if (drawable) 1665 1665 { 1666 1666 //drawable->setNumChildrenRequiringUpdateTraversal(drawable->getNumChildrenRequiringUpdateTraversal()+delta); 1667 1667 } 1668 else 1668 else 1669 1669 { 1670 1670 osg::Node* node = dynamic_cast<osg::Node*>(*itr); 1671 if (node) 1671 if (node) 1672 1672 { 1673 1673 node->setNumChildrenRequiringUpdateTraversal(node->getNumChildrenRequiringUpdateTraversal()+delta); … … 1724 1724 { 1725 1725 if (_eventCallback==ac) return; 1726 1726 1727 1727 int delta = 0; 1728 1728 if (_eventCallback.valid()) --delta; … … 1730 1730 1731 1731 _eventCallback = ac; 1732 1732 1733 1733 if (delta!=0 && _numChildrenRequiringEventTraversal==0) 1734 1734 { … … 1738 1738 { 1739 1739 osg::Drawable* drawable = dynamic_cast<osg::Drawable*>(*itr); 1740 if (drawable) 1740 if (drawable) 1741 1741 { 1742 1742 //drawable->setNumChildrenRequiringUpdateTraversal(drawable->getNumChildrenRequiringUpdateTraversal()+delta); 1743 1743 } 1744 else 1744 else 1745 1745 { 1746 1746 osg::Node* node = dynamic_cast<osg::Node*>(*itr); 1747 if (node) 1747 if (node) 1748 1748 { 1749 1749 node->setNumChildrenRequiringEventTraversal(node->getNumChildrenRequiringEventTraversal()+delta); … … 1805 1805 if (!_updateCallback && !_parents.empty()) 1806 1806 { 1807 1808 // need to pass on changes to parents. 1807 1808 // need to pass on changes to parents. 1809 1809 int delta = 0; 1810 1810 if (_numChildrenRequiringUpdateTraversal>0) --delta; … … 1818 1818 itr != _parents.end(); 1819 1819 ++itr) 1820 { 1820 { 1821 1821 osg::Drawable* drawable = dynamic_cast<osg::Drawable*>(*itr); 1822 if (drawable) 1822 if (drawable) 1823 1823 { 1824 1824 drawable->setNumChildrenRequiringUpdateTraversal(drawable->getNumChildrenRequiringUpdateTraversal()+delta); 1825 1825 } 1826 else 1826 else 1827 1827 { 1828 1828 osg::Node* node = dynamic_cast<osg::Node*>(*itr); 1829 if (node) 1829 if (node) 1830 1830 { 1831 1831 node->setNumChildrenRequiringUpdateTraversal(node->getNumChildrenRequiringUpdateTraversal()+delta); … … 1835 1835 } 1836 1836 } 1837 1837 1838 1838 // finally update this objects value. 1839 1839 _numChildrenRequiringUpdateTraversal=num; … … 1850 1850 if (!_eventCallback && !_parents.empty()) 1851 1851 { 1852 1853 // need to pass on changes to parents. 1852 1853 // need to pass on changes to parents. 1854 1854 int delta = 0; 1855 1855 if (_numChildrenRequiringEventTraversal>0) --delta; … … 1863 1863 itr != _parents.end(); 1864 1864 ++itr) 1865 { 1865 { 1866 1866 osg::Drawable* drawable = dynamic_cast<osg::Drawable*>(*itr); 1867 if (drawable) 1867 if (drawable) 1868 1868 { 1869 1869 drawable->setNumChildrenRequiringEventTraversal(drawable->getNumChildrenRequiringEventTraversal()+delta); 1870 1870 } 1871 else 1871 else 1872 1872 { 1873 1873 osg::Node* node = dynamic_cast<osg::Node*>(*itr); 1874 if (node) 1874 if (node) 1875 1875 { 1876 1876 node->setNumChildrenRequiringEventTraversal(node->getNumChildrenRequiringEventTraversal()+delta); … … 1880 1880 } 1881 1881 } 1882 1882 1883 1883 // finally Event this objects value. 1884 1884 _numChildrenRequiringEventTraversal=num;
