OgreTextureUnitState.cpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. #include "OgreTextureUnitState.h"
  25. #include "OgreException.h"
  26. namespace Ogre {
  27. //-----------------------------------------------------------------------
  28. TextureUnitState::TextureUnitState(TextureType type)
  29. : mTextureType(type)
  30. , mDesiredFormat(PF_UNKNOWN)
  31. , mTextureSrcMipmaps(MIP_DEFAULT)
  32. , mIsAlpha(false)
  33. , mHwGamma(false)
  34. , mMinFilter(FO_LINEAR)
  35. , mMagFilter(FO_LINEAR)
  36. , mMipFilter(FO_POINT)
  37. , mMaxAniso(0)
  38. , mMipmapBias(0)
  39. , mIsDefaultAniso(true)
  40. , mIsDefaultFiltering(true)
  41. , mBindingType(BT_FRAGMENT)
  42. {
  43. setTextureAddressingMode(TAM_WRAP);
  44. }
  45. //-----------------------------------------------------------------------
  46. TextureUnitState::TextureUnitState(const TextureUnitState& oth )
  47. {
  48. *this = oth;
  49. }
  50. //-----------------------------------------------------------------------
  51. TextureUnitState::~TextureUnitState()
  52. {
  53. }
  54. //-----------------------------------------------------------------------
  55. TextureUnitState & TextureUnitState::operator = (
  56. const TextureUnitState &oth )
  57. {
  58. return *this;
  59. }
  60. //-----------------------------------------------------------------------
  61. void TextureUnitState::setBindingType(TextureUnitState::BindingType bt)
  62. {
  63. mBindingType = bt;
  64. }
  65. //-----------------------------------------------------------------------
  66. TextureUnitState::BindingType TextureUnitState::getBindingType(void) const
  67. {
  68. return mBindingType;
  69. }
  70. //-----------------------------------------------------------------------
  71. bool TextureUnitState::isCubic(void) const
  72. {
  73. return mTextureType == TEX_TYPE_CUBE_MAP;
  74. }
  75. //-----------------------------------------------------------------------
  76. bool TextureUnitState::is3D(void) const
  77. {
  78. return mTextureType == TEX_TYPE_3D;
  79. }
  80. //-----------------------------------------------------------------------
  81. TextureType TextureUnitState::getTextureType(void) const
  82. {
  83. return mTextureType;
  84. }
  85. //-----------------------------------------------------------------------
  86. void TextureUnitState::setDesiredFormat(PixelFormat desiredFormat)
  87. {
  88. mDesiredFormat = desiredFormat;
  89. }
  90. //-----------------------------------------------------------------------
  91. PixelFormat TextureUnitState::getDesiredFormat(void) const
  92. {
  93. return mDesiredFormat;
  94. }
  95. //-----------------------------------------------------------------------
  96. void TextureUnitState::setNumMipmaps(int numMipmaps)
  97. {
  98. mTextureSrcMipmaps = numMipmaps;
  99. }
  100. //-----------------------------------------------------------------------
  101. int TextureUnitState::getNumMipmaps(void) const
  102. {
  103. return mTextureSrcMipmaps;
  104. }
  105. //-----------------------------------------------------------------------
  106. void TextureUnitState::setIsAlpha(bool isAlpha)
  107. {
  108. mIsAlpha = isAlpha;
  109. }
  110. //-----------------------------------------------------------------------
  111. bool TextureUnitState::getIsAlpha(void) const
  112. {
  113. return mIsAlpha;
  114. }
  115. //-----------------------------------------------------------------------
  116. void TextureUnitState::setHardwareGammaEnabled(bool g)
  117. {
  118. mHwGamma = g;
  119. }
  120. //-----------------------------------------------------------------------
  121. bool TextureUnitState::isHardwareGammaEnabled() const
  122. {
  123. return mHwGamma;
  124. }
  125. //-----------------------------------------------------------------------
  126. const TextureUnitState::UVWAddressingMode&
  127. TextureUnitState::getTextureAddressingMode(void) const
  128. {
  129. return mAddressMode;
  130. }
  131. //-----------------------------------------------------------------------
  132. void TextureUnitState::setTextureAddressingMode(
  133. TextureUnitState::TextureAddressingMode tam)
  134. {
  135. mAddressMode.u = tam;
  136. mAddressMode.v = tam;
  137. mAddressMode.w = tam;
  138. }
  139. //-----------------------------------------------------------------------
  140. void TextureUnitState::setTextureAddressingMode(
  141. TextureUnitState::TextureAddressingMode u,
  142. TextureUnitState::TextureAddressingMode v,
  143. TextureUnitState::TextureAddressingMode w)
  144. {
  145. mAddressMode.u = u;
  146. mAddressMode.v = v;
  147. mAddressMode.w = w;
  148. }
  149. //-----------------------------------------------------------------------
  150. void TextureUnitState::setTextureAddressingMode(
  151. const TextureUnitState::UVWAddressingMode& uvw)
  152. {
  153. mAddressMode = uvw;
  154. }
  155. //-----------------------------------------------------------------------
  156. void TextureUnitState::setTextureFiltering(TextureFilterOptions filterType)
  157. {
  158. switch (filterType)
  159. {
  160. case TFO_NONE:
  161. setTextureFiltering(FO_POINT, FO_POINT, FO_NONE);
  162. break;
  163. case TFO_BILINEAR:
  164. setTextureFiltering(FO_LINEAR, FO_LINEAR, FO_POINT);
  165. break;
  166. case TFO_TRILINEAR:
  167. setTextureFiltering(FO_LINEAR, FO_LINEAR, FO_LINEAR);
  168. break;
  169. case TFO_ANISOTROPIC:
  170. setTextureFiltering(FO_ANISOTROPIC, FO_ANISOTROPIC, FO_LINEAR);
  171. break;
  172. }
  173. mIsDefaultFiltering = false;
  174. }
  175. //-----------------------------------------------------------------------
  176. void TextureUnitState::setTextureFiltering(FilterType ft, FilterOptions fo)
  177. {
  178. switch (ft)
  179. {
  180. case FT_MIN:
  181. mMinFilter = fo;
  182. break;
  183. case FT_MAG:
  184. mMagFilter = fo;
  185. break;
  186. case FT_MIP:
  187. mMipFilter = fo;
  188. break;
  189. }
  190. mIsDefaultFiltering = false;
  191. }
  192. //-----------------------------------------------------------------------
  193. void TextureUnitState::setTextureFiltering(FilterOptions minFilter,
  194. FilterOptions magFilter, FilterOptions mipFilter)
  195. {
  196. mMinFilter = minFilter;
  197. mMagFilter = magFilter;
  198. mMipFilter = mipFilter;
  199. mIsDefaultFiltering = false;
  200. }
  201. //-----------------------------------------------------------------------
  202. FilterOptions TextureUnitState::getTextureFiltering(FilterType ft) const
  203. {
  204. switch (ft)
  205. {
  206. case FT_MIN:
  207. return mMinFilter;
  208. case FT_MAG:
  209. return mMagFilter;
  210. case FT_MIP:
  211. return mMipFilter;
  212. }
  213. // to keep compiler happy
  214. return mMinFilter;
  215. }
  216. //-----------------------------------------------------------------------
  217. void TextureUnitState::setTextureAnisotropy(unsigned int maxAniso)
  218. {
  219. mMaxAniso = maxAniso;
  220. mIsDefaultAniso = false;
  221. }
  222. //-----------------------------------------------------------------------
  223. unsigned int TextureUnitState::getTextureAnisotropy() const
  224. {
  225. return mMaxAniso;
  226. }
  227. }