Add ClusterShadingStage
[opensg.git] / Source / System / NodeCores / Drawables / Base / OSGMaterialDrawable.cpp
blobaf82036373b8fcb24149c0c43151002c90391cd5
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 //---------------------------------------------------------------------------
40 // Includes
41 //---------------------------------------------------------------------------
43 #include <cstdlib>
44 #include <cstdio>
45 #include <boost/bind.hpp>
47 #include "OSGConfig.h"
49 #include "OSGMaterialDrawable.h"
51 #include "OSGRenderAction.h"
52 #include "OSGPrimeMaterial.h"
54 OSG_USING_NAMESPACE
56 // Documentation for this class is emited in the
57 // OSGMaterialDrawableBase.cpp file.
58 // To modify it, please change the .fcd file (OSGMaterialDrawable.fcd) and
59 // regenerate the base file.
61 /*----------------------- constructors & destructors ----------------------*/
63 //! Constructor
64 MaterialDrawable::MaterialDrawable(void) :
65 Inherited(),
66 _drawFunc()
70 //! Copy Constructor
71 MaterialDrawable::MaterialDrawable(const MaterialDrawable &source) :
72 Inherited(source),
73 _drawFunc()
77 //! Destructor
78 MaterialDrawable::~MaterialDrawable(void)
82 /*----------------------------- class specific ----------------------------*/
84 Action::ResultE MaterialDrawable::renderEnter(Action *action)
86 RenderAction *a = dynamic_cast<RenderAction *>(action);
88 Material *m = a->getMaterial();
89 PrimeMaterial *pPrimeMat = NULL;
91 if(m == NULL)
93 if(this->getMaterial() != NULL)
95 pPrimeMat =
96 this->getMaterial()->finalize(a->getRenderProperties(),
97 a->getCurrentOverrides(),
98 a->getWindow() );
101 else
103 pPrimeMat = m->finalize(a->getRenderProperties(),
104 a->getCurrentOverrides(),
105 a->getWindow ());
108 if(pPrimeMat == NULL)
110 pPrimeMat = getDefaultMaterial();
112 FNOTICE(("MaterialDrawable::render: no Material!?!\n"));
115 UInt32 uiNPasses = pPrimeMat->getNPasses();
117 for(UInt32 uiPass = 0; uiPass < uiNPasses; ++uiPass)
119 State *st = pPrimeMat->getState(uiPass);
121 if(st != NULL)
123 a->dropFunctor(_drawFunc,
124 st,
125 pPrimeMat->getSortKey() + uiPass);
127 else
129 FINFO(("%s: Material %p has NULL state for pass %d\n",
130 OSG_FUNCNAME_MACRO, static_cast<void *>(pPrimeMat), uiPass));
134 if(a->pushVisibility())
136 if(a->selectVisibles() == 0)
138 a->popVisibility();
139 return Action::Skip;
143 return Action::Continue;
146 Action::ResultE MaterialDrawable::renderLeave(Action *action)
148 RenderAction *a = dynamic_cast<RenderAction *>(action);
150 a->popVisibility();
152 return Action::Continue;
155 //! initialize the static features of the class, e.g. action callbacks
156 void MaterialDrawable::drawPrimitives(DrawEnv *)
158 FWARNING (("You should overload drawPrimitives in your code\n"));
160 return;
163 void MaterialDrawable::initMethod(InitPhase ePhase)
165 Inherited::initMethod(ePhase);
168 void
169 MaterialDrawable::onCreateAspect(const MaterialDrawable *createAspect,
170 const MaterialDrawable *source )
172 Inherited::onCreateAspect(createAspect, source);
174 _drawFunc = boost::bind(&MaterialDrawable::drawPrimitives, this, _1);
177 //! react to field changes
178 void MaterialDrawable::changed(ConstFieldMaskArg whichField,
179 UInt32 origin,
180 BitVector details)
182 Inherited::changed(whichField, origin, details);
185 //! output the instance for debug purposes
186 void MaterialDrawable::dump( UInt32 ,
187 const BitVector ) const
189 SLOG << "Dump MaterialDrawable NI" << std::endl;