BsSamplerState.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsMatrix4.h"
  4. #include "BsString.h"
  5. #include "BsPixelUtil.h"
  6. #include "BsTexture.h"
  7. #include "BsColor.h"
  8. #include "BsResource.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 Class representing the state of a texture sampler.
  36. *
  37. * @note Sampler units are used for retrieving and filtering data from
  38. * textures set in a GPU program.
  39. * Sampler states are immutable. Thread safe.
  40. */
  41. class BS_CORE_EXPORT SamplerState : public Resource
  42. {
  43. public:
  44. virtual ~SamplerState() {}
  45. /**
  46. * @brief Returns texture addressing mode for each possible texture coordinate. Addressing
  47. * modes determine how are texture coordinates outside of [0, 1] range handled.
  48. */
  49. const UVWAddressingMode& getTextureAddressingMode() const { return mData.addressMode; }
  50. /**
  51. * @brief Gets the filtering used when sampling from a texture.
  52. */
  53. FilterOptions getTextureFiltering(FilterType ftpye) const;
  54. /**
  55. * @brief Gets the anisotropy level. Higher anisotropy means better filtering
  56. * for textures displayed on an angled slope relative to the viewer.
  57. */
  58. unsigned int getTextureAnisotropy() const { return mData.maxAniso; }
  59. /**
  60. * @brief Gets a function that compares sampled data with existing sampled data.
  61. */
  62. CompareFunction getComparisonFunction() const { return mData.comparisonFunc; }
  63. /**
  64. * @brief Mipmap bias allows you to adjust the mipmap selection calculation. Negative values
  65. * force a larger mipmap to be used, and positive values smaller. Units are in values
  66. * of mip levels, so -1 means use a mipmap one level higher than default.
  67. */
  68. float getTextureMipmapBias() const { return mData.mipmapBias; }
  69. /**
  70. * @brief Returns the minimum mip map level.
  71. */
  72. float getMinimumMip() const { return mData.mipMin; }
  73. /**
  74. * @brief Returns the maximum mip map level.
  75. */
  76. float getMaximumMip() const { return mData.mipMax; }
  77. /**
  78. * @brief Gets the border color that will be used when border texture addressing is used
  79. * and texture address is outside of the valid range.
  80. */
  81. const Color& getBorderColor() const;
  82. /**
  83. * @brief Creates a new sampler state using the provided descriptor structure.
  84. */
  85. static HSamplerState create(const SAMPLER_STATE_DESC& desc);
  86. /**
  87. * @brief Returns the default sampler state.
  88. */
  89. static const SamplerStatePtr& getDefault();
  90. protected:
  91. friend class RenderStateManager;
  92. /**
  93. * @brief Initializes the sampler state. Must be called right after construction.
  94. */
  95. virtual void initialize(const SAMPLER_STATE_DESC& desc);
  96. SAMPLER_STATE_DESC mData;
  97. /************************************************************************/
  98. /* RTTI */
  99. /************************************************************************/
  100. public:
  101. friend class SamplerStateRTTI;
  102. static RTTITypeBase* getRTTIStatic();
  103. virtual RTTITypeBase* getRTTI() const;
  104. };
  105. }