CmSamplerState.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 CamelotFramework
  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. , borderColor(Color::White)
  24. {
  25. }
  26. UVWAddressingMode addressMode;
  27. FilterOptions minFilter;
  28. FilterOptions magFilter;
  29. FilterOptions mipFilter;
  30. unsigned int maxAniso;
  31. float mipmapBias;
  32. float mipMin;
  33. float mipMax;
  34. Color borderColor;
  35. CompareFunction comparisonFunc;
  36. };
  37. // TODO Low priority - Write doc explaining various states
  38. /**
  39. * @brief Class representing the state of a single sampler unit during a Pass of a Technique, of a Material.
  40. *
  41. * @note Sampler units are pipelines for retrieving texture data for rendering onto
  42. * your objects in the world.
  43. *
  44. * Try not to make modifications to a created sampler state. Any modification will require the sampler state to
  45. * be recreated internally (depending on used render system). It is better to have multiple SamplerState objects with different
  46. * configurations and re-use them.
  47. */
  48. class CM_EXPORT SamplerState : public Resource
  49. {
  50. public:
  51. virtual ~SamplerState() {}
  52. /** Gets the texture addressing mode for a given coordinate,
  53. i.e. what happens at uv values above 1.0.
  54. @note
  55. The default is TAM_WRAP i.e. the texture repeats over values of 1.0.
  56. */
  57. const UVWAddressingMode& getTextureAddressingMode() const { return mData.addressMode; }
  58. // get the texture filtering for the given type
  59. FilterOptions getTextureFiltering(FilterType ftpye) const;
  60. // get this layer texture anisotropy level
  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. /** Gets the bias value applied to the mipmap calculation.
  67. @see TextureUnitState::setTextureMipmapBias
  68. */
  69. float getTextureMipmapBias() const { return mData.mipmapBias; }
  70. /**
  71. * @brief Returns the minimum mip level limit.
  72. */
  73. float getMinimumMip() const { return mData.mipMin; }
  74. /**
  75. * @brief Returns the maximum mip level limit.
  76. */
  77. float getMaximumMip() const { return mData.mipMax; }
  78. /**
  79. * @brief Gets the border color
  80. */
  81. const Color& getBorderColor() const;
  82. static HSamplerState create(const SAMPLER_STATE_DESC& desc);
  83. /**
  84. * @brief Returns the default sampler state;
  85. */
  86. static const SamplerStatePtr& getDefault();
  87. protected:
  88. friend class RenderStateManager;
  89. virtual void initialize(const SAMPLER_STATE_DESC& desc);
  90. SAMPLER_STATE_DESC mData;
  91. /************************************************************************/
  92. /* RTTI */
  93. /************************************************************************/
  94. public:
  95. friend class SamplerStateRTTI;
  96. static RTTITypeBase* getRTTIStatic();
  97. virtual RTTITypeBase* getRTTI() const;
  98. };
  99. }