CmTextureState.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. Copyright (c) 2000-2011 Torus Knot Software Ltd
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. -----------------------------------------------------------------------------
  23. */
  24. #ifndef __TextureState_H__
  25. #define __TextureState_H__
  26. #include "CmPrerequisites.h"
  27. #include "CmCommon.h"
  28. #include "CmMatrix4.h"
  29. #include "CmString.h"
  30. #include "CmPixelUtil.h"
  31. #include "CmTexture.h"
  32. namespace CamelotEngine {
  33. /** \addtogroup Core
  34. * @{
  35. */
  36. /** \addtogroup Materials
  37. * @{
  38. */
  39. /** Class representing the state of a single texture unit during a Pass of a
  40. Technique, of a Material.
  41. @remarks
  42. Texture units are pipelines for retrieving texture data for rendering onto
  43. your objects in the world. Using them is common to both the fixed-function and
  44. the programmable (vertex and fragment program) pipeline, but some of the
  45. settings will only have an effect in the fixed-function pipeline (for example,
  46. setting a texture rotation will have no effect if you use the programmable
  47. pipeline, because this is overridden by the fragment program). The effect
  48. of each setting as regards the 2 pipelines is commented in each setting.
  49. @par
  50. When I use the term 'fixed-function pipeline' I mean traditional rendering
  51. where you do not use vertex or fragment programs (shaders). Programmable
  52. pipeline means that for this pass you are using vertex or fragment programs.
  53. */
  54. class CM_EXPORT TextureState
  55. {
  56. public:
  57. /** Texture addressing modes - default is TAM_WRAP.
  58. @note
  59. These settings are relevant in both the fixed-function and the
  60. programmable pipeline.
  61. */
  62. enum TextureAddressingMode
  63. {
  64. /// Texture wraps at values over 1.0
  65. TAM_WRAP,
  66. /// Texture mirrors (flips) at joins over 1.0
  67. TAM_MIRROR,
  68. /// Texture clamps at 1.0
  69. TAM_CLAMP,
  70. /// Texture coordinates outside the range [0.0, 1.0] are set to the border colour
  71. TAM_BORDER
  72. };
  73. /** Texture addressing mode for each texture coordinate. */
  74. struct UVWAddressingMode
  75. {
  76. TextureAddressingMode u, v, w;
  77. };
  78. /** Enum identifying the frame indexes for faces of a cube map (not the composite 3D type.
  79. */
  80. enum TextureCubeFace
  81. {
  82. CUBE_FRONT = 0,
  83. CUBE_BACK = 1,
  84. CUBE_LEFT = 2,
  85. CUBE_RIGHT = 3,
  86. CUBE_UP = 4,
  87. CUBE_DOWN = 5
  88. };
  89. /** Default constructor.
  90. */
  91. TextureState(TextureType type);
  92. TextureState(const TextureState& oth );
  93. TextureState & operator = ( const TextureState& oth );
  94. /** Default destructor.
  95. */
  96. ~TextureState();
  97. /** The type of unit to bind the texture settings to. */
  98. enum BindingType
  99. {
  100. /** Regular fragment processing unit - the default. */
  101. BT_FRAGMENT = 0,
  102. /** Vertex processing unit - indicates this unit will be used for
  103. a vertex texture fetch.
  104. */
  105. BT_VERTEX = 1
  106. };
  107. /** Sets the type of unit these texture settings should be bound to.
  108. @remarks
  109. Some render systems, when implementing vertex texture fetch, separate
  110. the binding of textures for use in the vertex program versus those
  111. used in fragment programs. This setting allows you to target the
  112. vertex processing unit with a texture binding, in those cases. For
  113. rendersystems which have a unified binding for the vertex and fragment
  114. units, this setting makes no difference.
  115. */
  116. void setBindingType(BindingType bt);
  117. /** Gets the type of unit these texture settings should be bound to.
  118. */
  119. BindingType getBindingType(void) const;
  120. /** Returns true if this texture unit is either a series of 6 2D textures, each
  121. in it's own frame, or is a full 3D cube map. You can tell which by checking
  122. getTextureType.
  123. @note
  124. Applies to both fixed-function and programmable pipeline.
  125. */
  126. bool isCubic(void) const;
  127. /** Returns true if this texture layer uses a composite 3D cubic texture.
  128. @note
  129. Applies to both fixed-function and programmable pipeline.
  130. */
  131. bool is3D(void) const;
  132. /** Returns the type of this texture.
  133. @note
  134. Applies to both fixed-function and programmable pipeline.
  135. */
  136. TextureType getTextureType(void) const;
  137. /** Sets the desired pixel format when load the texture.
  138. */
  139. void setDesiredFormat(PixelFormat desiredFormat);
  140. /** Gets the desired pixel format when load the texture.
  141. */
  142. PixelFormat getDesiredFormat(void) const;
  143. /** Sets how many mipmaps have been requested for the texture.
  144. */
  145. void setNumMipmaps(int numMipmaps);
  146. /** Gets how many mipmaps have been requested for the texture.
  147. */
  148. int getNumMipmaps(void) const;
  149. /** Sets whether this texture is requested to be loaded as alpha if single channel
  150. */
  151. void setIsAlpha(bool isAlpha);
  152. /** Gets whether this texture is requested to be loaded as alpha if single channel
  153. */
  154. bool getIsAlpha(void) const;
  155. /// @copydoc Texture::setHardwareGammaEnabled
  156. void setHardwareGammaEnabled(bool enabled);
  157. /// @copydoc Texture::isHardwareGammaEnabled
  158. bool isHardwareGammaEnabled() const;
  159. /** Gets the texture addressing mode for a given coordinate,
  160. i.e. what happens at uv values above 1.0.
  161. @note
  162. The default is TAM_WRAP i.e. the texture repeats over values of 1.0.
  163. */
  164. const UVWAddressingMode& getTextureAddressingMode(void) const;
  165. /** Sets the texture addressing mode, i.e. what happens at uv values above 1.0.
  166. @note
  167. The default is TAM_WRAP i.e. the texture repeats over values of 1.0.
  168. @note This is a shortcut method which sets the addressing mode for all
  169. coordinates at once; you can also call the more specific method
  170. to set the addressing mode per coordinate.
  171. @note
  172. This applies for both the fixed-function and programmable pipelines.
  173. */
  174. void setTextureAddressingMode( TextureAddressingMode tam);
  175. /** Sets the texture addressing mode, i.e. what happens at uv values above 1.0.
  176. @note
  177. The default is TAM_WRAP i.e. the texture repeats over values of 1.0.
  178. @note
  179. This applies for both the fixed-function and programmable pipelines.
  180. */
  181. void setTextureAddressingMode( TextureAddressingMode u,
  182. TextureAddressingMode v, TextureAddressingMode w);
  183. /** Sets the texture addressing mode, i.e. what happens at uv values above 1.0.
  184. @note
  185. The default is TAM_WRAP i.e. the texture repeats over values of 1.0.
  186. @note
  187. This applies for both the fixed-function and programmable pipelines.
  188. */
  189. void setTextureAddressingMode( const UVWAddressingMode& uvw);
  190. /** Set the texture filtering for this unit, using the simplified interface.
  191. @remarks
  192. You also have the option of specifying the minification, magnification
  193. and mip filter individually if you want more control over filtering
  194. options. See the alternative setTextureFiltering methods for details.
  195. @note
  196. This option applies in both the fixed function and the programmable pipeline.
  197. @param filterType The high-level filter type to use.
  198. */
  199. void setTextureFiltering(TextureFilterOptions filterType);
  200. /** Set a single filtering option on this texture unit.
  201. @params ftype The filtering type to set
  202. @params opts The filtering option to set
  203. */
  204. void setTextureFiltering(FilterType ftype, FilterOptions opts);
  205. /** Set a the detailed filtering options on this texture unit.
  206. @params minFilter The filtering to use when reducing the size of the texture.
  207. Can be FO_POINT, FO_LINEAR or FO_ANISOTROPIC
  208. @params magFilter The filtering to use when increasing the size of the texture
  209. Can be FO_POINT, FO_LINEAR or FO_ANISOTROPIC
  210. @params mipFilter The filtering to use between mip levels
  211. Can be FO_NONE (turns off mipmapping), FO_POINT or FO_LINEAR (trilinear filtering)
  212. */
  213. void setTextureFiltering(FilterOptions minFilter, FilterOptions magFilter, FilterOptions mipFilter);
  214. // get the texture filtering for the given type
  215. FilterOptions getTextureFiltering(FilterType ftpye) const;
  216. /** Sets the anisotropy level to be used for this texture level.
  217. @par maxAniso The maximal anisotropy level, should be between 2 and the maximum supported by hardware (1 is the default, ie. no anisotrophy).
  218. @note
  219. This option applies in both the fixed function and the programmable pipeline.
  220. */
  221. void setTextureAnisotropy(unsigned int maxAniso);
  222. // get this layer texture anisotropy level
  223. unsigned int getTextureAnisotropy() const;
  224. /** Sets the bias value applied to the mipmap calculation.
  225. @remarks
  226. You can alter the mipmap calculation by biasing the result with a
  227. single floating point value. After the mip level has been calculated,
  228. this bias value is added to the result to give the final mip level.
  229. Lower mip levels are larger (higher detail), so a negative bias will
  230. force the larger mip levels to be used, and a positive bias
  231. will cause smaller mip levels to be used. The bias values are in
  232. mip levels, so a -1 bias will force mip levels one larger than by the
  233. default calculation.
  234. @param bias The bias value as described above, can be positive or negative.
  235. */
  236. void setTextureMipmapBias(float bias) { mMipmapBias = bias; }
  237. /** Gets the bias value applied to the mipmap calculation.
  238. @see TextureUnitState::setTextureMipmapBias
  239. */
  240. float getTextureMipmapBias(void) const { return mMipmapBias; }
  241. protected:
  242. // State
  243. TextureType mTextureType;
  244. PixelFormat mDesiredFormat;
  245. int mTextureSrcMipmaps; // Request number of mipmaps
  246. UVWAddressingMode mAddressMode;
  247. bool mIsAlpha;
  248. bool mHwGamma;
  249. /// Texture filtering - minification
  250. FilterOptions mMinFilter;
  251. /// Texture filtering - magnification
  252. FilterOptions mMagFilter;
  253. /// Texture filtering - mipmapping
  254. FilterOptions mMipFilter;
  255. ///Texture anisotropy
  256. unsigned int mMaxAniso;
  257. /// Mipmap bias (always float, not float)
  258. float mMipmapBias;
  259. bool mIsDefaultAniso;
  260. bool mIsDefaultFiltering;
  261. /// Binding type (fragment or vertex pipeline)
  262. BindingType mBindingType;
  263. };
  264. /** @} */
  265. /** @} */
  266. }
  267. #endif