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-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 : public TextureUnitStateAlloc
    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
    00493         void setHardwareGammaEnabled(bool enabled);
    00495         bool isHardwareGammaEnabled() const;
    00496
    00501         unsigned int getTextureCoordSet(void) const;
    00502
    00510         void setTextureCoordSet(unsigned int set);
    00511
    00527         void setTextureTransform(const Matrix4& xform);
    00528
    00536         const Matrix4& getTextureTransform(void) const;
    00537
    00550         void setTextureScroll(Real u, Real v);
    00551
    00556         void setTextureUScroll(Real value);
    00557         // get texture uscroll value
    00558         Real getTextureUScroll(void) const;
    00559
    00564         void setTextureVScroll(Real value);
    00565         // get texture vscroll value
    00566         Real getTextureVScroll(void) const;
    00567
    00572         void setTextureUScale(Real value);
    00573         // get texture uscale value
    00574         Real getTextureUScale(void) const;
    00575
    00580         void setTextureVScale(Real value);
    00581         // get texture vscale value
    00582         Real getTextureVScale(void) const;
    00583
    00597         void setTextureScale(Real uScale, Real vScale);
    00598
    00608         void setTextureRotate(const Radian& angle);
    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 _prepare(void);
    01028         void _unprepare(void);
    01030         void _load(void);
    01032         void _unload(void);
    01034         bool hasViewRelativeTextureCoordinateGeneration(void) const;
    01035
    01036         // Is this loaded?
    01037         bool isLoaded(void) const;
    01039         void _notifyNeedsRecompile(void);
    01040
    01046         void setName(const String& name);
    01048         const String& getName(void) const { return mName; }
    01049
    01053         void setTextureNameAlias(const String& name);
    01056         const String& getTextureNameAlias(void) const { return mTextureNameAlias;}
    01057
    01072         bool applyTextureAliases(const AliasTextureNamePairList& aliasList, const bool apply = true);
    01073
    01075         void _notifyParent(Pass* parent);
    01076
    01078         const TexturePtr& _getTexturePtr(void) const;
    01080         const TexturePtr& _getTexturePtr(size_t frame) const;
    01081
    01083         void _setTexturePtr(const TexturePtr& texptr);
    01085         void _setTexturePtr(const TexturePtr& texptr, size_t frame);
    01086
    01090         Controller<Real>* _getAnimController() const { return mAnimController; }
    01091 protected:
    01092         // State
    01094         unsigned int mCurrentFrame;
    01095
    01097         Real mAnimDuration;
    01098         bool mCubic; // is this a series of 6 2D textures to make up a cube?
    01099
    01100         TextureType mTextureType;
    01101         PixelFormat mDesiredFormat;
    01102         int mTextureSrcMipmaps; // Request number of mipmaps
    01103
    01104         unsigned int mTextureCoordSetIndex;
    01105         UVWAddressingMode mAddressMode;
    01106         ColourValue mBorderColour;
    01107
    01108         LayerBlendModeEx mColourBlendMode;
    01109         SceneBlendFactor mColourBlendFallbackSrc;
    01110         SceneBlendFactor mColourBlendFallbackDest;
    01111
    01112         LayerBlendModeEx mAlphaBlendMode;
    01113         mutable bool mTextureLoadFailed;
    01114         bool mIsAlpha;
    01115         bool mHwGamma;
    01116
    01117         mutable bool mRecalcTexMatrix;
    01118         Real mUMod, mVMod;
    01119         Real mUScale, mVScale;
    01120         Radian mRotate;
    01121         mutable Matrix4 mTexModMatrix;
    01122
    01124         FilterOptions mMinFilter;
    01126         FilterOptions mMagFilter;
    01128         FilterOptions mMipFilter;
    01130         unsigned int mMaxAniso;
    01132         float mMipmapBias;
    01133
    01134         bool mIsDefaultAniso;
    01135         bool mIsDefaultFiltering;
    01137         BindingType mBindingType;
    01139         ContentType mContentType;
    01140
    01141         //-----------------------------------------------------------------------------
    01142         // Complex members (those that can't be copied using memcpy) are at the end to
    01143         // allow for fast copying of the basic members.
    01144         //
    01145         std::vector<String> mFrames;
    01146         mutable std::vector<TexturePtr> mFramePtrs;
    01147         String mName;               // optional name for the TUS
    01148         String mTextureNameAlias;       // optional alias for texture frames
    01149         EffectMap mEffects;
    01150         //-----------------------------------------------------------------------------
    01151
    01152         //-----------------------------------------------------------------------------
    01153         // Pointer members (those that can't be copied using memcpy), and MUST
    01154         // preserving even if assign from others
    01155         //
    01156         Pass* mParent;
    01157         Controller<Real>* mAnimController;
    01158         //-----------------------------------------------------------------------------
    01159
    01160
    01163         void recalcTextureMatrix(void) const;
    01164
    01167         void createAnimController(void);
    01168
    01171         void createEffectController(TextureEffect& effect);
    01172
    01174         void ensurePrepared(size_t frame) const;
    01176         void ensureLoaded(size_t frame) const;
    01177
    01178
    01179     };
    01180
    01181
    01182 }
    01183
    01184 #endif

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Jul 26 11:32:21 2009