BsSamplerState.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsMatrix4.h"
  4. #include "BsPixelUtil.h"
  5. #include "BsTexture.h"
  6. #include "BsColor.h"
  7. #include "BsResource.h"
  8. namespace BansheeEngine
  9. {
  10. /**
  11. * @brief Structure used for initializing a SamplerState.
  12. *
  13. * @see SamplerState
  14. */
  15. struct BS_CORE_EXPORT SAMPLER_STATE_DESC
  16. {
  17. SAMPLER_STATE_DESC()
  18. : minFilter(FO_LINEAR), magFilter(FO_LINEAR), mipFilter(FO_POINT),
  19. maxAniso(0), mipmapBias(0), comparisonFunc(CMPF_ALWAYS_FAIL), mipMin(-FLT_MAX),
  20. mipMax(FLT_MAX), borderColor(Color::White)
  21. { }
  22. UVWAddressingMode addressMode;
  23. FilterOptions minFilter;
  24. FilterOptions magFilter;
  25. FilterOptions mipFilter;
  26. UINT32 maxAniso;
  27. float mipmapBias;
  28. float mipMin;
  29. float mipMax;
  30. Color borderColor;
  31. CompareFunction comparisonFunc;
  32. };
  33. /**
  34. * @brief Information about a sampler state.
  35. */
  36. class BS_CORE_EXPORT SamplerProperties
  37. {
  38. public:
  39. SamplerProperties(const SAMPLER_STATE_DESC& desc);
  40. /**
  41. * @brief Returns texture addressing mode for each possible texture coordinate. Addressing
  42. * modes determine how are texture coordinates outside of [0, 1] range handled.
  43. */
  44. const UVWAddressingMode& getTextureAddressingMode() const { return mData.addressMode; }
  45. /**
  46. * @brief Gets the filtering used when sampling from a texture.
  47. */
  48. FilterOptions getTextureFiltering(FilterType ftpye) const;
  49. /**
  50. * @brief Gets the anisotropy level. Higher anisotropy means better filtering
  51. * for textures displayed on an angled slope relative to the viewer.
  52. */
  53. unsigned int getTextureAnisotropy() const { return mData.maxAniso; }
  54. /**
  55. * @brief Gets a function that compares sampled data with existing sampled data.
  56. */
  57. CompareFunction getComparisonFunction() const { return mData.comparisonFunc; }
  58. /**
  59. * @brief Mipmap bias allows you to adjust the mipmap selection calculation. Negative values
  60. * force a larger mipmap to be used, and positive values smaller. Units are in values
  61. * of mip levels, so -1 means use a mipmap one level higher than default.
  62. */
  63. float getTextureMipmapBias() const { return mData.mipmapBias; }
  64. /**
  65. * @brief Returns the minimum mip map level.
  66. */
  67. float getMinimumMip() const { return mData.mipMin; }
  68. /**
  69. * @brief Returns the maximum mip map level.
  70. */
  71. float getMaximumMip() const { return mData.mipMax; }
  72. /**
  73. * @brief Gets the border color that will be used when border texture addressing is used
  74. * and texture address is outside of the valid range.
  75. */
  76. const Color& getBorderColor() const;
  77. protected:
  78. friend class SamplerState;
  79. friend class SamplerStateRTTI;
  80. SAMPLER_STATE_DESC mData;
  81. };
  82. /**
  83. * @brief Core thread version of a sampler state.
  84. *
  85. * @see SamplerState
  86. *
  87. * @note Core thread.
  88. */
  89. class BS_CORE_EXPORT SamplerStateCore : public CoreObjectCore
  90. {
  91. public:
  92. virtual ~SamplerStateCore() {}
  93. /**
  94. * @brief Returns information about the sampler state.
  95. */
  96. const SamplerProperties& getProperties() const;
  97. /**
  98. * @brief Returns the default sampler state.
  99. */
  100. static const SPtr<SamplerStateCore>& getDefault();
  101. protected:
  102. friend class RenderStateCoreManager;
  103. SamplerStateCore(const SAMPLER_STATE_DESC& desc);
  104. SamplerProperties mProperties;
  105. };
  106. /**
  107. * @brief Class representing the state of a texture sampler.
  108. *
  109. * @note Sampler units are used for retrieving and filtering data from
  110. * textures set in a GPU program. Sampler states are immutable.
  111. *
  112. * Sim thread.
  113. */
  114. class BS_CORE_EXPORT SamplerState : public Resource
  115. {
  116. public:
  117. virtual ~SamplerState() {}
  118. /**
  119. * @brief Returns information about the sampler state.
  120. */
  121. const SamplerProperties& getProperties() const;
  122. /**
  123. * @brief Retrieves a core implementation of the sampler state usable only from the
  124. * core thread.
  125. */
  126. SPtr<SamplerStateCore> getCore() const;
  127. /**
  128. * @brief Creates a new sampler state using the provided descriptor structure.
  129. */
  130. static HSamplerState create(const SAMPLER_STATE_DESC& desc);
  131. /**
  132. * @brief Returns the default sampler state.
  133. */
  134. static const SamplerStatePtr& getDefault();
  135. protected:
  136. SamplerState(const SAMPLER_STATE_DESC& desc);
  137. /**
  138. * @copydoc CoreObjectCore::createCore
  139. */
  140. SPtr<CoreObjectCore> createCore() const;
  141. SamplerProperties mProperties;
  142. friend class RenderStateManager;
  143. /************************************************************************/
  144. /* RTTI */
  145. /************************************************************************/
  146. public:
  147. friend class SamplerStateRTTI;
  148. static RTTITypeBase* getRTTIStatic();
  149. virtual RTTITypeBase* getRTTI() const;
  150. };
  151. }