CmSamplerState.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. #pragma once
  25. #include "CmPrerequisites.h"
  26. #include "CmCommon.h"
  27. #include "CmMatrix4.h"
  28. #include "CmString.h"
  29. #include "CmPixelUtil.h"
  30. #include "CmTexture.h"
  31. namespace CamelotEngine {
  32. /** \addtogroup Core
  33. * @{
  34. */
  35. /** \addtogroup Materials
  36. * @{
  37. */
  38. /** Class representing the state of a single sampler unit during a Pass of a
  39. Technique, of a Material.
  40. @remarks
  41. Sampler units are pipelines for retrieving texture data for rendering onto
  42. your objects in the world.
  43. */
  44. class CM_EXPORT SamplerState
  45. {
  46. public:
  47. static SamplerState EMPTY;
  48. /** Texture addressing modes - default is TAM_WRAP.
  49. @note
  50. These settings are relevant in both the fixed-function and the
  51. programmable pipeline.
  52. */
  53. enum TextureAddressingMode
  54. {
  55. /// Texture wraps at values over 1.0
  56. TAM_WRAP,
  57. /// Texture mirrors (flips) at joins over 1.0
  58. TAM_MIRROR,
  59. /// Texture clamps at 1.0
  60. TAM_CLAMP,
  61. /// Texture coordinates outside the range [0.0, 1.0] are set to the border colour
  62. TAM_BORDER
  63. };
  64. /** Texture addressing mode for each texture coordinate. */
  65. struct UVWAddressingMode
  66. {
  67. TextureAddressingMode u, v, w;
  68. };
  69. /** Enum identifying the frame indexes for faces of a cube map (not the composite 3D type.
  70. */
  71. enum TextureCubeFace
  72. {
  73. CUBE_FRONT = 0,
  74. CUBE_BACK = 1,
  75. CUBE_LEFT = 2,
  76. CUBE_RIGHT = 3,
  77. CUBE_UP = 4,
  78. CUBE_DOWN = 5
  79. };
  80. /** Default constructor.
  81. */
  82. SamplerState();
  83. SamplerState(const SamplerState& oth );
  84. SamplerState & operator = ( const SamplerState& oth );
  85. /** Default destructor.
  86. */
  87. ~SamplerState();
  88. /** The type of unit to bind the texture settings to. */
  89. enum BindingType
  90. {
  91. /** Regular fragment processing unit - the default. */
  92. BT_FRAGMENT = 0,
  93. /** Vertex processing unit - indicates this unit will be used for
  94. a vertex texture fetch.
  95. */
  96. BT_VERTEX = 1
  97. };
  98. /** Sets the type of unit these texture settings should be bound to.
  99. @remarks
  100. Some render systems, when implementing vertex texture fetch, separate
  101. the binding of textures for use in the vertex program versus those
  102. used in fragment programs. This setting allows you to target the
  103. vertex processing unit with a texture binding, in those cases. For
  104. rendersystems which have a unified binding for the vertex and fragment
  105. units, this setting makes no difference.
  106. */
  107. void setBindingType(BindingType bt);
  108. /** Gets the type of unit these texture settings should be bound to.
  109. */
  110. BindingType getBindingType(void) const;
  111. /// @copydoc Texture::setHardwareGammaEnabled
  112. void setHardwareGammaEnabled(bool enabled);
  113. /// @copydoc Texture::isHardwareGammaEnabled
  114. bool isHardwareGammaEnabled() const;
  115. /** Gets the texture addressing mode for a given coordinate,
  116. i.e. what happens at uv values above 1.0.
  117. @note
  118. The default is TAM_WRAP i.e. the texture repeats over values of 1.0.
  119. */
  120. const UVWAddressingMode& getTextureAddressingMode(void) const;
  121. /** Sets the texture addressing mode, i.e. what happens at uv values above 1.0.
  122. @note
  123. The default is TAM_WRAP i.e. the texture repeats over values of 1.0.
  124. @note This is a shortcut method which sets the addressing mode for all
  125. coordinates at once; you can also call the more specific method
  126. to set the addressing mode per coordinate.
  127. @note
  128. This applies for both the fixed-function and programmable pipelines.
  129. */
  130. void setTextureAddressingMode( TextureAddressingMode tam);
  131. /** Sets the texture addressing mode, i.e. what happens at uv values above 1.0.
  132. @note
  133. The default is TAM_WRAP i.e. the texture repeats over values of 1.0.
  134. @note
  135. This applies for both the fixed-function and programmable pipelines.
  136. */
  137. void setTextureAddressingMode( TextureAddressingMode u,
  138. TextureAddressingMode v, TextureAddressingMode w);
  139. /** Sets the texture addressing mode, i.e. what happens at uv values above 1.0.
  140. @note
  141. The default is TAM_WRAP i.e. the texture repeats over values of 1.0.
  142. @note
  143. This applies for both the fixed-function and programmable pipelines.
  144. */
  145. void setTextureAddressingMode( const UVWAddressingMode& uvw);
  146. /** Set the texture filtering for this unit, using the simplified interface.
  147. @remarks
  148. You also have the option of specifying the minification, magnification
  149. and mip filter individually if you want more control over filtering
  150. options. See the alternative setTextureFiltering methods for details.
  151. @note
  152. This option applies in both the fixed function and the programmable pipeline.
  153. @param filterType The high-level filter type to use.
  154. */
  155. void setTextureFiltering(TextureFilterOptions filterType);
  156. /** Set a single filtering option on this texture unit.
  157. @params ftype The filtering type to set
  158. @params opts The filtering option to set
  159. */
  160. void setTextureFiltering(FilterType ftype, FilterOptions opts);
  161. /** Set a the detailed filtering options on this texture unit.
  162. @params minFilter The filtering to use when reducing the size of the texture.
  163. Can be FO_POINT, FO_LINEAR or FO_ANISOTROPIC
  164. @params magFilter The filtering to use when increasing the size of the texture
  165. Can be FO_POINT, FO_LINEAR or FO_ANISOTROPIC
  166. @params mipFilter The filtering to use between mip levels
  167. Can be FO_NONE (turns off mipmapping), FO_POINT or FO_LINEAR (trilinear filtering)
  168. */
  169. void setTextureFiltering(FilterOptions minFilter, FilterOptions magFilter, FilterOptions mipFilter);
  170. // get the texture filtering for the given type
  171. FilterOptions getTextureFiltering(FilterType ftpye) const;
  172. /** Sets the anisotropy level to be used for this texture level.
  173. @par maxAniso The maximal anisotropy level, should be between 2 and the maximum supported by hardware (1 is the default, ie. no anisotrophy).
  174. @note
  175. This option applies in both the fixed function and the programmable pipeline.
  176. */
  177. void setTextureAnisotropy(unsigned int maxAniso);
  178. // get this layer texture anisotropy level
  179. unsigned int getTextureAnisotropy() const;
  180. /** Sets the bias value applied to the mipmap calculation.
  181. @remarks
  182. You can alter the mipmap calculation by biasing the result with a
  183. single floating point value. After the mip level has been calculated,
  184. this bias value is added to the result to give the final mip level.
  185. Lower mip levels are larger (higher detail), so a negative bias will
  186. force the larger mip levels to be used, and a positive bias
  187. will cause smaller mip levels to be used. The bias values are in
  188. mip levels, so a -1 bias will force mip levels one larger than by the
  189. default calculation.
  190. @param bias The bias value as described above, can be positive or negative.
  191. */
  192. void setTextureMipmapBias(float bias) { mMipmapBias = bias; }
  193. /** Gets the bias value applied to the mipmap calculation.
  194. @see TextureUnitState::setTextureMipmapBias
  195. */
  196. float getTextureMipmapBias(void) const { return mMipmapBias; }
  197. protected:
  198. UVWAddressingMode mAddressMode;
  199. bool mHwGamma;
  200. /// Texture filtering - minification
  201. FilterOptions mMinFilter;
  202. /// Texture filtering - magnification
  203. FilterOptions mMagFilter;
  204. /// Texture filtering - mipmapping
  205. FilterOptions mMipFilter;
  206. ///Texture anisotropy
  207. unsigned int mMaxAniso;
  208. /// Mipmap bias (always float, not float)
  209. float mMipmapBias;
  210. /// Binding type (fragment or vertex pipeline)
  211. BindingType mBindingType;
  212. };
  213. /** @} */
  214. /** @} */
  215. }