BsSamplerState.h 4.7 KB

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