1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2006 by the OpenSG Forum *
9 * contact: Johannes Brunen *
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 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
41 //---------------------------------------------------------------------------
46 #include "OSGConfig.h"
48 #include "OSGMaterialChunkOverrideGroup.h"
49 #include "OSGRenderAction.h"
50 #include "OSGChunkMaterial.h"
51 #include "OSGStateChunk.h"
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 /***************************************************************************\
62 \***************************************************************************/
64 /***************************************************************************\
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 /***************************************************************************\
89 \***************************************************************************/
91 /*-------------------------------------------------------------------------*\
93 \*-------------------------------------------------------------------------*/
95 /*----------------------- constructors & destructors ----------------------*/
97 MaterialChunkOverrideGroup::MaterialChunkOverrideGroup(void) :
102 MaterialChunkOverrideGroup::MaterialChunkOverrideGroup(
103 const MaterialChunkOverrideGroup
&source
) :
109 MaterialChunkOverrideGroup::~MaterialChunkOverrideGroup(void)
113 /*----------------------------- class specific ----------------------------*/
115 void MaterialChunkOverrideGroup::changed(ConstFieldMaskArg whichField
,
119 Inherited::changed(whichField
, origin
, details
);
122 void MaterialChunkOverrideGroup::dump( UInt32
,
123 const BitVector
) const
125 SLOG
<< "Dump MaterialChunkOverrideGroup NI" << std::endl
;
128 /*-------------------------------------------------------------------------*/
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 ());
144 ChunkMaterial
*pChunkMaterial
=
145 dynamic_cast<ChunkMaterial
*>(pMaterial
);
147 if(pChunkMaterial
!= NULL
)
149 ChunkBlockUnrecPtr pBlock
= this->finalize(0x0000);
153 pBlock
= ChunkBlock::create();
155 this->addChunkBlock(pBlock
, 0x0000);
158 pChunkMaterial
->fill(pBlock
);
160 return Inherited::renderEnter(action
);
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
)
171 pAction
->overrideMaterial(pMaterial
, pAction
->getActNode());
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);
202 pBlock
->clearChunks();
205 return Inherited::renderLeave(action
);
209 pAction
->overrideMaterial(NULL
, pAction
->getActNode());
213 return Group::renderLeave(action
);