fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / NodeCores / Groups / Misc / OSGMaterialChunkOverrideGroup.cpp
blobfcae7bb8c539fea404f7ed6d627113c781e991e2
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2006 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: Johannes Brunen *
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 //---------------------------------------------------------------------------
40 // Includes
41 //---------------------------------------------------------------------------
43 #include <cstdlib>
44 #include <cstdio>
46 #include "OSGConfig.h"
48 #include "OSGMaterialChunkOverrideGroup.h"
49 #include "OSGRenderAction.h"
50 #include "OSGChunkMaterial.h"
51 #include "OSGStateChunk.h"
53 OSG_BEGIN_NAMESPACE
55 // Documentation for this class is emitted in the
56 // OSGMaterialChunkOverrideGroupBase.cpp file.
57 // To modify it, please change the .fcd file (OSGMaterialChunkOverrideGroup.fcd) and
58 // regenerate the base file.
60 /***************************************************************************\
61 * Class variables *
62 \***************************************************************************/
64 /***************************************************************************\
65 * Class methods *
66 \***************************************************************************/
68 void MaterialChunkOverrideGroup::initMethod(InitPhase ePhase)
70 Inherited::initMethod(ePhase);
72 if(ePhase == TypeObject::SystemPost)
74 RenderAction::registerEnterDefault(
75 MaterialChunkOverrideGroup::getClassType(),
76 reinterpret_cast<Action::Callback>(
77 &MaterialChunkOverrideGroup::renderEnter));
79 RenderAction::registerLeaveDefault(
80 MaterialChunkOverrideGroup::getClassType(),
81 reinterpret_cast<Action::Callback>(
82 &MaterialChunkOverrideGroup::renderLeave));
87 /***************************************************************************\
88 * Instance methods *
89 \***************************************************************************/
91 /*-------------------------------------------------------------------------*\
92 - private -
93 \*-------------------------------------------------------------------------*/
95 /*----------------------- constructors & destructors ----------------------*/
97 MaterialChunkOverrideGroup::MaterialChunkOverrideGroup(void) :
98 Inherited()
102 MaterialChunkOverrideGroup::MaterialChunkOverrideGroup(
103 const MaterialChunkOverrideGroup &source) :
105 Inherited(source)
109 MaterialChunkOverrideGroup::~MaterialChunkOverrideGroup(void)
113 /*----------------------------- class specific ----------------------------*/
115 void MaterialChunkOverrideGroup::changed(ConstFieldMaskArg whichField,
116 UInt32 origin,
117 BitVector details)
119 Inherited::changed(whichField, origin, details);
122 void MaterialChunkOverrideGroup::dump( UInt32 ,
123 const BitVector ) const
125 SLOG << "Dump MaterialChunkOverrideGroup NI" << std::endl;
128 /*-------------------------------------------------------------------------*/
129 /* Render */
131 Action::ResultE MaterialChunkOverrideGroup::renderEnter(Action *action)
133 RenderAction *pAction = dynamic_cast<RenderAction *>(action);
134 Material *pMaterial = this->getMaterial();
136 if(pAction != NULL && pMaterial != NULL)
138 pMaterial = pMaterial->finalize(pAction->getRenderProperties(),
139 pAction->getCurrentOverrides(),
140 pAction->getWindow ());
142 if(pMaterial)
144 ChunkMaterial *pChunkMaterial =
145 dynamic_cast<ChunkMaterial*>(pMaterial);
147 if(pChunkMaterial != NULL)
149 ChunkBlockUnrecPtr pBlock = this->finalize(0x0000);
151 if(pBlock == NULL)
153 pBlock = ChunkBlock::create();
155 this->addChunkBlock(pBlock, 0x0000);
158 pChunkMaterial->fill(pBlock);
160 return Inherited::renderEnter(action);
162 else
164 Action::ResultE r = Group::renderEnter(action);
166 // ok all children are culled away so we leave
167 // immediately and don't set the material!
168 if(r == Action::Skip)
169 return r;
171 pAction->overrideMaterial(pMaterial, pAction->getActNode());
173 return r;
178 return Group::renderEnter(action);
181 Action::ResultE MaterialChunkOverrideGroup::renderLeave(Action *action)
183 RenderAction *pAction = dynamic_cast<RenderAction *>(action);
184 Material *pMaterial = this->getMaterial();
186 if(pAction != NULL && pMaterial != NULL)
188 pMaterial = pMaterial->finalize(pAction->getRenderProperties(),
189 pAction->getCurrentOverrides(),
190 pAction->getWindow ());
192 if(pMaterial != NULL)
194 ChunkMaterial *pChunkMaterial =
195 dynamic_cast<ChunkMaterial*>(pMaterial);
197 if(pChunkMaterial != NULL)
199 ChunkBlockUnrecPtr pBlock = this->finalize(0x0000);
201 if(pBlock != NULL)
202 pBlock->clearChunks();
205 return Inherited::renderLeave(action);
207 else
209 pAction->overrideMaterial(NULL, pAction->getActNode());
213 return Group::renderLeave(action);
216 OSG_END_NAMESPACE