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

OgreTextureUnitState.h

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://ogre.sourceforge.net/
00006 
00007 Copyright (c) 2000-2005 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 #ifndef __TextureUnitState_H__
00026 #define __TextureUnitState_H__
00027 
00028 #include "OgrePrerequisites.h"
00029 #include "OgreCommon.h"
00030 #include "OgreBlendMode.h"
00031 #include "OgreMatrix4.h"
00032 #include "OgreIteratorWrappers.h"
00033 #include "OgreString.h"
00034 #include "OgreTexture.h"
00035 
00036 namespace Ogre {
00052     class _OgreExport TextureUnitState
00053     {
00054         friend class RenderSystem;
00055     public:
00061         enum TextureEffectType
00062         {
00064             ET_ENVIRONMENT_MAP,
00066             ET_PROJECTIVE_TEXTURE,
00068             ET_UVSCROLL,
00070             ET_USCROLL,
00072             ET_VSCROLL,
00074             ET_ROTATE,
00076             ET_TRANSFORM
00077 
00078         };
00079 
00085         enum EnvMapType
00086         {
00088             ENV_PLANAR,
00090             ENV_CURVED,
00092             ENV_REFLECTION,
00094             ENV_NORMAL
00095         };
00096 
00102         enum TextureTransformType
00103         {
00104             TT_TRANSLATE_U,
00105             TT_TRANSLATE_V,
00106             TT_SCALE_U,
00107             TT_SCALE_V,
00108             TT_ROTATE
00109         };
00110 
00116         enum TextureAddressingMode
00117         {
00119             TAM_WRAP,
00121             TAM_MIRROR,
00123             TAM_CLAMP,
00125             TAM_BORDER
00126         };
00127 
00129         struct UVWAddressingMode
00130         {
00131             TextureAddressingMode u, v, w;
00132         };
00133 
00136         enum TextureCubeFace
00137         {
00138             CUBE_FRONT = 0,
00139             CUBE_BACK = 1,
00140             CUBE_LEFT = 2,
00141             CUBE_RIGHT = 3,
00142             CUBE_UP = 4,
00143             CUBE_DOWN = 5
00144         };
00145 
00148         struct TextureEffect {
00149             TextureEffectType type;
00150             int subtype;
00151             Real arg1, arg2;
00152             WaveformType waveType;
00153             Real base;
00154             Real frequency;
00155             Real phase;
00156             Real amplitude;
00157             Controller<Real>* controller;
00158             const Frustum* frustum;
00159         };
00160 
00163         typedef std::multimap<TextureEffectType, TextureEffect> EffectMap;
00164 
00167         TextureUnitState(Pass* parent);
00168 
00169         TextureUnitState(Pass* parent, const TextureUnitState& oth );
00170 
00171         TextureUnitState & operator = ( const TextureUnitState& oth );
00172 
00175         ~TextureUnitState();
00176 
00183         TextureUnitState( Pass* parent, const String& texName, unsigned int texCoordSet = 0);
00184 
00193         const String& getTextureName(void) const;
00194 
00200         void setTextureName( const String& name, TextureType ttype = TEX_TYPE_2D, int mipmaps = -1, bool isAlpha = false);
00201 
00248         void setCubicTextureName( const String& name, bool forUVW = false );
00249 
00296         void setCubicTextureName( const String* const names, bool forUVW = false );
00297 
00319         void setAnimatedTextureName( const String& name, unsigned int numFrames, Real duration = 0 );
00320 
00342         void setAnimatedTextureName( const String* const names, unsigned int numFrames, Real duration = 0 );
00343 
00346         std::pair< uint, uint > getTextureDimensions( unsigned int frame = 0 ) const;
00347 
00355         void setCurrentFrame( unsigned int frameNumber );
00356 
00361         unsigned int getCurrentFrame(void) const;
00362 
00368         const String& getFrameTextureName(unsigned int frameNumber) const;
00369 
00377         void setFrameTextureName(const String& name, unsigned int frameNumber);
00378 
00384         void addFrameTextureName(const String& name);
00392         void deleteFrameTextureName(const size_t frameNumber);
00397         unsigned int getNumFrames(void) const;
00398 
00405         bool isCubic(void) const;
00406 
00411         bool is3D(void) const;
00412 
00417         TextureType getTextureType(void) const;
00418 
00423         unsigned int getTextureCoordSet(void) const;
00424 
00432         void setTextureCoordSet(unsigned int set);
00433 
00449         void setTextureTransform(const Matrix4& xform);
00450 
00458         const Matrix4& getTextureTransform(void) const;
00459 
00472         void setTextureScroll(Real u, Real v);
00473 
00478         void setTextureUScroll(Real value);
00479         // get texture uscroll value
00480         Real getTextureUScroll(void) const;
00481 
00486         void setTextureVScroll(Real value);
00487         // get texture vscroll value
00488         Real getTextureVScroll(void) const;
00489 
00494         void setTextureUScale(Real value);
00495         // get texture uscale value
00496         Real getTextureUScale(void) const;
00497 
00502         void setTextureVScale(Real value);
00503         // get texture vscale value
00504         Real getTextureVScale(void) const;
00505 
00519         void setTextureScale(Real uScale, Real vScale);
00520 
00530         void setTextureRotate(const Radian& angle);
00531 #ifndef OGRE_FORCE_ANGLE_TYPES
00532         inline void setTextureRotate(Real angle) {
00533             setTextureRotate ( Degree(angle) );
00534         }
00535 #endif//OGRE_FORCE_ANGLE_TYPES
00536         // get texture rotation effects angle value
00537         const Radian& getTextureRotate(void) const;
00538 
00544         const UVWAddressingMode& getTextureAddressingMode(void) const;
00545 
00555         void setTextureAddressingMode( TextureAddressingMode tam);
00556 
00563         void setTextureAddressingMode( TextureAddressingMode u, 
00564             TextureAddressingMode v, TextureAddressingMode w);
00565 
00572         void setTextureAddressingMode( const UVWAddressingMode& uvw);
00573 
00581         void setTextureBorderColour(const ColourValue& colour);
00582 
00588         const ColourValue& getTextureBorderColour(void) const;
00589 
00654         void setColourOperationEx(
00655             LayerBlendOperationEx op,
00656             LayerBlendSource source1 = LBS_TEXTURE,
00657             LayerBlendSource source2 = LBS_CURRENT,
00658 
00659             const ColourValue& arg1 = ColourValue::White,
00660             const ColourValue& arg2 = ColourValue::White,
00661 
00662             Real manualBlend = 0.0);
00663 
00682         void setColourOperation( const LayerBlendOperation op);
00683 
00703         void setColourOpMultipassFallback( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor);
00704 
00707         const LayerBlendModeEx& getColourBlendMode(void) const;
00708 
00711         const LayerBlendModeEx& getAlphaBlendMode(void) const;
00712 
00715         SceneBlendFactor getColourBlendFallbackSrc(void) const;
00716 
00719         SceneBlendFactor getColourBlendFallbackDest(void) const;
00720 
00746         void setAlphaOperation(LayerBlendOperationEx op,
00747             LayerBlendSource source1 = LBS_TEXTURE,
00748             LayerBlendSource source2 = LBS_CURRENT,
00749             Real arg1 = 1.0,
00750             Real arg2 = 1.0,
00751             Real manualBlend = 0.0);
00752 
00764         void addEffect(TextureEffect& effect);
00765 
00793         void setEnvironmentMap(bool enable, EnvMapType envMapType = ENV_CURVED);
00794 
00805         void setScrollAnimation(Real uSpeed, Real vSpeed);
00806 
00815         void setRotateAnimation(Real speed);
00816 
00836         void setTransformAnimation( const TextureTransformType ttype,
00837             const WaveformType waveType, Real base = 0, Real frequency = 1, Real phase = 0, Real amplitude = 1 );
00838 
00839 
00858         void setProjectiveTexturing(bool enabled, const Frustum* projectionSettings = 0);
00859 
00862         void removeAllEffects(void);
00863 
00869         void removeEffect( const TextureEffectType type );
00870 
00876         bool isBlank(void) const;
00877 
00880         void setBlank(void);
00881 
00882         // get texture effects in a multimap paired array
00883         const EffectMap& getEffects(void) const;
00884         // get the animated-texture animation duration
00885         Real getAnimationDuration(void) const;
00886 
00896         void setTextureFiltering(TextureFilterOptions filterType);
00901         void setTextureFiltering(FilterType ftype, FilterOptions opts);
00910         void setTextureFiltering(FilterOptions minFilter, FilterOptions magFilter, FilterOptions mipFilter);
00911         // get the texture filtering for the given type
00912         FilterOptions getTextureFiltering(FilterType ftpye) const;
00913 
00919         void setTextureAnisotropy(unsigned int maxAniso);
00920         // get this layer texture anisotropy level
00921         unsigned int getTextureAnisotropy() const;
00922 
00924         Pass* getParent(void) const { return mParent; }
00925 
00927         void _load(void);
00929         void _unload(void);
00931         bool hasViewRelativeTextureCoordinateGeneration(void);
00932 
00933         // Is this loaded?
00934         bool isLoaded(void);
00936         void _notifyNeedsRecompile(void);
00937 
00943         void setName(const String& name);
00945         const String& getName(void) const { return mName; }
00946 
00950         void setTextureNameAlias(const String& name);
00953         const String& getTextureNameAlias(void) const { return mTextureNameAlias;}
00954 
00969         bool applyTextureAliases(const AliasTextureNamePairList& aliasList, const bool apply = true);
00970 
00972         void _notifyParent(Pass* parent);
00973     
00974 protected:
00975         // State
00977         unsigned int mCurrentFrame;
00978 
00980         Real mAnimDuration;            
00981         bool mCubic; // is this a series of 6 2D textures to make up a cube?
00982         
00983         TextureType mTextureType; 
00984         int mTextureSrcMipmaps; // Request number of mipmaps
00985 
00986         unsigned int mTextureCoordSetIndex;
00987         UVWAddressingMode mAddressMode;
00988         ColourValue mBorderColour;
00989 
00990         LayerBlendModeEx colourBlendMode;
00991         SceneBlendFactor colourBlendFallbackSrc;
00992         SceneBlendFactor colourBlendFallbackDest;
00993 
00994         LayerBlendModeEx alphaBlendMode;
00995         bool mIsBlank;
00996         bool mIsAlpha;
00997 
00998         mutable bool mRecalcTexMatrix;
00999         Real mUMod, mVMod;
01000         Real mUScale, mVScale;
01001         Radian mRotate;
01002         mutable Matrix4 mTexModMatrix;
01003 
01004         // Animation, will be set up as Controllers
01005         Real mUScrollAnim, mVScrollAnim;
01006         Real mRotateAnim;
01007 
01009         FilterOptions mMinFilter;
01011         FilterOptions mMagFilter;
01013         FilterOptions mMipFilter;
01015         unsigned int mMaxAniso;
01016 
01017         bool mIsDefaultAniso;
01018         bool mIsDefaultFiltering;
01019 
01020 
01021         //-----------------------------------------------------------------------------
01022         // Complex members (those that can't be copied using memcpy) are at the end to 
01023         // allow for fast copying of the basic members.
01024         //
01025         std::vector<String> mFrames;
01026         String mName;               // optional name for the TUS
01027         String mTextureNameAlias;       // optional alias for texture frames
01028         EffectMap mEffects;
01029         //-----------------------------------------------------------------------------
01030 
01031         //-----------------------------------------------------------------------------
01032         // Pointer members (those that can't be copied using memcpy), and MUST
01033         // preserving even if assign from others
01034         //
01035         Pass* mParent;
01036         Controller<Real>* mAnimController;
01037         //-----------------------------------------------------------------------------
01038 
01039 
01042         void recalcTextureMatrix(void) const;
01043 
01046         void createAnimController(void);
01047 
01050         void createEffectController(TextureEffect& effect);
01051 
01052 
01053     };
01054 
01055 
01056 }
01057 
01058 #endif

Copyright © 2000-2005 by The OGRE Team
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Mar 12 14:37:51 2006