- Main Page
- Namespaces
- Classes
- Files
- Directories
- 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://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
    00957         bool isTextureLoadFailing() const { return mTextureLoadFailed; }
    00958
    00961         void retryTextureLoad() { mTextureLoadFailed = false; }
    00962
    00963         // get texture effects in a multimap paired array
    00964         const EffectMap& getEffects(void) const;
    00965         // get the animated-texture animation duration
    00966         Real getAnimationDuration(void) const;
    00967
    00977         void setTextureFiltering(TextureFilterOptions filterType);
    00982         void setTextureFiltering(FilterType ftype, FilterOptions opts);
    00991         void setTextureFiltering(FilterOptions minFilter, FilterOptions magFilter, FilterOptions mipFilter);
    00992         // get the texture filtering for the given type
    00993         FilterOptions getTextureFiltering(FilterType ftpye) const;
    00994
    01000         void setTextureAnisotropy(unsigned int maxAniso);
    01001         // get this layer texture anisotropy level
    01002         unsigned int getTextureAnisotropy() const;
    01003
    01016         void setTextureMipmapBias(float bias) { mMipmapBias = bias; }
    01020         float getTextureMipmapBias(void) const { return mMipmapBias; }
    01021
    01023         Pass* getParent(void) const { return mParent; }
    01024
    01026         void _load(void);
    01028         void _unload(void);
    01030         bool hasViewRelativeTextureCoordinateGeneration(void) const;
    01031
    01032         // Is this loaded?
    01033         bool isLoaded(void) const;
    01035         void _notifyNeedsRecompile(void);
    01036
    01042         void setName(const String& name);
    01044         const String& getName(void) const { return mName; }
    01045
    01049         void setTextureNameAlias(const String& name);
    01052         const String& getTextureNameAlias(void) const { return mTextureNameAlias;}
    01053
    01068         bool applyTextureAliases(const AliasTextureNamePairList& aliasList, const bool apply = true);
    01069
    01071         void _notifyParent(Pass* parent);
    01072
    01074         const TexturePtr& _getTexturePtr(void) const;
    01076         const TexturePtr& _getTexturePtr(size_t frame) const;
    01077
    01079         void _setTexturePtr(const TexturePtr& texptr);
    01081         void _setTexturePtr(const TexturePtr& texptr, size_t frame);
    01082
    01086         Controller<Real>* _getAnimController() const { return mAnimController; }
    01087 protected:
    01088         // State
    01090         unsigned int mCurrentFrame;
    01091
    01093         Real mAnimDuration;
    01094         bool mCubic; // is this a series of 6 2D textures to make up a cube?
    01095
    01096         TextureType mTextureType;
    01097         PixelFormat mDesiredFormat;
    01098         int mTextureSrcMipmaps; // Request number of mipmaps
    01099
    01100         unsigned int mTextureCoordSetIndex;
    01101         UVWAddressingMode mAddressMode;
    01102         ColourValue mBorderColour;
    01103
    01104         LayerBlendModeEx mColourBlendMode;
    01105         SceneBlendFactor mColourBlendFallbackSrc;
    01106         SceneBlendFactor mColourBlendFallbackDest;
    01107
    01108         LayerBlendModeEx mAlphaBlendMode;
    01109         mutable bool mTextureLoadFailed;
    01110         bool mIsAlpha;
    01111
    01112         mutable bool mRecalcTexMatrix;
    01113         Real mUMod, mVMod;
    01114         Real mUScale, mVScale;
    01115         Radian mRotate;
    01116         mutable Matrix4 mTexModMatrix;
    01117
    01119         FilterOptions mMinFilter;
    01121         FilterOptions mMagFilter;
    01123         FilterOptions mMipFilter;
    01125         unsigned int mMaxAniso;
    01127         float mMipmapBias;
    01128
    01129         bool mIsDefaultAniso;
    01130         bool mIsDefaultFiltering;
    01132         BindingType mBindingType;
    01134         ContentType mContentType;
    01135
    01136         //-----------------------------------------------------------------------------
    01137         // Complex members (those that can't be copied using memcpy) are at the end to
    01138         // allow for fast copying of the basic members.
    01139         //
    01140         std::vector<String> mFrames;
    01141         mutable std::vector<TexturePtr> mFramePtrs;
    01142         String mName;               // optional name for the TUS
    01143         String mTextureNameAlias;       // optional alias for texture frames
    01144         EffectMap mEffects;
    01145         //-----------------------------------------------------------------------------
    01146
    01147         //-----------------------------------------------------------------------------
    01148         // Pointer members (those that can't be copied using memcpy), and MUST
    01149         // preserving even if assign from others
    01150         //
    01151         Pass* mParent;
    01152         Controller<Real>* mAnimController;
    01153         //-----------------------------------------------------------------------------
    01154
    01155
    01158         void recalcTextureMatrix(void) const;
    01159
    01162         void createAnimController(void);
    01163
    01166         void createEffectController(TextureEffect& effect);
    01167
    01169         void ensureLoaded(size_t frame) const;
    01170
    01171
    01172     };
    01173
    01174
    01175 }
    01176
    01177 #endif

Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Mon Jun 16 12:48:57 2008