[657] | 1 | /*
|
---|
| 2 | -----------------------------------------------------------------------------
|
---|
| 3 | This source file is part of OGRE
|
---|
| 4 | (Object-oriented Graphics Rendering Engine)
|
---|
| 5 | For the latest info, see http://ogre.sourceforge.net/
|
---|
| 6 |
|
---|
| 7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
| 8 | Also see acknowledgements in Readme.html
|
---|
| 9 |
|
---|
| 10 | This program is free software; you can redistribute it and/or modify it under
|
---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
| 13 | version.
|
---|
| 14 |
|
---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
| 18 |
|
---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
| 22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
| 23 | -----------------------------------------------------------------------------
|
---|
| 24 | */
|
---|
| 25 | #include "OgreStableHeaders.h"
|
---|
| 26 |
|
---|
| 27 | #include "OgreTextureUnitState.h"
|
---|
| 28 | #include "OgrePass.h"
|
---|
| 29 | #include "OgreMaterialManager.h"
|
---|
| 30 | #include "OgreControllerManager.h"
|
---|
| 31 | #include "OgreLogManager.h"
|
---|
| 32 | #include "OgreException.h"
|
---|
| 33 | #include "OgreTextureManager.h"
|
---|
| 34 |
|
---|
| 35 | namespace Ogre {
|
---|
| 36 |
|
---|
| 37 | //-----------------------------------------------------------------------
|
---|
| 38 | TextureUnitState::TextureUnitState(Pass* parent)
|
---|
| 39 | : mParent(parent)
|
---|
| 40 | {
|
---|
| 41 | mIsBlank = true;
|
---|
| 42 | colourBlendMode.blendType = LBT_COLOUR;
|
---|
| 43 | setColourOperation(LBO_MODULATE);
|
---|
| 44 | setTextureAddressingMode(TAM_WRAP);
|
---|
| 45 |
|
---|
| 46 | alphaBlendMode.operation = LBX_MODULATE;
|
---|
| 47 | alphaBlendMode.blendType = LBT_ALPHA;
|
---|
| 48 | alphaBlendMode.source1 = LBS_TEXTURE;
|
---|
| 49 | alphaBlendMode.source2 = LBS_CURRENT;
|
---|
| 50 |
|
---|
| 51 | //default filtering
|
---|
| 52 | mMinFilter = FO_LINEAR;
|
---|
| 53 | mMagFilter = FO_LINEAR;
|
---|
| 54 | mMipFilter = FO_POINT;
|
---|
| 55 | mMaxAniso = MaterialManager::getSingleton().getDefaultAnisotropy();
|
---|
| 56 | mIsDefaultAniso = true;
|
---|
| 57 | mIsDefaultFiltering = true;
|
---|
| 58 |
|
---|
| 59 | mUMod = mVMod = 0;
|
---|
| 60 | mUScale = mVScale = 1;
|
---|
| 61 | mRotate = 0;
|
---|
| 62 | mTexModMatrix = Matrix4::IDENTITY;
|
---|
| 63 | mRecalcTexMatrix = false;
|
---|
| 64 |
|
---|
| 65 | mNumFrames = 0;
|
---|
| 66 | mAnimDuration = 0;
|
---|
| 67 | mAnimController = 0;
|
---|
| 68 | mCubic = false;
|
---|
| 69 | mTextureType = TEX_TYPE_2D;
|
---|
| 70 | mTextureSrcMipmaps = -1;
|
---|
| 71 | mTextureCoordSetIndex = 0;
|
---|
| 72 |
|
---|
| 73 | mFrames[0] = StringUtil::BLANK;
|
---|
| 74 | mCurrentFrame = 0;
|
---|
| 75 |
|
---|
| 76 | mParent->_dirtyHash();
|
---|
| 77 |
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | //-----------------------------------------------------------------------
|
---|
| 81 | TextureUnitState::TextureUnitState(Pass* parent, const TextureUnitState& oth )
|
---|
| 82 | {
|
---|
| 83 | mParent = parent;
|
---|
| 84 | mAnimController = 0;
|
---|
| 85 | *this = oth;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | //-----------------------------------------------------------------------
|
---|
| 89 | TextureUnitState::TextureUnitState( Pass* parent, const String& texName, unsigned int texCoordSet)
|
---|
| 90 | :mParent(parent)
|
---|
| 91 | {
|
---|
| 92 | mIsBlank = true;
|
---|
| 93 | colourBlendMode.blendType = LBT_COLOUR;
|
---|
| 94 | setColourOperation(LBO_MODULATE);
|
---|
| 95 | setTextureAddressingMode(TAM_WRAP);
|
---|
| 96 |
|
---|
| 97 | alphaBlendMode.operation = LBX_MODULATE;
|
---|
| 98 | alphaBlendMode.blendType = LBT_ALPHA;
|
---|
| 99 | alphaBlendMode.source1 = LBS_TEXTURE;
|
---|
| 100 | alphaBlendMode.source2 = LBS_CURRENT;
|
---|
| 101 |
|
---|
| 102 | //default filtering && anisotropy
|
---|
| 103 | mMinFilter = FO_LINEAR;
|
---|
| 104 | mMagFilter = FO_LINEAR;
|
---|
| 105 | mMipFilter = FO_POINT;
|
---|
| 106 | mMaxAniso = MaterialManager::getSingleton().getDefaultAnisotropy();
|
---|
| 107 | mIsDefaultAniso = true;
|
---|
| 108 | mIsDefaultFiltering = true;
|
---|
| 109 |
|
---|
| 110 | mUMod = mVMod = 0;
|
---|
| 111 | mUScale = mVScale = 1;
|
---|
| 112 | mRotate = 0;
|
---|
| 113 | mAnimDuration = 0;
|
---|
| 114 | mAnimController = 0;
|
---|
| 115 | mTexModMatrix = Matrix4::IDENTITY;
|
---|
| 116 | mRecalcTexMatrix = false;
|
---|
| 117 |
|
---|
| 118 | mCubic = false;
|
---|
| 119 | mTextureType = TEX_TYPE_2D;
|
---|
| 120 | mTextureCoordSetIndex = 0;
|
---|
| 121 |
|
---|
| 122 | setTextureName(texName);
|
---|
| 123 | setTextureCoordSet(texCoordSet);
|
---|
| 124 |
|
---|
| 125 | mParent->_dirtyHash();
|
---|
| 126 |
|
---|
| 127 | }
|
---|
| 128 | //-----------------------------------------------------------------------
|
---|
| 129 | TextureUnitState::~TextureUnitState()
|
---|
| 130 | {
|
---|
| 131 | // Unload ensure all controllers destroyed
|
---|
| 132 | _unload();
|
---|
| 133 | }
|
---|
| 134 | //-----------------------------------------------------------------------
|
---|
| 135 | TextureUnitState & TextureUnitState::operator = (
|
---|
| 136 | const TextureUnitState &oth )
|
---|
| 137 | {
|
---|
| 138 | assert(mAnimController == 0);
|
---|
| 139 | assert(mEffects.empty());
|
---|
| 140 |
|
---|
| 141 | // copy basic members (int's, real's)
|
---|
| 142 | memcpy( this, &oth, (uchar *)(&oth.mFrames[0]) - (uchar *)(&oth) );
|
---|
| 143 |
|
---|
| 144 | // copy complex members
|
---|
| 145 | for( ushort i = 0; i<mNumFrames; i++ )
|
---|
| 146 | mFrames[i] = oth.mFrames[i];
|
---|
| 147 |
|
---|
| 148 | mEffects = oth.mEffects;
|
---|
| 149 |
|
---|
| 150 | // Can't sharing controllers with other TUS, reset to null to avoid potential bug.
|
---|
| 151 | for (EffectMap::iterator j = mEffects.begin(); j != mEffects.end(); ++j)
|
---|
| 152 | {
|
---|
| 153 | j->second.controller = 0;
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | // Load immediately if Material loaded
|
---|
| 157 | if (isLoaded())
|
---|
| 158 | {
|
---|
| 159 | _load();
|
---|
| 160 | // Tell parent to recalculate hash
|
---|
| 161 | mParent->_dirtyHash();
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 | return *this;
|
---|
| 165 | }
|
---|
| 166 | //-----------------------------------------------------------------------
|
---|
| 167 | const String& TextureUnitState::getTextureName(void) const
|
---|
| 168 | {
|
---|
| 169 | // Return name of current frame
|
---|
| 170 | return mFrames[mCurrentFrame];
|
---|
| 171 | }
|
---|
| 172 | //-----------------------------------------------------------------------
|
---|
| 173 | void TextureUnitState::setTextureName( const String& name, TextureType texType, int mipmaps)
|
---|
| 174 | {
|
---|
| 175 | if (texType == TEX_TYPE_CUBE_MAP)
|
---|
| 176 | {
|
---|
| 177 | // delegate to cubic texture implementation
|
---|
| 178 | setCubicTextureName(name, true);
|
---|
| 179 | }
|
---|
| 180 | else
|
---|
| 181 | {
|
---|
| 182 | mFrames[0] = name;
|
---|
| 183 | mNumFrames = 1;
|
---|
| 184 | mCurrentFrame = 0;
|
---|
| 185 | mCubic = false;
|
---|
| 186 | mTextureType = texType;
|
---|
| 187 | mTextureSrcMipmaps = mipmaps;
|
---|
| 188 |
|
---|
| 189 | if (name == "")
|
---|
| 190 | {
|
---|
| 191 | mIsBlank = true;
|
---|
| 192 | return;
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | // Load immediately ?
|
---|
| 196 | if (isLoaded())
|
---|
| 197 | {
|
---|
| 198 | _load(); // reload
|
---|
| 199 | // Tell parent to recalculate hash
|
---|
| 200 | mParent->_dirtyHash();
|
---|
| 201 | }
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | }
|
---|
| 205 | //-----------------------------------------------------------------------
|
---|
| 206 | void TextureUnitState::setCubicTextureName( const String& name, bool forUVW)
|
---|
| 207 | {
|
---|
| 208 | if (forUVW)
|
---|
| 209 | {
|
---|
| 210 | setCubicTextureName(&name, forUVW);
|
---|
| 211 | }
|
---|
| 212 | else
|
---|
| 213 | {
|
---|
| 214 | String ext;
|
---|
| 215 | String suffixes[6] = {"_fr", "_bk", "_lf", "_rt", "_up", "_dn"};
|
---|
| 216 | String baseName;
|
---|
| 217 | String fullNames[6];
|
---|
| 218 |
|
---|
| 219 |
|
---|
| 220 | size_t pos = name.find_last_of(".");
|
---|
| 221 | baseName = name.substr(0, pos);
|
---|
| 222 | ext = name.substr(pos);
|
---|
| 223 |
|
---|
| 224 | for (int i = 0; i < 6; ++i)
|
---|
| 225 | {
|
---|
| 226 | fullNames[i] = baseName + suffixes[i] + ext;
|
---|
| 227 | }
|
---|
| 228 |
|
---|
| 229 | setCubicTextureName(fullNames, forUVW);
|
---|
| 230 | }
|
---|
| 231 | }
|
---|
| 232 | //-----------------------------------------------------------------------
|
---|
| 233 | void TextureUnitState::setCubicTextureName(const String* const names, bool forUVW)
|
---|
| 234 | {
|
---|
| 235 | mNumFrames = forUVW ? 1 : 6;
|
---|
| 236 | mCurrentFrame = 0;
|
---|
| 237 | mCubic = true;
|
---|
| 238 | mTextureType = forUVW ? TEX_TYPE_CUBE_MAP : TEX_TYPE_2D;
|
---|
| 239 |
|
---|
| 240 | for (unsigned int i = 0; i < mNumFrames; ++i)
|
---|
| 241 | {
|
---|
| 242 | mFrames[i] = names[i];
|
---|
| 243 | }
|
---|
| 244 | // Tell parent we need recompiling, will cause reload too
|
---|
| 245 | mParent->_notifyNeedsRecompile();
|
---|
| 246 | }
|
---|
| 247 | //-----------------------------------------------------------------------
|
---|
| 248 | bool TextureUnitState::isCubic(void) const
|
---|
| 249 | {
|
---|
| 250 | return mCubic;
|
---|
| 251 | }
|
---|
| 252 | //-----------------------------------------------------------------------
|
---|
| 253 | bool TextureUnitState::is3D(void) const
|
---|
| 254 | {
|
---|
| 255 | return mTextureType == TEX_TYPE_CUBE_MAP;
|
---|
| 256 | }
|
---|
| 257 | //-----------------------------------------------------------------------
|
---|
| 258 | TextureType TextureUnitState::getTextureType(void) const
|
---|
| 259 | {
|
---|
| 260 | return mTextureType;
|
---|
| 261 |
|
---|
| 262 | }
|
---|
| 263 | //-----------------------------------------------------------------------
|
---|
| 264 | void TextureUnitState::setAnimatedTextureName( const String& name, unsigned int numFrames, Real duration)
|
---|
| 265 | {
|
---|
| 266 | String ext;
|
---|
| 267 | String baseName;
|
---|
| 268 |
|
---|
| 269 | size_t pos = name.find_last_of(".");
|
---|
| 270 | baseName = name.substr(0, pos);
|
---|
| 271 | ext = name.substr(pos);
|
---|
| 272 |
|
---|
| 273 | if (numFrames > OGRE_MAX_TEXTURE_FRAMES)
|
---|
| 274 | {
|
---|
| 275 | StringUtil::StrStreamType str;
|
---|
| 276 | str << "Maximum number of frames is " << OGRE_MAX_TEXTURE_FRAMES << ".";
|
---|
| 277 | OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, str.str(), "TextureUnitState::setAnimatedTextureName");
|
---|
| 278 | }
|
---|
| 279 | mNumFrames = numFrames;
|
---|
| 280 | mAnimDuration = duration;
|
---|
| 281 | mCurrentFrame = 0;
|
---|
| 282 | mCubic = false;
|
---|
| 283 |
|
---|
| 284 | for (unsigned int i = 0; i < mNumFrames; ++i)
|
---|
| 285 | {
|
---|
| 286 | StringUtil::StrStreamType str;
|
---|
| 287 | str << baseName << "_" << i << ext;
|
---|
| 288 | mFrames[i] = str.str();
|
---|
| 289 | }
|
---|
| 290 |
|
---|
| 291 | // Load immediately if Material loaded
|
---|
| 292 | if (isLoaded())
|
---|
| 293 | {
|
---|
| 294 | _load();
|
---|
| 295 | // Tell parent to recalculate hash
|
---|
| 296 | mParent->_dirtyHash();
|
---|
| 297 | }
|
---|
| 298 |
|
---|
| 299 | }
|
---|
| 300 | //-----------------------------------------------------------------------
|
---|
| 301 | void TextureUnitState::setAnimatedTextureName(const String* const names, unsigned int numFrames, Real duration)
|
---|
| 302 | {
|
---|
| 303 | if (numFrames > OGRE_MAX_TEXTURE_FRAMES)
|
---|
| 304 | {
|
---|
| 305 | StringUtil::StrStreamType str;
|
---|
| 306 | str << "Maximum number of frames is " << OGRE_MAX_TEXTURE_FRAMES << ".";
|
---|
| 307 | OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, str.str(), "TextureUnitState::setAnimatedTextureName");
|
---|
| 308 | }
|
---|
| 309 | mNumFrames = numFrames;
|
---|
| 310 | mAnimDuration = duration;
|
---|
| 311 | mCurrentFrame = 0;
|
---|
| 312 | mCubic = false;
|
---|
| 313 |
|
---|
| 314 | for (unsigned int i = 0; i < mNumFrames; ++i)
|
---|
| 315 | {
|
---|
| 316 | mFrames[i] = names[i];
|
---|
| 317 | }
|
---|
| 318 |
|
---|
| 319 | // Load immediately if Material loaded
|
---|
| 320 | if (isLoaded())
|
---|
| 321 | {
|
---|
| 322 | _load();
|
---|
| 323 | // Tell parent to recalculate hash
|
---|
| 324 | mParent->_dirtyHash();
|
---|
| 325 | }
|
---|
| 326 | }
|
---|
| 327 | //-----------------------------------------------------------------------
|
---|
| 328 | std::pair< uint, uint > TextureUnitState::getTextureDimensions( unsigned int frame ) const
|
---|
| 329 | {
|
---|
| 330 | TexturePtr tex = TextureManager::getSingleton().getByName( mFrames[ frame ] );
|
---|
| 331 |
|
---|
| 332 | if (tex.isNull())
|
---|
| 333 | OGRE_EXCEPT( Exception::ERR_ITEM_NOT_FOUND, "Could not find texture " + mFrames[ frame ],
|
---|
| 334 | "TextureUnitState::getTextureDimensions" );
|
---|
| 335 | return std::pair< uint, uint >( tex->getWidth(), tex->getHeight() );
|
---|
| 336 | }
|
---|
| 337 | //-----------------------------------------------------------------------
|
---|
| 338 | void TextureUnitState::setCurrentFrame(unsigned int frameNumber)
|
---|
| 339 | {
|
---|
| 340 | assert(frameNumber < mNumFrames);
|
---|
| 341 | mCurrentFrame = frameNumber;
|
---|
| 342 | // this will affect the hash
|
---|
| 343 | mParent->_dirtyHash();
|
---|
| 344 |
|
---|
| 345 | }
|
---|
| 346 | //-----------------------------------------------------------------------
|
---|
| 347 | unsigned int TextureUnitState::getCurrentFrame(void) const
|
---|
| 348 | {
|
---|
| 349 | return mCurrentFrame;
|
---|
| 350 | }
|
---|
| 351 | //-----------------------------------------------------------------------
|
---|
| 352 | unsigned int TextureUnitState::getNumFrames(void) const
|
---|
| 353 | {
|
---|
| 354 | return mNumFrames;
|
---|
| 355 | }
|
---|
| 356 | //-----------------------------------------------------------------------
|
---|
| 357 | const String& TextureUnitState::getFrameTextureName(unsigned int frameNumber) const
|
---|
| 358 | {
|
---|
| 359 | assert(frameNumber < mNumFrames);
|
---|
| 360 | return mFrames[frameNumber];
|
---|
| 361 | }
|
---|
| 362 | //-----------------------------------------------------------------------
|
---|
| 363 | unsigned int TextureUnitState::getTextureCoordSet(void) const
|
---|
| 364 | {
|
---|
| 365 | return mTextureCoordSetIndex;
|
---|
| 366 | }
|
---|
| 367 | //-----------------------------------------------------------------------
|
---|
| 368 | void TextureUnitState::setTextureCoordSet(unsigned int set)
|
---|
| 369 | {
|
---|
| 370 | mTextureCoordSetIndex = set;
|
---|
| 371 | }
|
---|
| 372 | //-----------------------------------------------------------------------
|
---|
| 373 | void TextureUnitState::setColourOperationEx(LayerBlendOperationEx op,
|
---|
| 374 | LayerBlendSource source1,
|
---|
| 375 | LayerBlendSource source2,
|
---|
| 376 | const ColourValue& arg1,
|
---|
| 377 | const ColourValue& arg2,
|
---|
| 378 | Real manualBlend)
|
---|
| 379 | {
|
---|
| 380 | colourBlendMode.operation = op;
|
---|
| 381 | colourBlendMode.source1 = source1;
|
---|
| 382 | colourBlendMode.source2 = source2;
|
---|
| 383 | colourBlendMode.colourArg1 = arg1;
|
---|
| 384 | colourBlendMode.colourArg2 = arg2;
|
---|
| 385 | colourBlendMode.factor = manualBlend;
|
---|
| 386 | }
|
---|
| 387 | //-----------------------------------------------------------------------
|
---|
| 388 | void TextureUnitState::setColourOperation(LayerBlendOperation op)
|
---|
| 389 | {
|
---|
| 390 | // Set up the multitexture and multipass blending operations
|
---|
| 391 | switch (op)
|
---|
| 392 | {
|
---|
| 393 | case LBO_REPLACE:
|
---|
| 394 | setColourOperationEx(LBX_SOURCE1, LBS_TEXTURE, LBS_CURRENT);
|
---|
| 395 | setColourOpMultipassFallback(SBF_ONE, SBF_ZERO);
|
---|
| 396 | break;
|
---|
| 397 | case LBO_ADD:
|
---|
| 398 | setColourOperationEx(LBX_ADD, LBS_TEXTURE, LBS_CURRENT);
|
---|
| 399 | setColourOpMultipassFallback(SBF_ONE, SBF_ONE);
|
---|
| 400 | break;
|
---|
| 401 | case LBO_MODULATE:
|
---|
| 402 | setColourOperationEx(LBX_MODULATE, LBS_TEXTURE, LBS_CURRENT);
|
---|
| 403 | setColourOpMultipassFallback(SBF_DEST_COLOUR, SBF_ZERO);
|
---|
| 404 | break;
|
---|
| 405 | case LBO_ALPHA_BLEND:
|
---|
| 406 | setColourOperationEx(LBX_BLEND_TEXTURE_ALPHA, LBS_TEXTURE, LBS_CURRENT);
|
---|
| 407 | setColourOpMultipassFallback(SBF_SOURCE_ALPHA, SBF_ONE_MINUS_SOURCE_ALPHA);
|
---|
| 408 | break;
|
---|
| 409 | }
|
---|
| 410 |
|
---|
| 411 |
|
---|
| 412 | }
|
---|
| 413 | //-----------------------------------------------------------------------
|
---|
| 414 | void TextureUnitState::setColourOpMultipassFallback(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor)
|
---|
| 415 | {
|
---|
| 416 | colourBlendFallbackSrc = sourceFactor;
|
---|
| 417 | colourBlendFallbackDest = destFactor;
|
---|
| 418 | }
|
---|
| 419 | //-----------------------------------------------------------------------
|
---|
| 420 | void TextureUnitState::setAlphaOperation(LayerBlendOperationEx op,
|
---|
| 421 | LayerBlendSource source1,
|
---|
| 422 | LayerBlendSource source2,
|
---|
| 423 | Real arg1,
|
---|
| 424 | Real arg2,
|
---|
| 425 | Real manualBlend)
|
---|
| 426 | {
|
---|
| 427 | alphaBlendMode.operation = op;
|
---|
| 428 | alphaBlendMode.source1 = source1;
|
---|
| 429 | alphaBlendMode.source2 = source2;
|
---|
| 430 | alphaBlendMode.alphaArg1 = arg1;
|
---|
| 431 | alphaBlendMode.alphaArg2 = arg2;
|
---|
| 432 | alphaBlendMode.factor = manualBlend;
|
---|
| 433 | }
|
---|
| 434 | //-----------------------------------------------------------------------
|
---|
| 435 | void TextureUnitState::addEffect(TextureEffect& effect)
|
---|
| 436 | {
|
---|
| 437 | // Ensure controller pointer is null
|
---|
| 438 | effect.controller = 0;
|
---|
| 439 |
|
---|
| 440 | if (effect.type == ET_ENVIRONMENT_MAP || effect.type == ET_SCROLL || effect.type == ET_ROTATE
|
---|
| 441 | || effect.type == ET_PROJECTIVE_TEXTURE)
|
---|
| 442 | {
|
---|
| 443 | // Replace - must be unique
|
---|
| 444 | // Search for existing effect of this type
|
---|
| 445 | EffectMap::iterator i = mEffects.find(effect.type);
|
---|
| 446 | if (i != mEffects.end())
|
---|
| 447 | {
|
---|
| 448 | // Destroy old effect controller if exist
|
---|
| 449 | if (i->second.controller)
|
---|
| 450 | {
|
---|
| 451 | ControllerManager::getSingleton().destroyController(i->second.controller);
|
---|
| 452 | }
|
---|
| 453 |
|
---|
| 454 | mEffects.erase(i);
|
---|
| 455 | }
|
---|
| 456 | }
|
---|
| 457 |
|
---|
| 458 | if (isLoaded())
|
---|
| 459 | {
|
---|
| 460 | // Create controller
|
---|
| 461 | createEffectController(effect);
|
---|
| 462 | }
|
---|
| 463 |
|
---|
| 464 | // Record new effect
|
---|
| 465 | mEffects.insert(EffectMap::value_type(effect.type, effect));
|
---|
| 466 |
|
---|
| 467 | }
|
---|
| 468 | //-----------------------------------------------------------------------
|
---|
| 469 | void TextureUnitState::removeAllEffects(void)
|
---|
| 470 | {
|
---|
| 471 | // Iterate over effects to remove controllers
|
---|
| 472 | EffectMap::iterator i, iend;
|
---|
| 473 | iend = mEffects.end();
|
---|
| 474 | for (i = mEffects.begin(); i != iend; ++i)
|
---|
| 475 | {
|
---|
| 476 | if (i->second.controller)
|
---|
| 477 | {
|
---|
| 478 | ControllerManager::getSingleton().destroyController(i->second.controller);
|
---|
| 479 | }
|
---|
| 480 | }
|
---|
| 481 |
|
---|
| 482 | mEffects.clear();
|
---|
| 483 | }
|
---|
| 484 |
|
---|
| 485 | //-----------------------------------------------------------------------
|
---|
| 486 | bool TextureUnitState::isBlank(void) const
|
---|
| 487 | {
|
---|
| 488 | return mIsBlank;
|
---|
| 489 | }
|
---|
| 490 |
|
---|
| 491 | //-----------------------------------------------------------------------
|
---|
| 492 | SceneBlendFactor TextureUnitState::getColourBlendFallbackSrc(void) const
|
---|
| 493 | {
|
---|
| 494 | return colourBlendFallbackSrc;
|
---|
| 495 | }
|
---|
| 496 | //-----------------------------------------------------------------------
|
---|
| 497 | SceneBlendFactor TextureUnitState::getColourBlendFallbackDest(void) const
|
---|
| 498 | {
|
---|
| 499 | return colourBlendFallbackDest;
|
---|
| 500 | }
|
---|
| 501 | //-----------------------------------------------------------------------
|
---|
| 502 | const LayerBlendModeEx& TextureUnitState::getColourBlendMode(void) const
|
---|
| 503 | {
|
---|
| 504 | return colourBlendMode;
|
---|
| 505 | }
|
---|
| 506 | //-----------------------------------------------------------------------
|
---|
| 507 | const LayerBlendModeEx& TextureUnitState::getAlphaBlendMode(void) const
|
---|
| 508 | {
|
---|
| 509 | return alphaBlendMode;
|
---|
| 510 | }
|
---|
| 511 | //-----------------------------------------------------------------------
|
---|
| 512 | TextureUnitState::TextureAddressingMode TextureUnitState::getTextureAddressingMode(void) const
|
---|
| 513 | {
|
---|
| 514 | return mAddressMode;
|
---|
| 515 | }
|
---|
| 516 | //-----------------------------------------------------------------------
|
---|
| 517 | void TextureUnitState::setTextureAddressingMode(TextureUnitState::TextureAddressingMode tam)
|
---|
| 518 | {
|
---|
| 519 | mAddressMode = tam;
|
---|
| 520 | }
|
---|
| 521 | //-----------------------------------------------------------------------
|
---|
| 522 | void TextureUnitState::setEnvironmentMap(bool enable, EnvMapType envMapType)
|
---|
| 523 | {
|
---|
| 524 | if (enable)
|
---|
| 525 | {
|
---|
| 526 | TextureEffect eff;
|
---|
| 527 | eff.type = ET_ENVIRONMENT_MAP;
|
---|
| 528 |
|
---|
| 529 | eff.subtype = envMapType;
|
---|
| 530 | addEffect(eff);
|
---|
| 531 | }
|
---|
| 532 | else
|
---|
| 533 | {
|
---|
| 534 | removeEffect(ET_ENVIRONMENT_MAP);
|
---|
| 535 | }
|
---|
| 536 | }
|
---|
| 537 | //-----------------------------------------------------------------------
|
---|
| 538 | void TextureUnitState::removeEffect(TextureEffectType type)
|
---|
| 539 | {
|
---|
| 540 | // Get range of items matching this effect
|
---|
| 541 | std::pair< EffectMap::iterator, EffectMap::iterator > remPair =
|
---|
| 542 | mEffects.equal_range( type );
|
---|
| 543 | // Remove controllers
|
---|
| 544 | for (EffectMap::iterator i = remPair.first; i != remPair.second; ++i)
|
---|
| 545 | {
|
---|
| 546 | if (i->second.controller)
|
---|
| 547 | {
|
---|
| 548 | ControllerManager::getSingleton().destroyController(i->second.controller);
|
---|
| 549 | }
|
---|
| 550 | }
|
---|
| 551 | // Erase
|
---|
| 552 | mEffects.erase( remPair.first, remPair.second );
|
---|
| 553 | }
|
---|
| 554 | //-----------------------------------------------------------------------
|
---|
| 555 | void TextureUnitState::setBlank(void)
|
---|
| 556 | {
|
---|
| 557 | mIsBlank = true;
|
---|
| 558 | }
|
---|
| 559 | //-----------------------------------------------------------------------
|
---|
| 560 | void TextureUnitState::setTextureTransform(const Matrix4& xform)
|
---|
| 561 | {
|
---|
| 562 | mTexModMatrix = xform;
|
---|
| 563 | mRecalcTexMatrix = false;
|
---|
| 564 | }
|
---|
| 565 | //-----------------------------------------------------------------------
|
---|
| 566 | void TextureUnitState::setTextureScroll(Real u, Real v)
|
---|
| 567 | {
|
---|
| 568 | mUMod = u;
|
---|
| 569 | mVMod = v;
|
---|
| 570 | mRecalcTexMatrix = true;
|
---|
| 571 | }
|
---|
| 572 | //-----------------------------------------------------------------------
|
---|
| 573 | void TextureUnitState::setTextureScale(Real uScale, Real vScale)
|
---|
| 574 | {
|
---|
| 575 | mUScale = uScale;
|
---|
| 576 | mVScale = vScale;
|
---|
| 577 | mRecalcTexMatrix = true;
|
---|
| 578 | }
|
---|
| 579 | //-----------------------------------------------------------------------
|
---|
| 580 | void TextureUnitState::setTextureRotate(const Radian& angle)
|
---|
| 581 | {
|
---|
| 582 | mRotate = angle;
|
---|
| 583 | mRecalcTexMatrix = true;
|
---|
| 584 | }
|
---|
| 585 | //-----------------------------------------------------------------------
|
---|
| 586 | const Matrix4& TextureUnitState::getTextureTransform() const
|
---|
| 587 | {
|
---|
| 588 | if (mRecalcTexMatrix)
|
---|
| 589 | recalcTextureMatrix();
|
---|
| 590 | return mTexModMatrix;
|
---|
| 591 |
|
---|
| 592 | }
|
---|
| 593 | //-----------------------------------------------------------------------
|
---|
| 594 | void TextureUnitState::recalcTextureMatrix() const
|
---|
| 595 | {
|
---|
| 596 | // Assumption: 2D texture coords
|
---|
| 597 | Matrix3 xform, rot;
|
---|
| 598 |
|
---|
| 599 | xform = Matrix3::IDENTITY;
|
---|
| 600 | if (mUScale || mVScale)
|
---|
| 601 | {
|
---|
| 602 | // Offset to center of texture
|
---|
| 603 | xform[0][0] = 1/mUScale;
|
---|
| 604 | xform[1][1] = 1/mVScale;
|
---|
| 605 | // Skip matrix concat since first matrix update
|
---|
| 606 | xform[0][2] = (-0.5 * xform[0][0]) + 0.5;
|
---|
| 607 | xform[1][2] = (-0.5 * xform[1][1]) + 0.5;
|
---|
| 608 |
|
---|
| 609 | }
|
---|
| 610 |
|
---|
| 611 | if (mUMod || mVMod)
|
---|
| 612 | {
|
---|
| 613 | Matrix3 xlate = Matrix3::IDENTITY;
|
---|
| 614 |
|
---|
| 615 | xlate[0][2] = mUMod;
|
---|
| 616 | xlate[1][2] = mVMod;
|
---|
| 617 |
|
---|
| 618 | xform = xlate * xform;
|
---|
| 619 | }
|
---|
| 620 |
|
---|
| 621 | if (mRotate != Radian(0))
|
---|
| 622 | {
|
---|
| 623 | rot = Matrix3::IDENTITY;
|
---|
| 624 | Radian theta ( mRotate );
|
---|
| 625 | Real cosTheta = Math::Cos(theta);
|
---|
| 626 | Real sinTheta = Math::Sin(theta);
|
---|
| 627 |
|
---|
| 628 | rot[0][0] = cosTheta;
|
---|
| 629 | rot[0][1] = -sinTheta;
|
---|
| 630 | rot[1][0] = sinTheta;
|
---|
| 631 | rot[1][1] = cosTheta;
|
---|
| 632 | // Offset center of rotation to center of texture
|
---|
| 633 | rot[0][2] = 0.5 + ( (-0.5 * cosTheta) - (-0.5 * sinTheta) );
|
---|
| 634 | rot[1][2] = 0.5 + ( (-0.5 * sinTheta) + (-0.5 * cosTheta) );
|
---|
| 635 |
|
---|
| 636 |
|
---|
| 637 | xform = rot * xform;
|
---|
| 638 | }
|
---|
| 639 |
|
---|
| 640 | mTexModMatrix = xform;
|
---|
| 641 |
|
---|
| 642 | }
|
---|
| 643 | //-----------------------------------------------------------------------
|
---|
| 644 | void TextureUnitState::setTextureUScroll(Real value)
|
---|
| 645 | {
|
---|
| 646 | mUMod = value;
|
---|
| 647 | mRecalcTexMatrix = true;
|
---|
| 648 | }
|
---|
| 649 | //-----------------------------------------------------------------------
|
---|
| 650 | void TextureUnitState::setTextureVScroll(Real value)
|
---|
| 651 | {
|
---|
| 652 | mVMod = value;
|
---|
| 653 | mRecalcTexMatrix = true;
|
---|
| 654 | }
|
---|
| 655 | //-----------------------------------------------------------------------
|
---|
| 656 | void TextureUnitState::setTextureUScale(Real value)
|
---|
| 657 | {
|
---|
| 658 | mUScale = value;
|
---|
| 659 | mRecalcTexMatrix = true;
|
---|
| 660 | }
|
---|
| 661 | //-----------------------------------------------------------------------
|
---|
| 662 | void TextureUnitState::setTextureVScale(Real value)
|
---|
| 663 | {
|
---|
| 664 | mVScale = value;
|
---|
| 665 | mRecalcTexMatrix = true;
|
---|
| 666 | }
|
---|
| 667 | //-----------------------------------------------------------------------
|
---|
| 668 | void TextureUnitState::setScrollAnimation(Real uSpeed, Real vSpeed)
|
---|
| 669 | {
|
---|
| 670 | // Remove existing effect
|
---|
| 671 | removeEffect(ET_SCROLL);
|
---|
| 672 | // Create new effect
|
---|
| 673 | TextureEffect eff;
|
---|
| 674 | eff.type = ET_SCROLL;
|
---|
| 675 | eff.arg1 = uSpeed;
|
---|
| 676 | eff.arg2 = vSpeed;
|
---|
| 677 | addEffect(eff);
|
---|
| 678 | }
|
---|
| 679 | //-----------------------------------------------------------------------
|
---|
| 680 | void TextureUnitState::setRotateAnimation(Real speed)
|
---|
| 681 | {
|
---|
| 682 | // Remove existing effect
|
---|
| 683 | removeEffect(ET_ROTATE);
|
---|
| 684 | // Create new effect
|
---|
| 685 | TextureEffect eff;
|
---|
| 686 | eff.type = ET_ROTATE;
|
---|
| 687 | eff.arg1 = speed;
|
---|
| 688 | addEffect(eff);
|
---|
| 689 | }
|
---|
| 690 | //-----------------------------------------------------------------------
|
---|
| 691 | void TextureUnitState::setTransformAnimation(TextureTransformType ttype,
|
---|
| 692 | WaveformType waveType, Real base, Real frequency, Real phase, Real amplitude)
|
---|
| 693 | {
|
---|
| 694 | // Remove existing effect
|
---|
| 695 | removeEffect(ET_TRANSFORM);
|
---|
| 696 | // Create new effect
|
---|
| 697 | TextureEffect eff;
|
---|
| 698 | eff.type = ET_TRANSFORM;
|
---|
| 699 | eff.subtype = ttype;
|
---|
| 700 | eff.waveType = waveType;
|
---|
| 701 | eff.base = base;
|
---|
| 702 | eff.frequency = frequency;
|
---|
| 703 | eff.phase = phase;
|
---|
| 704 | eff.amplitude = amplitude;
|
---|
| 705 | addEffect(eff);
|
---|
| 706 | }
|
---|
| 707 | //-----------------------------------------------------------------------
|
---|
| 708 | void TextureUnitState::_load(void)
|
---|
| 709 | {
|
---|
| 710 | // Unload first
|
---|
| 711 | _unload();
|
---|
| 712 |
|
---|
| 713 | // Load textures
|
---|
| 714 | for (unsigned int i = 0; i < mNumFrames; ++i)
|
---|
| 715 | {
|
---|
| 716 | if (mFrames[i] != "")
|
---|
| 717 | {
|
---|
| 718 | // Ensure texture is loaded, specified number of mipmaps and priority
|
---|
| 719 | try {
|
---|
| 720 |
|
---|
| 721 | TextureManager::getSingleton().load(mFrames[i],
|
---|
| 722 | mParent->getResourceGroup(), mTextureType, mTextureSrcMipmaps);
|
---|
| 723 | mIsBlank = false;
|
---|
| 724 | }
|
---|
| 725 | catch (Exception &e) {
|
---|
| 726 | String msg;
|
---|
| 727 | msg = msg + "Error loading texture " + mFrames[i] +
|
---|
| 728 | ". Texture layer will be blank. Loading the texture failed with the following exception: "+e.getFullDescription();
|
---|
| 729 | LogManager::getSingleton().logMessage(msg);
|
---|
| 730 | mIsBlank = true;
|
---|
| 731 | }
|
---|
| 732 | }
|
---|
| 733 | }
|
---|
| 734 | // Animation controller
|
---|
| 735 | if (mAnimDuration != 0)
|
---|
| 736 | {
|
---|
| 737 | createAnimController();
|
---|
| 738 | }
|
---|
| 739 | // Effect controllers
|
---|
| 740 | for (EffectMap::iterator it = mEffects.begin(); it != mEffects.end(); ++it)
|
---|
| 741 | {
|
---|
| 742 | createEffectController(it->second);
|
---|
| 743 | }
|
---|
| 744 |
|
---|
| 745 | }
|
---|
| 746 | //-----------------------------------------------------------------------
|
---|
| 747 | void TextureUnitState::createAnimController(void)
|
---|
| 748 | {
|
---|
| 749 | assert(mAnimController == 0);
|
---|
| 750 | mAnimController = ControllerManager::getSingleton().createTextureAnimator(this, mAnimDuration);
|
---|
| 751 |
|
---|
| 752 | }
|
---|
| 753 | //-----------------------------------------------------------------------
|
---|
| 754 | void TextureUnitState::createEffectController(TextureEffect& effect)
|
---|
| 755 | {
|
---|
| 756 | assert(effect.controller == 0);
|
---|
| 757 | ControllerManager& cMgr = ControllerManager::getSingleton();
|
---|
| 758 | switch (effect.type)
|
---|
| 759 | {
|
---|
| 760 | case ET_SCROLL:
|
---|
| 761 | effect.controller = cMgr.createTextureScroller(this, effect.arg1, effect.arg2);
|
---|
| 762 | break;
|
---|
| 763 | case ET_ROTATE:
|
---|
| 764 | effect.controller = cMgr.createTextureRotater(this, effect.arg1);
|
---|
| 765 | break;
|
---|
| 766 | case ET_TRANSFORM:
|
---|
| 767 | effect.controller = cMgr.createTextureWaveTransformer(this, (TextureUnitState::TextureTransformType)effect.subtype, effect.waveType, effect.base,
|
---|
| 768 | effect.frequency, effect.phase, effect.amplitude);
|
---|
| 769 | break;
|
---|
| 770 | case ET_ENVIRONMENT_MAP:
|
---|
| 771 | break;
|
---|
| 772 | default:
|
---|
| 773 | break;
|
---|
| 774 | }
|
---|
| 775 | }
|
---|
| 776 | //-----------------------------------------------------------------------
|
---|
| 777 | Real TextureUnitState::getTextureUScroll(void) const
|
---|
| 778 | {
|
---|
| 779 | return mUMod;
|
---|
| 780 | }
|
---|
| 781 |
|
---|
| 782 | //-----------------------------------------------------------------------
|
---|
| 783 | Real TextureUnitState::getTextureVScroll(void) const
|
---|
| 784 | {
|
---|
| 785 | return mVMod;
|
---|
| 786 | }
|
---|
| 787 |
|
---|
| 788 | //-----------------------------------------------------------------------
|
---|
| 789 | Real TextureUnitState::getTextureUScale(void) const
|
---|
| 790 | {
|
---|
| 791 | return mUScale;
|
---|
| 792 | }
|
---|
| 793 |
|
---|
| 794 | //-----------------------------------------------------------------------
|
---|
| 795 | Real TextureUnitState::getTextureVScale(void) const
|
---|
| 796 | {
|
---|
| 797 | return mVScale;
|
---|
| 798 | }
|
---|
| 799 |
|
---|
| 800 | //-----------------------------------------------------------------------
|
---|
| 801 | const Radian& TextureUnitState::getTextureRotate(void) const
|
---|
| 802 | {
|
---|
| 803 | return mRotate;
|
---|
| 804 | }
|
---|
| 805 |
|
---|
| 806 | //-----------------------------------------------------------------------
|
---|
| 807 | Real TextureUnitState::getAnimationDuration(void) const
|
---|
| 808 | {
|
---|
| 809 | return mAnimDuration;
|
---|
| 810 | }
|
---|
| 811 |
|
---|
| 812 | //-----------------------------------------------------------------------
|
---|
| 813 | std::multimap<TextureUnitState::TextureEffectType, TextureUnitState::TextureEffect> TextureUnitState::getEffects(void) const
|
---|
| 814 | {
|
---|
| 815 | return mEffects;
|
---|
| 816 | }
|
---|
| 817 |
|
---|
| 818 | //-----------------------------------------------------------------------
|
---|
| 819 | void TextureUnitState::setTextureFiltering(TextureFilterOptions filterType)
|
---|
| 820 | {
|
---|
| 821 | switch (filterType)
|
---|
| 822 | {
|
---|
| 823 | case TFO_NONE:
|
---|
| 824 | setTextureFiltering(FO_POINT, FO_POINT, FO_NONE);
|
---|
| 825 | break;
|
---|
| 826 | case TFO_BILINEAR:
|
---|
| 827 | setTextureFiltering(FO_LINEAR, FO_LINEAR, FO_POINT);
|
---|
| 828 | break;
|
---|
| 829 | case TFO_TRILINEAR:
|
---|
| 830 | setTextureFiltering(FO_LINEAR, FO_LINEAR, FO_LINEAR);
|
---|
| 831 | break;
|
---|
| 832 | case TFO_ANISOTROPIC:
|
---|
| 833 | setTextureFiltering(FO_ANISOTROPIC, FO_ANISOTROPIC, FO_LINEAR);
|
---|
| 834 | break;
|
---|
| 835 | }
|
---|
| 836 | mIsDefaultFiltering = false;
|
---|
| 837 | }
|
---|
| 838 | //-----------------------------------------------------------------------
|
---|
| 839 | void TextureUnitState::setTextureFiltering(FilterType ft, FilterOptions fo)
|
---|
| 840 | {
|
---|
| 841 | switch (ft)
|
---|
| 842 | {
|
---|
| 843 | case FT_MIN:
|
---|
| 844 | mMinFilter = fo;
|
---|
| 845 | break;
|
---|
| 846 | case FT_MAG:
|
---|
| 847 | mMagFilter = fo;
|
---|
| 848 | break;
|
---|
| 849 | case FT_MIP:
|
---|
| 850 | mMipFilter = fo;
|
---|
| 851 | break;
|
---|
| 852 | }
|
---|
| 853 | mIsDefaultFiltering = false;
|
---|
| 854 | }
|
---|
| 855 | //-----------------------------------------------------------------------
|
---|
| 856 | void TextureUnitState::setTextureFiltering(FilterOptions minFilter,
|
---|
| 857 | FilterOptions magFilter, FilterOptions mipFilter)
|
---|
| 858 | {
|
---|
| 859 | mMinFilter = minFilter;
|
---|
| 860 | mMagFilter = magFilter;
|
---|
| 861 | mMipFilter = mipFilter;
|
---|
| 862 | mIsDefaultFiltering = false;
|
---|
| 863 | }
|
---|
| 864 | //-----------------------------------------------------------------------
|
---|
| 865 | FilterOptions TextureUnitState::getTextureFiltering(FilterType ft) const
|
---|
| 866 | {
|
---|
| 867 |
|
---|
| 868 | switch (ft)
|
---|
| 869 | {
|
---|
| 870 | case FT_MIN:
|
---|
| 871 | return mIsDefaultFiltering ?
|
---|
| 872 | MaterialManager::getSingleton().getDefaultTextureFiltering(FT_MIN) : mMinFilter;
|
---|
| 873 | case FT_MAG:
|
---|
| 874 | return mIsDefaultFiltering ?
|
---|
| 875 | MaterialManager::getSingleton().getDefaultTextureFiltering(FT_MAG) : mMagFilter;
|
---|
| 876 | case FT_MIP:
|
---|
| 877 | return mIsDefaultFiltering ?
|
---|
| 878 | MaterialManager::getSingleton().getDefaultTextureFiltering(FT_MIP) : mMipFilter;
|
---|
| 879 | }
|
---|
| 880 | // to keep compiler happy
|
---|
| 881 | return mMinFilter;
|
---|
| 882 | }
|
---|
| 883 |
|
---|
| 884 | //-----------------------------------------------------------------------
|
---|
| 885 | void TextureUnitState::setTextureAnisotropy(unsigned int maxAniso)
|
---|
| 886 | {
|
---|
| 887 | mMaxAniso = maxAniso;
|
---|
| 888 | mIsDefaultAniso = false;
|
---|
| 889 | }
|
---|
| 890 | //-----------------------------------------------------------------------
|
---|
| 891 | unsigned int TextureUnitState::getTextureAnisotropy() const
|
---|
| 892 | {
|
---|
| 893 | return mIsDefaultAniso? MaterialManager::getSingleton().getDefaultAnisotropy() : mMaxAniso;
|
---|
| 894 | }
|
---|
| 895 |
|
---|
| 896 | //-----------------------------------------------------------------------
|
---|
| 897 | void TextureUnitState::_unload(void)
|
---|
| 898 | {
|
---|
| 899 | // Destroy animation controller
|
---|
| 900 | if (mAnimController)
|
---|
| 901 | {
|
---|
| 902 | ControllerManager::getSingleton().destroyController(mAnimController);
|
---|
| 903 | mAnimController = 0;
|
---|
| 904 | }
|
---|
| 905 |
|
---|
| 906 | // Destroy effect controllers
|
---|
| 907 | for (EffectMap::iterator i = mEffects.begin(); i != mEffects.end(); ++i)
|
---|
| 908 | {
|
---|
| 909 | if (i->second.controller)
|
---|
| 910 | {
|
---|
| 911 | ControllerManager::getSingleton().destroyController(i->second.controller);
|
---|
| 912 | i->second.controller = 0;
|
---|
| 913 | }
|
---|
| 914 | }
|
---|
| 915 |
|
---|
| 916 | // Don't unload textures. may be used elsewhere
|
---|
| 917 | }
|
---|
| 918 | //-----------------------------------------------------------------------------
|
---|
| 919 | bool TextureUnitState::isLoaded(void)
|
---|
| 920 | {
|
---|
| 921 | return mParent->isLoaded();
|
---|
| 922 | }
|
---|
| 923 | //-----------------------------------------------------------------------
|
---|
| 924 | void TextureUnitState::_notifyNeedsRecompile(void)
|
---|
| 925 | {
|
---|
| 926 | mParent->_notifyNeedsRecompile();
|
---|
| 927 | }
|
---|
| 928 | //-----------------------------------------------------------------------
|
---|
| 929 | bool TextureUnitState::hasViewRelativeTextureCoordinateGeneration(void)
|
---|
| 930 | {
|
---|
| 931 | // Right now this only returns true for reflection maps
|
---|
| 932 |
|
---|
| 933 | EffectMap::const_iterator i, iend;
|
---|
| 934 | iend = mEffects.end();
|
---|
| 935 |
|
---|
| 936 | for(i = mEffects.find(ET_ENVIRONMENT_MAP); i != iend; ++i)
|
---|
| 937 | {
|
---|
| 938 | if (i->second.subtype == ENV_REFLECTION)
|
---|
| 939 | return true;
|
---|
| 940 | }
|
---|
| 941 | for(i = mEffects.find(ET_PROJECTIVE_TEXTURE); i != iend; ++i)
|
---|
| 942 | {
|
---|
| 943 | return true;
|
---|
| 944 | }
|
---|
| 945 |
|
---|
| 946 | return false;
|
---|
| 947 | }
|
---|
| 948 | //-----------------------------------------------------------------------
|
---|
| 949 | void TextureUnitState::setProjectiveTexturing(bool enable,
|
---|
| 950 | const Frustum* projectionSettings)
|
---|
| 951 | {
|
---|
| 952 | if (enable)
|
---|
| 953 | {
|
---|
| 954 | TextureEffect eff;
|
---|
| 955 | eff.type = ET_PROJECTIVE_TEXTURE;
|
---|
| 956 | eff.frustum = projectionSettings;
|
---|
| 957 | addEffect(eff);
|
---|
| 958 | }
|
---|
| 959 | else
|
---|
| 960 | {
|
---|
| 961 | removeEffect(ET_PROJECTIVE_TEXTURE);
|
---|
| 962 | }
|
---|
| 963 |
|
---|
| 964 | }
|
---|
| 965 | //-----------------------------------------------------------------------------
|
---|
| 966 | void TextureUnitState::_notifyParent(Pass* parent)
|
---|
| 967 | {
|
---|
| 968 | mParent = parent;
|
---|
| 969 | }
|
---|
| 970 |
|
---|
| 971 |
|
---|
| 972 | }
|
---|