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 //--------------------------------------------------------------------------- 00040 // Includes 00041 //--------------------------------------------------------------------------- 00042 00043 #include <stdlib.h> 00044 #include <stdio.h> 00045 00046 #include <OSGConfig.h> 00047 00048 #include "OSGMultiPassMaterial.h" 00049 00050 OSG_USING_NAMESPACE 00051 00052 /***************************************************************************\ 00053 * Description * 00054 \***************************************************************************/ 00055 00060 /***************************************************************************\ 00061 * Class variables * 00062 \***************************************************************************/ 00063 00064 /***************************************************************************\ 00065 * Class methods * 00066 \***************************************************************************/ 00067 00068 void MultiPassMaterial::initMethod (void) 00069 { 00070 } 00071 00072 00073 /***************************************************************************\ 00074 * Instance methods * 00075 \***************************************************************************/ 00076 00077 /*-------------------------------------------------------------------------*\ 00078 - private - 00079 \*-------------------------------------------------------------------------*/ 00080 00081 /*----------------------- constructors & destructors ----------------------*/ 00082 00083 MultiPassMaterial::MultiPassMaterial(void) : 00084 Inherited() 00085 { 00086 } 00087 00088 MultiPassMaterial::MultiPassMaterial(const MultiPassMaterial &source) : 00089 Inherited(source) 00090 { 00091 } 00092 00093 MultiPassMaterial::~MultiPassMaterial(void) 00094 { 00095 MFMaterialPtr::iterator matIt = _mfMaterials.begin(); 00096 MFMaterialPtr::iterator matEnd = _mfMaterials.end (); 00097 00098 while(matIt != matEnd) 00099 { 00100 subRefCP(*matIt); 00101 00102 ++matIt; 00103 } 00104 } 00105 00106 /*----------------------------- class specific ----------------------------*/ 00107 00108 void MultiPassMaterial::changed(BitVector whichField, UInt32 origin) 00109 { 00110 if(origin & ChangedOrigin::Abstract) 00111 { 00112 MFMaterialPtr::iterator matIt = _mfMaterials.begin(); 00113 MFMaterialPtr::iterator matEnd = _mfMaterials.end (); 00114 00115 while(matIt != matEnd) 00116 { 00117 addRefCP(*matIt); 00118 00119 ++matIt; 00120 } 00121 } 00122 00123 Inherited::changed(whichField, origin); 00124 } 00125 00126 void MultiPassMaterial::addMaterial(MaterialPtr mat) 00127 { 00128 if(mat == NullFC) 00129 return; 00130 00131 _mfMaterials.push_back(mat); 00132 addRefCP(mat); 00133 } 00134 00135 void MultiPassMaterial::subMaterial(MaterialPtr mat) 00136 { 00137 if(mat == NullFC) 00138 return; 00139 00140 UInt32 i; 00141 00142 for(i = 0; i < _mfMaterials.size(); ++i) 00143 { 00144 if(_mfMaterials[i] == mat) 00145 { 00146 subRefCP(mat); 00147 _mfMaterials.erase(_mfMaterials.begin() + i); 00148 return; 00149 } 00150 } 00151 00152 SWARNING << "MultiPassMaterial::subMaterial(" << this << ") has no material " 00153 << mat << std::endl; 00154 } 00155 00156 bool MultiPassMaterial::hasMaterial(MaterialPtr mat) 00157 { 00158 UInt32 i; 00159 00160 for(i = 0; i < _mfMaterials.size(); ++i) 00161 { 00162 if(_mfMaterials[i] == mat) 00163 return true; 00164 } 00165 00166 return false; 00167 } 00168 00169 00173 void MultiPassMaterial::draw(Geometry* geo, DrawActionBase * action) 00174 { 00175 } 00176 00182 void MultiPassMaterial::draw(DrawFunctor& func, DrawActionBase * action) 00183 { 00184 } 00185 00189 StatePtr MultiPassMaterial::makeState(void) 00190 { 00191 return NullFC; 00192 } 00193 00197 void MultiPassMaterial::rebuildState(void) 00198 { 00199 for(UInt32 i = 0; i < _mfMaterials.size(); ++i) 00200 { 00201 if(_mfMaterials[i] != NullFC) 00202 _mfMaterials[i]->rebuildState(); 00203 } 00204 } 00205 00206 StatePtr MultiPassMaterial::getState(UInt32 index) 00207 { 00208 if(index >= _mfMaterials.size()) 00209 { 00210 SWARNING << "MultiPassMaterial::getState: index out of range!" << std::endl; 00211 return NullFC; 00212 } 00213 00214 if(_mfMaterials[index] != NullFC) 00215 return _mfMaterials[index]->getState(); 00216 00217 return NullFC; 00218 } 00219 00220 bool MultiPassMaterial::isMultiPass(void) const 00221 { 00222 return true; 00223 } 00224 00225 UInt32 MultiPassMaterial::getNPasses(void) const 00226 { 00227 return _mfMaterials.size(); 00228 } 00229 00232 bool MultiPassMaterial::isTransparent(void) const 00233 { 00234 Int32 tm = getTransparencyMode(); 00235 if(tm != Material::TransparencyAutoDetection) 00236 { 00237 return (tm == Material::TransparencyForceTransparent); 00238 } 00239 00240 MFMaterialPtr::const_iterator it = _mfMaterials.begin(); 00241 MFMaterialPtr::const_iterator matsEnd = _mfMaterials.end(); 00242 00243 // ok just check the first (base) material. 00244 if(it != matsEnd && (*it) != NullFC && (*it)->isTransparent()) 00245 return true; 00246 00247 return false; 00248 } 00249 00250 void MultiPassMaterial::dump( UInt32 , 00251 const BitVector ) const 00252 { 00253 SLOG << "Dump MultiPassMaterial NI" << std::endl; 00254 } 00255 00256 /*------------------------------------------------------------------------*/ 00257 /* cvs id's */ 00258 00259 #ifdef OSG_SGI_CC 00260 #pragma set woff 1174 00261 #endif 00262 00263 #ifdef OSG_LINUX_ICC 00264 #pragma warning( disable : 177 ) 00265 #endif 00266 00267 namespace 00268 { 00269 static Char8 cvsid_cpp [] = "@(#)$Id: OSGMultiPassMaterial.cpp,v 1.7 2006/09/27 10:20:11 a-m-z Exp $"; 00270 static Char8 cvsid_hpp [] = OSGMULTIPASSMATERIALBASE_HEADER_CVSID; 00271 static Char8 cvsid_inl [] = OSGMULTIPASSMATERIALBASE_INLINE_CVSID; 00272 00273 static Char8 cvsid_fields_hpp[] = OSGMULTIPASSMATERIALFIELDS_HEADER_CVSID; 00274 } 00275 00276 #ifdef __sgi 00277 #pragma reset woff 1174 00278 #endif 00279
1.5.5