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 00204 int getNumRequestedMipMaps() const { return mTextureSrcMipmaps; } 00205 00208 bool isAlpha() const { return mIsAlpha; } 00209 00256 void setCubicTextureName( const String& name, bool forUVW = false ); 00257 00304 void setCubicTextureName( const String* const names, bool forUVW = false ); 00305 00327 void setAnimatedTextureName( const String& name, unsigned int numFrames, Real duration = 0 ); 00328 00350 void setAnimatedTextureName( const String* const names, unsigned int numFrames, Real duration = 0 ); 00351 00354 std::pair< uint, uint > getTextureDimensions( unsigned int frame = 0 ) const; 00355 00363 void setCurrentFrame( unsigned int frameNumber ); 00364 00369 unsigned int getCurrentFrame(void) const; 00370 00376 const String& getFrameTextureName(unsigned int frameNumber) const; 00377 00385 void setFrameTextureName(const String& name, unsigned int frameNumber); 00386 00392 void addFrameTextureName(const String& name); 00400 void deleteFrameTextureName(const size_t frameNumber); 00405 unsigned int getNumFrames(void) const; 00406 00413 bool isCubic(void) const; 00414 00419 bool is3D(void) const; 00420 00425 TextureType getTextureType(void) const; 00426 00431 unsigned int getTextureCoordSet(void) const; 00432 00440 void setTextureCoordSet(unsigned int set); 00441 00457 void setTextureTransform(const Matrix4& xform); 00458 00466 const Matrix4& getTextureTransform(void) const; 00467 00480 void setTextureScroll(Real u, Real v); 00481 00486 void setTextureUScroll(Real value); 00487 // get texture uscroll value 00488 Real getTextureUScroll(void) const; 00489 00494 void setTextureVScroll(Real value); 00495 // get texture vscroll value 00496 Real getTextureVScroll(void) const; 00497 00502 void setTextureUScale(Real value); 00503 // get texture uscale value 00504 Real getTextureUScale(void) const; 00505 00510 void setTextureVScale(Real value); 00511 // get texture vscale value 00512 Real getTextureVScale(void) const; 00513 00527 void setTextureScale(Real uScale, Real vScale); 00528 00538 void setTextureRotate(const Radian& angle); 00539 #ifndef OGRE_FORCE_ANGLE_TYPES 00540 inline void setTextureRotate(Real angle) { 00541 setTextureRotate ( Degree(angle) ); 00542 } 00543 #endif//OGRE_FORCE_ANGLE_TYPES 00544 // get texture rotation effects angle value 00545 const Radian& getTextureRotate(void) const; 00546 00552 const UVWAddressingMode& getTextureAddressingMode(void) const; 00553 00563 void setTextureAddressingMode( TextureAddressingMode tam); 00564 00571 void setTextureAddressingMode( TextureAddressingMode u, 00572 TextureAddressingMode v, TextureAddressingMode w); 00573 00580 void setTextureAddressingMode( const UVWAddressingMode& uvw); 00581 00589 void setTextureBorderColour(const ColourValue& colour); 00590 00596 const ColourValue& getTextureBorderColour(void) const; 00597 00662 void setColourOperationEx( 00663 LayerBlendOperationEx op, 00664 LayerBlendSource source1 = LBS_TEXTURE, 00665 LayerBlendSource source2 = LBS_CURRENT, 00666 00667 const ColourValue& arg1 = ColourValue::White, 00668 const ColourValue& arg2 = ColourValue::White, 00669 00670 Real manualBlend = 0.0); 00671 00690 void setColourOperation( const LayerBlendOperation op); 00691 00711 void setColourOpMultipassFallback( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor); 00712 00715 const LayerBlendModeEx& getColourBlendMode(void) const; 00716 00719 const LayerBlendModeEx& getAlphaBlendMode(void) const; 00720 00723 SceneBlendFactor getColourBlendFallbackSrc(void) const; 00724 00727 SceneBlendFactor getColourBlendFallbackDest(void) const; 00728 00754 void setAlphaOperation(LayerBlendOperationEx op, 00755 LayerBlendSource source1 = LBS_TEXTURE, 00756 LayerBlendSource source2 = LBS_CURRENT, 00757 Real arg1 = 1.0, 00758 Real arg2 = 1.0, 00759 Real manualBlend = 0.0); 00760 00772 void addEffect(TextureEffect& effect); 00773 00801 void setEnvironmentMap(bool enable, EnvMapType envMapType = ENV_CURVED); 00802 00813 void setScrollAnimation(Real uSpeed, Real vSpeed); 00814 00823 void setRotateAnimation(Real speed); 00824 00844 void setTransformAnimation( const TextureTransformType ttype, 00845 const WaveformType waveType, Real base = 0, Real frequency = 1, Real phase = 0, Real amplitude = 1 ); 00846 00847 00866 void setProjectiveTexturing(bool enabled, const Frustum* projectionSettings = 0); 00867 00870 void removeAllEffects(void); 00871 00877 void removeEffect( const TextureEffectType type ); 00878 00884 bool isBlank(void) const; 00885 00888 void setBlank(void); 00889 00890 // get texture effects in a multimap paired array 00891 const EffectMap& getEffects(void) const; 00892 // get the animated-texture animation duration 00893 Real getAnimationDuration(void) const; 00894 00904 void setTextureFiltering(TextureFilterOptions filterType); 00909 void setTextureFiltering(FilterType ftype, FilterOptions opts); 00918 void setTextureFiltering(FilterOptions minFilter, FilterOptions magFilter, FilterOptions mipFilter); 00919 // get the texture filtering for the given type 00920 FilterOptions getTextureFiltering(FilterType ftpye) const; 00921 00927 void setTextureAnisotropy(unsigned int maxAniso); 00928 // get this layer texture anisotropy level 00929 unsigned int getTextureAnisotropy() const; 00930 00932 Pass* getParent(void) const { return mParent; } 00933 00935 void _load(void); 00937 void _unload(void); 00939 bool hasViewRelativeTextureCoordinateGeneration(void); 00940 00941 // Is this loaded? 00942 bool isLoaded(void); 00944 void _notifyNeedsRecompile(void); 00945 00951 void setName(const String& name); 00953 const String& getName(void) const { return mName; } 00954 00958 void setTextureNameAlias(const String& name); 00961 const String& getTextureNameAlias(void) const { return mTextureNameAlias;} 00962 00977 bool applyTextureAliases(const AliasTextureNamePairList& aliasList, const bool apply = true); 00978 00980 void _notifyParent(Pass* parent); 00981 00982 protected: 00983 // State 00985 unsigned int mCurrentFrame; 00986 00988 Real mAnimDuration; 00989 bool mCubic; // is this a series of 6 2D textures to make up a cube? 00990 00991 TextureType mTextureType; 00992 int mTextureSrcMipmaps; // Request number of mipmaps 00993 00994 unsigned int mTextureCoordSetIndex; 00995 UVWAddressingMode mAddressMode; 00996 ColourValue mBorderColour; 00997 00998 LayerBlendModeEx colourBlendMode; 00999 SceneBlendFactor colourBlendFallbackSrc; 01000 SceneBlendFactor colourBlendFallbackDest; 01001 01002 LayerBlendModeEx alphaBlendMode; 01003 bool mIsBlank; 01004 bool mIsAlpha; 01005 01006 mutable bool mRecalcTexMatrix; 01007 Real mUMod, mVMod; 01008 Real mUScale, mVScale; 01009 Radian mRotate; 01010 mutable Matrix4 mTexModMatrix; 01011 01013 FilterOptions mMinFilter; 01015 FilterOptions mMagFilter; 01017 FilterOptions mMipFilter; 01019 unsigned int mMaxAniso; 01020 01021 bool mIsDefaultAniso; 01022 bool mIsDefaultFiltering; 01023 01024 01025 //----------------------------------------------------------------------------- 01026 // Complex members (those that can't be copied using memcpy) are at the end to 01027 // allow for fast copying of the basic members. 01028 // 01029 std::vector<String> mFrames; 01030 String mName; // optional name for the TUS 01031 String mTextureNameAlias; // optional alias for texture frames 01032 EffectMap mEffects; 01033 //----------------------------------------------------------------------------- 01034 01035 //----------------------------------------------------------------------------- 01036 // Pointer members (those that can't be copied using memcpy), and MUST 01037 // preserving even if assign from others 01038 // 01039 Pass* mParent; 01040 Controller<Real>* mAnimController; 01041 //----------------------------------------------------------------------------- 01042 01043 01046 void recalcTextureMatrix(void) const; 01047 01050 void createAnimController(void); 01051 01054 void createEffectController(TextureEffect& effect); 01055 01056 01057 }; 01058 01059 01060 } 01061 01062 #endif
Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Jan 21 10:01:40 2007