OGRE  1.9
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 "OgreIteratorWrappers.h"
36 #include "OgreString.h"
37 #include "OgreTexture.h"
38 #include "OgreHeaderPrefix.h"
39 
40 namespace Ogre {
63  {
64  friend class RenderSystem;
65  public:
72  {
86  ET_TRANSFORM
87 
88  };
89 
96  {
104  ENV_NORMAL
105  };
106 
113  {
118  TT_ROTATE
119  };
120 
127  {
137  TAM_UNKNOWN = 99
138  };
139 
142  {
144  };
145 
149  {
150  CUBE_FRONT = 0,
151  CUBE_BACK = 1,
152  CUBE_LEFT = 2,
153  CUBE_RIGHT = 3,
154  CUBE_UP = 4,
155  CUBE_DOWN = 5
156  };
157 
160  struct TextureEffect {
162  int subtype;
163  Real arg1, arg2;
170  const Frustum* frustum;
171  };
172 
176 
179  TextureUnitState(Pass* parent);
180 
181  TextureUnitState(Pass* parent, const TextureUnitState& oth );
182 
183  TextureUnitState & operator = ( const TextureUnitState& oth );
184 
187  ~TextureUnitState();
188 
195  TextureUnitState( Pass* parent, const String& texName, unsigned int texCoordSet = 0);
196 
205  const String& getTextureName(void) const;
206 
212  void setTextureName( const String& name, TextureType ttype = TEX_TYPE_2D);
213 
219  void setTexture( const TexturePtr& texPtr);
220 
267  void setCubicTextureName( const String& name, bool forUVW = false );
268 
313  void setCubicTextureName( const String* const names, bool forUVW = false );
314 
359  void setCubicTexture( const TexturePtr* const texPtrs, bool forUVW = false );
360 
382  void setAnimatedTextureName( const String& name, unsigned int numFrames, Real duration = 0 );
383 
405  void setAnimatedTextureName( const String* const names, unsigned int numFrames, Real duration = 0 );
406 
409  std::pair< size_t, size_t > getTextureDimensions( unsigned int frame = 0 ) const;
410 
418  void setCurrentFrame( unsigned int frameNumber );
419 
424  unsigned int getCurrentFrame(void) const;
425 
431  const String& getFrameTextureName(unsigned int frameNumber) const;
432 
442  void setFrameTextureName(const String& name, unsigned int frameNumber);
443 
450  void addFrameTextureName(const String& name);
459  void deleteFrameTextureName(const size_t frameNumber);
464  unsigned int getNumFrames(void) const;
465 
466 
469  {
471  BT_FRAGMENT = 0,
475  BT_VERTEX = 1,
477  BT_GEOMETRY = 2,
479  BT_TESSELATION_HULL = 3,
481  BT_TESSELATION_DOMAIN = 4,
483  BT_COMPUTE = 5
484  };
488  {
490  CONTENT_NAMED = 0,
492  CONTENT_SHADOW = 1,
494  CONTENT_COMPOSITOR = 2
495  };
496 
506  void setBindingType(BindingType bt);
507 
510  BindingType getBindingType(void) const;
511 
517  void setContentType(ContentType ct);
519  ContentType getContentType(void) const;
520 
527  bool isCubic(void) const;
528 
533  bool is3D(void) const;
534 
539  TextureType getTextureType(void) const;
540 
543  void setDesiredFormat(PixelFormat desiredFormat);
544 
547  PixelFormat getDesiredFormat(void) const;
548 
551  void setNumMipmaps(int numMipmaps);
552 
555  int getNumMipmaps(void) const;
556 
559  void setIsAlpha(bool isAlpha);
560 
563  bool getIsAlpha(void) const;
564 
566  Real getGamma() const { return mGamma; }
568  void setGamma(Real gamma) { mGamma = gamma; }
569 
571  void setHardwareGammaEnabled(bool enabled);
573  bool isHardwareGammaEnabled() const;
574 
579  unsigned int getTextureCoordSet(void) const;
580 
588  void setTextureCoordSet(unsigned int set);
589 
605  void setTextureTransform(const Matrix4& xform);
606 
614  const Matrix4& getTextureTransform(void) const;
615 
630  void setTextureScroll(Real u, Real v);
631 
636  void setTextureUScroll(Real value);
638  Real getTextureUScroll(void) const;
639 
644  void setTextureVScroll(Real value);
646  Real getTextureVScroll(void) const;
647 
652  void setTextureUScale(Real value);
654  Real getTextureUScale(void) const;
655 
660  void setTextureVScale(Real value);
662  Real getTextureVScale(void) const;
663 
677  void setTextureScale(Real uScale, Real vScale);
678 
688  void setTextureRotate(const Radian& angle);
690  const Radian& getTextureRotate(void) const;
691 
697  const UVWAddressingMode& getTextureAddressingMode(void) const;
698 
712  void setTextureAddressingMode( TextureAddressingMode tam);
713 
720  void setTextureAddressingMode( TextureAddressingMode u,
721  TextureAddressingMode v, TextureAddressingMode w);
722 
729  void setTextureAddressingMode( const UVWAddressingMode& uvw);
730 
738  void setTextureBorderColour(const ColourValue& colour);
739 
745  const ColourValue& getTextureBorderColour(void) const;
746 
811  void setColourOperationEx(
813  LayerBlendSource source1 = LBS_TEXTURE,
814  LayerBlendSource source2 = LBS_CURRENT,
815 
816  const ColourValue& arg1 = ColourValue::White,
817  const ColourValue& arg2 = ColourValue::White,
818 
819  Real manualBlend = 0.0);
820 
839  void setColourOperation( const LayerBlendOperation op);
840 
860  void setColourOpMultipassFallback( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor);
861 
864  const LayerBlendModeEx& getColourBlendMode(void) const;
865 
868  const LayerBlendModeEx& getAlphaBlendMode(void) const;
869 
872  SceneBlendFactor getColourBlendFallbackSrc(void) const;
873 
876  SceneBlendFactor getColourBlendFallbackDest(void) const;
877 
903  void setAlphaOperation(LayerBlendOperationEx op,
904  LayerBlendSource source1 = LBS_TEXTURE,
905  LayerBlendSource source2 = LBS_CURRENT,
906  Real arg1 = 1.0,
907  Real arg2 = 1.0,
908  Real manualBlend = 0.0);
909 
921  void addEffect(TextureEffect& effect);
922 
949  void setEnvironmentMap(bool enable, EnvMapType envMapType = ENV_CURVED);
950 
961  void setScrollAnimation(Real uSpeed, Real vSpeed);
962 
971  void setRotateAnimation(Real speed);
972 
992  void setTransformAnimation( const TextureTransformType ttype,
993  const WaveformType waveType, Real base = 0, Real frequency = 1, Real phase = 0, Real amplitude = 1 );
994 
995 
1016  void setProjectiveTexturing(bool enabled, const Frustum* projectionSettings = 0);
1017 
1020  void removeAllEffects(void);
1021 
1027  void removeEffect( const TextureEffectType type );
1028 
1034  bool isBlank(void) const;
1035 
1038  void setBlank(void);
1039 
1042  bool isTextureLoadFailing() const { return mTextureLoadFailed; }
1043 
1046  void retryTextureLoad() { mTextureLoadFailed = false; }
1047 
1049  const EffectMap& getEffects(void) const;
1051  Real getAnimationDuration(void) const;
1052 
1063  void setTextureFiltering(TextureFilterOptions filterType);
1070  void setTextureFiltering(FilterType ftype, FilterOptions opts);
1082  void setTextureFiltering(FilterOptions minFilter, FilterOptions magFilter, FilterOptions mipFilter);
1084  FilterOptions getTextureFiltering(FilterType ftpye) const;
1085 
1086  void setTextureCompareEnabled(bool enabled);
1087  bool getTextureCompareEnabled() const;
1088 
1089  void setTextureCompareFunction(CompareFunction function);
1090  CompareFunction getTextureCompareFunction() const;
1091 
1099  void setTextureAnisotropy(unsigned int maxAniso);
1101  unsigned int getTextureAnisotropy() const;
1102 
1116  void setTextureMipmapBias(float bias) { mMipmapBias = bias; }
1120  float getTextureMipmapBias(void) const { return mMipmapBias; }
1121 
1132  void setCompositorReference(const String& compositorName, const String& textureName, size_t mrtIndex = 0);
1133 
1135  const String& getReferencedCompositorName() const { return mCompositorRefName; }
1137  const String& getReferencedTextureName() const { return mCompositorRefTexName; }
1139  size_t getReferencedMRTIndex() const { return mCompositorRefMrtIndex; }
1140 
1142  Pass* getParent(void) const { return mParent; }
1143 
1145  void _prepare(void);
1147  void _unprepare(void);
1149  void _load(void);
1151  void _unload(void);
1153  bool hasViewRelativeTextureCoordinateGeneration(void) const;
1154 
1156  bool isLoaded(void) const;
1158  void _notifyNeedsRecompile(void);
1159 
1165  void setName(const String& name);
1167  const String& getName(void) const { return mName; }
1168 
1173  void setTextureNameAlias(const String& name);
1176  const String& getTextureNameAlias(void) const { return mTextureNameAlias;}
1177 
1192  bool applyTextureAliases(const AliasTextureNamePairList& aliasList, const bool apply = true);
1193 
1195  void _notifyParent(Pass* parent);
1196 
1198  const TexturePtr& _getTexturePtr(void) const;
1200  const TexturePtr& _getTexturePtr(size_t frame) const;
1201 
1203  void _setTexturePtr(const TexturePtr& texptr);
1205  void _setTexturePtr(const TexturePtr& texptr, size_t frame);
1206 
1207  size_t calculateSize(void) const;
1208 
1212  Controller<Real>* _getAnimController() const { return mAnimController; }
1213 protected:
1214  // State
1216  unsigned int mCurrentFrame;
1217 
1220  bool mCubic;
1221 
1225 
1229 
1233 
1235  mutable bool mTextureLoadFailed;
1236  bool mIsAlpha;
1237  bool mHwGamma;
1239 
1240  mutable bool mRecalcTexMatrix;
1241  Real mUMod, mVMod;
1242  Real mUScale, mVScale;
1245 
1252 
1255 
1257  unsigned int mMaxAniso;
1260 
1269 
1270  //-----------------------------------------------------------------------------
1271  // Complex members (those that can't be copied using memcpy) are at the end to
1272  // allow for fast copying of the basic members.
1273  //
1282  //-----------------------------------------------------------------------------
1283 
1284  //-----------------------------------------------------------------------------
1285  // Pointer members (those that can't be copied using memcpy), and MUST
1286  // preserving even if assign from others
1287  //
1290  //-----------------------------------------------------------------------------
1291 
1292 
1295  void recalcTextureMatrix(void) const;
1296 
1299  void createAnimController(void);
1300 
1303  void createEffectController(TextureEffect& effect);
1304 
1306  void ensurePrepared(size_t frame) const;
1308  void ensureLoaded(size_t frame) const;
1309 
1310 
1311  };
1312 
1316 } // namespace Ogre
1317 
1318 #include "OgreHeaderSuffix.h"
1319 
1320 #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:78
float Real
Software floating point type.
Generate texture coords based on a frustum.
#define _OgreExport
Definition: OgrePlatform.h:260
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:161
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:85
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:90
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:80
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
vector< String >::type mFrames
BindingType mBindingType
Binding type (fragment or vertex 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.
const String & getReferencedTextureName() const
Gets the name of the texture in the compositor that this texture references.
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.
const String & getReferencedCompositorName() const
Gets the name of the compositor that this texture referneces.
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:47
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:67
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:72
_StringBase String
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:100
map< String, String >::type AliasTextureNamePairList
Alias / Texture name pair (first = alias, second = texture name)
Definition: OgreCommon.h:553
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:64
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.
String mCompositorRefName
The data that references the compositor.
TextureFilterOptions
High-level filtering options providing shortcuts to settings the minification, magnification and mip ...
Definition: OgreCommon.h:78
float getTextureMipmapBias(void) const
Gets the bias value applied to the mipmap calculation.