OGRE  1.8
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-2013 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  {
135  TAM_BORDER
136  };
137 
140  {
142  };
143 
147  {
148  CUBE_FRONT = 0,
149  CUBE_BACK = 1,
150  CUBE_LEFT = 2,
151  CUBE_RIGHT = 3,
152  CUBE_UP = 4,
153  CUBE_DOWN = 5
154  };
155 
158  struct TextureEffect {
160  int subtype;
161  Real arg1, arg2;
168  const Frustum* frustum;
169  };
170 
174 
177  TextureUnitState(Pass* parent);
178 
179  TextureUnitState(Pass* parent, const TextureUnitState& oth );
180 
181  TextureUnitState & operator = ( const TextureUnitState& oth );
182 
185  ~TextureUnitState();
186 
193  TextureUnitState( Pass* parent, const String& texName, unsigned int texCoordSet = 0);
194 
203  const String& getTextureName(void) const;
204 
210  void setTextureName( const String& name, TextureType ttype = TEX_TYPE_2D);
211 
217  void setTexture( const TexturePtr& texPtr);
218 
265  void setCubicTextureName( const String& name, bool forUVW = false );
266 
311  void setCubicTextureName( const String* const names, bool forUVW = false );
312 
357  void setCubicTexture( const TexturePtr* const texPtrs, bool forUVW = false );
358 
380  void setAnimatedTextureName( const String& name, unsigned int numFrames, Real duration = 0 );
381 
403  void setAnimatedTextureName( const String* const names, unsigned int numFrames, Real duration = 0 );
404 
407  std::pair< size_t, size_t > getTextureDimensions( unsigned int frame = 0 ) const;
408 
416  void setCurrentFrame( unsigned int frameNumber );
417 
422  unsigned int getCurrentFrame(void) const;
423 
429  const String& getFrameTextureName(unsigned int frameNumber) const;
430 
438  void setFrameTextureName(const String& name, unsigned int frameNumber);
439 
445  void addFrameTextureName(const String& name);
453  void deleteFrameTextureName(const size_t frameNumber);
458  unsigned int getNumFrames(void) const;
459 
460 
463  {
465  BT_FRAGMENT = 0,
469  BT_VERTEX = 1
470  };
474  {
476  CONTENT_NAMED = 0,
478  CONTENT_SHADOW = 1,
480  CONTENT_COMPOSITOR = 2
481  };
482 
492  void setBindingType(BindingType bt);
493 
496  BindingType getBindingType(void) const;
497 
503  void setContentType(ContentType ct);
505  ContentType getContentType(void) const;
506 
513  bool isCubic(void) const;
514 
519  bool is3D(void) const;
520 
525  TextureType getTextureType(void) const;
526 
529  void setDesiredFormat(PixelFormat desiredFormat);
530 
533  PixelFormat getDesiredFormat(void) const;
534 
537  void setNumMipmaps(int numMipmaps);
538 
541  int getNumMipmaps(void) const;
542 
545  void setIsAlpha(bool isAlpha);
546 
549  bool getIsAlpha(void) const;
550 
552  void setHardwareGammaEnabled(bool enabled);
554  bool isHardwareGammaEnabled() const;
555 
560  unsigned int getTextureCoordSet(void) const;
561 
569  void setTextureCoordSet(unsigned int set);
570 
586  void setTextureTransform(const Matrix4& xform);
587 
595  const Matrix4& getTextureTransform(void) const;
596 
609  void setTextureScroll(Real u, Real v);
610 
615  void setTextureUScroll(Real value);
616  // Get texture uscroll value
617  Real getTextureUScroll(void) const;
618 
623  void setTextureVScroll(Real value);
624  // Get texture vscroll value
625  Real getTextureVScroll(void) const;
626 
631  void setTextureUScale(Real value);
633  Real getTextureUScale(void) const;
634 
639  void setTextureVScale(Real value);
641  Real getTextureVScale(void) const;
642 
656  void setTextureScale(Real uScale, Real vScale);
657 
667  void setTextureRotate(const Radian& angle);
669  const Radian& getTextureRotate(void) const;
670 
676  const UVWAddressingMode& getTextureAddressingMode(void) const;
677 
687  void setTextureAddressingMode( TextureAddressingMode tam);
688 
695  void setTextureAddressingMode( TextureAddressingMode u,
696  TextureAddressingMode v, TextureAddressingMode w);
697 
704  void setTextureAddressingMode( const UVWAddressingMode& uvw);
705 
713  void setTextureBorderColour(const ColourValue& colour);
714 
720  const ColourValue& getTextureBorderColour(void) const;
721 
786  void setColourOperationEx(
788  LayerBlendSource source1 = LBS_TEXTURE,
789  LayerBlendSource source2 = LBS_CURRENT,
790 
791  const ColourValue& arg1 = ColourValue::White,
792  const ColourValue& arg2 = ColourValue::White,
793 
794  Real manualBlend = 0.0);
795 
814  void setColourOperation( const LayerBlendOperation op);
815 
835  void setColourOpMultipassFallback( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor);
836 
839  const LayerBlendModeEx& getColourBlendMode(void) const;
840 
843  const LayerBlendModeEx& getAlphaBlendMode(void) const;
844 
847  SceneBlendFactor getColourBlendFallbackSrc(void) const;
848 
851  SceneBlendFactor getColourBlendFallbackDest(void) const;
852 
878  void setAlphaOperation(LayerBlendOperationEx op,
879  LayerBlendSource source1 = LBS_TEXTURE,
880  LayerBlendSource source2 = LBS_CURRENT,
881  Real arg1 = 1.0,
882  Real arg2 = 1.0,
883  Real manualBlend = 0.0);
884 
896  void addEffect(TextureEffect& effect);
897 
925  void setEnvironmentMap(bool enable, EnvMapType envMapType = ENV_CURVED);
926 
937  void setScrollAnimation(Real uSpeed, Real vSpeed);
938 
947  void setRotateAnimation(Real speed);
948 
968  void setTransformAnimation( const TextureTransformType ttype,
969  const WaveformType waveType, Real base = 0, Real frequency = 1, Real phase = 0, Real amplitude = 1 );
970 
971 
990  void setProjectiveTexturing(bool enabled, const Frustum* projectionSettings = 0);
991 
994  void removeAllEffects(void);
995 
1001  void removeEffect( const TextureEffectType type );
1002 
1008  bool isBlank(void) const;
1009 
1012  void setBlank(void);
1013 
1016  bool isTextureLoadFailing() const { return mTextureLoadFailed; }
1017 
1020  void retryTextureLoad() { mTextureLoadFailed = false; }
1021 
1023  const EffectMap& getEffects(void) const;
1025  Real getAnimationDuration(void) const;
1026 
1036  void setTextureFiltering(TextureFilterOptions filterType);
1041  void setTextureFiltering(FilterType ftype, FilterOptions opts);
1050  void setTextureFiltering(FilterOptions minFilter, FilterOptions magFilter, FilterOptions mipFilter);
1052  FilterOptions getTextureFiltering(FilterType ftpye) const;
1053 
1059  void setTextureAnisotropy(unsigned int maxAniso);
1061  unsigned int getTextureAnisotropy() const;
1062 
1075  void setTextureMipmapBias(float bias) { mMipmapBias = bias; }
1079  float getTextureMipmapBias(void) const { return mMipmapBias; }
1080 
1088  void setCompositorReference(const String& compositorName, const String& textureName, size_t mrtIndex = 0);
1089 
1091  const String& getReferencedCompositorName() const { return mCompositorRefName; }
1093  const String& getReferencedTextureName() const { return mCompositorRefTexName; }
1095  size_t getReferencedMRTIndex() const { return mCompositorRefMrtIndex; }
1096 
1098  Pass* getParent(void) const { return mParent; }
1099 
1101  void _prepare(void);
1103  void _unprepare(void);
1105  void _load(void);
1107  void _unload(void);
1109  bool hasViewRelativeTextureCoordinateGeneration(void) const;
1110 
1112  bool isLoaded(void) const;
1114  void _notifyNeedsRecompile(void);
1115 
1121  void setName(const String& name);
1123  const String& getName(void) const { return mName; }
1124 
1128  void setTextureNameAlias(const String& name);
1131  const String& getTextureNameAlias(void) const { return mTextureNameAlias;}
1132 
1147  bool applyTextureAliases(const AliasTextureNamePairList& aliasList, const bool apply = true);
1148 
1150  void _notifyParent(Pass* parent);
1151 
1153  const TexturePtr& _getTexturePtr(void) const;
1155  const TexturePtr& _getTexturePtr(size_t frame) const;
1156 
1158  void _setTexturePtr(const TexturePtr& texptr);
1160  void _setTexturePtr(const TexturePtr& texptr, size_t frame);
1161 
1165  Controller<Real>* _getAnimController() const { return mAnimController; }
1166 protected:
1167  // State
1169  unsigned int mCurrentFrame;
1170 
1173  bool mCubic; // is this a series of 6 2D textures to make up a cube?
1174 
1177  int mTextureSrcMipmaps; // Request number of mipmaps
1178 
1182 
1186 
1188  mutable bool mTextureLoadFailed;
1189  bool mIsAlpha;
1190  bool mHwGamma;
1191 
1192  mutable bool mRecalcTexMatrix;
1193  Real mUMod, mVMod;
1194  Real mUScale, mVScale;
1197 
1205  unsigned int mMaxAniso;
1208 
1217 
1218  //-----------------------------------------------------------------------------
1219  // Complex members (those that can't be copied using memcpy) are at the end to
1220  // allow for fast copying of the basic members.
1221  //
1224  String mName; // optional name for the TUS
1225  String mTextureNameAlias; // optional alias for texture frames
1230  //-----------------------------------------------------------------------------
1231 
1232  //-----------------------------------------------------------------------------
1233  // Pointer members (those that can't be copied using memcpy), and MUST
1234  // preserving even if assign from others
1235  //
1238  //-----------------------------------------------------------------------------
1239 
1240 
1243  void recalcTextureMatrix(void) const;
1244 
1247  void createAnimController(void);
1248 
1251  void createEffectController(TextureEffect& effect);
1252 
1254  void ensurePrepared(size_t frame) const;
1256  void ensureLoaded(size_t frame) const;
1257 
1258 
1259  };
1260 
1264 }
1265 
1266 #include "OgreHeaderSuffix.h"
1267 
1268 #endif
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:233
Generate all texture coords based on angle between camera and vertex.
WaveformType
Enumerates the wave types usable with the Ogre engine.
Definition: OgreCommon.h:164
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.
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:93
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.
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.
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.
Specialisation of SharedPtr to allow SharedPtr to be assigned to TexturePtr.
Definition: OgreTexture.h:443
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.
Wrapper class which indicates a given angle value is in Radians.
Definition: OgreMath.h:46
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:68
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:73
_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:103
map< String, String >::type AliasTextureNamePairList
Alias / Texture name pair (first = alias, second = texture name)
Definition: OgreCommon.h:556
Defines the functionality of a 3D API.
Envmap based on vector from camera to vertex position, good for planar geometry.
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.
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:81
float getTextureMipmapBias(void) const
Gets the bias value applied to the mipmap calculation.