1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
42 #include "OSGConfig.h"
44 #include "OSGRenderTreeNodePool.h"
45 #include "OSGTreeBuilderBase.h"
46 #include "OSGBaseFunctions.h"
47 #include "OSGRenderPartitionBase.h"
51 //#define OSG_DUMP_SORTING
55 /*! \class OSG::TreeBuilderBase
56 \ingroup GrpSystemRenderingBackend
59 /*-------------------------------------------------------------------------*/
63 TreeBuilderBase::TreeBuilderBase(void) :
73 TreeBuilderBase::~TreeBuilderBase(void)
77 void TreeBuilderBase::setNodePool(RenderTreeNodePool
*pNodePool
)
79 _pNodePool
= pNodePool
;
82 RenderTreeNodePool
*TreeBuilderBase::getNodePool(void)
87 void TreeBuilderBase::reset(void)
92 void TreeBuilderBase::drawNode(RenderTreeNode
*pNode
,
94 RenderPartitionBase
*part
)
98 UInt32 uiNextMatrix
= pNode
->getMatrixStore().first
;
100 if(uiNextMatrix
!= 0 && uiNextMatrix
!= _uiActiveMatrix
)
102 #if !defined(OSG_OGL_COREONLY)
103 glLoadMatrixf(pNode
->getMatrixStore().second
.getValues());
106 _uiActiveMatrix
= uiNextMatrix
;
108 _currMatrix
.second
= pNode
->getMatrixStore().second
;
110 updateTopMatrix(denv
);
112 denv
.setObjectToWorld(_accMatrix
);
113 denv
._openGLState
.setModelView (_currMatrix
.second
);
115 ++part
->_uiNumMatrixChanges
;
117 // Negative scaled matrices in conjunction with double sided
119 // gives wrong render results cause the lighting itselfs gets
120 // inverted. This corrects this behavior.
122 if(part
->_bCorrectNegScale
)
124 const Matrix
&m
= _currMatrix
.second
;
126 // test for a "flipped" matrix
127 // glFrontFace can give conflicts with the polygon chunk ...
129 if(m
[0].cross(m
[1]).dot(m
[2]) < 0.0)
140 State
*pNewState
= pNode
->getState();
141 StateOverride
*pNewStateOverride
= pNode
->getStateOverride();
143 denv
.setLightState(pNode
->getLightState());
144 denv
.setSGNode (pNode
->getNode ());
146 denv
.activateState(pNewState
, pNewStateOverride
);
148 if(pNode
->hasFunctor() == true)
150 pNode
->getFunctor()(&denv
);
153 denv
.setSGNode(NULL
);
155 if(pNode
->getFirstChild() != NULL
)
157 drawNode(pNode
->getFirstChild(), denv
, part
);
160 pNode
= pNode
->getBrother();
164 void TreeBuilderBase::updateTopMatrix(DrawEnv
&denv
)
166 _accMatrix
= denv
.getCameraToWorld();
167 _accMatrix
.mult(_currMatrix
.second
);
170 const Matrix
&TreeBuilderBase::topMatrix(void)