OgreTextureState.h 12 KB

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