Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound 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 © 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 #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_SCROLL,
00068             ET_ROTATE,
00070             ET_TRANSFORM
00071 
00072         };
00073 
00079         enum EnvMapType
00080         {
00082             ENV_PLANAR,
00084             ENV_CURVED,
00086             ENV_REFLECTION,
00088             ENV_NORMAL
00089         };
00090 
00096         enum TextureTransformType
00097         {
00098             TT_TRANSLATE_U,
00099             TT_TRANSLATE_V,
00100             TT_SCALE_U,
00101             TT_SCALE_V,
00102             TT_ROTATE
00103         };
00104 
00110         enum TextureAddressingMode
00111         {
00113             TAM_WRAP,
00115             TAM_MIRROR,
00117             TAM_CLAMP
00118         };
00119 
00122         enum TextureCubeFace
00123         {
00124             CUBE_FRONT = 0,
00125             CUBE_BACK = 1,
00126             CUBE_LEFT = 2,
00127             CUBE_RIGHT = 3,
00128             CUBE_UP = 4,
00129             CUBE_DOWN = 5
00130         };
00131 
00134         struct TextureEffect {
00135             TextureEffectType type;
00136             int subtype;
00137             Real arg1, arg2;
00138             WaveformType waveType;
00139             Real base;
00140             Real frequency;
00141             Real phase;
00142             Real amplitude;
00143             Controller<Real>* controller;
00144         };
00145 
00146 
00149         TextureUnitState(Pass* parent);
00150 
00151         TextureUnitState(Pass* parent, const TextureUnitState& oth );
00152 
00153         TextureUnitState & operator = ( const TextureUnitState& oth );
00154 
00157         ~TextureUnitState();
00158 
00165         TextureUnitState( Pass* parent, const String& texName, unsigned int texCoordSet = 0);
00166 
00175         const String& getTextureName(void) const;
00176 
00182         void setTextureName( const String& name, TextureType ttype = TEX_TYPE_2D );
00183 
00230         void setCubicTextureName( const String& name, bool forUVW = false );
00231 
00278         void setCubicTextureName( const String* const names, bool forUVW = false );
00279 
00300         void setAnimatedTextureName( const String& name, unsigned int numFrames, Real duration = 0 );
00301 
00323         void setAnimatedTextureName( const String* const names, unsigned int numFrames, Real duration = 0 );
00324 
00327         std::pair< uint, uint > getTextureDimensions( unsigned int frame = 0 ) const;
00328 
00336         void setCurrentFrame( unsigned int frameNumber );
00337 
00342         unsigned int getCurrentFrame(void) const;
00343 
00348         const String& getFrameTextureName(unsigned int frameNumber) const;
00349 
00354         unsigned int getNumFrames(void) const;
00355 
00362         bool isCubic(void) const;
00363 
00368         bool is3D(void) const;
00369 
00374         TextureType getTextureType(void) const;
00375 
00380         unsigned int getTextureCoordSet(void) const;
00381 
00389         void setTextureCoordSet(unsigned int set);
00390 
00406         void setTextureTransform(const Matrix4& xform);
00407 
00415         const Matrix4& getTextureTransform(void);
00416 
00429         void setTextureScroll(Real u, Real v);
00430 
00435         void setTextureUScroll(Real value);
00436         // get texture uscroll value
00437         Real getTextureUScroll(void) const;
00438 
00443         void setTextureVScroll(Real value);
00444         // get texture vscroll value
00445         Real getTextureVScroll(void) const;
00446 
00451         void setTextureUScale(Real value);
00452         // get texture uscale value
00453         Real getTextureUScale(void) const;
00454 
00459         void setTextureVScale(Real value);
00460         // get texture vscale value
00461         Real getTextureVScale(void) const;
00462 
00476         void setTextureScale(Real uScale, Real vScale);
00477 
00487         void setTextureRotate(Real degrees);
00488         // get texture rotation effects degree value
00489         Real getTextureRotate(void) const;
00490 
00495         TextureAddressingMode getTextureAddressingMode(void) const;
00496 
00503         void setTextureAddressingMode( TextureAddressingMode tam);
00504 
00569         void setColourOperationEx(
00570             LayerBlendOperationEx op,
00571             LayerBlendSource source1 = LBS_TEXTURE,
00572             LayerBlendSource source2 = LBS_CURRENT,
00573 
00574             const ColourValue& arg1 = ColourValue::White,
00575             const ColourValue& arg2 = ColourValue::White,
00576 
00577             Real manualBlend = 0.0);
00578 
00597         void setColourOperation( const LayerBlendOperation op);
00598 
00618         void setColourOpMultipassFallback( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor);
00619 
00622         LayerBlendModeEx getColourBlendMode(void) const;
00623 
00626         LayerBlendModeEx getAlphaBlendMode(void) const;
00627 
00630         SceneBlendFactor getColourBlendFallbackSrc(void) const;
00631 
00634         SceneBlendFactor getColourBlendFallbackDest(void) const;
00635 
00661         void setAlphaOperation(LayerBlendOperationEx op,
00662             LayerBlendSource source1 = LBS_TEXTURE,
00663             LayerBlendSource source2 = LBS_CURRENT,
00664             Real arg1 = 1.0,
00665             Real arg2 = 1.0,
00666             Real manualBlend = 0.0);
00667 
00679         void addEffect(TextureEffect& effect);
00680 
00708         void setEnvironmentMap(bool enable, EnvMapType envMapType = ENV_CURVED);
00709 
00720         void setScrollAnimation(Real uSpeed, Real vSpeed);
00721 
00730         void setRotateAnimation(Real speed);
00731 
00751         void setTransformAnimation( const TextureTransformType ttype,
00752             const WaveformType waveType, Real base = 0, Real frequency = 1, Real phase = 0, Real amplitude = 1 );
00753 
00764         void setAlphaRejectSettings( const CompareFunction func, unsigned char value );
00765 
00768         CompareFunction getAlphaRejectFunction(void) const;
00769 
00772         unsigned char getAlphaRejectValue(void) const;
00773 
00776         void removeAllEffects(void);
00777 
00783         void removeEffect( const TextureEffectType type );
00784 
00790         bool isBlank(void) const;
00791 
00794         void setBlank(void);
00795 
00796         // get texture effects in a multimap paired array
00797         std::multimap<TextureEffectType, TextureEffect> getEffects(void) const;
00798         // get the animated-texture animation duration
00799         Real getAnimationDuration(void) const;
00800 
00810         void setTextureFiltering(TextureFilterOptions filterType);
00815         void setTextureFiltering(FilterType ftype, FilterOptions opts);
00824         void setTextureFiltering(FilterOptions minFilter, FilterOptions magFilter, FilterOptions mipFilter);
00825         // get the texture filtering for the given type
00826         FilterOptions getTextureFiltering(FilterType ftpye) const;
00827 
00833         void setTextureAnisotropy(unsigned int maxAniso);
00834         // get this layer texture anisotropy level
00835         unsigned int getTextureAnisotropy() const;
00836 
00838         Pass* getParent(void) { return mParent; }
00839 
00841         void _load(void);
00843         void _unload(void);
00845         bool hasViewRelativeTextureCoordinateGeneration(void);
00846 
00847         // Is this loaded?
00848         bool isLoaded(void);
00850         void _notifyNeedsRecompile(void);
00851 
00852     
00853 protected:
00854         Pass* mParent;
00855 
00856         // State
00857 #define MAX_FRAMES 32
00858 
00860         unsigned int mNumFrames;        
00862         unsigned int mCurrentFrame;
00863         // String mFrames[MAX_FRAMES] is at the end of the class                
00864 
00866         Real mAnimDuration;            
00867         Controller<Real>* mAnimController;
00868         bool mCubic; // is this a series of 6 2D textures to make up a cube?
00869         TextureType mTextureType; 
00870 
00871         unsigned int mTextureCoordSetIndex;
00872         TextureAddressingMode mAddressMode;                
00873 
00874         LayerBlendModeEx colourBlendMode;
00875         SceneBlendFactor colourBlendFallbackSrc;
00876         SceneBlendFactor colourBlendFallbackDest;
00877 
00878         LayerBlendModeEx alphaBlendMode;
00879         bool mIsBlank;
00880 
00881         bool mRecalcTexMatrix;
00882         Real mUMod, mVMod;
00883         Real mUScale, mVScale;
00884         Real mRotate;
00885         Matrix4 mTexModMatrix;
00886         CompareFunction mAlphaRejectFunc;
00887         unsigned char mAlphaRejectVal;
00888 
00889         // Animation, will be set up as Controllers
00890         Real mUScrollAnim, mVScrollAnim;
00891         Real mRotateAnim;
00892 
00894         FilterOptions mMinFilter;
00896         FilterOptions mMagFilter;
00898         FilterOptions mMipFilter;
00900         unsigned int mMaxAniso;
00901 
00902         bool mIsDefaultAniso;
00903         bool mIsDefaultFiltering;
00904 
00905 
00906         //-----------------------------------------------------------------------------
00907         // Complex members (those that can't be copied using memcpy) are at the end to 
00908         // allow for fast copying of the basic members.
00909         //
00910         String mFrames[MAX_FRAMES]; // Names of frames
00911 
00912         typedef std::multimap<TextureEffectType, TextureEffect> EffectMap;
00913         EffectMap mEffects;
00914         //-----------------------------------------------------------------------------
00915 
00916 
00917 
00920         void recalcTextureMatrix(void);
00921 
00924         void createAnimController(void);
00925 
00928         void createEffectController(TextureEffect& effect);
00929 
00930 
00931     };
00932 
00933 
00934 }
00935 
00936 #endif

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