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 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
41 //---------------------------------------------------------------------------
45 #include <boost/bind.hpp>
47 #include "OSGConfig.h"
49 #include "OSGMaterialDrawable.h"
51 #include "OSGRenderAction.h"
52 #include "OSGPrimeMaterial.h"
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 ----------------------*/
64 MaterialDrawable::MaterialDrawable(void) :
71 MaterialDrawable::MaterialDrawable(const MaterialDrawable
&source
) :
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
;
93 if(this->getMaterial() != NULL
)
96 this->getMaterial()->finalize(a
->getRenderProperties(),
97 a
->getCurrentOverrides(),
103 pPrimeMat
= m
->finalize(a
->getRenderProperties(),
104 a
->getCurrentOverrides(),
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
);
123 a
->dropFunctor(_drawFunc
,
125 pPrimeMat
->getSortKey() + uiPass
);
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)
143 return Action::Continue
;
146 Action::ResultE
MaterialDrawable::renderLeave(Action
*action
)
148 RenderAction
*a
= dynamic_cast<RenderAction
*>(action
);
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"));
163 void MaterialDrawable::initMethod(InitPhase ePhase
)
165 Inherited::initMethod(ePhase
);
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
,
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
;