Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

OgreTextureLayer.cpp

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004     (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org/
00006 
00007 Copyright © 2000-2002 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 #include "OgreMaterial.h"
00027 
00028 #include "OgreLogManager.h"
00029 #include "OgreMath.h"
00030 #include "OgreControllerManager.h"
00031 #include "OgreMaterialManager.h"
00032 
00033 namespace Ogre {
00034 
00035     //-----------------------------------------------------------------------
00036     Material::TextureLayer::TextureLayer(bool deferLoad)
00037     {
00038         mIsBlank = true;
00039         colourBlendMode.blendType = LBT_COLOUR;
00040         setColourOperation(LBO_MODULATE);
00041         setTextureAddressingMode(TAM_WRAP);
00042 
00043         alphaBlendMode.operation = LBX_MODULATE;
00044         alphaBlendMode.blendType = LBT_ALPHA;
00045         alphaBlendMode.source1 = LBS_TEXTURE;
00046         alphaBlendMode.source2 = LBS_CURRENT;
00047         
00048         //default filtering
00049         mTextureLayerFiltering = MaterialManager::getSingleton().getDefaultTextureFiltering();
00050         mMaxAniso = MaterialManager::getSingleton().getDefaultAnisotropy();
00051         mIsDefAniso = true;
00052         mIsDefFiltering = true;
00053 
00054         mUMod = mVMod = 0;
00055         mUScale = mVScale = 1;
00056         mRotate = 0;
00057         mTexModMatrix = Matrix4::IDENTITY;
00058         mRecalcTexMatrix = false;
00059         mAlphaRejectFunc = CMPF_ALWAYS_PASS;
00060         mAlphaRejectVal = 0;
00061 
00062         mNumFrames = 0;
00063         mAnimDuration = 0;
00064         mAnimController = 0;
00065         mCubic = false;
00066 
00067         mDeferLoad = deferLoad;
00068     }
00069 
00070     //-----------------------------------------------------------------------
00071     Material::TextureLayer::TextureLayer( const TextureLayer& oth )
00072     {
00073         *this = oth;
00074     }
00075 
00076     //-----------------------------------------------------------------------
00077     Material::TextureLayer::TextureLayer( const String& texName, int texCoordSet, bool deferLoad)
00078     {
00079         mIsBlank = true;
00080         colourBlendMode.blendType = LBT_COLOUR;
00081         setColourOperation(LBO_MODULATE);
00082         setTextureAddressingMode(TAM_WRAP);
00083 
00084         alphaBlendMode.operation = LBX_MODULATE;
00085         alphaBlendMode.blendType = LBT_ALPHA;
00086         alphaBlendMode.source1 = LBS_TEXTURE;
00087         alphaBlendMode.source2 = LBS_CURRENT;
00088 
00089         //default filtering && anisotropy
00090         mTextureLayerFiltering = MaterialManager::getSingleton().getDefaultTextureFiltering();
00091         mMaxAniso = MaterialManager::getSingleton().getDefaultAnisotropy();
00092         mIsDefAniso = true;
00093         mIsDefFiltering = true;
00094 
00095         mUMod = mVMod = 0;
00096         mUScale = mVScale = 1;
00097         mRotate = 0;
00098         mAnimDuration = 0;
00099         mAnimController = 0;
00100         mTexModMatrix = Matrix4::IDENTITY;
00101         mRecalcTexMatrix = false;
00102         mAlphaRejectFunc = CMPF_ALWAYS_PASS;
00103         mAlphaRejectVal = 0;
00104         mDeferLoad = deferLoad;
00105 
00106         setTextureName(texName);
00107         setTextureCoordSet(texCoordSet);
00108     }
00109 
00110     Material::TextureLayer::~TextureLayer()
00111     {
00112         // Destroy controllers
00113         if (mAnimController)
00114         {
00115             ControllerManager::getSingleton().destroyController(mAnimController);
00116         }
00117         // Destroy effect controllers
00118         for (EffectMap::iterator i = mEffects.begin(); i != mEffects.end(); ++i)
00119         {
00120             if (i->second.controller)
00121             {
00122                 ControllerManager::getSingleton().destroyController(i->second.controller);
00123             }
00124 
00125         }
00126         // Don't unload textures. may be used elsewhere
00127 
00128     }
00129     //-----------------------------------------------------------------------
00130     Material::TextureLayer & Material::TextureLayer::operator = ( 
00131         const Material::TextureLayer &oth )
00132     {
00133         // copy basic members (int's, real's)
00134         memcpy( this, &oth, (uchar *)(&oth.mFrames[0]) - (uchar *)(&oth) );
00135 
00136         // copy complex members
00137         for( ushort i = 0; i<mNumFrames; i++ )
00138             mFrames[i] = oth.mFrames[i];
00139 
00140         mEffects = oth.mEffects;
00141 
00142         return *this;
00143     }
00144     //-----------------------------------------------------------------------
00145     const String& Material::TextureLayer::getTextureName(void) const
00146     {
00147         // Return name of current frame
00148         return mFrames[mCurrentFrame];
00149     }
00150     //-----------------------------------------------------------------------
00151     void Material::TextureLayer::setTextureName( const String& name)
00152     {
00153         mFrames[0] = name;
00154         mNumFrames = 1;
00155         mCurrentFrame = 0;
00156         mCubic = false;
00157 
00158         if (name == "")
00159         {
00160             mIsBlank = true;
00161         }
00162         else if (!mDeferLoad)
00163         {
00164             // Ensure texture is loaded, default MipMaps and priority
00165             if( TextureManager::getSingleton().getByName( name ) != NULL )
00166             {
00167                 mIsBlank = false;
00168                 return;
00169             }
00170 
00171             try {                
00172                 TextureManager::getSingleton().load(name);
00173                 mIsBlank = false;
00174             }
00175             catch (...) {
00176                 String msg;
00177                 msg = msg + "Error loading texture " + name  + ". Texture layer will be blank.";
00178                 LogManager::getSingleton().logMessage(msg);
00179                 mIsBlank = true;
00180             }
00181         }
00182 
00183     }
00184     //-----------------------------------------------------------------------
00185     void Material::TextureLayer::setCubicTextureName( const String& name, bool forUVW)
00186     {
00187         if (forUVW)
00188         {
00189             setCubicTextureName(&name, forUVW);
00190         }
00191         else
00192         {
00193             String ext;
00194             String suffixes[6] = {"_fr", "_bk", "_lf", "_rt", "_up", "_dn"};
00195             String baseName;
00196             String fullNames[6];
00197 
00198 
00199             size_t pos = name.find_last_of(".");
00200             baseName = name.substr(0, pos);
00201             ext = name.substr(pos);
00202 
00203             for (int i = 0; i < 6; ++i)
00204             {
00205                 fullNames[i] = baseName + suffixes[i] + ext;
00206             }
00207 
00208             setCubicTextureName(fullNames, forUVW);
00209         }
00210     }
00211     //-----------------------------------------------------------------------
00212     void Material::TextureLayer::setCubicTextureName(const String* const names, bool forUVW)
00213     {
00214         mNumFrames = forUVW ? 1 : 6;
00215         mCurrentFrame = 0;
00216         mCubic = true;
00217 
00218         for (int i = 0; i < mNumFrames; ++i)
00219         {
00220             mFrames[i] = names[i];
00221             if (!mDeferLoad)
00222             {
00223                 // Ensure texture is loaded, default MipMaps and priority
00224                 try {
00225 
00226                     if(forUVW)
00227                     {
00228                         TextureManager::getSingleton().load(mFrames[i], 
00229                             TEX_TYPE_CUBE_MAP);
00230                     }
00231                     else
00232                     {
00233                         TextureManager::getSingleton().load(mFrames[i]);
00234                     }
00235                     mIsBlank = false;
00236                 }
00237                 catch (...) {
00238                     String msg;
00239                     msg = msg + "Error loading texture " + mFrames[i]  + ". Texture layer will be blank.";
00240                     LogManager::getSingleton().logMessage(msg);
00241                     mIsBlank = true;
00242                 }
00243             }
00244         }
00245     }
00246     //-----------------------------------------------------------------------
00247     bool Material::TextureLayer::isCubic(void) const
00248     {
00249         return mCubic;
00250     }
00251     //-----------------------------------------------------------------------
00252     bool Material::TextureLayer::is3D(void) const
00253     {
00254         return mCubic && (mNumFrames == 1);
00255 
00256     }
00257     //-----------------------------------------------------------------------
00258     void Material::TextureLayer::setAnimatedTextureName( const String& name, int numFrames, Real duration)
00259     {
00260         String ext;
00261         String baseName;
00262 
00263         size_t pos = name.find_last_of(".");
00264         baseName = name.substr(0, pos);
00265         ext = name.substr(pos);
00266 
00267         if (numFrames > MAX_FRAMES)
00268         {
00269             char cmsg[128];
00270             sprintf(cmsg, "Maximum number of frames is %d.", MAX_FRAMES);
00271             Except(Exception::ERR_INVALIDPARAMS, cmsg, "TextureLayer::setAnimatedTextureName");
00272         }
00273         mNumFrames = numFrames;
00274         mAnimDuration = duration;
00275         mCurrentFrame = 0;
00276         mCubic = false;
00277 
00278         for (int i = 0; i < mNumFrames; ++i)
00279         {
00280             char suffix[5];
00281             sprintf(suffix, "_%d", i);
00282 
00283             mFrames[i] = baseName + suffix + ext;
00284             if (!mDeferLoad)
00285             {
00286                 // Ensure texture is loaded, default MipMaps and priority
00287                 try {
00288 
00289                     TextureManager::getSingleton().load(mFrames[i]);
00290                     mIsBlank = false;
00291                 }
00292                 catch (...) {
00293                     String msg;
00294                     msg = msg + "Error loading texture " + mFrames[i]  + ". Texture layer will be blank.";
00295                     LogManager::getSingleton().logMessage(msg);
00296                     mIsBlank = true;
00297                 }
00298             }
00299         }
00300 
00301         // Set up automatic transition
00302         if (mAnimDuration != 0 && !mDeferLoad)
00303         {
00304             createAnimController();
00305         }
00306     }
00307     //-----------------------------------------------------------------------
00308     void Material::TextureLayer::setAnimatedTextureName(const String* const names, int numFrames, Real duration)
00309     {
00310         if (numFrames > MAX_FRAMES)
00311         {
00312             char cmsg[128];
00313             sprintf(cmsg, "Maximum number of frames is %d.", MAX_FRAMES);
00314             Except(Exception::ERR_INVALIDPARAMS, cmsg, "TextureLayer::setAnimatedTextureName");
00315         }
00316         mNumFrames = numFrames;
00317         mAnimDuration = duration;
00318         mCurrentFrame = 0;
00319         mCubic = false;
00320 
00321         for (int i = 0; i < mNumFrames; ++i)
00322         {
00323             mFrames[i] = names[i];
00324 
00325             if (!mDeferLoad)
00326             {
00327                 // Ensure texture is loaded, default MipMaps and priority
00328                 try {
00329 
00330                     TextureManager::getSingleton().load(mFrames[i]);
00331                     mIsBlank = false;
00332                 }
00333                 catch (...) {
00334                     String msg;
00335                     msg = msg + "Error loading texture " + mFrames[i]  + ". Texture layer will be blank.";
00336                     LogManager::getSingleton().logMessage(msg);
00337                     mIsBlank = true;
00338                 }
00339             }
00340         }
00341         // Set up automatic transition
00342         if (mAnimDuration != 0 && !mDeferLoad)
00343         {
00344             createAnimController();
00345         }
00346     }
00347     //-----------------------------------------------------------------------
00348     std::pair< uint, uint > Material::TextureLayer::getTextureDimensions( int frame ) const
00349     {
00350         Texture *tex = (Texture *)TextureManager::getSingleton().getByName( mFrames[ frame ] );
00351         if (!tex)
00352             Except( Exception::ERR_ITEM_NOT_FOUND, "Could not find texture " + mFrames[ frame ],
00353                 "Material::TextureLayer::getTextureDimensions" );
00354         return std::pair< uint, uint >( tex->getWidth(), tex->getHeight() );
00355     }
00356     //-----------------------------------------------------------------------
00357     void Material::TextureLayer::setCurrentFrame(int frameNumber)
00358     {
00359         assert(frameNumber < mNumFrames);
00360         mCurrentFrame = frameNumber;
00361 
00362     }
00363     //-----------------------------------------------------------------------
00364     int Material::TextureLayer::getCurrentFrame(void) const
00365     {
00366         return mCurrentFrame;
00367     }
00368     //-----------------------------------------------------------------------
00369     int Material::TextureLayer::getNumFrames(void) const
00370     {
00371         return mNumFrames;
00372     }
00373     //-----------------------------------------------------------------------
00374     const String& Material::TextureLayer::getFrameTextureName(int frameNumber) const
00375     {
00376         assert(frameNumber < mNumFrames);
00377         return mFrames[frameNumber];
00378     }
00379     //-----------------------------------------------------------------------
00380     int Material::TextureLayer::getTextureCoordSet(void) const
00381     {
00382         return mTextureCoordSetIndex;
00383     }
00384     //-----------------------------------------------------------------------
00385     void Material::TextureLayer::setTextureCoordSet(int set)
00386     {
00387         mTextureCoordSetIndex = set;
00388     }
00389     //-----------------------------------------------------------------------
00390     void Material::TextureLayer::setColourOperationEx(LayerBlendOperationEx op,
00391         LayerBlendSource source1,
00392         LayerBlendSource source2,
00393         const ColourValue& arg1,
00394         const ColourValue& arg2,
00395         Real manualBlend)
00396     {
00397         colourBlendMode.operation = op;
00398         colourBlendMode.source1 = source1;
00399         colourBlendMode.source2 = source2;
00400         colourBlendMode.colourArg1 = arg1;
00401         colourBlendMode.colourArg2 = arg2;
00402         colourBlendMode.factor = manualBlend;
00403     }
00404     //-----------------------------------------------------------------------
00405     void Material::TextureLayer::setColourOperation(LayerBlendOperation op)
00406     {
00407         // Set up the multitexture and multipass blending operations
00408         switch (op)
00409         {
00410         case LBO_REPLACE:
00411             setColourOperationEx(LBX_SOURCE1, LBS_TEXTURE, LBS_CURRENT);
00412             setColourOpMultipassFallback(SBF_ONE, SBF_ZERO);
00413             break;
00414         case LBO_ADD:
00415             setColourOperationEx(LBX_ADD, LBS_TEXTURE, LBS_CURRENT);
00416             setColourOpMultipassFallback(SBF_ONE, SBF_ONE);
00417             break;
00418         case LBO_MODULATE:
00419             setColourOperationEx(LBX_MODULATE, LBS_TEXTURE, LBS_CURRENT);
00420             setColourOpMultipassFallback(SBF_DEST_COLOUR, SBF_ZERO);
00421             break;
00422         case LBO_ALPHA_BLEND:
00423             setColourOperationEx(LBX_BLEND_TEXTURE_ALPHA, LBS_TEXTURE, LBS_CURRENT);
00424             setColourOpMultipassFallback(SBF_SOURCE_ALPHA, SBF_ONE_MINUS_SOURCE_ALPHA);
00425             break;
00426         }
00427 
00428 
00429     }
00430     //-----------------------------------------------------------------------
00431     void Material::TextureLayer::setColourOpMultipassFallback(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor)
00432     {
00433         colourBlendFallbackSrc = sourceFactor;
00434         colourBlendFallbackDest = destFactor;
00435     }
00436     //-----------------------------------------------------------------------
00437     void Material::TextureLayer::setAlphaOperation(LayerBlendOperationEx op,
00438         LayerBlendSource source1,
00439         LayerBlendSource source2,
00440         Real arg1,
00441         Real arg2,
00442         Real manualBlend)
00443     {
00444         alphaBlendMode.operation = op;
00445         alphaBlendMode.source1 = source1;
00446         alphaBlendMode.source2 = source2;
00447         alphaBlendMode.alphaArg1 = arg1;
00448         alphaBlendMode.alphaArg2 = arg2;
00449         alphaBlendMode.factor = manualBlend;
00450     }
00451     //-----------------------------------------------------------------------
00452     void Material::TextureLayer::addEffect(TextureEffect& effect)
00453     {
00454         // Ensure controller pointer is null
00455         effect.controller = 0;
00456 
00457         if (effect.type == ET_ENVIRONMENT_MAP || effect.type == ET_SCROLL || effect.type == ET_ROTATE)
00458         {
00459             // Replace - must be unique
00460             // Search for existing effect of this type
00461             EffectMap::iterator i = mEffects.find(effect.type);
00462             if (i != mEffects.end())
00463             {
00464                 mEffects.erase(i);
00465             }
00466         }
00467 
00468         if (!mDeferLoad)
00469         {
00470             // Create controller
00471             createEffectController(effect);
00472         }
00473 
00474         // Record new effect
00475         mEffects.insert(EffectMap::value_type(effect.type, effect));
00476 
00477     }
00478     //-----------------------------------------------------------------------
00479     void Material::TextureLayer::removeAllEffects(void)
00480     {
00481         mEffects.clear();
00482     }
00483 
00484     //-----------------------------------------------------------------------
00485     bool Material::TextureLayer::isBlank(void) const
00486     {
00487         return mIsBlank;
00488     }
00489 
00490     //-----------------------------------------------------------------------
00491     SceneBlendFactor Material::TextureLayer::getColourBlendFallbackSrc(void) const
00492     {
00493         return colourBlendFallbackSrc;
00494     }
00495     //-----------------------------------------------------------------------
00496     SceneBlendFactor Material::TextureLayer::getColourBlendFallbackDest(void) const
00497     {
00498         return colourBlendFallbackDest;
00499     }
00500     //-----------------------------------------------------------------------
00501     LayerBlendModeEx Material::TextureLayer::getColourBlendMode(void) const
00502     {
00503         return colourBlendMode;
00504     }
00505     //-----------------------------------------------------------------------
00506     LayerBlendModeEx Material::TextureLayer::getAlphaBlendMode(void) const
00507     {
00508         return alphaBlendMode;
00509     }
00510     //-----------------------------------------------------------------------
00511     Material::TextureLayer::TextureAddressingMode Material::TextureLayer::getTextureAddressingMode(void) const
00512     {
00513         return mAddressMode;
00514     }
00515     //-----------------------------------------------------------------------
00516     void Material::TextureLayer::setTextureAddressingMode(Material::TextureLayer::TextureAddressingMode tam)
00517     {
00518         mAddressMode = tam;
00519     }
00520     //-----------------------------------------------------------------------
00521     void Material::TextureLayer::setEnvironmentMap(bool enable, EnvMapType envMapType)
00522     {
00523         if (enable)
00524         {
00525             TextureEffect eff;
00526             eff.type = ET_ENVIRONMENT_MAP;
00527 
00528             eff.subtype = envMapType;
00529             addEffect(eff);
00530         }
00531         else
00532         {
00533             removeEffect(ET_ENVIRONMENT_MAP);
00534         }
00535     }
00536     //-----------------------------------------------------------------------
00537     void Material::TextureLayer::removeEffect(TextureEffectType type)
00538     {
00539       // EffectMap::iterator i = mEffects.find(type);
00540         std::pair< EffectMap::iterator, EffectMap::iterator > remPair = mEffects.equal_range( type );
00541         mEffects.erase( remPair.first, remPair.second );
00542         //EffectMap::iterator i = mEffects.find(type);
00543 /*        for (; i != mEffects.end() && i->first == type; ++i)
00544         {
00545             // Remove all instances of this type
00546 #ifdef __GNUC__
00547             assert(0);
00548             // Why do I get an error here???
00549             //i = mEffects.erase(i);
00550 #else
00551             i++;
00552             EffectMap::iterator j = i;
00553             i--;
00554             mEffects.erase( i );
00555             i = j;
00556 #endif
00557         }
00558 */
00559     }
00560     //-----------------------------------------------------------------------
00561     void Material::TextureLayer::setBlank(void)
00562     {
00563         mIsBlank = true;
00564     }
00565     //-----------------------------------------------------------------------
00566     void Material::TextureLayer::setTextureTransform(const Matrix4& xform)
00567     {
00568         mTexModMatrix = xform;
00569         mRecalcTexMatrix = false;
00570     }
00571     //-----------------------------------------------------------------------
00572     void Material::TextureLayer::setTextureScroll(Real u, Real v)
00573     {
00574         mUMod = u;
00575         mVMod = v;
00576         mRecalcTexMatrix = true;
00577     }
00578     //-----------------------------------------------------------------------
00579     void Material::TextureLayer::setTextureScale(Real uScale, Real vScale)
00580     {
00581         mUScale = uScale;
00582         mVScale = vScale;
00583         mRecalcTexMatrix = true;
00584     }
00585     //-----------------------------------------------------------------------
00586     void Material::TextureLayer::setTextureRotate(Real degrees)
00587     {
00588         mRotate = degrees;
00589         mRecalcTexMatrix = true;
00590     }
00591     //-----------------------------------------------------------------------
00592     const Matrix4& Material::TextureLayer::getTextureTransform()
00593     {
00594         if (mRecalcTexMatrix)
00595             recalcTextureMatrix();
00596         return mTexModMatrix;
00597 
00598     }
00599     //-----------------------------------------------------------------------
00600     void Material::TextureLayer::recalcTextureMatrix()
00601     {
00602         // Assumption: 2D texture coords
00603         Matrix3 xform, rot;
00604 
00605         xform = Matrix3::IDENTITY;
00606         if (mUScale || mVScale)
00607         {
00608             // Offset to center of texture
00609             xform[0][0] = 1/mUScale;
00610             xform[1][1] = 1/mVScale;
00611             // Skip matrix concat since first matrix update
00612             xform[0][2] = (-0.5 * xform[0][0]) + 0.5;
00613             xform[1][2] = (-0.5 * xform[1][1]) + 0.5;
00614 
00615         }
00616 
00617         if (mUMod || mVMod)
00618         {
00619             Matrix3 xlate = Matrix3::IDENTITY;
00620 
00621             xlate[0][2] = mUMod;
00622             xlate[1][2] = mVMod;
00623 
00624             xform = xlate * xform;
00625         }
00626 
00627         if (mRotate != 0)
00628         {
00629             rot = Matrix3::IDENTITY;
00630             Real theta = Math::AngleUnitsToRadians(mRotate);
00631             Real cosTheta = Math::Cos(theta);
00632             Real sinTheta = Math::Sin(theta);
00633 
00634             rot[0][0] = cosTheta;
00635             rot[0][1] = -sinTheta;
00636             rot[1][0] = sinTheta;
00637             rot[1][1] = cosTheta;
00638             // Offset center of rotation to center of texture
00639             Real cosThetaOff = cosTheta * -0.5;
00640             Real sinThetaOff = sinTheta * -0.5;
00641             rot[0][2] = cosThetaOff - sinThetaOff;
00642             rot[1][2] = sinThetaOff + cosThetaOff;
00643 
00644 
00645             xform = xform * rot;
00646         }
00647 
00648         mTexModMatrix = xform;
00649 
00650     }
00651     //-----------------------------------------------------------------------
00652     void Material::TextureLayer::setTextureUScroll(Real value)
00653     {
00654         mUMod = value;
00655         mRecalcTexMatrix = true;
00656     }
00657     //-----------------------------------------------------------------------
00658     void Material::TextureLayer::setTextureVScroll(Real value)
00659     {
00660         mVMod = value;
00661         mRecalcTexMatrix = true;
00662     }
00663     //-----------------------------------------------------------------------
00664     void Material::TextureLayer::setTextureUScale(Real value)
00665     {
00666         mUScale = value;
00667         mRecalcTexMatrix = true;
00668     }
00669     //-----------------------------------------------------------------------
00670     void Material::TextureLayer::setTextureVScale(Real value)
00671     {
00672         mVScale = value;
00673         mRecalcTexMatrix = true;
00674     }
00675     //-----------------------------------------------------------------------
00676     void Material::TextureLayer::setAlphaRejectSettings(CompareFunction func, unsigned char value)
00677     {
00678         mAlphaRejectFunc = func;
00679         mAlphaRejectVal = value;
00680     }
00681     //-----------------------------------------------------------------------
00682     CompareFunction Material::TextureLayer::getAlphaRejectFunction(void) const
00683     {
00684         return mAlphaRejectFunc;
00685     }
00686     //-----------------------------------------------------------------------
00687     unsigned char Material::TextureLayer::getAlphaRejectValue(void) const
00688     {
00689         return mAlphaRejectVal;
00690     }
00691     //-----------------------------------------------------------------------
00692     void Material::TextureLayer::setScrollAnimation(Real uSpeed, Real vSpeed)
00693     {
00694         TextureEffect eff;
00695         eff.type = ET_SCROLL;
00696         eff.arg1 = uSpeed;
00697         eff.arg2 = vSpeed;
00698         addEffect(eff);
00699     }
00700     //-----------------------------------------------------------------------
00701     void Material::TextureLayer::setRotateAnimation(Real speed)
00702     {
00703         TextureEffect eff;
00704         eff.type = ET_ROTATE;
00705         eff.arg1 = speed;
00706         addEffect(eff);
00707     }
00708     //-----------------------------------------------------------------------
00709     void Material::TextureLayer::setTransformAnimation(TextureTransformType ttype,
00710         WaveformType waveType, Real base, Real frequency, Real phase, Real amplitude)
00711     {
00712         TextureEffect eff;
00713         eff.type = ET_TRANSFORM;
00714         eff.subtype = ttype;
00715         eff.waveType = waveType;
00716         eff.base = base;
00717         eff.frequency = frequency;
00718         eff.phase = phase;
00719         eff.amplitude = amplitude;
00720         addEffect(eff);
00721     }
00722     //-----------------------------------------------------------------------
00723     void Material::TextureLayer::_load(void)
00724     {
00725         // Load textures
00726         for (int i = 0; i < mNumFrames; ++i)
00727         {
00728             if (mFrames[i] != "")
00729             {
00730                 // Ensure texture is loaded, default MipMaps and priority
00731                 try {
00732 
00733                     if(is3D())
00734                         TextureManager::getSingleton().load(mFrames[i], TEX_TYPE_CUBE_MAP);
00735                     else
00736                         TextureManager::getSingleton().load(mFrames[i]);
00737 
00738                     mIsBlank = false;
00739                 }
00740                 catch (...) {
00741                     String msg;
00742                     msg = msg + "Error loading texture " + mFrames[i]  + ". Texture layer will be blank.";
00743                     LogManager::getSingleton().logMessage(msg);
00744                     mIsBlank = true;
00745                 }
00746             }
00747         }
00748         // Animation controller
00749         if (mAnimDuration != 0)
00750         {
00751             createAnimController();
00752         }
00753         // Effect controllers
00754         for (EffectMap::iterator it = mEffects.begin(); it != mEffects.end(); ++it)
00755         {
00756             createEffectController(it->second);
00757         }
00758 
00759         mDeferLoad = false;
00760 
00761     }
00762     //-----------------------------------------------------------------------
00763     void Material::TextureLayer::createAnimController(void)
00764     {
00765         mAnimController = ControllerManager::getSingleton().createTextureAnimator(this, mAnimDuration);
00766 
00767     }
00768     //-----------------------------------------------------------------------
00769     void Material::TextureLayer::createEffectController(TextureEffect& effect)
00770     {
00771         ControllerManager& cMgr = ControllerManager::getSingleton();
00772         switch (effect.type)
00773         {
00774         case ET_SCROLL:
00775             effect.controller = cMgr.createTextureScroller(this, effect.arg1, effect.arg2);
00776             break;
00777         case ET_ROTATE:
00778             effect.controller = cMgr.createTextureRotater(this, effect.arg1);
00779             break;
00780         case ET_TRANSFORM:
00781             effect.controller = cMgr.createTextureWaveTransformer(this, (Material::TextureLayer::TextureTransformType)effect.subtype, effect.waveType, effect.base,
00782                 effect.frequency, effect.phase, effect.amplitude);
00783             break;
00784     case ET_ENVIRONMENT_MAP:
00785         break;
00786         }
00787     }
00788     //-----------------------------------------------------------------------
00789     void Material::TextureLayer::setDeferredLoad(bool defer)
00790     {
00791         mDeferLoad = defer;
00792     }
00793 
00794     //-----------------------------------------------------------------------
00795     Real Material::TextureLayer::getTextureUScroll(void) const
00796     {
00797         return mUMod;
00798     }
00799 
00800     //-----------------------------------------------------------------------
00801     Real Material::TextureLayer::getTextureVScroll(void) const
00802     {
00803         return mVMod;
00804     }
00805 
00806     //-----------------------------------------------------------------------
00807     Real Material::TextureLayer::getTextureUScale(void) const
00808     {
00809         return mUScale;
00810     }
00811 
00812     //-----------------------------------------------------------------------
00813     Real Material::TextureLayer::getTextureVScale(void) const
00814     {
00815         return mVScale;
00816     }
00817 
00818     //-----------------------------------------------------------------------
00819     Real Material::TextureLayer::getTextureRotate(void) const
00820     {
00821         return mRotate;
00822     }
00823     
00824     //-----------------------------------------------------------------------
00825     Real Material::TextureLayer::getAnimationDuration(void) const
00826     {
00827         return mAnimDuration;
00828     }
00829 
00830     //-----------------------------------------------------------------------
00831     std::multimap<Material::TextureLayer::TextureEffectType, Material::TextureLayer::TextureEffect> Material::TextureLayer::getEffects(void) const
00832     {
00833         return mEffects;
00834     }
00835 
00836     //-----------------------------------------------------------------------
00837     void Material::TextureLayer::setTextureLayerFiltering(TextureFilterOptions filterType)
00838     {
00839         mTextureLayerFiltering = filterType;
00840         mIsDefFiltering = false;
00841     }
00842 
00843     //-----------------------------------------------------------------------
00844     TextureFilterOptions Material::TextureLayer::getTextureLayerFiltering() const
00845     {
00846         return mTextureLayerFiltering;
00847     }
00848 
00849     //-----------------------------------------------------------------------
00850     void Material::TextureLayer::setTextureAnisotropy(int maxAniso)
00851     {
00852         mMaxAniso = maxAniso;
00853         mIsDefAniso = false;
00854     }
00855 
00856     //-----------------------------------------------------------------------
00857     void Material::TextureLayer::_setDefTextureAnisotropy(int maxAniso)
00858     {
00859         if (mIsDefAniso)
00860             mMaxAniso = maxAniso;
00861     }
00862 
00863     //-----------------------------------------------------------------------
00864     void Material::TextureLayer::_setDefTextureLayerFiltering(TextureFilterOptions filterType)
00865     {
00866         if (mIsDefFiltering)
00867             mTextureLayerFiltering = filterType;
00868     }
00869 
00870     //-----------------------------------------------------------------------
00871     int Material::TextureLayer::getTextureAnisotropy() const
00872     {
00873         return mMaxAniso;
00874     }
00875 }

Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:30 2004