BsSamplerState.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. protected:
  98. friend class RenderStateCoreManager;
  99. SamplerStateCore(const SAMPLER_STATE_DESC& desc);
  100. SamplerProperties mProperties;
  101. };
  102. /**
  103. * @brief Class representing the state of a texture sampler.
  104. *
  105. * @note Sampler units are used for retrieving and filtering data from
  106. * textures set in a GPU program. Sampler states are immutable.
  107. *
  108. * Sim thread.
  109. */
  110. class BS_CORE_EXPORT SamplerState : public Resource
  111. {
  112. public:
  113. virtual ~SamplerState() {}
  114. /**
  115. * @brief Returns information about the sampler state.
  116. */
  117. const SamplerProperties& getProperties() const;
  118. /**
  119. * @brief Retrieves a core implementation of the sampler state usable only from the
  120. * core thread.
  121. */
  122. SPtr<SamplerStateCore> getCore() const;
  123. /**
  124. * @brief Creates a new sampler state using the provided descriptor structure.
  125. */
  126. static HSamplerState create(const SAMPLER_STATE_DESC& desc);
  127. /**
  128. * @brief Returns the default sampler state.
  129. */
  130. static const SamplerStatePtr& getDefault();
  131. protected:
  132. SamplerState(const SAMPLER_STATE_DESC& desc);
  133. /**
  134. * @copydoc CoreObjectCore::createCore
  135. */
  136. SPtr<CoreObjectCore> createCore() const;
  137. SamplerProperties mProperties;
  138. friend class RenderStateManager;
  139. /************************************************************************/
  140. /* RTTI */
  141. /************************************************************************/
  142. public:
  143. friend class SamplerStateRTTI;
  144. static RTTITypeBase* getRTTIStatic();
  145. virtual RTTITypeBase* getRTTI() const;
  146. };
  147. }