CmSamplerState.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 "CmSamplerState.h"
  25. #include "CmException.h"
  26. namespace CamelotEngine {
  27. SamplerState SamplerState::EMPTY;
  28. //-----------------------------------------------------------------------
  29. SamplerState::SamplerState()
  30. : mHwGamma(false)
  31. , mMinFilter(FO_LINEAR)
  32. , mMagFilter(FO_LINEAR)
  33. , mMipFilter(FO_POINT)
  34. , mMaxAniso(0)
  35. , mMipmapBias(0)
  36. , mBindingType(BT_FRAGMENT)
  37. {
  38. setTextureAddressingMode(TAM_WRAP);
  39. }
  40. //-----------------------------------------------------------------------
  41. SamplerState::SamplerState(const SamplerState& oth )
  42. {
  43. *this = oth;
  44. }
  45. //-----------------------------------------------------------------------
  46. SamplerState::~SamplerState()
  47. {
  48. }
  49. //-----------------------------------------------------------------------
  50. SamplerState & SamplerState::operator = (
  51. const SamplerState &oth )
  52. {
  53. return *this;
  54. }
  55. //-----------------------------------------------------------------------
  56. void SamplerState::setBindingType(SamplerState::BindingType bt)
  57. {
  58. mBindingType = bt;
  59. }
  60. //-----------------------------------------------------------------------
  61. SamplerState::BindingType SamplerState::getBindingType(void) const
  62. {
  63. return mBindingType;
  64. }
  65. //-----------------------------------------------------------------------
  66. void SamplerState::setHardwareGammaEnabled(bool g)
  67. {
  68. mHwGamma = g;
  69. }
  70. //-----------------------------------------------------------------------
  71. bool SamplerState::isHardwareGammaEnabled() const
  72. {
  73. return mHwGamma;
  74. }
  75. //-----------------------------------------------------------------------
  76. const SamplerState::UVWAddressingMode&
  77. SamplerState::getTextureAddressingMode(void) const
  78. {
  79. return mAddressMode;
  80. }
  81. //-----------------------------------------------------------------------
  82. void SamplerState::setTextureAddressingMode(
  83. SamplerState::TextureAddressingMode tam)
  84. {
  85. mAddressMode.u = tam;
  86. mAddressMode.v = tam;
  87. mAddressMode.w = tam;
  88. }
  89. //-----------------------------------------------------------------------
  90. void SamplerState::setTextureAddressingMode(
  91. SamplerState::TextureAddressingMode u,
  92. SamplerState::TextureAddressingMode v,
  93. SamplerState::TextureAddressingMode w)
  94. {
  95. mAddressMode.u = u;
  96. mAddressMode.v = v;
  97. mAddressMode.w = w;
  98. }
  99. //-----------------------------------------------------------------------
  100. void SamplerState::setTextureAddressingMode(
  101. const SamplerState::UVWAddressingMode& uvw)
  102. {
  103. mAddressMode = uvw;
  104. }
  105. //-----------------------------------------------------------------------
  106. void SamplerState::setTextureFiltering(TextureFilterOptions filterType)
  107. {
  108. switch (filterType)
  109. {
  110. case TFO_NONE:
  111. setTextureFiltering(FO_POINT, FO_POINT, FO_NONE);
  112. break;
  113. case TFO_BILINEAR:
  114. setTextureFiltering(FO_LINEAR, FO_LINEAR, FO_POINT);
  115. break;
  116. case TFO_TRILINEAR:
  117. setTextureFiltering(FO_LINEAR, FO_LINEAR, FO_LINEAR);
  118. break;
  119. case TFO_ANISOTROPIC:
  120. setTextureFiltering(FO_ANISOTROPIC, FO_ANISOTROPIC, FO_LINEAR);
  121. break;
  122. }
  123. }
  124. //-----------------------------------------------------------------------
  125. void SamplerState::setTextureFiltering(FilterType ft, FilterOptions fo)
  126. {
  127. switch (ft)
  128. {
  129. case FT_MIN:
  130. mMinFilter = fo;
  131. break;
  132. case FT_MAG:
  133. mMagFilter = fo;
  134. break;
  135. case FT_MIP:
  136. mMipFilter = fo;
  137. break;
  138. }
  139. }
  140. //-----------------------------------------------------------------------
  141. void SamplerState::setTextureFiltering(FilterOptions minFilter,
  142. FilterOptions magFilter, FilterOptions mipFilter)
  143. {
  144. mMinFilter = minFilter;
  145. mMagFilter = magFilter;
  146. mMipFilter = mipFilter;
  147. }
  148. //-----------------------------------------------------------------------
  149. FilterOptions SamplerState::getTextureFiltering(FilterType ft) const
  150. {
  151. switch (ft)
  152. {
  153. case FT_MIN:
  154. return mMinFilter;
  155. case FT_MAG:
  156. return mMagFilter;
  157. case FT_MIP:
  158. return mMipFilter;
  159. }
  160. // to keep compiler happy
  161. return mMinFilter;
  162. }
  163. //-----------------------------------------------------------------------
  164. void SamplerState::setTextureAnisotropy(unsigned int maxAniso)
  165. {
  166. mMaxAniso = maxAniso;
  167. }
  168. //-----------------------------------------------------------------------
  169. unsigned int SamplerState::getTextureAnisotropy() const
  170. {
  171. return mMaxAniso;
  172. }
  173. }