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_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 );
00186 
00233         void setCubicTextureName( const String& name, bool forUVW = false );
00234 
00281         void setCubicTextureName( const String* const names, bool forUVW = false );
00282 
00303         void setAnimatedTextureName( const String& name, unsigned int numFrames, Real duration = 0 );
00304 
00326         void setAnimatedTextureName( const String* const names, unsigned int numFrames, Real duration = 0 );
00327 
00330         std::pair< uint, uint > getTextureDimensions( unsigned int frame = 0 ) const;
00331 
00339         void setCurrentFrame( unsigned int frameNumber );
00340 
00345         unsigned int getCurrentFrame(void) const;
00346 
00351         const String& getFrameTextureName(unsigned int frameNumber) const;
00352 
00357         unsigned int getNumFrames(void) const;
00358 
00365         bool isCubic(void) const;
00366 
00371         bool is3D(void) const;
00372 
00377         TextureType getTextureType(void) const;
00378 
00383         unsigned int getTextureCoordSet(void) const;
00384 
00392         void setTextureCoordSet(unsigned int set);
00393 
00409         void setTextureTransform(const Matrix4& xform);
00410 
00418         const Matrix4& getTextureTransform(void);
00419 
00432         void setTextureScroll(Real u, Real v);
00433 
00438         void setTextureUScroll(Real value);
00439         // get texture uscroll value
00440         Real getTextureUScroll(void) const;
00441 
00446         void setTextureVScroll(Real value);
00447         // get texture vscroll value
00448         Real getTextureVScroll(void) const;
00449 
00454         void setTextureUScale(Real value);
00455         // get texture uscale value
00456         Real getTextureUScale(void) const;
00457 
00462         void setTextureVScale(Real value);
00463         // get texture vscale value
00464         Real getTextureVScale(void) const;
00465 
00479         void setTextureScale(Real uScale, Real vScale);
00480 
00490         void setTextureRotate(Real degrees);
00491         // get texture rotation effects degree value
00492         Real getTextureRotate(void) const;
00493 
00498         TextureAddressingMode getTextureAddressingMode(void) const;
00499 
00506         void setTextureAddressingMode( TextureAddressingMode tam);
00507 
00572         void setColourOperationEx(
00573             LayerBlendOperationEx op,
00574             LayerBlendSource source1 = LBS_TEXTURE,
00575             LayerBlendSource source2 = LBS_CURRENT,
00576 
00577             const ColourValue& arg1 = ColourValue::White,
00578             const ColourValue& arg2 = ColourValue::White,
00579 
00580             Real manualBlend = 0.0);
00581 
00600         void setColourOperation( const LayerBlendOperation op);
00601 
00621         void setColourOpMultipassFallback( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor);
00622 
00625         const LayerBlendModeEx& getColourBlendMode(void) const;
00626 
00629         const LayerBlendModeEx& getAlphaBlendMode(void) const;
00630 
00633         SceneBlendFactor getColourBlendFallbackSrc(void) const;
00634 
00637         SceneBlendFactor getColourBlendFallbackDest(void) const;
00638 
00664         void setAlphaOperation(LayerBlendOperationEx op,
00665             LayerBlendSource source1 = LBS_TEXTURE,
00666             LayerBlendSource source2 = LBS_CURRENT,
00667             Real arg1 = 1.0,
00668             Real arg2 = 1.0,
00669             Real manualBlend = 0.0);
00670 
00682         void addEffect(TextureEffect& effect);
00683 
00711         void setEnvironmentMap(bool enable, EnvMapType envMapType = ENV_CURVED);
00712 
00723         void setScrollAnimation(Real uSpeed, Real vSpeed);
00724 
00733         void setRotateAnimation(Real speed);
00734 
00754         void setTransformAnimation( const TextureTransformType ttype,
00755             const WaveformType waveType, Real base = 0, Real frequency = 1, Real phase = 0, Real amplitude = 1 );
00756 
00767         void setAlphaRejectSettings( const CompareFunction func, unsigned char value );
00768 
00771         CompareFunction getAlphaRejectFunction(void) const;
00772 
00775         unsigned char getAlphaRejectValue(void) const;
00776 
00795         void setProjectiveTexturing(bool enabled, const Frustum* projectionSettings = 0);
00796 
00799         void removeAllEffects(void);
00800 
00806         void removeEffect( const TextureEffectType type );
00807 
00813         bool isBlank(void) const;
00814 
00817         void setBlank(void);
00818 
00819         // get texture effects in a multimap paired array
00820         std::multimap<TextureEffectType, TextureEffect> getEffects(void) const;
00821         // get the animated-texture animation duration
00822         Real getAnimationDuration(void) const;
00823 
00833         void setTextureFiltering(TextureFilterOptions filterType);
00838         void setTextureFiltering(FilterType ftype, FilterOptions opts);
00847         void setTextureFiltering(FilterOptions minFilter, FilterOptions magFilter, FilterOptions mipFilter);
00848         // get the texture filtering for the given type
00849         FilterOptions getTextureFiltering(FilterType ftpye) const;
00850 
00856         void setTextureAnisotropy(unsigned int maxAniso);
00857         // get this layer texture anisotropy level
00858         unsigned int getTextureAnisotropy() const;
00859 
00861         Pass* getParent(void) { return mParent; }
00862 
00864         void _load(void);
00866         void _unload(void);
00868         bool hasViewRelativeTextureCoordinateGeneration(void);
00869 
00870         // Is this loaded?
00871         bool isLoaded(void);
00873         void _notifyNeedsRecompile(void);
00874 
00875     
00876 protected:
00877         Pass* mParent;
00878 
00879         // State
00880 #define MAX_FRAMES 32
00881 
00883         unsigned int mNumFrames;        
00885         unsigned int mCurrentFrame;
00886         // String mFrames[MAX_FRAMES] is at the end of the class                
00887 
00889         Real mAnimDuration;            
00890         Controller<Real>* mAnimController;
00891         bool mCubic; // is this a series of 6 2D textures to make up a cube?
00892         TextureType mTextureType; 
00893 
00894         unsigned int mTextureCoordSetIndex;
00895         TextureAddressingMode mAddressMode;                
00896 
00897         LayerBlendModeEx colourBlendMode;
00898         SceneBlendFactor colourBlendFallbackSrc;
00899         SceneBlendFactor colourBlendFallbackDest;
00900 
00901         LayerBlendModeEx alphaBlendMode;
00902         bool mIsBlank;
00903 
00904         bool mRecalcTexMatrix;
00905         Real mUMod, mVMod;
00906         Real mUScale, mVScale;
00907         Real mRotate;
00908         Matrix4 mTexModMatrix;
00909         CompareFunction mAlphaRejectFunc;
00910         unsigned char mAlphaRejectVal;
00911 
00912         // Animation, will be set up as Controllers
00913         Real mUScrollAnim, mVScrollAnim;
00914         Real mRotateAnim;
00915 
00917         FilterOptions mMinFilter;
00919         FilterOptions mMagFilter;
00921         FilterOptions mMipFilter;
00923         unsigned int mMaxAniso;
00924 
00925         bool mIsDefaultAniso;
00926         bool mIsDefaultFiltering;
00927 
00928 
00929         //-----------------------------------------------------------------------------
00930         // Complex members (those that can't be copied using memcpy) are at the end to 
00931         // allow for fast copying of the basic members.
00932         //
00933         String mFrames[MAX_FRAMES]; // Names of frames
00934 
00935         typedef std::multimap<TextureEffectType, TextureEffect> EffectMap;
00936         EffectMap mEffects;
00937         //-----------------------------------------------------------------------------
00938 
00939 
00940 
00943         void recalcTextureMatrix(void);
00944 
00947         void createAnimController(void);
00948 
00951         void createEffectController(TextureEffect& effect);
00952 
00953 
00954     };
00955 
00956 
00957 }
00958 
00959 #endif

Copyright © 2002-2003 by The OGRE Team
Last modified Fri May 14 23:22:53 2004