OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreTextureUnitState.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org
6 
7 Copyright (c) 2000-2014 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef __TextureUnitState_H__
29 #define __TextureUnitState_H__
30 
31 #include "OgrePrerequisites.h"
32 #include "OgreCommon.h"
33 #include "OgreBlendMode.h"
34 #include "OgreMatrix4.h"
35 #include "OgreTexture.h"
36 #include "OgreIdString.h"
37 #include "OgreHeaderPrefix.h"
38 
39 namespace Ogre {
62  {
63  friend class RenderSystem;
64  public:
71  {
85  ET_TRANSFORM
86 
87  };
88 
95  {
103  ENV_NORMAL
104  };
105 
112  {
117  TT_ROTATE
118  };
119 
126  {
136  TAM_UNKNOWN = 99
137  };
138 
141  {
143  };
144 
148  {
149  CUBE_FRONT = 0,
150  CUBE_BACK = 1,
151  CUBE_LEFT = 2,
152  CUBE_RIGHT = 3,
153  CUBE_UP = 4,
154  CUBE_DOWN = 5
155  };
156 
159  struct TextureEffect {
161  int subtype;
162  Real arg1, arg2;
169  const Frustum* frustum;
170  };
171 
175 
178  TextureUnitState(Pass* parent);
179 
180  TextureUnitState(Pass* parent, const TextureUnitState& oth );
181 
182  TextureUnitState & operator = ( const TextureUnitState& oth );
183 
186  ~TextureUnitState();
187 
194  TextureUnitState( Pass* parent, const String& texName, unsigned int texCoordSet = 0);
195 
204  const String& getTextureName(void) const;
205 
211  void setTextureName( const String& name, TextureType ttype = TEX_TYPE_2D);
212 
218  void setTexture( const TexturePtr& texPtr);
219 
266  void setCubicTextureName( const String& name, bool forUVW = false );
267 
312  void setCubicTextureName( const String* const names, bool forUVW = false );
313 
358  void setCubicTexture( const TexturePtr* const texPtrs, bool forUVW = false );
359 
381  void setAnimatedTextureName( const String& name, unsigned int numFrames, Real duration = 0 );
382 
404  void setAnimatedTextureName( const String* const names, unsigned int numFrames, Real duration = 0 );
405 
408  std::pair< size_t, size_t > getTextureDimensions( unsigned int frame = 0 ) const;
409 
417  void setCurrentFrame( unsigned int frameNumber );
418 
423  unsigned int getCurrentFrame(void) const;
424 
430  const String& getFrameTextureName(unsigned int frameNumber) const;
431 
441  void setFrameTextureName(const String& name, unsigned int frameNumber);
442 
449  void addFrameTextureName(const String& name);
458  void deleteFrameTextureName(const size_t frameNumber);
463  unsigned int getNumFrames(void) const;
464 
465 
468  {
470  BT_FRAGMENT = 0,
474  BT_VERTEX = 1,
476  BT_GEOMETRY = 2,
478  BT_TESSELLATION_HULL = 3,
480  BT_TESSELLATION_DOMAIN = 4,
482  BT_COMPUTE = 5
483  };
487  {
489  CONTENT_NAMED = 0,
491  CONTENT_SHADOW = 1,
493  CONTENT_COMPOSITOR = 2
494  };
495 
505  void setBindingType(BindingType bt);
506 
509  BindingType getBindingType(void) const;
510 
516  void setContentType(ContentType ct);
518  ContentType getContentType(void) const;
519 
526  bool isCubic(void) const;
527 
532  bool is3D(void) const;
533 
538  TextureType getTextureType(void) const;
539 
542  void setDesiredFormat(PixelFormat desiredFormat);
543 
546  PixelFormat getDesiredFormat(void) const;
547 
550  void setNumMipmaps(int numMipmaps);
551 
554  int getNumMipmaps(void) const;
555 
558  void setIsAlpha(bool isAlpha);
559 
562  bool getIsAlpha(void) const;
563 
565  Real getGamma() const { return mGamma; }
567  void setGamma(Real gamma) { mGamma = gamma; }
568 
570  void setHardwareGammaEnabled(bool enabled);
572  bool isHardwareGammaEnabled() const;
573 
578  unsigned int getTextureCoordSet(void) const;
579 
587  void setTextureCoordSet(unsigned int set);
588 
604  void setTextureTransform(const Matrix4& xform);
605 
613  const Matrix4& getTextureTransform(void) const;
614 
629  void setTextureScroll(Real u, Real v);
630 
635  void setTextureUScroll(Real value);
637  Real getTextureUScroll(void) const;
638 
643  void setTextureVScroll(Real value);
645  Real getTextureVScroll(void) const;
646 
651  void setTextureUScale(Real value);
653  Real getTextureUScale(void) const;
654 
659  void setTextureVScale(Real value);
661  Real getTextureVScale(void) const;
662 
676  void setTextureScale(Real uScale, Real vScale);
677 
687  void setTextureRotate(const Radian& angle);
689  const Radian& getTextureRotate(void) const;
690 
696  const UVWAddressingMode& getTextureAddressingMode(void) const;
697 
711  void setTextureAddressingMode( TextureAddressingMode tam);
712 
719  void setTextureAddressingMode( TextureAddressingMode u,
720  TextureAddressingMode v, TextureAddressingMode w);
721 
728  void setTextureAddressingMode( const UVWAddressingMode& uvw);
729 
737  void setTextureBorderColour(const ColourValue& colour);
738 
744  const ColourValue& getTextureBorderColour(void) const;
745 
810  void setColourOperationEx(
812  LayerBlendSource source1 = LBS_TEXTURE,
813  LayerBlendSource source2 = LBS_CURRENT,
814 
815  const ColourValue& arg1 = ColourValue::White,
816  const ColourValue& arg2 = ColourValue::White,
817 
818  Real manualBlend = 0.0);
819 
838  void setColourOperation( const LayerBlendOperation op);
839 
859  void setColourOpMultipassFallback( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor);
860 
863  const LayerBlendModeEx& getColourBlendMode(void) const;
864 
867  const LayerBlendModeEx& getAlphaBlendMode(void) const;
868 
871  SceneBlendFactor getColourBlendFallbackSrc(void) const;
872 
875  SceneBlendFactor getColourBlendFallbackDest(void) const;
876 
902  void setAlphaOperation(LayerBlendOperationEx op,
903  LayerBlendSource source1 = LBS_TEXTURE,
904  LayerBlendSource source2 = LBS_CURRENT,
905  Real arg1 = 1.0,
906  Real arg2 = 1.0,
907  Real manualBlend = 0.0);
908 
920  void addEffect(TextureEffect& effect);
921 
948  void setEnvironmentMap(bool enable, EnvMapType envMapType = ENV_CURVED);
949 
960  void setScrollAnimation(Real uSpeed, Real vSpeed);
961 
970  void setRotateAnimation(Real speed);
971 
991  void setTransformAnimation( const TextureTransformType ttype,
992  const WaveformType waveType, Real base = 0, Real frequency = 1, Real phase = 0, Real amplitude = 1 );
993 
994 
1015  void setProjectiveTexturing(bool enabled, const Frustum* projectionSettings = 0);
1016 
1019  void removeAllEffects(void);
1020 
1026  void removeEffect( const TextureEffectType type );
1027 
1033  bool isBlank(void) const;
1034 
1037  void setBlank(void);
1038 
1041  bool isTextureLoadFailing() const { return mTextureLoadFailed; }
1042 
1045  void retryTextureLoad() { mTextureLoadFailed = false; }
1046 
1048  const EffectMap& getEffects(void) const;
1050  Real getAnimationDuration(void) const;
1051 
1062  void setTextureFiltering(TextureFilterOptions filterType);
1069  void setTextureFiltering(FilterType ftype, FilterOptions opts);
1081  void setTextureFiltering(FilterOptions minFilter, FilterOptions magFilter, FilterOptions mipFilter);
1083  FilterOptions getTextureFiltering(FilterType ftpye) const;
1084 
1085  void setTextureCompareEnabled(bool enabled);
1086  bool getTextureCompareEnabled() const;
1087 
1088  void setTextureCompareFunction(CompareFunction function);
1089  CompareFunction getTextureCompareFunction() const;
1090 
1098  void setTextureAnisotropy(unsigned int maxAniso);
1100  unsigned int getTextureAnisotropy() const;
1101 
1115  void setTextureMipmapBias(float bias) { mMipmapBias = bias; }
1119  float getTextureMipmapBias(void) const { return mMipmapBias; }
1120 
1129  void setCompositorReference(const String& textureName, size_t mrtIndex = 0);
1130 
1132  IdString getReferencedTextureName() const { return mCompositorRefTexName; }
1134  size_t getReferencedMRTIndex() const { return mCompositorRefMrtIndex; }
1135 
1137  Pass* getParent(void) const { return mParent; }
1138 
1140  void _prepare(void);
1142  void _unprepare(void);
1144  void _load(void);
1146  void _unload(void);
1148  bool hasViewRelativeTextureCoordinateGeneration(void) const;
1149 
1151  bool isLoaded(void) const;
1153  void _notifyNeedsRecompile(void);
1154 
1160  void setName(const String& name);
1162  const String& getName(void) const { return mName; }
1163 
1168  void setTextureNameAlias(const String& name);
1171  const String& getTextureNameAlias(void) const { return mTextureNameAlias;}
1172 
1187  bool applyTextureAliases(const AliasTextureNamePairList& aliasList, const bool apply = true);
1188 
1190  void _notifyParent(Pass* parent);
1191 
1193  const TexturePtr& _getTexturePtr(void) const;
1195  const TexturePtr& _getTexturePtr(size_t frame) const;
1196 
1198  void _setTexturePtr(const TexturePtr& texptr);
1200  void _setTexturePtr(const TexturePtr& texptr, size_t frame);
1201 
1202  size_t calculateSize(void) const;
1203 
1207  Controller<Real>* _getAnimController() const { return mAnimController; }
1208 protected:
1209  // State
1211  unsigned int mCurrentFrame;
1212 
1215  bool mCubic;
1216 
1220 
1224 
1228 
1230  mutable bool mTextureLoadFailed;
1231  bool mIsAlpha;
1232  bool mHwGamma;
1234 
1235  mutable bool mRecalcTexMatrix;
1236  Real mUMod, mVMod;
1237  Real mUScale, mVScale;
1240 
1247 
1250 
1252  unsigned int mMaxAniso;
1255 
1264 
1265  //-----------------------------------------------------------------------------
1266  // Complex members (those that can't be copied using memcpy) are at the end to
1267  // allow for fast copying of the basic members.
1268  //
1276  //-----------------------------------------------------------------------------
1277 
1278  //-----------------------------------------------------------------------------
1279  // Pointer members (those that can't be copied using memcpy), and MUST
1280  // preserving even if assign from others
1281  //
1284  //-----------------------------------------------------------------------------
1285 
1286 
1289  void recalcTextureMatrix(void) const;
1290 
1293  void createAnimController(void);
1294 
1297  void createEffectController(TextureEffect& effect);
1298 
1300  void ensurePrepared(size_t frame) const;
1302  void ensureLoaded(size_t frame) const;
1303 
1304 
1305  };
1306 
1310 } // namespace Ogre
1311 
1312 #include "OgreHeaderSuffix.h"
1313 
1314 #endif // __TextureUnitState_H__
void setTextureMipmapBias(float bias)
Sets the bias value applied to the mipmap calculation.
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:79
float Real
Software floating point type.
Generate texture coords based on a frustum.
#define _OgreExport
Definition: OgrePlatform.h:255
TextureType mTextureType
Is this a series of 6 2D textures to make up a cube?
Generate all texture coords based on angle between camera and vertex.
String mTextureNameAlias
Optional alias for texture frames.
WaveformType
Enumerates the wave types usable with the Ogre engine.
Definition: OgreCommon.h:192
float mMipmapBias
Mipmap bias (always float, not Real).
Controller< Real > * mAnimController
Controller< Real > * _getAnimController() const
Gets the animation controller (as created because of setAnimatedTexture) if it exists.
Texture coordinates outside the range [0.0, 1.0] are set to the border colour.
Class representing colour.
static const ColourValue White
A frustum represents a pyramid, capped at the near and far end which is used to represent either a vi...
Definition: OgreFrustum.h:84
Internal structure defining a texture effect.
FilterOptions mMipFilter
Texture filtering - mipmapping.
Envmap intended to supply reflection vectors for cube mapping.
FilterOptions mMinFilter
Texture filtering - minification.
multimap< TextureEffectType, TextureEffect >::type EffectMap
Texture effects in a multimap paired array.
FilterType
Definition: OgreCommon.h:121
bool isTextureLoadFailing() const
Tests if the texture associated with this unit has failed to load.
ContentType mContentType
Content type of texture (normal loaded texture, auto-texture).
SceneBlendFactor
Blending factors for manually blending objects with the scene.
BindingType
The type of unit to bind the texture settings to.
unsigned int mTextureCoordSetIndex
Request number of mipmaps.
TextureCubeFace
Enum identifying the frame indexes for faces of a cube map (not the composite 3D type.
EnvMapType
Enumeration to specify type of envmap.
unsigned int mMaxAniso
Texture anisotropy.
Pass * getParent(void) const
Gets the parent Pass object.
Class defining a single pass of a Technique (of a Material), i.e.
Definition: OgrePass.h:78
the colour derived from the texture assigned to this layer
Real mAnimDuration
Duration of animation in seconds.
String mName
Optional name for the TUS.
LayerBlendOperation
List of valid texture blending operations, for use with TextureUnitState::setColourOperation.
Definition: OgreBlendMode.h:57
IdString mCompositorRefTexName
The data that references the compositor.
vector< String >::type mFrames
BindingType mBindingType
Binding type (fragment, vertex, tessellation hull and domain pipeline).
PixelFormat
The pixel format used for images, textures, and render surfaces.
Texture addressing mode for each texture coordinate.
TextureAddressingMode
Texture addressing modes - default is TAM_WRAP.
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
size_t getReferencedMRTIndex() const
Gets the MRT index of the texture in the compositor that this texture references. ...
TextureEffectType
Definition of the broad types of texture effect you can apply to a texture unit.
Envmap based on dot of vector from camera to vertex and vertex normal, good for curves.
Hashed string.
Definition: OgreIdString.h:94
UVWAddressingMode mAddressMode
LayerBlendSource
List of valid sources of values for blending operations used in TextureUnitState::setColourOperation ...
unsigned int mCurrentFrame
The current animation frame.
Constant u/v scrolling effect.
SceneBlendFactor mColourBlendFallbackDest
FilterOptions mMagFilter
Texture filtering - magnification.
SceneBlendFactor mColourBlendFallbackSrc
const String & getName(void) const
Get the name of the Texture Unit State.
Constant u scrolling effect.
Real getGamma() const
Returns the gamma adjustment factor applied to this texture on loading.
Wrapper class which indicates a given angle value is in Radians.
Definition: OgreMath.h:49
size_t mCompositorRefMrtIndex
The index of the referenced texture if referencing an MRT in a compositor.
TextureTransformType
Useful enumeration when dealing with procedural transforms.
TextureType
Enum identifying the texture type.
Definition: OgreTexture.h:76
Texture wraps at values over 1.0.
the colour as built up from previous stages
2D texture, used in combination with 2D texture coordinates (default)
Definition: OgreTexture.h:81
_StringBase String
Definition: OgreCommon.h:53
Constant u/v scrolling effect.
const String & getTextureNameAlias(void) const
Gets the Texture Name Alias of the Texture Unit.
LayerBlendOperationEx
Expert list of valid texture blending operations, for use with TextureUnitState::setColourOperationEx...
Definition: OgreBlendMode.h:75
void retryTextureLoad()
Tells the unit to retry loading the texture if it had failed to load.
FilterOptions
Filtering options for textures / mipmaps.
Definition: OgreCommon.h:131
map< String, String >::type AliasTextureNamePairList
Alias / Texture name pair (first = alias, second = texture name)
Definition: OgreCommon.h:583
Defines the functionality of a 3D API.
Envmap based on vector from camera to vertex position, good for planar geometry.
CompareFunction
Comparison functions used for the depth/stencil buffer operations and others.
Definition: OgreCommon.h:74
Class representing the state of a single texture unit during a Pass of a Technique, of a Material.
LayerBlendModeEx mColourBlendMode
Class which manages blending of both colour and alpha components.
ContentType
Enum identifying the type of content this texture unit contains.
void setGamma(Real gamma)
Sets the gamma adjustment factor applied to this texture on loading the data.
vector< TexturePtr >::type mFramePtrs
LayerBlendModeEx mAlphaBlendMode
Texture mirrors (flips) at joins over 1.0.
IdString getReferencedTextureName() const
Gets the name of the texture in the compositor that this texture references.
TextureFilterOptions
High-level filtering options providing shortcuts to settings the minification, magnification and mip ...
Definition: OgreCommon.h:109
float getTextureMipmapBias(void) const
Gets the bias value applied to the mipmap calculation.