BsSamplerState.h 3.9 KB

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