CmSamplerState.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmCommonEnums.h"
  4. #include "CmMatrix4.h"
  5. #include "CmString.h"
  6. #include "CmPixelUtil.h"
  7. #include "CmTexture.h"
  8. #include "CmColor.h"
  9. #include "CmResource.h"
  10. namespace BansheeEngine
  11. {
  12. /**
  13. * @brief Structure used for initializing a SamplerState.
  14. *
  15. * @see SamplerState
  16. */
  17. struct CM_EXPORT SAMPLER_STATE_DESC
  18. {
  19. SAMPLER_STATE_DESC()
  20. : minFilter(FO_LINEAR), magFilter(FO_LINEAR), mipFilter(FO_POINT),
  21. maxAniso(0), mipmapBias(0), comparisonFunc(CMPF_ALWAYS_FAIL), mipMin(-FLT_MAX),
  22. mipMax(FLT_MAX), borderColor(Color::White)
  23. { }
  24. UVWAddressingMode addressMode;
  25. FilterOptions minFilter;
  26. FilterOptions magFilter;
  27. FilterOptions mipFilter;
  28. UINT32 maxAniso;
  29. float mipmapBias;
  30. float mipMin;
  31. float mipMax;
  32. Color borderColor;
  33. CompareFunction comparisonFunc;
  34. };
  35. /**
  36. * @brief Class representing the state of a texture sampler.
  37. *
  38. * @note Sampler units are used for retrieving and filtering data from
  39. * textures set in a GPU program.
  40. * Sampler states are immutable. Thread safe.
  41. */
  42. class CM_EXPORT SamplerState : public Resource
  43. {
  44. public:
  45. virtual ~SamplerState() {}
  46. /**
  47. * @brief Returns texture addressing mode for each possible texture coordinate. Addressing
  48. * modes determine how are texture coordinates outside of [0, 1] range handled.
  49. */
  50. const UVWAddressingMode& getTextureAddressingMode() const { return mData.addressMode; }
  51. /**
  52. * @brief Gets the filtering used when sampling from a texture.
  53. */
  54. FilterOptions getTextureFiltering(FilterType ftpye) const;
  55. /**
  56. * @brief Gets the anisotropy level. Higher anisotropy means better filtering
  57. * for textures displayed on an angled slope relative to the viewer.
  58. */
  59. unsigned int getTextureAnisotropy() const { return mData.maxAniso; }
  60. /**
  61. * @brief Gets a function that compares sampled data with existing sampled data.
  62. */
  63. CompareFunction getComparisonFunction() const { return mData.comparisonFunc; }
  64. /**
  65. * @brief Mipmap bias allows you to adjust the mipmap selection calculation. Negative values
  66. * force a larger mipmap to be used, and positive values smaller. Units are in values
  67. * of mip levels, so -1 means use a mipmap one level higher than default.
  68. */
  69. float getTextureMipmapBias() const { return mData.mipmapBias; }
  70. /**
  71. * @brief Returns the minimum mip map level.
  72. */
  73. float getMinimumMip() const { return mData.mipMin; }
  74. /**
  75. * @brief Returns the maximum mip map level.
  76. */
  77. float getMaximumMip() const { return mData.mipMax; }
  78. /**
  79. * @brief Gets the border color that will be used when border texture addressing is used
  80. * and texture address is outside of the valid range.
  81. */
  82. const Color& getBorderColor() const;
  83. /**
  84. * @brief Creates a new sampler state using the provided descriptor structure.
  85. */
  86. static HSamplerState create(const SAMPLER_STATE_DESC& desc);
  87. /**
  88. * @brief Returns the default sampler state.
  89. */
  90. static const SamplerStatePtr& getDefault();
  91. protected:
  92. friend class RenderStateManager;
  93. /**
  94. * @brief Initializes the sampler state. Must be called right after construction.
  95. */
  96. virtual void initialize(const SAMPLER_STATE_DESC& desc);
  97. SAMPLER_STATE_DESC mData;
  98. /************************************************************************/
  99. /* RTTI */
  100. /************************************************************************/
  101. public:
  102. friend class SamplerStateRTTI;
  103. static RTTITypeBase* getRTTIStatic();
  104. virtual RTTITypeBase* getRTTI() const;
  105. };
  106. }