00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org 00006 00007 Copyright (c) 2000-2006 Torus Knot Software Ltd 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 You may alternatively use this source under the terms of a specific version of 00025 the OGRE Unrestricted License provided you have obtained such a license from 00026 Torus Knot Software Ltd. 00027 ----------------------------------------------------------------------------- 00028 */ 00029 #ifndef __TextureUnitState_H__ 00030 #define __TextureUnitState_H__ 00031 00032 #include "OgrePrerequisites.h" 00033 #include "OgreCommon.h" 00034 #include "OgreBlendMode.h" 00035 #include "OgreMatrix4.h" 00036 #include "OgreIteratorWrappers.h" 00037 #include "OgreString.h" 00038 #include "OgreTexture.h" 00039 00040 namespace Ogre { 00056 class _OgreExport TextureUnitState 00057 { 00058 friend class RenderSystem; 00059 public: 00065 enum TextureEffectType 00066 { 00068 ET_ENVIRONMENT_MAP, 00070 ET_PROJECTIVE_TEXTURE, 00072 ET_UVSCROLL, 00074 ET_USCROLL, 00076 ET_VSCROLL, 00078 ET_ROTATE, 00080 ET_TRANSFORM 00081 00082 }; 00083 00089 enum EnvMapType 00090 { 00092 ENV_PLANAR, 00094 ENV_CURVED, 00096 ENV_REFLECTION, 00098 ENV_NORMAL 00099 }; 00100 00106 enum TextureTransformType 00107 { 00108 TT_TRANSLATE_U, 00109 TT_TRANSLATE_V, 00110 TT_SCALE_U, 00111 TT_SCALE_V, 00112 TT_ROTATE 00113 }; 00114 00120 enum TextureAddressingMode 00121 { 00123 TAM_WRAP, 00125 TAM_MIRROR, 00127 TAM_CLAMP, 00129 TAM_BORDER 00130 }; 00131 00133 struct UVWAddressingMode 00134 { 00135 TextureAddressingMode u, v, w; 00136 }; 00137 00140 enum TextureCubeFace 00141 { 00142 CUBE_FRONT = 0, 00143 CUBE_BACK = 1, 00144 CUBE_LEFT = 2, 00145 CUBE_RIGHT = 3, 00146 CUBE_UP = 4, 00147 CUBE_DOWN = 5 00148 }; 00149 00152 struct TextureEffect { 00153 TextureEffectType type; 00154 int subtype; 00155 Real arg1, arg2; 00156 WaveformType waveType; 00157 Real base; 00158 Real frequency; 00159 Real phase; 00160 Real amplitude; 00161 Controller<Real>* controller; 00162 const Frustum* frustum; 00163 }; 00164 00167 typedef std::multimap<TextureEffectType, TextureEffect> EffectMap; 00168 00171 TextureUnitState(Pass* parent); 00172 00173 TextureUnitState(Pass* parent, const TextureUnitState& oth ); 00174 00175 TextureUnitState & operator = ( const TextureUnitState& oth ); 00176 00179 ~TextureUnitState(); 00180 00187 TextureUnitState( Pass* parent, const String& texName, unsigned int texCoordSet = 0); 00188 00197 const String& getTextureName(void) const; 00198 00204 void setTextureName( const String& name, TextureType ttype = TEX_TYPE_2D); 00205 00252 void setCubicTextureName( const String& name, bool forUVW = false ); 00253 00300 void setCubicTextureName( const String* const names, bool forUVW = false ); 00301 00323 void setAnimatedTextureName( const String& name, unsigned int numFrames, Real duration = 0 ); 00324 00346 void setAnimatedTextureName( const String* const names, unsigned int numFrames, Real duration = 0 ); 00347 00350 std::pair< size_t, size_t > getTextureDimensions( unsigned int frame = 0 ) const; 00351 00359 void setCurrentFrame( unsigned int frameNumber ); 00360 00365 unsigned int getCurrentFrame(void) const; 00366 00372 const String& getFrameTextureName(unsigned int frameNumber) const; 00373 00381 void setFrameTextureName(const String& name, unsigned int frameNumber); 00382 00388 void addFrameTextureName(const String& name); 00396 void deleteFrameTextureName(const size_t frameNumber); 00401 unsigned int getNumFrames(void) const; 00402 00403 00405 enum BindingType 00406 { 00408 BT_FRAGMENT = 0, 00412 BT_VERTEX = 1 00413 }; 00416 enum ContentType 00417 { 00419 CONTENT_NAMED = 0, 00421 CONTENT_SHADOW = 1 00422 }; 00423 00433 void setBindingType(BindingType bt); 00434 00437 BindingType getBindingType(void) const; 00438 00444 void setContentType(ContentType ct); 00446 ContentType getContentType(void) const; 00447 00454 bool isCubic(void) const; 00455 00460 bool is3D(void) const; 00461 00466 TextureType getTextureType(void) const; 00467 00470 void setDesiredFormat(PixelFormat desiredFormat); 00471 00474 PixelFormat getDesiredFormat(void) const; 00475 00478 void setNumMipmaps(int numMipmaps); 00479 00482 int getNumMipmaps(void) const; 00483 00486 void setIsAlpha(bool isAlpha); 00487 00490 bool getIsAlpha(void) const; 00491 00496 unsigned int getTextureCoordSet(void) const; 00497 00505 void setTextureCoordSet(unsigned int set); 00506 00522 void setTextureTransform(const Matrix4& xform); 00523 00531 const Matrix4& getTextureTransform(void) const; 00532 00545 void setTextureScroll(Real u, Real v); 00546 00551 void setTextureUScroll(Real value); 00552 // get texture uscroll value 00553 Real getTextureUScroll(void) const; 00554 00559 void setTextureVScroll(Real value); 00560 // get texture vscroll value 00561 Real getTextureVScroll(void) const; 00562 00567 void setTextureUScale(Real value); 00568 // get texture uscale value 00569 Real getTextureUScale(void) const; 00570 00575 void setTextureVScale(Real value); 00576 // get texture vscale value 00577 Real getTextureVScale(void) const; 00578 00592 void setTextureScale(Real uScale, Real vScale); 00593 00603 void setTextureRotate(const Radian& angle); 00604 #ifndef OGRE_FORCE_ANGLE_TYPES 00605 inline void setTextureRotate(Real angle) { 00606 setTextureRotate ( Degree(angle) ); 00607 } 00608 #endif//OGRE_FORCE_ANGLE_TYPES 00609 // get texture rotation effects angle value 00610 const Radian& getTextureRotate(void) const; 00611 00617 const UVWAddressingMode& getTextureAddressingMode(void) const; 00618 00628 void setTextureAddressingMode( TextureAddressingMode tam); 00629 00636 void setTextureAddressingMode( TextureAddressingMode u, 00637 TextureAddressingMode v, TextureAddressingMode w); 00638 00645 void setTextureAddressingMode( const UVWAddressingMode& uvw); 00646 00654 void setTextureBorderColour(const ColourValue& colour); 00655 00661 const ColourValue& getTextureBorderColour(void) const; 00662 00727 void setColourOperationEx( 00728 LayerBlendOperationEx op, 00729 LayerBlendSource source1 = LBS_TEXTURE, 00730 LayerBlendSource source2 = LBS_CURRENT, 00731 00732 const ColourValue& arg1 = ColourValue::White, 00733 const ColourValue& arg2 = ColourValue::White, 00734 00735 Real manualBlend = 0.0); 00736 00755 void setColourOperation( const LayerBlendOperation op); 00756 00776 void setColourOpMultipassFallback( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor); 00777 00780 const LayerBlendModeEx& getColourBlendMode(void) const; 00781 00784 const LayerBlendModeEx& getAlphaBlendMode(void) const; 00785 00788 SceneBlendFactor getColourBlendFallbackSrc(void) const; 00789 00792 SceneBlendFactor getColourBlendFallbackDest(void) const; 00793 00819 void setAlphaOperation(LayerBlendOperationEx op, 00820 LayerBlendSource source1 = LBS_TEXTURE, 00821 LayerBlendSource source2 = LBS_CURRENT, 00822 Real arg1 = 1.0, 00823 Real arg2 = 1.0, 00824 Real manualBlend = 0.0); 00825 00837 void addEffect(TextureEffect& effect); 00838 00866 void setEnvironmentMap(bool enable, EnvMapType envMapType = ENV_CURVED); 00867 00878 void setScrollAnimation(Real uSpeed, Real vSpeed); 00879 00888 void setRotateAnimation(Real speed); 00889 00909 void setTransformAnimation( const TextureTransformType ttype, 00910 const WaveformType waveType, Real base = 0, Real frequency = 1, Real phase = 0, Real amplitude = 1 ); 00911 00912 00931 void setProjectiveTexturing(bool enabled, const Frustum* projectionSettings = 0); 00932 00935 void removeAllEffects(void); 00936 00942 void removeEffect( const TextureEffectType type ); 00943 00949 bool isBlank(void) const; 00950 00953 void setBlank(void); 00954 00955 // get texture effects in a multimap paired array 00956 const EffectMap& getEffects(void) const; 00957 // get the animated-texture animation duration 00958 Real getAnimationDuration(void) const; 00959 00969 void setTextureFiltering(TextureFilterOptions filterType); 00974 void setTextureFiltering(FilterType ftype, FilterOptions opts); 00983 void setTextureFiltering(FilterOptions minFilter, FilterOptions magFilter, FilterOptions mipFilter); 00984 // get the texture filtering for the given type 00985 FilterOptions getTextureFiltering(FilterType ftpye) const; 00986 00992 void setTextureAnisotropy(unsigned int maxAniso); 00993 // get this layer texture anisotropy level 00994 unsigned int getTextureAnisotropy() const; 00995 01008 void setTextureMipmapBias(float bias) { mMipmapBias = bias; } 01012 float getTextureMipmapBias(void) const { return mMipmapBias; } 01013 01015 Pass* getParent(void) const { return mParent; } 01016 01018 void _load(void); 01020 void _unload(void); 01022 bool hasViewRelativeTextureCoordinateGeneration(void) const; 01023 01024 // Is this loaded? 01025 bool isLoaded(void) const; 01027 void _notifyNeedsRecompile(void); 01028 01034 void setName(const String& name); 01036 const String& getName(void) const { return mName; } 01037 01041 void setTextureNameAlias(const String& name); 01044 const String& getTextureNameAlias(void) const { return mTextureNameAlias;} 01045 01060 bool applyTextureAliases(const AliasTextureNamePairList& aliasList, const bool apply = true); 01061 01063 void _notifyParent(Pass* parent); 01064 01066 const TexturePtr& _getTexturePtr(void) const; 01068 const TexturePtr& _getTexturePtr(size_t frame) const; 01069 01071 void _setTexturePtr(const TexturePtr& texptr); 01073 void _setTexturePtr(const TexturePtr& texptr, size_t frame); 01074 01078 Controller<Real>* _getAnimController() const { return mAnimController; } 01079 protected: 01080 // State 01082 unsigned int mCurrentFrame; 01083 01085 Real mAnimDuration; 01086 bool mCubic; // is this a series of 6 2D textures to make up a cube? 01087 01088 TextureType mTextureType; 01089 PixelFormat mDesiredFormat; 01090 int mTextureSrcMipmaps; // Request number of mipmaps 01091 01092 unsigned int mTextureCoordSetIndex; 01093 UVWAddressingMode mAddressMode; 01094 ColourValue mBorderColour; 01095 01096 LayerBlendModeEx mColourBlendMode; 01097 SceneBlendFactor mColourBlendFallbackSrc; 01098 SceneBlendFactor mColourBlendFallbackDest; 01099 01100 LayerBlendModeEx mAlphaBlendMode; 01101 mutable bool mIsBlank; 01102 bool mIsAlpha; 01103 01104 mutable bool mRecalcTexMatrix; 01105 Real mUMod, mVMod; 01106 Real mUScale, mVScale; 01107 Radian mRotate; 01108 mutable Matrix4 mTexModMatrix; 01109 01111 FilterOptions mMinFilter; 01113 FilterOptions mMagFilter; 01115 FilterOptions mMipFilter; 01117 unsigned int mMaxAniso; 01119 float mMipmapBias; 01120 01121 bool mIsDefaultAniso; 01122 bool mIsDefaultFiltering; 01124 BindingType mBindingType; 01126 ContentType mContentType; 01127 01128 //----------------------------------------------------------------------------- 01129 // Complex members (those that can't be copied using memcpy) are at the end to 01130 // allow for fast copying of the basic members. 01131 // 01132 std::vector<String> mFrames; 01133 mutable std::vector<TexturePtr> mFramePtrs; 01134 String mName; // optional name for the TUS 01135 String mTextureNameAlias; // optional alias for texture frames 01136 EffectMap mEffects; 01137 //----------------------------------------------------------------------------- 01138 01139 //----------------------------------------------------------------------------- 01140 // Pointer members (those that can't be copied using memcpy), and MUST 01141 // preserving even if assign from others 01142 // 01143 Pass* mParent; 01144 Controller<Real>* mAnimController; 01145 //----------------------------------------------------------------------------- 01146 01147 01150 void recalcTextureMatrix(void) const; 01151 01154 void createAnimController(void); 01155 01158 void createEffectController(TextureEffect& effect); 01159 01161 void ensureLoaded(size_t frame) const; 01162 01163 01164 }; 01165 01166 01167 } 01168 01169 #endif
Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun May 6 10:54:23 2007