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-2013 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 #include "OgreHeaderPrefix.h"
00039 
00040 namespace Ogre {
00062     class _OgreExport TextureUnitState : public TextureUnitStateAlloc
00063     {
00064         friend class RenderSystem;
00065     public:
00071         enum TextureEffectType
00072         {
00074             ET_ENVIRONMENT_MAP,
00076             ET_PROJECTIVE_TEXTURE,
00078             ET_UVSCROLL,
00080             ET_USCROLL,
00082             ET_VSCROLL,
00084             ET_ROTATE,
00086             ET_TRANSFORM
00087 
00088         };
00089 
00095         enum EnvMapType
00096         {
00098             ENV_PLANAR,
00100             ENV_CURVED,
00102             ENV_REFLECTION,
00104             ENV_NORMAL
00105         };
00106 
00112         enum TextureTransformType
00113         {
00114             TT_TRANSLATE_U,
00115             TT_TRANSLATE_V,
00116             TT_SCALE_U,
00117             TT_SCALE_V,
00118             TT_ROTATE
00119         };
00120 
00126         enum TextureAddressingMode
00127         {
00129             TAM_WRAP,
00131             TAM_MIRROR,
00133             TAM_CLAMP,
00135             TAM_BORDER,
00137             TAM_UNKNOWN = 99
00138         };
00139 
00141         struct UVWAddressingMode
00142         {
00143             TextureAddressingMode u, v, w;
00144         };
00145 
00148         enum TextureCubeFace
00149         {
00150             CUBE_FRONT = 0,
00151             CUBE_BACK = 1,
00152             CUBE_LEFT = 2,
00153             CUBE_RIGHT = 3,
00154             CUBE_UP = 4,
00155             CUBE_DOWN = 5
00156         };
00157 
00160         struct TextureEffect {
00161             TextureEffectType type;
00162             int subtype;
00163             Real arg1, arg2;
00164             WaveformType waveType;
00165             Real base;
00166             Real frequency;
00167             Real phase;
00168             Real amplitude;
00169             Controller<Real>* controller;
00170             const Frustum* frustum;
00171         };
00172 
00175         typedef multimap<TextureEffectType, TextureEffect>::type EffectMap;
00176 
00179         TextureUnitState(Pass* parent);
00180 
00181         TextureUnitState(Pass* parent, const TextureUnitState& oth );
00182 
00183         TextureUnitState & operator = ( const TextureUnitState& oth );
00184 
00187         ~TextureUnitState();
00188 
00195         TextureUnitState( Pass* parent, const String& texName, unsigned int texCoordSet = 0);
00196 
00205         const String& getTextureName(void) const;
00206 
00212         void setTextureName( const String& name, TextureType ttype = TEX_TYPE_2D);
00213 
00219         void setTexture( const TexturePtr& texPtr);
00220 
00267         void setCubicTextureName( const String& name, bool forUVW = false );
00268 
00313         void setCubicTextureName( const String* const names, bool forUVW = false );
00314 
00359         void setCubicTexture( const TexturePtr* const texPtrs, bool forUVW = false );
00360 
00382         void setAnimatedTextureName( const String& name, unsigned int numFrames, Real duration = 0 );
00383 
00405         void setAnimatedTextureName( const String* const names, unsigned int numFrames, Real duration = 0 );
00406 
00409         std::pair< size_t, size_t > getTextureDimensions( unsigned int frame = 0 ) const;
00410 
00418         void setCurrentFrame( unsigned int frameNumber );
00419 
00424         unsigned int getCurrentFrame(void) const;
00425 
00431         const String& getFrameTextureName(unsigned int frameNumber) const;
00432 
00442         void setFrameTextureName(const String& name, unsigned int frameNumber);
00443 
00450         void addFrameTextureName(const String& name);
00459         void deleteFrameTextureName(const size_t frameNumber);
00464         unsigned int getNumFrames(void) const;
00465 
00466 
00468         enum BindingType
00469         {
00471             BT_FRAGMENT = 0,
00475             BT_VERTEX = 1,          
00477             BT_GEOMETRY = 2,
00479             BT_TESSELATION_HULL = 3,
00481             BT_TESSELATION_DOMAIN = 4,
00483             BT_COMPUTE = 5
00484         };
00487         enum ContentType
00488         {
00490             CONTENT_NAMED = 0,
00492             CONTENT_SHADOW = 1,
00494             CONTENT_COMPOSITOR = 2
00495         };
00496 
00506         void setBindingType(BindingType bt);
00507 
00510         BindingType getBindingType(void) const;
00511 
00517         void setContentType(ContentType ct);
00519         ContentType getContentType(void) const;
00520 
00527         bool isCubic(void) const;
00528 
00533         bool is3D(void) const;
00534 
00539         TextureType getTextureType(void) const;
00540 
00543         void setDesiredFormat(PixelFormat desiredFormat);
00544 
00547         PixelFormat getDesiredFormat(void) const;
00548 
00551         void setNumMipmaps(int numMipmaps);
00552 
00555         int getNumMipmaps(void) const;
00556 
00559         void setIsAlpha(bool isAlpha);
00560 
00563         bool getIsAlpha(void) const;
00564 
00566         Real getGamma() const { return mGamma; }
00568         void setGamma(Real gamma) { mGamma = gamma; }
00569 
00571         void setHardwareGammaEnabled(bool enabled);
00573         bool isHardwareGammaEnabled() const;
00574 
00579         unsigned int getTextureCoordSet(void) const;
00580 
00588         void setTextureCoordSet(unsigned int set);
00589 
00605         void setTextureTransform(const Matrix4& xform);
00606 
00614         const Matrix4& getTextureTransform(void) const;
00615 
00630         void setTextureScroll(Real u, Real v);
00631 
00636         void setTextureUScroll(Real value);
00638         Real getTextureUScroll(void) const;
00639 
00644         void setTextureVScroll(Real value);
00646         Real getTextureVScroll(void) const;
00647 
00652         void setTextureUScale(Real value);
00654         Real getTextureUScale(void) const;
00655 
00660         void setTextureVScale(Real value);
00662         Real getTextureVScale(void) const;
00663 
00677         void setTextureScale(Real uScale, Real vScale);
00678 
00688         void setTextureRotate(const Radian& angle);
00690         const Radian& getTextureRotate(void) const;
00691 
00697         const UVWAddressingMode& getTextureAddressingMode(void) const;
00698 
00712         void setTextureAddressingMode( TextureAddressingMode tam);
00713 
00720         void setTextureAddressingMode( TextureAddressingMode u, 
00721             TextureAddressingMode v, TextureAddressingMode w);
00722 
00729         void setTextureAddressingMode( const UVWAddressingMode& uvw);
00730 
00738         void setTextureBorderColour(const ColourValue& colour);
00739 
00745         const ColourValue& getTextureBorderColour(void) const;
00746 
00811         void setColourOperationEx(
00812             LayerBlendOperationEx op,
00813             LayerBlendSource source1 = LBS_TEXTURE,
00814             LayerBlendSource source2 = LBS_CURRENT,
00815 
00816             const ColourValue& arg1 = ColourValue::White,
00817             const ColourValue& arg2 = ColourValue::White,
00818 
00819             Real manualBlend = 0.0);
00820 
00839         void setColourOperation( const LayerBlendOperation op);
00840 
00860         void setColourOpMultipassFallback( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor);
00861 
00864         const LayerBlendModeEx& getColourBlendMode(void) const;
00865 
00868         const LayerBlendModeEx& getAlphaBlendMode(void) const;
00869 
00872         SceneBlendFactor getColourBlendFallbackSrc(void) const;
00873 
00876         SceneBlendFactor getColourBlendFallbackDest(void) const;
00877 
00903         void setAlphaOperation(LayerBlendOperationEx op,
00904             LayerBlendSource source1 = LBS_TEXTURE,
00905             LayerBlendSource source2 = LBS_CURRENT,
00906             Real arg1 = 1.0,
00907             Real arg2 = 1.0,
00908             Real manualBlend = 0.0);
00909 
00921         void addEffect(TextureEffect& effect);
00922 
00949         void setEnvironmentMap(bool enable, EnvMapType envMapType = ENV_CURVED);
00950 
00961         void setScrollAnimation(Real uSpeed, Real vSpeed);
00962 
00971         void setRotateAnimation(Real speed);
00972 
00992         void setTransformAnimation( const TextureTransformType ttype,
00993             const WaveformType waveType, Real base = 0, Real frequency = 1, Real phase = 0, Real amplitude = 1 );
00994 
00995 
01016         void setProjectiveTexturing(bool enabled, const Frustum* projectionSettings = 0);
01017 
01020         void removeAllEffects(void);
01021 
01027         void removeEffect( const TextureEffectType type );
01028 
01034         bool isBlank(void) const;
01035 
01038         void setBlank(void);
01039 
01042         bool isTextureLoadFailing() const { return mTextureLoadFailed; }
01043 
01046         void retryTextureLoad() { mTextureLoadFailed = false; }
01047 
01049         const EffectMap& getEffects(void) const;
01051         Real getAnimationDuration(void) const;
01052 
01063         void setTextureFiltering(TextureFilterOptions filterType);
01070         void setTextureFiltering(FilterType ftype, FilterOptions opts);
01082         void setTextureFiltering(FilterOptions minFilter, FilterOptions magFilter, FilterOptions mipFilter);
01084         FilterOptions getTextureFiltering(FilterType ftpye) const;
01085 
01086         void setTextureCompareEnabled(bool enabled);
01087         bool getTextureCompareEnabled() const;
01088     
01089         void setTextureCompareFunction(CompareFunction function);
01090         CompareFunction getTextureCompareFunction() const;
01091 
01099         void setTextureAnisotropy(unsigned int maxAniso);
01101         unsigned int getTextureAnisotropy() const;
01102 
01116         void setTextureMipmapBias(float bias) { mMipmapBias = bias; }
01120         float getTextureMipmapBias(void) const { return mMipmapBias; }
01121 
01132         void setCompositorReference(const String& compositorName, const String& textureName, size_t mrtIndex = 0);
01133 
01135         const String& getReferencedCompositorName() const { return mCompositorRefName; }
01137         const String& getReferencedTextureName() const { return mCompositorRefTexName; }
01139         size_t getReferencedMRTIndex() const { return mCompositorRefMrtIndex; }
01140     
01142         Pass* getParent(void) const { return mParent; }
01143 
01145         void _prepare(void);
01147         void _unprepare(void);
01149         void _load(void);
01151         void _unload(void);
01153         bool hasViewRelativeTextureCoordinateGeneration(void) const;
01154 
01156         bool isLoaded(void) const;
01158         void _notifyNeedsRecompile(void);
01159 
01165         void setName(const String& name);
01167         const String& getName(void) const { return mName; }
01168 
01173         void setTextureNameAlias(const String& name);
01176         const String& getTextureNameAlias(void) const { return mTextureNameAlias;}
01177 
01192         bool applyTextureAliases(const AliasTextureNamePairList& aliasList, const bool apply = true);
01193 
01195         void _notifyParent(Pass* parent);
01196 
01198         const TexturePtr& _getTexturePtr(void) const;
01200         const TexturePtr& _getTexturePtr(size_t frame) const;
01201     
01203         void _setTexturePtr(const TexturePtr& texptr);
01205         void _setTexturePtr(const TexturePtr& texptr, size_t frame);
01206 
01207         size_t calculateSize(void) const;
01208 
01212         Controller<Real>* _getAnimController() const { return mAnimController; }
01213 protected:
01214         // State
01216         unsigned int mCurrentFrame;
01217 
01219         Real mAnimDuration;
01220         bool mCubic; 
01221         
01222         TextureType mTextureType; 
01223         PixelFormat mDesiredFormat;
01224         int mTextureSrcMipmaps; 
01225 
01226         unsigned int mTextureCoordSetIndex;
01227         UVWAddressingMode mAddressMode;
01228         ColourValue mBorderColour;
01229 
01230         LayerBlendModeEx mColourBlendMode;
01231         SceneBlendFactor mColourBlendFallbackSrc;
01232         SceneBlendFactor mColourBlendFallbackDest;
01233 
01234         LayerBlendModeEx mAlphaBlendMode;
01235         mutable bool mTextureLoadFailed;
01236         bool mIsAlpha;
01237         bool mHwGamma;
01238         Real mGamma;
01239 
01240         mutable bool mRecalcTexMatrix;
01241         Real mUMod, mVMod;
01242         Real mUScale, mVScale;
01243         Radian mRotate;
01244         mutable Matrix4 mTexModMatrix;
01245 
01247         FilterOptions mMinFilter;
01249         FilterOptions mMagFilter;
01251         FilterOptions mMipFilter;
01252 
01253         bool mCompareEnabled;
01254         CompareFunction mCompareFunc;
01255 
01257         unsigned int mMaxAniso;
01259         float mMipmapBias;
01260 
01261         bool mIsDefaultAniso;
01262         bool mIsDefaultFiltering;
01264         BindingType mBindingType;
01266         ContentType mContentType;
01268         size_t mCompositorRefMrtIndex;
01269 
01270         //-----------------------------------------------------------------------------
01271         // Complex members (those that can't be copied using memcpy) are at the end to 
01272         // allow for fast copying of the basic members.
01273         //
01274         vector<String>::type mFrames;
01275         mutable vector<TexturePtr>::type mFramePtrs;
01276         String mName;               
01277         String mTextureNameAlias;   
01278         EffectMap mEffects;
01280         String mCompositorRefName;
01281         String mCompositorRefTexName;
01282         //-----------------------------------------------------------------------------
01283 
01284         //-----------------------------------------------------------------------------
01285         // Pointer members (those that can't be copied using memcpy), and MUST
01286         // preserving even if assign from others
01287         //
01288         Pass* mParent;
01289         Controller<Real>* mAnimController;
01290         //-----------------------------------------------------------------------------
01291 
01292 
01295         void recalcTextureMatrix(void) const;
01296 
01299         void createAnimController(void);
01300 
01303         void createEffectController(TextureEffect& effect);
01304 
01306         void ensurePrepared(size_t frame) const;
01308         void ensureLoaded(size_t frame) const;
01309 
01310 
01311     };
01312 
01316 } // namespace Ogre
01317 
01318 #include "OgreHeaderSuffix.h"
01319 
01320 #endif // __TextureUnitState_H__

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:48