CmSamplerState.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmCommon.h"
  4. #include "CmMatrix4.h"
  5. #include "CmString.h"
  6. #include "CmPixelUtil.h"
  7. #include "CmTexture.h"
  8. #include "CmColor.h"
  9. #include "CmIReflectable.h"
  10. namespace CamelotEngine
  11. {
  12. struct CM_EXPORT SAMPLER_STATE_DESC
  13. {
  14. SAMPLER_STATE_DESC()
  15. : minFilter(FO_LINEAR)
  16. , magFilter(FO_LINEAR)
  17. , mipFilter(FO_POINT)
  18. , maxAniso(0)
  19. , mipmapBias(0)
  20. , comparisonFunc(CMPF_ALWAYS_FAIL)
  21. , mipMin(-FLT_MAX)
  22. , mipMax(FLT_MAX)
  23. {
  24. for(int i = 0; i < 4; i++)
  25. borderColor[i] = Color::White;
  26. }
  27. UVWAddressingMode addressMode;
  28. FilterOptions minFilter;
  29. FilterOptions magFilter;
  30. FilterOptions mipFilter;
  31. unsigned int maxAniso;
  32. float mipmapBias;
  33. float mipMin;
  34. float mipMax;
  35. Color borderColor[4];
  36. CompareFunction comparisonFunc;
  37. };
  38. // TODO Low priority - Write doc explaining various states
  39. /**
  40. * @brief Class representing the state of a single sampler unit during a Pass of a Technique, of a Material.
  41. *
  42. * @note Sampler units are pipelines for retrieving texture data for rendering onto
  43. * your objects in the world.
  44. *
  45. * Try not to make modifications to a created sampler state. Any modification will require the sampler state to
  46. * be recreated internally (depending on used render system). It is better to have multiple SamplerState objects with different
  47. * configurations and re-use them.
  48. */
  49. class CM_EXPORT SamplerState : public IReflectable
  50. {
  51. public:
  52. virtual ~SamplerState() {}
  53. /** Gets the texture addressing mode for a given coordinate,
  54. i.e. what happens at uv values above 1.0.
  55. @note
  56. The default is TAM_WRAP i.e. the texture repeats over values of 1.0.
  57. */
  58. const UVWAddressingMode& getTextureAddressingMode() const { return mData.addressMode; }
  59. // get the texture filtering for the given type
  60. FilterOptions getTextureFiltering(FilterType ftpye) const;
  61. // get this layer texture anisotropy level
  62. unsigned int getTextureAnisotropy() const { return mData.maxAniso; }
  63. /**
  64. * @brief Gets a function that compares sampled data with existing sampled data.
  65. */
  66. CompareFunction getComparisonFunction() const { return mData.comparisonFunc; }
  67. /** Gets the bias value applied to the mipmap calculation.
  68. @see TextureUnitState::setTextureMipmapBias
  69. */
  70. float getTextureMipmapBias() const { return mData.mipmapBias; }
  71. /**
  72. * @brief Returns the minimum mip level limit.
  73. */
  74. float getMinimumMip() const { return mData.mipMin; }
  75. /**
  76. * @brief Returns the maximum mip level limit.
  77. */
  78. float getMaximumMip() const { return mData.mipMax; }
  79. /**
  80. * @brief Gets a border color for the specified side. Index must be >= 0 and < 4.
  81. */
  82. const Color& getBorderColor(UINT32 idx) const;
  83. static SamplerStatePtr create(const SAMPLER_STATE_DESC& desc);
  84. /**
  85. * @brief Returns the default sampler state;
  86. */
  87. static const SamplerState& getDefault();
  88. private:
  89. friend class RenderStateManager;
  90. virtual void initialize(const SAMPLER_STATE_DESC& desc);
  91. SAMPLER_STATE_DESC mData;
  92. /************************************************************************/
  93. /* RTTI */
  94. /************************************************************************/
  95. public:
  96. friend class SamplerStateRTTI;
  97. static RTTITypeBase* getRTTIStatic();
  98. virtual RTTITypeBase* getRTTI() const;
  99. };
  100. }