BsSamplerState.h 3.5 KB

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