00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://ogre.sourceforge.net/ 00006 00007 Copyright © 2000-2003 The OGRE Team 00008 Also see acknowledgements in Readme.html 00009 00010 This program is free software; you can redistribute it and/or modify it under 00011 the terms of the GNU Lesser General Public License as published by the Free Software 00012 Foundation; either version 2 of the License, or (at your option) any later 00013 version. 00014 00015 This program is distributed in the hope that it will be useful, but WITHOUT 00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License along with 00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to 00022 http://www.gnu.org/copyleft/lesser.txt. 00023 ----------------------------------------------------------------------------- 00024 */ 00025 #include "OgreStableHeaders.h" 00026 00027 #include "OgrePass.h" 00028 #include "OgreTechnique.h" 00029 #include "OgreMaterialManager.h" 00030 #include "OgreException.h" 00031 #include "OgreGpuProgramUsage.h" 00032 #include "OgreTextureUnitState.h" 00033 00034 namespace Ogre { 00035 00036 //----------------------------------------------------------------------------- 00037 Pass::Pass(Technique* parent, unsigned short index) 00038 : mParent(parent), mIndex(index) 00039 { 00040 // Default to white ambient & diffuse, no specular / emissive 00041 mAmbient = mDiffuse = ColourValue::White; 00042 mSpecular = mEmissive = ColourValue::Black; 00043 mShininess = 0; 00044 mHash = 0; 00045 00046 // No fog 00047 mFogOverride = false; 00048 00049 // Default blending (overwrite) 00050 mSourceBlendFactor = SBF_ONE; 00051 mDestBlendFactor = SBF_ZERO; 00052 00053 mDepthCheck = true; 00054 mDepthWrite = true; 00055 mColourWrite = true; 00056 mDepthFunc = CMPF_LESS_EQUAL; 00057 mDepthBias = 0; 00058 mCullMode = CULL_CLOCKWISE; 00059 mManualCullMode = MANUAL_CULL_BACK; 00060 mLightingEnabled = true; 00061 mMaxSimultaneousLights = OGRE_MAX_SIMULTANEOUS_LIGHTS; 00062 mRunOncePerLight = false; 00063 mRunOnlyForOneLightType = true; 00064 mOnlyLightType = Light::LT_POINT; 00065 mShadeOptions = SO_GOURAUD; 00066 00067 mVertexProgramUsage = NULL; 00068 mFragmentProgramUsage = NULL; 00069 } 00070 00071 //----------------------------------------------------------------------------- 00072 Pass::Pass(Technique *parent, unsigned short index, const Pass& oth) 00073 :mParent(parent), mIndex(index) 00074 { 00075 *this = oth; 00076 mParent = parent; 00077 mIndex = index; 00078 } 00079 //----------------------------------------------------------------------------- 00080 Pass::~Pass() 00081 { 00082 removeAllTextureUnitStates(); 00083 if (mVertexProgramUsage) 00084 { 00085 delete mVertexProgramUsage; 00086 mVertexProgramUsage = 0; 00087 } 00088 if (mFragmentProgramUsage) 00089 { 00090 delete mFragmentProgramUsage; 00091 mFragmentProgramUsage = 0; 00092 } 00093 00094 } 00095 //----------------------------------------------------------------------------- 00096 Pass& Pass::operator=(const Pass& oth) 00097 { 00098 mAmbient = oth.mAmbient; 00099 mDiffuse = oth.mDiffuse; 00100 mSpecular = oth.mSpecular; 00101 mEmissive = oth.mEmissive; 00102 mShininess = oth.mShininess; 00103 00104 // No fog 00105 mFogOverride = oth.mFogOverride; 00106 00107 // Default blending (overwrite) 00108 mSourceBlendFactor = oth.mSourceBlendFactor; 00109 mDestBlendFactor = oth.mDestBlendFactor; 00110 00111 mDepthCheck = oth.mDepthCheck; 00112 mDepthWrite = oth.mDepthWrite; 00113 mColourWrite = oth.mColourWrite; 00114 mDepthFunc = oth.mDepthFunc; 00115 mDepthBias = oth.mDepthBias; 00116 mCullMode = oth.mCullMode; 00117 mManualCullMode = oth.mManualCullMode; 00118 mLightingEnabled = oth.mLightingEnabled; 00119 mMaxSimultaneousLights = oth.mMaxSimultaneousLights; 00120 mRunOncePerLight = oth.mRunOncePerLight; 00121 mRunOnlyForOneLightType = oth.mRunOnlyForOneLightType; 00122 mOnlyLightType = oth.mOnlyLightType; 00123 mShadeOptions = oth.mShadeOptions; 00124 00125 if (oth.mVertexProgramUsage) 00126 { 00127 mVertexProgramUsage = new GpuProgramUsage(*(oth.mVertexProgramUsage)); 00128 } 00129 else 00130 { 00131 mVertexProgramUsage = NULL; 00132 } 00133 if (oth.mFragmentProgramUsage) 00134 { 00135 mFragmentProgramUsage = new GpuProgramUsage(*(oth.mFragmentProgramUsage)); 00136 } 00137 else 00138 { 00139 mFragmentProgramUsage = NULL; 00140 } 00141 00142 // Copy texture units 00143 removeAllTextureUnitStates(); 00144 TextureUnitStates::const_iterator i, iend; 00145 iend = oth.mTextureUnitStates.end(); 00146 for (i = oth.mTextureUnitStates.begin(); i != iend; ++i) 00147 { 00148 TextureUnitState* t = new TextureUnitState(this, *(*i)); 00149 mTextureUnitStates.push_back(t); 00150 } 00151 00152 00153 return *this; 00154 } 00155 //----------------------------------------------------------------------- 00156 void Pass::setAmbient(Real red, Real green, Real blue) 00157 { 00158 mAmbient.r = red; 00159 mAmbient.g = green; 00160 mAmbient.b = blue; 00161 00162 } 00163 //----------------------------------------------------------------------- 00164 void Pass::setAmbient(const ColourValue& ambient) 00165 { 00166 mAmbient = ambient; 00167 } 00168 //----------------------------------------------------------------------- 00169 void Pass::setDiffuse(Real red, Real green, Real blue) 00170 { 00171 mDiffuse.r = red; 00172 mDiffuse.g = green; 00173 mDiffuse.b = blue; 00174 } 00175 //----------------------------------------------------------------------- 00176 void Pass::setDiffuse(const ColourValue& diffuse) 00177 { 00178 mDiffuse = diffuse; 00179 } 00180 //----------------------------------------------------------------------- 00181 void Pass::setSpecular(Real red, Real green, Real blue) 00182 { 00183 mSpecular.r = red; 00184 mSpecular.g = green; 00185 mSpecular.b = blue; 00186 } 00187 //----------------------------------------------------------------------- 00188 void Pass::setSpecular(const ColourValue& specular) 00189 { 00190 mSpecular = specular; 00191 } 00192 //----------------------------------------------------------------------- 00193 void Pass::setShininess(Real val) 00194 { 00195 mShininess = val; 00196 } 00197 //----------------------------------------------------------------------- 00198 void Pass::setSelfIllumination(Real red, Real green, Real blue) 00199 { 00200 mEmissive.r = red; 00201 mEmissive.g = green; 00202 mEmissive.b = blue; 00203 00204 } 00205 //----------------------------------------------------------------------- 00206 void Pass::setSelfIllumination(const ColourValue& selfIllum) 00207 { 00208 mEmissive = selfIllum; 00209 } 00210 //----------------------------------------------------------------------- 00211 const ColourValue& Pass::getAmbient(void) const 00212 { 00213 return mAmbient; 00214 } 00215 //----------------------------------------------------------------------- 00216 const ColourValue& Pass::getDiffuse(void) const 00217 { 00218 return mDiffuse; 00219 } 00220 //----------------------------------------------------------------------- 00221 const ColourValue& Pass::getSpecular(void) const 00222 { 00223 return mSpecular; 00224 } 00225 //----------------------------------------------------------------------- 00226 const ColourValue& Pass::getSelfIllumination(void) const 00227 { 00228 return mEmissive; 00229 } 00230 //----------------------------------------------------------------------- 00231 Real Pass::getShininess(void) const 00232 { 00233 return mShininess; 00234 } 00235 //----------------------------------------------------------------------- 00236 TextureUnitState* Pass::createTextureUnitState(void) 00237 { 00238 TextureUnitState *t = new TextureUnitState(this); 00239 mTextureUnitStates.push_back(t); 00240 // Needs recompilation 00241 mParent->_notifyNeedsRecompile(); 00242 return t; 00243 } 00244 //----------------------------------------------------------------------- 00245 TextureUnitState* Pass::createTextureUnitState( 00246 const String& textureName, unsigned short texCoordSet) 00247 { 00248 TextureUnitState *t = new TextureUnitState(this); 00249 t->setTextureName(textureName); 00250 t->setTextureCoordSet(texCoordSet); 00251 mTextureUnitStates.push_back(t); 00252 // Needs recompilation 00253 mParent->_notifyNeedsRecompile(); 00254 return t; 00255 } 00256 //----------------------------------------------------------------------- 00257 void Pass::addTextureUnitState(TextureUnitState* state) 00258 { 00259 mTextureUnitStates.push_back(state); 00260 // Needs recompilation 00261 mParent->_notifyNeedsRecompile(); 00262 } 00263 //----------------------------------------------------------------------- 00264 TextureUnitState* Pass::getTextureUnitState(unsigned short index) 00265 { 00266 assert (index < mTextureUnitStates.size() && "Index out of bounds"); 00267 return mTextureUnitStates[index]; 00268 } 00269 //----------------------------------------------------------------------- 00270 Pass::TextureUnitStateIterator 00271 Pass::getTextureUnitStateIterator(void) 00272 { 00273 return TextureUnitStateIterator(mTextureUnitStates.begin(), mTextureUnitStates.end()); 00274 } 00275 //----------------------------------------------------------------------- 00276 void Pass::removeTextureUnitState(unsigned short index) 00277 { 00278 assert (index < mTextureUnitStates.size() && "Index out of bounds"); 00279 00280 TextureUnitStates::iterator i = mTextureUnitStates.begin() + index; 00281 delete *i; 00282 mTextureUnitStates.erase(i); 00283 // Needs recompilation 00284 mParent->_notifyNeedsRecompile(); 00285 } 00286 //----------------------------------------------------------------------- 00287 void Pass::removeAllTextureUnitStates(void) 00288 { 00289 TextureUnitStates::iterator i, iend; 00290 iend = mTextureUnitStates.end(); 00291 for (i = mTextureUnitStates.begin(); i != iend; ++i) 00292 { 00293 delete *i; 00294 } 00295 mTextureUnitStates.clear(); 00296 // Needs recompilation 00297 mParent->_notifyNeedsRecompile(); 00298 } 00299 //----------------------------------------------------------------------- 00300 void Pass::setSceneBlending(SceneBlendType sbt) 00301 { 00302 // Turn predefined type into blending factors 00303 switch (sbt) 00304 { 00305 case SBT_TRANSPARENT_ALPHA: 00306 setSceneBlending(SBF_SOURCE_ALPHA, SBF_ONE_MINUS_SOURCE_ALPHA); 00307 break; 00308 case SBT_TRANSPARENT_COLOUR: 00309 setSceneBlending(SBF_SOURCE_COLOUR, SBF_ONE_MINUS_SOURCE_COLOUR); 00310 break; 00311 case SBT_ADD: 00312 setSceneBlending(SBF_ONE, SBF_ONE); 00313 break; 00314 // TODO: more 00315 } 00316 00317 } 00318 //----------------------------------------------------------------------- 00319 void Pass::setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor) 00320 { 00321 mSourceBlendFactor = sourceFactor; 00322 mDestBlendFactor = destFactor; 00323 } 00324 //----------------------------------------------------------------------- 00325 SceneBlendFactor Pass::getSourceBlendFactor(void) const 00326 { 00327 return mSourceBlendFactor; 00328 } 00329 //----------------------------------------------------------------------- 00330 SceneBlendFactor Pass::getDestBlendFactor(void) const 00331 { 00332 return mDestBlendFactor; 00333 } 00334 //----------------------------------------------------------------------- 00335 bool Pass::isTransparent(void) const 00336 { 00337 // Transparent if any of the destination colour is taken into account 00338 if (mDestBlendFactor != SBF_ZERO) 00339 return true; 00340 else 00341 return false; 00342 } 00343 //----------------------------------------------------------------------- 00344 void Pass::setDepthCheckEnabled(bool enabled) 00345 { 00346 mDepthCheck = enabled; 00347 } 00348 //----------------------------------------------------------------------- 00349 bool Pass::getDepthCheckEnabled(void) const 00350 { 00351 return mDepthCheck; 00352 } 00353 //----------------------------------------------------------------------- 00354 void Pass::setDepthWriteEnabled(bool enabled) 00355 { 00356 mDepthWrite = enabled; 00357 } 00358 //----------------------------------------------------------------------- 00359 bool Pass::getDepthWriteEnabled(void) const 00360 { 00361 return mDepthWrite; 00362 } 00363 //----------------------------------------------------------------------- 00364 void Pass::setDepthFunction( CompareFunction func) 00365 { 00366 mDepthFunc = func; 00367 } 00368 //----------------------------------------------------------------------- 00369 CompareFunction Pass::getDepthFunction(void) const 00370 { 00371 return mDepthFunc; 00372 } 00373 //----------------------------------------------------------------------- 00374 void Pass::setColourWriteEnabled(bool enabled) 00375 { 00376 mColourWrite = enabled; 00377 } 00378 //----------------------------------------------------------------------- 00379 bool Pass::getColourWriteEnabled(void) const 00380 { 00381 return mColourWrite; 00382 } 00383 //----------------------------------------------------------------------- 00384 void Pass::setCullingMode( CullingMode mode) 00385 { 00386 mCullMode = mode; 00387 } 00388 //----------------------------------------------------------------------- 00389 CullingMode Pass::getCullingMode(void) const 00390 { 00391 return mCullMode; 00392 } 00393 //----------------------------------------------------------------------- 00394 void Pass::setLightingEnabled(bool enabled) 00395 { 00396 mLightingEnabled = enabled; 00397 } 00398 //----------------------------------------------------------------------- 00399 bool Pass::getLightingEnabled(void) const 00400 { 00401 return mLightingEnabled; 00402 } 00403 //----------------------------------------------------------------------- 00404 void Pass::setMaxSimultaneousLights(unsigned short maxLights) 00405 { 00406 mMaxSimultaneousLights = maxLights; 00407 } 00408 //----------------------------------------------------------------------- 00409 unsigned short Pass::getMaxSimultaneousLights(void) const 00410 { 00411 return mMaxSimultaneousLights; 00412 } 00413 //----------------------------------------------------------------------- 00414 void Pass::setRunOncePerLight(bool enabled, 00415 bool onlyForOneLightType, Light::LightTypes lightType) 00416 { 00417 mRunOncePerLight = enabled; 00418 mRunOnlyForOneLightType = onlyForOneLightType; 00419 mOnlyLightType = lightType; 00420 } 00421 //----------------------------------------------------------------------- 00422 void Pass::setShadingMode(ShadeOptions mode) 00423 { 00424 mShadeOptions = mode; 00425 } 00426 //----------------------------------------------------------------------- 00427 ShadeOptions Pass::getShadingMode(void) const 00428 { 00429 return mShadeOptions; 00430 } 00431 //----------------------------------------------------------------------- 00432 void Pass::setManualCullingMode(ManualCullingMode mode) 00433 { 00434 mManualCullMode = mode; 00435 } 00436 //----------------------------------------------------------------------- 00437 ManualCullingMode Pass::getManualCullingMode(void) const 00438 { 00439 return mManualCullMode; 00440 } 00441 //----------------------------------------------------------------------- 00442 void Pass::setFog(bool overrideScene, FogMode mode, const ColourValue& colour, Real density, Real start, Real end) 00443 { 00444 mFogOverride = overrideScene; 00445 if (overrideScene) 00446 { 00447 mFogMode = mode; 00448 mFogColour = colour; 00449 mFogStart = start; 00450 mFogEnd = end; 00451 mFogDensity = density; 00452 } 00453 } 00454 //----------------------------------------------------------------------- 00455 bool Pass::getFogOverride(void) const 00456 { 00457 return mFogOverride; 00458 } 00459 //----------------------------------------------------------------------- 00460 FogMode Pass::getFogMode(void) const 00461 { 00462 return mFogMode; 00463 } 00464 //----------------------------------------------------------------------- 00465 const ColourValue& Pass::getFogColour(void) const 00466 { 00467 return mFogColour; 00468 } 00469 //----------------------------------------------------------------------- 00470 Real Pass::getFogStart(void) const 00471 { 00472 return mFogStart; 00473 } 00474 //----------------------------------------------------------------------- 00475 Real Pass::getFogEnd(void) const 00476 { 00477 return mFogEnd; 00478 } 00479 //----------------------------------------------------------------------- 00480 Real Pass::getFogDensity(void) const 00481 { 00482 return mFogDensity; 00483 } 00484 //----------------------------------------------------------------------- 00485 void Pass::setDepthBias(ushort bias) 00486 { 00487 assert(bias <= 16 && "Depth bias must be between 0 and 16"); 00488 mDepthBias = bias; 00489 } 00490 //----------------------------------------------------------------------- 00491 ushort Pass::getDepthBias(void) const 00492 { 00493 return mDepthBias; 00494 } 00495 //----------------------------------------------------------------------- 00496 Pass* Pass::_split(unsigned short numUnits) 00497 { 00498 if (mFragmentProgramUsage) 00499 { 00500 Except(Exception::ERR_INVALIDPARAMS, "Passes with fragment programs cannot be " 00501 "automatically split, define a fallback technique instead.", 00502 "Pass:_split"); 00503 } 00504 00505 if (mTextureUnitStates.size() > numUnits) 00506 { 00507 size_t start = mTextureUnitStates.size() - numUnits; 00508 00509 Pass* newPass = mParent->createPass(); 00510 00511 TextureUnitStates::iterator istart, i, iend; 00512 iend = mTextureUnitStates.end(); 00513 i = istart = mTextureUnitStates.begin() + start; 00514 // Set the new pass to fallback using scene blend 00515 newPass->setSceneBlending( 00516 (*i)->getColourBlendFallbackSrc(), (*i)->getColourBlendFallbackDest()); 00517 // Add all the other passes 00518 for (; i != iend; ++i) 00519 { 00520 newPass->addTextureUnitState(*i); 00521 } 00522 // Now remove texture units from this Pass, we don't need to delete since they've 00523 // been transferred 00524 mTextureUnitStates.erase(istart, iend); 00525 return newPass; 00526 } 00527 return NULL; 00528 } 00529 //----------------------------------------------------------------------- 00530 void Pass::_load(void) 00531 { 00532 // We assume the Technique only calls this when the material is being 00533 // loaded 00534 00535 // Load each TextureUnitState 00536 TextureUnitStates::iterator i, iend; 00537 iend = mTextureUnitStates.end(); 00538 for (i = mTextureUnitStates.begin(); i != iend; ++i) 00539 { 00540 (*i)->_load(); 00541 } 00542 00543 // Load programs 00544 if (mVertexProgramUsage) 00545 { 00546 // Load vertex program 00547 mVertexProgramUsage->_load(); 00548 } 00549 if (mFragmentProgramUsage) 00550 { 00551 // Load fragment program 00552 mFragmentProgramUsage->_load(); 00553 } 00554 00555 // Recalculate hash 00556 _recalculateHash(); 00557 00558 } 00559 //----------------------------------------------------------------------- 00560 void Pass::_unload(void) 00561 { 00562 // Unload each TextureUnitState 00563 TextureUnitStates::iterator i, iend; 00564 iend = mTextureUnitStates.end(); 00565 for (i = mTextureUnitStates.begin(); i != iend; ++i) 00566 { 00567 (*i)->_unload(); 00568 } 00569 00570 // Unload programs 00571 if (mVertexProgramUsage) 00572 { 00573 // TODO 00574 } 00575 if (mFragmentProgramUsage) 00576 { 00577 // TODO 00578 } 00579 } 00580 //----------------------------------------------------------------------- 00581 void Pass::setVertexProgram(const String& name) 00582 { 00583 // Turn off vertex program if name blank 00584 if (name.empty()) 00585 { 00586 if (mVertexProgramUsage) delete mVertexProgramUsage; 00587 mVertexProgramUsage = NULL; 00588 } 00589 else 00590 { 00591 if (!mVertexProgramUsage) 00592 { 00593 mVertexProgramUsage = new GpuProgramUsage(GPT_VERTEX_PROGRAM); 00594 } 00595 mVertexProgramUsage->setProgramName(name); 00596 } 00597 // Needs recompilation 00598 mParent->_notifyNeedsRecompile(); 00599 } 00600 //----------------------------------------------------------------------- 00601 void Pass::setVertexProgramParameters(GpuProgramParametersSharedPtr params) 00602 { 00603 if (!mVertexProgramUsage) 00604 { 00605 Except (Exception::ERR_INVALIDPARAMS, 00606 "This pass does not have a vertex program assigned!", 00607 "Pass::setVertexProgramParameters"); 00608 } 00609 mVertexProgramUsage->setParameters(params); 00610 } 00611 //----------------------------------------------------------------------- 00612 void Pass::setFragmentProgram(const String& name) 00613 { 00614 // Turn off fragment program if name blank 00615 if (name.empty()) 00616 { 00617 if (mFragmentProgramUsage) delete mFragmentProgramUsage; 00618 mFragmentProgramUsage = NULL; 00619 } 00620 else 00621 { 00622 if (!mFragmentProgramUsage) 00623 { 00624 mFragmentProgramUsage = new GpuProgramUsage(GPT_FRAGMENT_PROGRAM); 00625 } 00626 mFragmentProgramUsage->setProgramName(name); 00627 } 00628 // Needs recompilation 00629 mParent->_notifyNeedsRecompile(); 00630 } 00631 //----------------------------------------------------------------------- 00632 void Pass::setFragmentProgramParameters(GpuProgramParametersSharedPtr params) 00633 { 00634 if (!mFragmentProgramUsage) 00635 { 00636 Except (Exception::ERR_INVALIDPARAMS, 00637 "This pass does not have a fragment program assigned!", 00638 "Pass::setFragmentProgramParameters"); 00639 } 00640 mFragmentProgramUsage->setParameters(params); 00641 } 00642 //----------------------------------------------------------------------- 00643 const String& Pass::getVertexProgramName(void) 00644 { 00645 if (!mVertexProgramUsage) 00646 return String::BLANK; 00647 else 00648 return mVertexProgramUsage->getProgramName(); 00649 } 00650 //----------------------------------------------------------------------- 00651 GpuProgramParametersSharedPtr Pass::getVertexProgramParameters(void) 00652 { 00653 if (!mVertexProgramUsage) 00654 { 00655 Except (Exception::ERR_INVALIDPARAMS, 00656 "This pass does not have a vertex program assigned!", 00657 "Pass::getVertexProgramParameters"); 00658 } 00659 return mVertexProgramUsage->getParameters(); 00660 } 00661 //----------------------------------------------------------------------- 00662 GpuProgram* Pass::getVertexProgram(void) 00663 { 00664 return mVertexProgramUsage->getProgram(); 00665 } 00666 //----------------------------------------------------------------------- 00667 const String& Pass::getFragmentProgramName(void) 00668 { 00669 return mFragmentProgramUsage->getProgramName(); 00670 } 00671 //----------------------------------------------------------------------- 00672 GpuProgramParametersSharedPtr Pass::getFragmentProgramParameters(void) 00673 { 00674 return mFragmentProgramUsage->getParameters(); 00675 } 00676 //----------------------------------------------------------------------- 00677 GpuProgram* Pass::getFragmentProgram(void) 00678 { 00679 return mFragmentProgramUsage->getProgram(); 00680 } 00681 //----------------------------------------------------------------------- 00682 bool Pass::isLoaded(void) const 00683 { 00684 return mParent->isLoaded(); 00685 } 00686 //----------------------------------------------------------------------- 00687 unsigned long Pass::getHash(void) const 00688 { 00689 return mHash; 00690 } 00691 //----------------------------------------------------------------------- 00692 void Pass::_recalculateHash(void) 00693 { 00694 /* Hash format is 32-bit, divided as follows (high to low bits) 00695 bits purpose 00696 4 Pass index (i.e. max 16 passes!) 00697 14 Hashed texture name from unit 0 00698 14 Hashed texture name from unit 1 00699 00700 Note that at the moment we don't sort on the 3rd texture unit plus 00701 on the assumption that these are less frequently used; sorting on 00702 the first 2 gives us the most benefit for now. 00703 */ 00704 _StringHash H; 00705 mHash = (mIndex << 28); 00706 size_t c = getNumTextureUnitStates(); 00707 00708 if (c && !mTextureUnitStates[0]->isBlank()) 00709 mHash += (H(mTextureUnitStates[0]->getTextureName()) % (1 << 14)) << 14; 00710 if (c > 1 && !mTextureUnitStates[1]->isBlank()) 00711 mHash += (H(mTextureUnitStates[1]->getTextureName()) % (1 << 14)); 00712 } 00713 00714 //----------------------------------------------------------------------- 00715 void Pass::_notifyNeedsRecompile(void) 00716 { 00717 mParent->_notifyNeedsRecompile(); 00718 } 00719 //----------------------------------------------------------------------- 00720 void Pass::setTextureFiltering(TextureFilterOptions filterType) 00721 { 00722 TextureUnitStates::iterator i, iend; 00723 iend = mTextureUnitStates.end(); 00724 for (i = mTextureUnitStates.begin(); i != iend; ++i) 00725 { 00726 (*i)->setTextureFiltering(filterType); 00727 } 00728 } 00729 // -------------------------------------------------------------------- 00730 void Pass::setTextureAnisotropy(unsigned int maxAniso) 00731 { 00732 TextureUnitStates::iterator i, iend; 00733 iend = mTextureUnitStates.end(); 00734 for (i = mTextureUnitStates.begin(); i != iend; ++i) 00735 { 00736 (*i)->setTextureAnisotropy(maxAniso); 00737 } 00738 } 00739 //----------------------------------------------------------------------- 00740 void Pass::_updateAutoParamsNoLights(const AutoParamDataSource& source) 00741 { 00742 if (hasVertexProgram()) 00743 { 00744 // Update vertex program auto params 00745 mVertexProgramUsage->getParameters()->_updateAutoParamsNoLights(source); 00746 } 00747 00748 if (hasFragmentProgram()) 00749 { 00750 // Update fragment program auto params 00751 mFragmentProgramUsage->getParameters()->_updateAutoParamsNoLights(source); 00752 } 00753 } 00754 //----------------------------------------------------------------------- 00755 void Pass::_updateAutoParamsLightsOnly(const AutoParamDataSource& source) 00756 { 00757 if (hasVertexProgram()) 00758 { 00759 // Update vertex program auto params 00760 mVertexProgramUsage->getParameters()->_updateAutoParamsLightsOnly(source); 00761 } 00762 00763 if (hasFragmentProgram()) 00764 { 00765 // Update fragment program auto params 00766 mFragmentProgramUsage->getParameters()->_updateAutoParamsLightsOnly(source); 00767 } 00768 } 00769 00770 }
Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:21 2004