OGRE: OgreTextureUnitState.h Source File - OGRE Documentation

# 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-2009 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
    00257         void setCubicTextureName( const String& name, bool forUVW = false );
    00258
    00305         void setCubicTextureName( const String* const names, bool forUVW = false );
    00306
    00328         void setAnimatedTextureName( const String& name, unsigned int numFrames, Real duration = 0 );
    00329
    00351         void setAnimatedTextureName( const String* const names, unsigned int numFrames, Real duration = 0 );
    00352
    00355         std::pair< size_t, size_t > getTextureDimensions( unsigned int frame = 0 ) const;
    00356
    00364         void setCurrentFrame( unsigned int frameNumber );
    00365
    00370         unsigned int getCurrentFrame(void) const;
    00371
    00377         const String& getFrameTextureName(unsigned int frameNumber) const;
    00378
    00386         void setFrameTextureName(const String& name, unsigned int frameNumber);
    00387
    00393         void addFrameTextureName(const String& name);
    00401         void deleteFrameTextureName(const size_t frameNumber);
    00406         unsigned int getNumFrames(void) const;
    00407
    00408
    00410         enum BindingType
    00411         {
    00413             BT_FRAGMENT = 0,
    00417             BT_VERTEX = 1
    00418         };
    00421         enum ContentType
    00422         {
    00424             CONTENT_NAMED = 0,
    00426             CONTENT_SHADOW = 1,
    00428             CONTENT_COMPOSITOR = 2
    00429         };
    00430
    00440         void setBindingType(BindingType bt);
    00441
    00444         BindingType getBindingType(void) const;
    00445
    00451         void setContentType(ContentType ct);
    00453         ContentType getContentType(void) const;
    00454
    00461         bool isCubic(void) const;
    00462
    00467         bool is3D(void) const;
    00468
    00473         TextureType getTextureType(void) const;
    00474
    00477         void setDesiredFormat(PixelFormat desiredFormat);
    00478
    00481         PixelFormat getDesiredFormat(void) const;
    00482
    00485         void setNumMipmaps(int numMipmaps);
    00486
    00489         int getNumMipmaps(void) const;
    00490
    00493         void setIsAlpha(bool isAlpha);
    00494
    00497         bool getIsAlpha(void) const;
    00498
    00500         void setHardwareGammaEnabled(bool enabled);
    00502         bool isHardwareGammaEnabled() const;
    00503
    00508         unsigned int getTextureCoordSet(void) const;
    00509
    00517         void setTextureCoordSet(unsigned int set);
    00518
    00534         void setTextureTransform(const Matrix4& xform);
    00535
    00543         const Matrix4& getTextureTransform(void) const;
    00544
    00557         void setTextureScroll(Real u, Real v);
    00558
    00563         void setTextureUScroll(Real value);
    00564         // get texture uscroll value
    00565         Real getTextureUScroll(void) const;
    00566
    00571         void setTextureVScroll(Real value);
    00572         // get texture vscroll value
    00573         Real getTextureVScroll(void) const;
    00574
    00579         void setTextureUScale(Real value);
    00580         // get texture uscale value
    00581         Real getTextureUScale(void) const;
    00582
    00587         void setTextureVScale(Real value);
    00588         // get texture vscale value
    00589         Real getTextureVScale(void) const;
    00590
    00604         void setTextureScale(Real uScale, Real vScale);
    00605
    00615         void setTextureRotate(const Radian& angle);
    00616         // get texture rotation effects angle value
    00617         const Radian& getTextureRotate(void) const;
    00618
    00624         const UVWAddressingMode& getTextureAddressingMode(void) const;
    00625
    00635         void setTextureAddressingMode( TextureAddressingMode tam);
    00636
    00643         void setTextureAddressingMode( TextureAddressingMode u,
    00644             TextureAddressingMode v, TextureAddressingMode w);
    00645
    00652         void setTextureAddressingMode( const UVWAddressingMode& uvw);
    00653
    00661         void setTextureBorderColour(const ColourValue& colour);
    00662
    00668         const ColourValue& getTextureBorderColour(void) const;
    00669
    00734         void setColourOperationEx(
    00735             LayerBlendOperationEx op,
    00736             LayerBlendSource source1 = LBS_TEXTURE,
    00737             LayerBlendSource source2 = LBS_CURRENT,
    00738
    00739             const ColourValue& arg1 = ColourValue::White,
    00740             const ColourValue& arg2 = ColourValue::White,
    00741
    00742             Real manualBlend = 0.0);
    00743
    00762         void setColourOperation( const LayerBlendOperation op);
    00763
    00783         void setColourOpMultipassFallback( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor);
    00784
    00787         const LayerBlendModeEx& getColourBlendMode(void) const;
    00788
    00791         const LayerBlendModeEx& getAlphaBlendMode(void) const;
    00792
    00795         SceneBlendFactor getColourBlendFallbackSrc(void) const;
    00796
    00799         SceneBlendFactor getColourBlendFallbackDest(void) const;
    00800
    00826         void setAlphaOperation(LayerBlendOperationEx op,
    00827             LayerBlendSource source1 = LBS_TEXTURE,
    00828             LayerBlendSource source2 = LBS_CURRENT,
    00829             Real arg1 = 1.0,
    00830             Real arg2 = 1.0,
    00831             Real manualBlend = 0.0);
    00832
    00844         void addEffect(TextureEffect& effect);
    00845
    00873         void setEnvironmentMap(bool enable, EnvMapType envMapType = ENV_CURVED);
    00874
    00885         void setScrollAnimation(Real uSpeed, Real vSpeed);
    00886
    00895         void setRotateAnimation(Real speed);
    00896
    00916         void setTransformAnimation( const TextureTransformType ttype,
    00917             const WaveformType waveType, Real base = 0, Real frequency = 1, Real phase = 0, Real amplitude = 1 );
    00918
    00919
    00938         void setProjectiveTexturing(bool enabled, const Frustum* projectionSettings = 0);
    00939
    00942         void removeAllEffects(void);
    00943
    00949         void removeEffect( const TextureEffectType type );
    00950
    00956         bool isBlank(void) const;
    00957
    00960         void setBlank(void);
    00961
    00964         bool isTextureLoadFailing() const { return mTextureLoadFailed; }
    00965
    00968         void retryTextureLoad() { mTextureLoadFailed = false; }
    00969
    00970         // get texture effects in a multimap paired array
    00971         const EffectMap& getEffects(void) const;
    00972         // get the animated-texture animation duration
    00973         Real getAnimationDuration(void) const;
    00974
    00984         void setTextureFiltering(TextureFilterOptions filterType);
    00989         void setTextureFiltering(FilterType ftype, FilterOptions opts);
    00998         void setTextureFiltering(FilterOptions minFilter, FilterOptions magFilter, FilterOptions mipFilter);
    00999         // get the texture filtering for the given type
    01000         FilterOptions getTextureFiltering(FilterType ftpye) const;
    01001
    01007         void setTextureAnisotropy(unsigned int maxAniso);
    01008         // get this layer texture anisotropy level
    01009         unsigned int getTextureAnisotropy() const;
    01010
    01023         void setTextureMipmapBias(float bias) { mMipmapBias = bias; }
    01027         float getTextureMipmapBias(void) const { return mMipmapBias; }
    01028
    01036         void setCompositorReference(const String& compositorName, const String& textureName, size_t mrtIndex = 0);
    01037
    01039         const String& getReferencedCompositorName() const { return mCompositorRefName; }
    01041         const String& getReferencedTextureName() const { return mCompositorRefTexName; }
    01043         size_t getReferencedMRTIndex() const { return mCompositorRefMrtIndex; }
    01044
    01046         Pass* getParent(void) const { return mParent; }
    01047
    01049         void _prepare(void);
    01051         void _unprepare(void);
    01053         void _load(void);
    01055         void _unload(void);
    01057         bool hasViewRelativeTextureCoordinateGeneration(void) const;
    01058
    01059         // Is this loaded?
    01060         bool isLoaded(void) const;
    01062         void _notifyNeedsRecompile(void);
    01063
    01069         void setName(const String& name);
    01071         const String& getName(void) const { return mName; }
    01072
    01076         void setTextureNameAlias(const String& name);
    01079         const String& getTextureNameAlias(void) const { return mTextureNameAlias;}
    01080
    01095         bool applyTextureAliases(const AliasTextureNamePairList& aliasList, const bool apply = true);
    01096
    01098         void _notifyParent(Pass* parent);
    01099
    01101         const TexturePtr& _getTexturePtr(void) const;
    01103         const TexturePtr& _getTexturePtr(size_t frame) const;
    01104
    01106         void _setTexturePtr(const TexturePtr& texptr);
    01108         void _setTexturePtr(const TexturePtr& texptr, size_t frame);
    01109
    01113         Controller<Real>* _getAnimController() const { return mAnimController; }
    01114 protected:
    01115         // State
    01117         unsigned int mCurrentFrame;
    01118
    01120         Real mAnimDuration;
    01121         bool mCubic; // is this a series of 6 2D textures to make up a cube?
    01122
    01123         TextureType mTextureType;
    01124         PixelFormat mDesiredFormat;
    01125         int mTextureSrcMipmaps; // Request number of mipmaps
    01126
    01127         unsigned int mTextureCoordSetIndex;
    01128         UVWAddressingMode mAddressMode;
    01129         ColourValue mBorderColour;
    01130
    01131         LayerBlendModeEx mColourBlendMode;
    01132         SceneBlendFactor mColourBlendFallbackSrc;
    01133         SceneBlendFactor mColourBlendFallbackDest;
    01134
    01135         LayerBlendModeEx mAlphaBlendMode;
    01136         mutable bool mTextureLoadFailed;
    01137         bool mIsAlpha;
    01138         bool mHwGamma;
    01139
    01140         mutable bool mRecalcTexMatrix;
    01141         Real mUMod, mVMod;
    01142         Real mUScale, mVScale;
    01143         Radian mRotate;
    01144         mutable Matrix4 mTexModMatrix;
    01145
    01147         FilterOptions mMinFilter;
    01149         FilterOptions mMagFilter;
    01151         FilterOptions mMipFilter;
    01153         unsigned int mMaxAniso;
    01155         float mMipmapBias;
    01156
    01157         bool mIsDefaultAniso;
    01158         bool mIsDefaultFiltering;
    01160         BindingType mBindingType;
    01162         ContentType mContentType;
    01164         size_t mCompositorRefMrtIndex;
    01165
    01166         //-----------------------------------------------------------------------------
    01167         // Complex members (those that can't be copied using memcpy) are at the end to
    01168         // allow for fast copying of the basic members.
    01169         //
    01170         vector<String>::type mFrames;
    01171         mutable vector<TexturePtr>::type mFramePtrs;
    01172         String mName;               // optional name for the TUS
    01173         String mTextureNameAlias;       // optional alias for texture frames
    01174         EffectMap mEffects;
    01176         String mCompositorRefName;
    01177         String mCompositorRefTexName;
    01178         //-----------------------------------------------------------------------------
    01179
    01180         //-----------------------------------------------------------------------------
    01181         // Pointer members (those that can't be copied using memcpy), and MUST
    01182         // preserving even if assign from others
    01183         //
    01184         Pass* mParent;
    01185         Controller<Real>* mAnimController;
    01186         //-----------------------------------------------------------------------------
    01187
    01188
    01191         void recalcTextureMatrix(void) const;
    01192
    01195         void createAnimController(void);
    01196
    01199         void createEffectController(TextureEffect& effect);
    01200
    01202         void ensurePrepared(size_t frame) const;
    01204         void ensureLoaded(size_t frame) const;
    01205
    01206
    01207     };
    01208
    01212 }
    01213
    01214 #endif

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Wed Nov 3 2010 19:24:52