| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | #include <osgUtil/PositionalStateContainer> |
|---|
| 14 | |
|---|
| 15 | using namespace osg; |
|---|
| 16 | using namespace osgUtil; |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | PositionalStateContainer::PositionalStateContainer() |
|---|
| 22 | { |
|---|
| 23 | } |
|---|
| 24 | |
|---|
| 25 | PositionalStateContainer::~PositionalStateContainer() |
|---|
| 26 | { |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | void PositionalStateContainer::reset() |
|---|
| 30 | { |
|---|
| 31 | _attrList.clear(); |
|---|
| 32 | _texAttrListMap.clear(); |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | void PositionalStateContainer::draw(osg::State& state,RenderLeaf*& previous, const osg::Matrix* postMultMatrix) |
|---|
| 36 | { |
|---|
| 37 | |
|---|
| 38 | if (previous) |
|---|
| 39 | { |
|---|
| 40 | StateGraph::moveToRootStateGraph(state,previous->_parent); |
|---|
| 41 | state.apply(); |
|---|
| 42 | previous = NULL; |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | for(AttrMatrixList::iterator litr=_attrList.begin(); |
|---|
| 47 | litr!=_attrList.end(); |
|---|
| 48 | ++litr) |
|---|
| 49 | { |
|---|
| 50 | if (postMultMatrix) |
|---|
| 51 | { |
|---|
| 52 | if ((*litr).second.valid()) |
|---|
| 53 | state.applyModelViewMatrix(new osg::RefMatrix( (*((*litr).second)) * (*postMultMatrix))); |
|---|
| 54 | else |
|---|
| 55 | state.applyModelViewMatrix(new osg::RefMatrix( *postMultMatrix)); |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | else |
|---|
| 59 | { |
|---|
| 60 | state.applyModelViewMatrix((*litr).second.get()); |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | litr->first->apply(state); |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | state.haveAppliedAttribute(litr->first.get()); |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | state.setGlobalDefaultAttribute(litr->first.get()); |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | for(TexUnitAttrMatrixListMap::iterator titr=_texAttrListMap.begin(); |
|---|
| 74 | titr!=_texAttrListMap.end(); |
|---|
| 75 | ++titr) |
|---|
| 76 | { |
|---|
| 77 | state.setActiveTextureUnit(titr->first); |
|---|
| 78 | |
|---|
| 79 | AttrMatrixList attrList = titr->second; |
|---|
| 80 | |
|---|
| 81 | for(AttrMatrixList::iterator litr=attrList.begin(); |
|---|
| 82 | litr!=attrList.end(); |
|---|
| 83 | ++litr) |
|---|
| 84 | { |
|---|
| 85 | if (postMultMatrix) |
|---|
| 86 | { |
|---|
| 87 | if ((*litr).second.valid()) |
|---|
| 88 | state.applyModelViewMatrix(new osg::RefMatrix( (*((*litr).second)) * (*postMultMatrix))); |
|---|
| 89 | else |
|---|
| 90 | state.applyModelViewMatrix(new osg::RefMatrix( *postMultMatrix)); |
|---|
| 91 | } |
|---|
| 92 | else |
|---|
| 93 | { |
|---|
| 94 | state.applyModelViewMatrix((*litr).second.get()); |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | litr->first->apply(state); |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | state.haveAppliedTextureAttribute(titr->first, litr->first.get()); |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | state.setGlobalDefaultTextureAttribute(titr->first, litr->first.get()); |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | } |
|---|
| 108 | } |
|---|