1 /* -*-c++-*-
2  *
3  * Copyright (C) 2006 Mathias Froehlich
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18  * MA 02110-1301, USA.
19  *
20  */
21 
22 #ifdef HAVE_CONFIG_H
23 #  include <simgear_config.h>
24 #endif
25 
26 #include "SGTextureStateAttributeVisitor.hxx"
27 
SGTextureStateAttributeVisitor()28 SGTextureStateAttributeVisitor::SGTextureStateAttributeVisitor() :
29   osg::NodeVisitor(osg::NodeVisitor::NODE_VISITOR,
30                    osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
31 {
32 }
33 
34 void
apply(int textureUnit,osg::StateSet::RefAttributePair & refAttr)35 SGTextureStateAttributeVisitor::apply(int textureUnit, osg::StateSet::RefAttributePair& refAttr)
36 {
37 }
38 
39 void
apply(int textureUnit,osg::StateSet::AttributeList & attrList)40 SGTextureStateAttributeVisitor::apply(int textureUnit, osg::StateSet::AttributeList& attrList)
41 {
42   osg::StateSet::AttributeList::iterator i;
43   i = attrList.begin();
44   while (i != attrList.end()) {
45     apply(textureUnit, i->second);
46     ++i;
47   }
48 }
49 
50 void
apply(osg::StateSet::TextureAttributeList & attrList)51 SGTextureStateAttributeVisitor::apply(osg::StateSet::TextureAttributeList& attrList)
52 {
53   for (unsigned i = 0; i < attrList.size(); ++i)
54     apply(i, attrList[i]);
55 }
56 
57 void
apply(osg::StateSet * stateSet)58 SGTextureStateAttributeVisitor::apply(osg::StateSet* stateSet)
59 {
60   if (!stateSet)
61     return;
62   apply(stateSet->getTextureAttributeList());
63 }
64 
65 void
apply(osg::Node & node)66 SGTextureStateAttributeVisitor::apply(osg::Node& node)
67 {
68   apply(node.getStateSet());
69   traverse(node);
70 }
71 
72 void
apply(osg::Geode & node)73 SGTextureStateAttributeVisitor::apply(osg::Geode& node)
74 {
75   unsigned nDrawables = node.getNumDrawables();
76   for (unsigned i = 0; i < nDrawables; ++i)
77     apply(node.getDrawable(i)->getStateSet());
78   apply(node.getStateSet());
79   traverse(node);
80 }
81