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-2012 Torus Knot Software Ltd
    00008
    00009 Permission is hereby granted, free of charge, to any person obtaining a copy
    00010 of this software and associated documentation files (the "Software"), to deal
    00011 in the Software without restriction, including without limitation the rights
    00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00013 copies of the Software, and to permit persons to whom the Software is
    00014 furnished to do so, subject to the following conditions:
    00015
    00016 The above copyright notice and this permission notice shall be included in
    00017 all copies or substantial portions of the Software.
    00018
    00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    00025 THE SOFTWARE.
    00026 -----------------------------------------------------------------------------
    00027 */
    00028 #ifndef __TextureUnitState_H__
    00029 #define __TextureUnitState_H__
    00030
    00031 #include "OgrePrerequisites.h"
    00032 #include "OgreCommon.h"
    00033 #include "OgreBlendMode.h"
    00034 #include "OgreMatrix4.h"
    00035 #include "OgreIteratorWrappers.h"
    00036 #include "OgreString.h"
    00037 #include "OgreTexture.h"
    00038
    00039 namespace Ogre {
    00061     class _OgreExport TextureUnitState : public TextureUnitStateAlloc
    00062     {
    00063         friend class RenderSystem;
    00064     public:
    00070         enum TextureEffectType
    00071         {
    00073             ET_ENVIRONMENT_MAP,
    00075             ET_PROJECTIVE_TEXTURE,
    00077             ET_UVSCROLL,
    00079             ET_USCROLL,
    00081             ET_VSCROLL,
    00083             ET_ROTATE,
    00085             ET_TRANSFORM
    00086
    00087         };
    00088
    00094         enum EnvMapType
    00095         {
    00097             ENV_PLANAR,
    00099             ENV_CURVED,
    00101             ENV_REFLECTION,
    00103             ENV_NORMAL
    00104         };
    00105
    00111         enum TextureTransformType
    00112         {
    00113             TT_TRANSLATE_U,
    00114             TT_TRANSLATE_V,
    00115             TT_SCALE_U,
    00116             TT_SCALE_V,
    00117             TT_ROTATE
    00118         };
    00119
    00125         enum TextureAddressingMode
    00126         {
    00128             TAM_WRAP,
    00130             TAM_MIRROR,
    00132             TAM_CLAMP,
    00134             TAM_BORDER
    00135         };
    00136
    00138         struct UVWAddressingMode
    00139         {
    00140             TextureAddressingMode u, v, w;
    00141         };
    00142
    00145         enum TextureCubeFace
    00146         {
    00147             CUBE_FRONT = 0,
    00148             CUBE_BACK = 1,
    00149             CUBE_LEFT = 2,
    00150             CUBE_RIGHT = 3,
    00151             CUBE_UP = 4,
    00152             CUBE_DOWN = 5
    00153         };
    00154
    00157         struct TextureEffect {
    00158             TextureEffectType type;
    00159             int subtype;
    00160             Real arg1, arg2;
    00161             WaveformType waveType;
    00162             Real base;
    00163             Real frequency;
    00164             Real phase;
    00165             Real amplitude;
    00166             Controller<Real>* controller;
    00167             const Frustum* frustum;
    00168         };
    00169
    00172         typedef multimap<TextureEffectType, TextureEffect>::type EffectMap;
    00173
    00176         TextureUnitState(Pass* parent);
    00177
    00178         TextureUnitState(Pass* parent, const TextureUnitState& oth );
    00179
    00180         TextureUnitState & operator = ( const TextureUnitState& oth );
    00181
    00184         ~TextureUnitState();
    00185
    00192         TextureUnitState( Pass* parent, const String& texName, unsigned int texCoordSet = 0);
    00193
    00202         const String& getTextureName(void) const;
    00203
    00209         void setTextureName( const String& name, TextureType ttype = TEX_TYPE_2D);
    00210
    00216         void setTexture( const TexturePtr& texPtr);
    00217
    00264         void setCubicTextureName( const String& name, bool forUVW = false );
    00265
    00310         void setCubicTextureName( const String* const names, bool forUVW = false );
    00311
    00356         void setCubicTexture( const TexturePtr* const texPtrs, bool forUVW = false );
    00357
    00379         void setAnimatedTextureName( const String& name, unsigned int numFrames, Real duration = 0 );
    00380
    00402         void setAnimatedTextureName( const String* const names, unsigned int numFrames, Real duration = 0 );
    00403
    00406         std::pair< size_t, size_t > getTextureDimensions( unsigned int frame = 0 ) const;
    00407
    00415         void setCurrentFrame( unsigned int frameNumber );
    00416
    00421         unsigned int getCurrentFrame(void) const;
    00422
    00428         const String& getFrameTextureName(unsigned int frameNumber) const;
    00429
    00437         void setFrameTextureName(const String& name, unsigned int frameNumber);
    00438
    00444         void addFrameTextureName(const String& name);
    00452         void deleteFrameTextureName(const size_t frameNumber);
    00457         unsigned int getNumFrames(void) const;
    00458
    00459
    00461         enum BindingType
    00462         {
    00464             BT_FRAGMENT = 0,
    00468             BT_VERTEX = 1
    00469         };
    00472         enum ContentType
    00473         {
    00475             CONTENT_NAMED = 0,
    00477             CONTENT_SHADOW = 1,
    00479             CONTENT_COMPOSITOR = 2
    00480         };
    00481
    00491         void setBindingType(BindingType bt);
    00492
    00495         BindingType getBindingType(void) const;
    00496
    00502         void setContentType(ContentType ct);
    00504         ContentType getContentType(void) const;
    00505
    00512         bool isCubic(void) const;
    00513
    00518         bool is3D(void) const;
    00519
    00524         TextureType getTextureType(void) const;
    00525
    00528         void setDesiredFormat(PixelFormat desiredFormat);
    00529
    00532         PixelFormat getDesiredFormat(void) const;
    00533
    00536         void setNumMipmaps(int numMipmaps);
    00537
    00540         int getNumMipmaps(void) const;
    00541
    00544         void setIsAlpha(bool isAlpha);
    00545
    00548         bool getIsAlpha(void) const;
    00549
    00551         void setHardwareGammaEnabled(bool enabled);
    00553         bool isHardwareGammaEnabled() const;
    00554
    00559         unsigned int getTextureCoordSet(void) const;
    00560
    00568         void setTextureCoordSet(unsigned int set);
    00569
    00585         void setTextureTransform(const Matrix4& xform);
    00586
    00594         const Matrix4& getTextureTransform(void) const;
    00595
    00608         void setTextureScroll(Real u, Real v);
    00609
    00614         void setTextureUScroll(Real value);
    00615         // Get texture uscroll value
    00616         Real getTextureUScroll(void) const;
    00617
    00622         void setTextureVScroll(Real value);
    00623         // Get texture vscroll value
    00624         Real getTextureVScroll(void) const;
    00625
    00630         void setTextureUScale(Real value);
    00632         Real getTextureUScale(void) const;
    00633
    00638         void setTextureVScale(Real value);
    00640         Real getTextureVScale(void) const;
    00641
    00655         void setTextureScale(Real uScale, Real vScale);
    00656
    00666         void setTextureRotate(const Radian& angle);
    00668         const Radian& getTextureRotate(void) const;
    00669
    00675         const UVWAddressingMode& getTextureAddressingMode(void) const;
    00676
    00686         void setTextureAddressingMode( TextureAddressingMode tam);
    00687
    00694         void setTextureAddressingMode( TextureAddressingMode u,
    00695             TextureAddressingMode v, TextureAddressingMode w);
    00696
    00703         void setTextureAddressingMode( const UVWAddressingMode& uvw);
    00704
    00712         void setTextureBorderColour(const ColourValue& colour);
    00713
    00719         const ColourValue& getTextureBorderColour(void) const;
    00720
    00785         void setColourOperationEx(
    00786             LayerBlendOperationEx op,
    00787             LayerBlendSource source1 = LBS_TEXTURE,
    00788             LayerBlendSource source2 = LBS_CURRENT,
    00789
    00790             const ColourValue& arg1 = ColourValue::White,
    00791             const ColourValue& arg2 = ColourValue::White,
    00792
    00793             Real manualBlend = 0.0);
    00794
    00813         void setColourOperation( const LayerBlendOperation op);
    00814
    00834         void setColourOpMultipassFallback( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor);
    00835
    00838         const LayerBlendModeEx& getColourBlendMode(void) const;
    00839
    00842         const LayerBlendModeEx& getAlphaBlendMode(void) const;
    00843
    00846         SceneBlendFactor getColourBlendFallbackSrc(void) const;
    00847
    00850         SceneBlendFactor getColourBlendFallbackDest(void) const;
    00851
    00877         void setAlphaOperation(LayerBlendOperationEx op,
    00878             LayerBlendSource source1 = LBS_TEXTURE,
    00879             LayerBlendSource source2 = LBS_CURRENT,
    00880             Real arg1 = 1.0,
    00881             Real arg2 = 1.0,
    00882             Real manualBlend = 0.0);
    00883
    00895         void addEffect(TextureEffect& effect);
    00896
    00924         void setEnvironmentMap(bool enable, EnvMapType envMapType = ENV_CURVED);
    00925
    00936         void setScrollAnimation(Real uSpeed, Real vSpeed);
    00937
    00946         void setRotateAnimation(Real speed);
    00947
    00967         void setTransformAnimation( const TextureTransformType ttype,
    00968             const WaveformType waveType, Real base = 0, Real frequency = 1, Real phase = 0, Real amplitude = 1 );
    00969
    00970
    00989         void setProjectiveTexturing(bool enabled, const Frustum* projectionSettings = 0);
    00990
    00993         void removeAllEffects(void);
    00994
    01000         void removeEffect( const TextureEffectType type );
    01001
    01007         bool isBlank(void) const;
    01008
    01011         void setBlank(void);
    01012
    01015         bool isTextureLoadFailing() const { return mTextureLoadFailed; }
    01016
    01019         void retryTextureLoad() { mTextureLoadFailed = false; }
    01020
    01022         const EffectMap& getEffects(void) const;
    01024         Real getAnimationDuration(void) const;
    01025
    01035         void setTextureFiltering(TextureFilterOptions filterType);
    01040         void setTextureFiltering(FilterType ftype, FilterOptions opts);
    01049         void setTextureFiltering(FilterOptions minFilter, FilterOptions magFilter, FilterOptions mipFilter);
    01051         FilterOptions getTextureFiltering(FilterType ftpye) const;
    01052
    01058         void setTextureAnisotropy(unsigned int maxAniso);
    01060         unsigned int getTextureAnisotropy() const;
    01061
    01074         void setTextureMipmapBias(float bias) { mMipmapBias = bias; }
    01078         float getTextureMipmapBias(void) const { return mMipmapBias; }
    01079
    01087         void setCompositorReference(const String& compositorName, const String& textureName, size_t mrtIndex = 0);
    01088
    01090         const String& getReferencedCompositorName() const { return mCompositorRefName; }
    01092         const String& getReferencedTextureName() const { return mCompositorRefTexName; }
    01094         size_t getReferencedMRTIndex() const { return mCompositorRefMrtIndex; }
    01095
    01097         Pass* getParent(void) const { return mParent; }
    01098
    01100         void _prepare(void);
    01102         void _unprepare(void);
    01104         void _load(void);
    01106         void _unload(void);
    01108         bool hasViewRelativeTextureCoordinateGeneration(void) const;
    01109
    01111         bool isLoaded(void) const;
    01113         void _notifyNeedsRecompile(void);
    01114
    01120         void setName(const String& name);
    01122         const String& getName(void) const { return mName; }
    01123
    01127         void setTextureNameAlias(const String& name);
    01130         const String& getTextureNameAlias(void) const { return mTextureNameAlias;}
    01131
    01146         bool applyTextureAliases(const AliasTextureNamePairList& aliasList, const bool apply = true);
    01147
    01149         void _notifyParent(Pass* parent);
    01150
    01152         const TexturePtr& _getTexturePtr(void) const;
    01154         const TexturePtr& _getTexturePtr(size_t frame) const;
    01155
    01157         void _setTexturePtr(const TexturePtr& texptr);
    01159         void _setTexturePtr(const TexturePtr& texptr, size_t frame);
    01160
    01164         Controller<Real>* _getAnimController() const { return mAnimController; }
    01165 protected:
    01166         // State
    01168         unsigned int mCurrentFrame;
    01169
    01171         Real mAnimDuration;
    01172         bool mCubic; // is this a series of 6 2D textures to make up a cube?
    01173
    01174         TextureType mTextureType;
    01175         PixelFormat mDesiredFormat;
    01176         int mTextureSrcMipmaps; // Request number of mipmaps
    01177
    01178         unsigned int mTextureCoordSetIndex;
    01179         UVWAddressingMode mAddressMode;
    01180         ColourValue mBorderColour;
    01181
    01182         LayerBlendModeEx mColourBlendMode;
    01183         SceneBlendFactor mColourBlendFallbackSrc;
    01184         SceneBlendFactor mColourBlendFallbackDest;
    01185
    01186         LayerBlendModeEx mAlphaBlendMode;
    01187         mutable bool mTextureLoadFailed;
    01188         bool mIsAlpha;
    01189         bool mHwGamma;
    01190
    01191         mutable bool mRecalcTexMatrix;
    01192         Real mUMod, mVMod;
    01193         Real mUScale, mVScale;
    01194         Radian mRotate;
    01195         mutable Matrix4 mTexModMatrix;
    01196
    01198         FilterOptions mMinFilter;
    01200         FilterOptions mMagFilter;
    01202         FilterOptions mMipFilter;
    01204         unsigned int mMaxAniso;
    01206         float mMipmapBias;
    01207
    01208         bool mIsDefaultAniso;
    01209         bool mIsDefaultFiltering;
    01211         BindingType mBindingType;
    01213         ContentType mContentType;
    01215         size_t mCompositorRefMrtIndex;
    01216
    01217         //-----------------------------------------------------------------------------
    01218         // Complex members (those that can't be copied using memcpy) are at the end to
    01219         // allow for fast copying of the basic members.
    01220         //
    01221         vector<String>::type mFrames;
    01222         mutable vector<TexturePtr>::type mFramePtrs;
    01223         String mName;               // optional name for the TUS
    01224         String mTextureNameAlias;       // optional alias for texture frames
    01225         EffectMap mEffects;
    01227         String mCompositorRefName;
    01228         String mCompositorRefTexName;
    01229         //-----------------------------------------------------------------------------
    01230
    01231         //-----------------------------------------------------------------------------
    01232         // Pointer members (those that can't be copied using memcpy), and MUST
    01233         // preserving even if assign from others
    01234         //
    01235         Pass* mParent;
    01236         Controller<Real>* mAnimController;
    01237         //-----------------------------------------------------------------------------
    01238
    01239
    01242         void recalcTextureMatrix(void) const;
    01243
    01246         void createAnimController(void);
    01247
    01250         void createEffectController(TextureEffect& effect);
    01251
    01253         void ensurePrepared(size_t frame) const;
    01255         void ensureLoaded(size_t frame) const;
    01256
    01257
    01258     };
    01259
    01263 }
    01264
    01265 #endif

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun Sep 2 2012 07:27:24