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_SCROLL,
00070             ET_ROTATE,
00072             ET_TRANSFORM
00073 
00074         };
00075 
00081         enum EnvMapType
00082         {
00084             ENV_PLANAR,
00086             ENV_CURVED,
00088             ENV_REFLECTION,
00090             ENV_NORMAL
00091         };
00092 
00098         enum TextureTransformType
00099         {
00100             TT_TRANSLATE_U,
00101             TT_TRANSLATE_V,
00102             TT_SCALE_U,
00103             TT_SCALE_V,
00104             TT_ROTATE
00105         };
00106 
00112         enum TextureAddressingMode
00113         {
00115             TAM_WRAP,
00117             TAM_MIRROR,
00119             TAM_CLAMP
00120         };
00121 
00124         enum TextureCubeFace
00125         {
00126             CUBE_FRONT = 0,
00127             CUBE_BACK = 1,
00128             CUBE_LEFT = 2,
00129             CUBE_RIGHT = 3,
00130             CUBE_UP = 4,
00131             CUBE_DOWN = 5
00132         };
00133 
00136         struct TextureEffect {
00137             TextureEffectType type;
00138             int subtype;
00139             Real arg1, arg2;
00140             WaveformType waveType;
00141             Real base;
00142             Real frequency;
00143             Real phase;
00144             Real amplitude;
00145             Controller<Real>* controller;
00146             const Frustum* frustum;
00147         };
00148 
00149 
00152         TextureUnitState(Pass* parent);
00153 
00154         TextureUnitState(Pass* parent, const TextureUnitState& oth );
00155 
00156         TextureUnitState & operator = ( const TextureUnitState& oth );
00157 
00160         ~TextureUnitState();
00161 
00168         TextureUnitState( Pass* parent, const String& texName, unsigned int texCoordSet = 0);
00169 
00178         const String& getTextureName(void) const;
00179 
00185         void setTextureName( const String& name, TextureType ttype = TEX_TYPE_2D, int mipmaps = -1 );
00186 
00233         void setCubicTextureName( const String& name, bool forUVW = false );
00234 
00281         void setCubicTextureName( const String* const names, bool forUVW = false );
00282 
00304         void setAnimatedTextureName( const String& name, unsigned int numFrames, Real duration = 0 );
00305 
00327         void setAnimatedTextureName( const String* const names, unsigned int numFrames, Real duration = 0 );
00328 
00331         std::pair< uint, uint > getTextureDimensions( unsigned int frame = 0 ) const;
00332 
00340         void setCurrentFrame( unsigned int frameNumber );
00341 
00346         unsigned int getCurrentFrame(void) const;
00347 
00352         const String& getFrameTextureName(unsigned int frameNumber) const;
00353 
00358         unsigned int getNumFrames(void) const;
00359 
00366         bool isCubic(void) const;
00367 
00372         bool is3D(void) const;
00373 
00378         TextureType getTextureType(void) const;
00379 
00384         unsigned int getTextureCoordSet(void) const;
00385 
00393         void setTextureCoordSet(unsigned int set);
00394 
00410         void setTextureTransform(const Matrix4& xform);
00411 
00419         const Matrix4& getTextureTransform(void) const;
00420 
00433         void setTextureScroll(Real u, Real v);
00434 
00439         void setTextureUScroll(Real value);
00440         // get texture uscroll value
00441         Real getTextureUScroll(void) const;
00442 
00447         void setTextureVScroll(Real value);
00448         // get texture vscroll value
00449         Real getTextureVScroll(void) const;
00450 
00455         void setTextureUScale(Real value);
00456         // get texture uscale value
00457         Real getTextureUScale(void) const;
00458 
00463         void setTextureVScale(Real value);
00464         // get texture vscale value
00465         Real getTextureVScale(void) const;
00466 
00480         void setTextureScale(Real uScale, Real vScale);
00481 
00491         void setTextureRotate(const Radian& angle);
00492 #ifndef OGRE_FORCE_ANGLE_TYPES
00493         inline void setTextureRotate(Real angle) {
00494             setTextureRotate ( Degree(angle) );
00495         }
00496 #endif//OGRE_FORCE_ANGLE_TYPES
00497         // get texture rotation effects angle value
00498         const Radian& getTextureRotate(void) const;
00499 
00504         TextureAddressingMode getTextureAddressingMode(void) const;
00505 
00512         void setTextureAddressingMode( TextureAddressingMode tam);
00513 
00578         void setColourOperationEx(
00579             LayerBlendOperationEx op,
00580             LayerBlendSource source1 = LBS_TEXTURE,
00581             LayerBlendSource source2 = LBS_CURRENT,
00582 
00583             const ColourValue& arg1 = ColourValue::White,
00584             const ColourValue& arg2 = ColourValue::White,
00585 
00586             Real manualBlend = 0.0);
00587 
00606         void setColourOperation( const LayerBlendOperation op);
00607 
00627         void setColourOpMultipassFallback( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor);
00628 
00631         const LayerBlendModeEx& getColourBlendMode(void) const;
00632 
00635         const LayerBlendModeEx& getAlphaBlendMode(void) const;
00636 
00639         SceneBlendFactor getColourBlendFallbackSrc(void) const;
00640 
00643         SceneBlendFactor getColourBlendFallbackDest(void) const;
00644 
00670         void setAlphaOperation(LayerBlendOperationEx op,
00671             LayerBlendSource source1 = LBS_TEXTURE,
00672             LayerBlendSource source2 = LBS_CURRENT,
00673             Real arg1 = 1.0,
00674             Real arg2 = 1.0,
00675             Real manualBlend = 0.0);
00676 
00688         void addEffect(TextureEffect& effect);
00689 
00717         void setEnvironmentMap(bool enable, EnvMapType envMapType = ENV_CURVED);
00718 
00729         void setScrollAnimation(Real uSpeed, Real vSpeed);
00730 
00739         void setRotateAnimation(Real speed);
00740 
00760         void setTransformAnimation( const TextureTransformType ttype,
00761             const WaveformType waveType, Real base = 0, Real frequency = 1, Real phase = 0, Real amplitude = 1 );
00762 
00763 
00782         void setProjectiveTexturing(bool enabled, const Frustum* projectionSettings = 0);
00783 
00786         void removeAllEffects(void);
00787 
00793         void removeEffect( const TextureEffectType type );
00794 
00800         bool isBlank(void) const;
00801 
00804         void setBlank(void);
00805 
00806         // get texture effects in a multimap paired array
00807         std::multimap<TextureEffectType, TextureEffect> getEffects(void) const;
00808         // get the animated-texture animation duration
00809         Real getAnimationDuration(void) const;
00810 
00820         void setTextureFiltering(TextureFilterOptions filterType);
00825         void setTextureFiltering(FilterType ftype, FilterOptions opts);
00834         void setTextureFiltering(FilterOptions minFilter, FilterOptions magFilter, FilterOptions mipFilter);
00835         // get the texture filtering for the given type
00836         FilterOptions getTextureFiltering(FilterType ftpye) const;
00837 
00843         void setTextureAnisotropy(unsigned int maxAniso);
00844         // get this layer texture anisotropy level
00845         unsigned int getTextureAnisotropy() const;
00846 
00848         Pass* getParent(void) { return mParent; }
00849 
00851         void _load(void);
00853         void _unload(void);
00855         bool hasViewRelativeTextureCoordinateGeneration(void);
00856 
00857         // Is this loaded?
00858         bool isLoaded(void);
00860         void _notifyNeedsRecompile(void);
00861 
00863         void _notifyParent(Pass* parent);
00864 
00865 
00866     
00867 protected:
00868         // State
00869 #define OGRE_MAX_TEXTURE_FRAMES 32
00870 
00872         unsigned int mNumFrames;        
00874         unsigned int mCurrentFrame;
00875         // String mFrames[OGRE_MAX_TEXTURE_FRAMES] is at the end of the class                
00876 
00878         Real mAnimDuration;            
00879         bool mCubic; // is this a series of 6 2D textures to make up a cube?
00880         
00881         TextureType mTextureType; 
00882         int mTextureSrcMipmaps; // Request number of mipmaps
00883 
00884         unsigned int mTextureCoordSetIndex;
00885         TextureAddressingMode mAddressMode;                
00886 
00887         LayerBlendModeEx colourBlendMode;
00888         SceneBlendFactor colourBlendFallbackSrc;
00889         SceneBlendFactor colourBlendFallbackDest;
00890 
00891         LayerBlendModeEx alphaBlendMode;
00892         bool mIsBlank;
00893 
00894         mutable bool mRecalcTexMatrix;
00895         Real mUMod, mVMod;
00896         Real mUScale, mVScale;
00897         Radian mRotate;
00898         mutable Matrix4 mTexModMatrix;
00899 
00900         // Animation, will be set up as Controllers
00901         Real mUScrollAnim, mVScrollAnim;
00902         Real mRotateAnim;
00903 
00905         FilterOptions mMinFilter;
00907         FilterOptions mMagFilter;
00909         FilterOptions mMipFilter;
00911         unsigned int mMaxAniso;
00912 
00913         bool mIsDefaultAniso;
00914         bool mIsDefaultFiltering;
00915 
00916 
00917         //-----------------------------------------------------------------------------
00918         // Complex members (those that can't be copied using memcpy) are at the end to 
00919         // allow for fast copying of the basic members.
00920         //
00921         String mFrames[OGRE_MAX_TEXTURE_FRAMES]; // Names of frames
00922 
00923         typedef std::multimap<TextureEffectType, TextureEffect> EffectMap;
00924         EffectMap mEffects;
00925         //-----------------------------------------------------------------------------
00926 
00927         //-----------------------------------------------------------------------------
00928         // Pointer members (those that can't be copied using memcpy), and MUST
00929         // preserving even if assign from others
00930         //
00931         Pass* mParent;
00932         Controller<Real>* mAnimController;
00933         //-----------------------------------------------------------------------------
00934 
00935 
00938         void recalcTextureMatrix(void) const;
00939 
00942         void createAnimController(void);
00943 
00946         void createEffectController(TextureEffect& effect);
00947 
00948 
00949     };
00950 
00951 
00952 }
00953 
00954 #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 Feb 12 12:59:54 2006