BsSamplerState.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #include "BsSamplerState.h"
  2. #include "BsSamplerStateRTTI.h"
  3. #include "BsRenderStateManager.h"
  4. #include "BsRenderAPI.h"
  5. #include "BsException.h"
  6. #include "BsResources.h"
  7. namespace BansheeEngine
  8. {
  9. bool SAMPLER_STATE_DESC::operator == (const SAMPLER_STATE_DESC& rhs) const
  10. {
  11. return addressMode == rhs.addressMode &&
  12. minFilter == rhs.minFilter &&
  13. magFilter == rhs.magFilter &&
  14. mipFilter == rhs.mipFilter &&
  15. maxAniso == rhs.maxAniso &&
  16. mipmapBias == rhs.mipmapBias &&
  17. mipMin == rhs.mipMin &&
  18. mipMax == rhs.mipMax &&
  19. borderColor == rhs.borderColor &&
  20. comparisonFunc == rhs.comparisonFunc;
  21. }
  22. SamplerProperties::SamplerProperties(const SAMPLER_STATE_DESC& desc)
  23. :mData(desc), mHash(SamplerState::generateHash(desc))
  24. { }
  25. FilterOptions SamplerProperties::getTextureFiltering(FilterType ft) const
  26. {
  27. switch (ft)
  28. {
  29. case FT_MIN:
  30. return mData.minFilter;
  31. case FT_MAG:
  32. return mData.magFilter;
  33. case FT_MIP:
  34. return mData.mipFilter;
  35. }
  36. return mData.minFilter;
  37. }
  38. const Color& SamplerProperties::getBorderColor() const
  39. {
  40. return mData.borderColor;
  41. }
  42. SamplerStateCore::SamplerStateCore(const SAMPLER_STATE_DESC& desc)
  43. :mProperties(desc)
  44. {
  45. }
  46. SamplerStateCore::~SamplerStateCore()
  47. {
  48. RenderStateCoreManager::instance().notifySamplerStateDestroyed(mProperties.mData);
  49. }
  50. const SamplerProperties& SamplerStateCore::getProperties() const
  51. {
  52. return mProperties;
  53. }
  54. const SPtr<SamplerStateCore>& SamplerStateCore::getDefault()
  55. {
  56. return RenderStateCoreManager::instance().getDefaultSamplerState();
  57. }
  58. SamplerState::SamplerState(const SAMPLER_STATE_DESC& desc)
  59. :mProperties(desc)
  60. {
  61. }
  62. SamplerState::~SamplerState()
  63. {
  64. RenderStateManager::instance().notifySamplerStateDestroyed(mProperties.mData);
  65. }
  66. SPtr<SamplerStateCore> SamplerState::getCore() const
  67. {
  68. return std::static_pointer_cast<SamplerStateCore>(mCoreSpecific);
  69. }
  70. SPtr<CoreObjectCore> SamplerState::createCore() const
  71. {
  72. return RenderStateCoreManager::instance().createSamplerStateInternal(mProperties.mData);
  73. }
  74. SamplerStatePtr SamplerState::create(const SAMPLER_STATE_DESC& desc)
  75. {
  76. return RenderStateManager::instance().createSamplerState(desc);
  77. }
  78. const SamplerStatePtr& SamplerState::getDefault()
  79. {
  80. return RenderStateManager::instance().getDefaultSamplerState();
  81. }
  82. UINT64 SamplerState::generateHash(const SAMPLER_STATE_DESC& desc)
  83. {
  84. size_t hash = 0;
  85. hash_combine(hash, (UINT32)desc.addressMode.u);
  86. hash_combine(hash, (UINT32)desc.addressMode.v);
  87. hash_combine(hash, (UINT32)desc.addressMode.w);
  88. hash_combine(hash, (UINT32)desc.minFilter);
  89. hash_combine(hash, (UINT32)desc.magFilter);
  90. hash_combine(hash, (UINT32)desc.mipFilter);
  91. hash_combine(hash, desc.maxAniso);
  92. hash_combine(hash, desc.mipmapBias);
  93. hash_combine(hash, desc.mipMin);
  94. hash_combine(hash, desc.mipMax);
  95. hash_combine(hash, desc.borderColor);
  96. hash_combine(hash, (UINT32)desc.comparisonFunc);
  97. return (UINT64)hash;
  98. }
  99. const SamplerProperties& SamplerState::getProperties() const
  100. {
  101. return mProperties;
  102. }
  103. /************************************************************************/
  104. /* RTTI */
  105. /************************************************************************/
  106. RTTITypeBase* SamplerState::getRTTIStatic()
  107. {
  108. return SamplerStateRTTI::instance();
  109. }
  110. RTTITypeBase* SamplerState::getRTTI() const
  111. {
  112. return SamplerState::getRTTIStatic();
  113. }
  114. }