fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / RenderingBackend / OSGTreeBuilderBase.cpp
blobd3e427cb4fe3109c03f168fddae1274059c8289c
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
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. *
18 * *
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. *
23 * *
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. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 #include <cstdlib>
40 #include <cstdio>
42 #include "OSGConfig.h"
44 #include "OSGRenderTreeNodePool.h"
45 #include "OSGTreeBuilderBase.h"
46 #include "OSGBaseFunctions.h"
47 #include "OSGRenderPartitionBase.h"
49 #include "OSGGLEXT.h"
51 //#define OSG_DUMP_SORTING
53 OSG_BEGIN_NAMESPACE
55 /*! \class OSG::TreeBuilderBase
56 \ingroup GrpSystemRenderingBackend
59 /*-------------------------------------------------------------------------*/
60 /* Constructors */
63 TreeBuilderBase::TreeBuilderBase(void) :
64 _pNodePool (NULL),
65 _uiNodePoolIdx (0 ),
66 _uiActiveMatrix (0 ),
67 _uiMatrixId (0 ),
68 _currMatrix ( ),
69 _accMatrix ( )
73 TreeBuilderBase::~TreeBuilderBase(void)
77 void TreeBuilderBase::setNodePool(RenderTreeNodePool *pNodePool)
79 _pNodePool = pNodePool;
82 RenderTreeNodePool *TreeBuilderBase::getNodePool(void)
84 return _pNodePool;
87 void TreeBuilderBase::reset(void)
89 _uiMatrixId = 0;
92 void TreeBuilderBase::drawNode(RenderTreeNode *pNode,
93 DrawEnv &denv,
94 RenderPartitionBase *part)
96 while (pNode != NULL)
98 UInt32 uiNextMatrix = pNode->getMatrixStore().first;
100 if(uiNextMatrix != 0 && uiNextMatrix != _uiActiveMatrix)
102 #if !defined(OSG_OGL_COREONLY)
103 glLoadMatrixf(pNode->getMatrixStore().second.getValues());
104 #endif
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
118 // lighting
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)
131 glFrontFace(GL_CW);
133 else
135 glFrontFace(GL_CCW);
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)
172 return _accMatrix;
175 OSG_END_NAMESPACE