Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGMaterialGroup.cpp

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright (C) 2000-2002 by the OpenSG Forum                   *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038 
00039 #include <stdlib.h>
00040 #include <stdio.h>
00041 
00042 #include <OSGConfig.h>
00043 
00044 #include "OSGNodePtr.h"
00045 #include "OSGMaterialGroup.h"
00046 #include "OSGDrawAction.h"
00047 #include "OSGRenderAction.h"
00048 
00049 OSG_USING_NAMESPACE
00050 
00054 /*-------------------------------------------------------------------------*/
00055 /*                                Sync                                     */
00056 
00057 void MaterialGroup::changed(BitVector whichField, UInt32 origin)
00058 {
00059     if(whichField & MaterialFieldMask)
00060     {
00061         if(origin & ChangedOrigin::Abstract)
00062         {
00063             if(origin & ChangedOrigin::AbstrIncRefCount)
00064             {
00065                 addRefCP(_sfMaterial.getValue());
00066             }
00067             else
00068             {
00069                 MaterialPtr pMat = _sfMaterial.getValue();
00070                 
00071                 _sfMaterial.setValue(NullFC);
00072                 
00073                 setMaterial(pMat);
00074             }
00075         }
00076     }
00077 
00078     Inherited::changed(whichField, origin);
00079 }
00080 
00081 /*-------------------------------------------------------------------------*/
00082 /*                                Dump                                     */
00083 
00084 void MaterialGroup::dump(      UInt32    uiIndent, 
00085                          const BitVector bvFlags) const
00086 {
00087     Inherited::dump(uiIndent, bvFlags);
00088 }
00089 
00090 /*-------------------------------------------------------------------------*/
00091 /*                            Constructors                                 */
00092 
00093 MaterialGroup::MaterialGroup(void) :
00094     Inherited()
00095 {
00096 }
00097 
00098 MaterialGroup::MaterialGroup(const MaterialGroup &source) :
00099     Inherited(source)
00100 {
00101 }
00102 
00103 /*-------------------------------------------------------------------------*/
00104 /*                             Destructor                                  */
00105 
00106 MaterialGroup::~MaterialGroup(void)
00107 {
00108     subRefCP(_sfMaterial.getValue());
00109 }
00110 
00111 /*-------------------------------------------------------------------------*/
00112 /*                                Draw                                     */
00113 
00114 Action::ResultE MaterialGroup::drawEnter(Action *action)
00115 {
00116     DrawAction *da = dynamic_cast<DrawAction *>(action);
00117 
00118     if(da != NULL && _sfMaterial.getValue() != NullFC &&
00119        da->getMaterial() == NULL)
00120     {
00121         da->setMaterial(&(*(_sfMaterial.getValue())), action->getActNode());
00122     }
00123 
00124     da->selectVisibles();
00125     
00126     return Action::Continue;
00127 }
00128 
00129 Action::ResultE MaterialGroup::drawLeave(Action * action)
00130 {
00131     DrawAction *da = dynamic_cast<DrawAction *>(action);
00132 
00133     if(da != NULL && da->getMaterialNode() == action->getActNode())
00134     {
00135         da->setMaterial(NULL, NullFC);
00136     }
00137 
00138     return Action::Continue;
00139 }
00140 
00141 /*-------------------------------------------------------------------------*/
00142 /*                               Render                                    */
00143 
00144 Action::ResultE MaterialGroup::renderEnter(Action * action)
00145 {
00146     RenderAction *da = dynamic_cast<RenderAction *>(action);
00147 
00148     if(da != NULL && _sfMaterial.getValue() != NullFC &&
00149        da->getMaterial() == NULL)
00150     {
00151         da->setMaterial(&(*(_sfMaterial.getValue())), action->getActNode());
00152     }
00153 
00154     return Group::renderEnter(action);
00155 }
00156 
00157 Action::ResultE MaterialGroup::renderLeave(Action * action)
00158 {
00159     RenderAction *da = dynamic_cast<RenderAction *>(action);
00160 
00161     if(da != NULL && da->getMaterialNode() == action->getActNode())
00162     {
00163         da->setMaterial(NULL, NullFC);
00164     }
00165 
00166     return Group::renderLeave(action);
00167 }
00168 
00169 /*-------------------------------------------------------------------------*/
00170 /*                                Init                                     */
00171  
00172 void MaterialGroup::initMethod(void)
00173 {
00174     DrawAction::registerEnterDefault( 
00175         getClassType(), 
00176         osgTypedMethodFunctor2BaseCPtrRef<
00177             Action::ResultE,
00178             MaterialGroupPtr  , 
00179             CNodePtr          ,  
00180             Action           *>(&MaterialGroup::drawEnter));
00181 
00182     DrawAction::registerLeaveDefault( 
00183         getClassType(), 
00184         osgTypedMethodFunctor2BaseCPtrRef<
00185             Action::ResultE,
00186             MaterialGroupPtr  , 
00187             CNodePtr          ,  
00188             Action           *>(&MaterialGroup::drawLeave));
00189 
00190     RenderAction::registerEnterDefault(
00191         getClassType(), 
00192         osgTypedMethodFunctor2BaseCPtrRef<
00193             Action::ResultE,
00194             MaterialGroupPtr  , 
00195             CNodePtr          ,  
00196             Action           *>(&MaterialGroup::renderEnter));
00197 
00198     RenderAction::registerLeaveDefault(
00199         getClassType(), 
00200         osgTypedMethodFunctor2BaseCPtrRef<
00201             Action::ResultE,
00202             MaterialGroupPtr  , 
00203             CNodePtr          ,  
00204             Action           *>(&MaterialGroup::renderLeave));
00205 }
00206 
00207 
00208 /*-------------------------------------------------------------------------*/
00209 /*                              cvs id's                                   */
00210 
00211 #ifdef __sgi
00212 #pragma set woff 1174
00213 #endif
00214 
00215 #ifdef OSG_LINUX_ICC
00216 #pragma warning( disable : 177 )
00217 #endif
00218 
00219 namespace
00220 {
00221     static Char8 cvsid_cpp[] = "@(#)$Id: $";
00222     static Char8 cvsid_hpp[] = OSGMATERIALGROUP_HEADER_CVSID;
00223     static Char8 cvsid_inl[] = OSGMATERIALGROUP_INLINE_CVSID;
00224 }

Generated on Thu Aug 25 04:07:26 2005 for OpenSG by  doxygen 1.4.3