BsSamplerState.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsSamplerState.h"
  4. #include "BsSamplerStateRTTI.h"
  5. #include "BsRenderStateManager.h"
  6. namespace BansheeEngine
  7. {
  8. bool SAMPLER_STATE_DESC::operator == (const SAMPLER_STATE_DESC& rhs) const
  9. {
  10. return addressMode == rhs.addressMode &&
  11. minFilter == rhs.minFilter &&
  12. magFilter == rhs.magFilter &&
  13. mipFilter == rhs.mipFilter &&
  14. maxAniso == rhs.maxAniso &&
  15. mipmapBias == rhs.mipmapBias &&
  16. mipMin == rhs.mipMin &&
  17. mipMax == rhs.mipMax &&
  18. borderColor == rhs.borderColor &&
  19. comparisonFunc == rhs.comparisonFunc;
  20. }
  21. SamplerProperties::SamplerProperties(const SAMPLER_STATE_DESC& desc)
  22. :mData(desc), mHash(SamplerState::generateHash(desc))
  23. { }
  24. FilterOptions SamplerProperties::getTextureFiltering(FilterType ft) const
  25. {
  26. switch (ft)
  27. {
  28. case FT_MIN:
  29. return mData.minFilter;
  30. case FT_MAG:
  31. return mData.magFilter;
  32. case FT_MIP:
  33. return mData.mipFilter;
  34. }
  35. return mData.minFilter;
  36. }
  37. const Color& SamplerProperties::getBorderColor() const
  38. {
  39. return mData.borderColor;
  40. }
  41. SamplerStateCore::SamplerStateCore(const SAMPLER_STATE_DESC& desc)
  42. :mProperties(desc)
  43. {
  44. }
  45. SamplerStateCore::~SamplerStateCore()
  46. {
  47. RenderStateCoreManager::instance().notifySamplerStateDestroyed(mProperties.mData);
  48. }
  49. void SamplerStateCore::initialize()
  50. {
  51. // Since we cache states it's possible this object was already initialized
  52. // (i.e. multiple sim-states can share a single core-state)
  53. if (isInitialized())
  54. return;
  55. createInternal();
  56. CoreObjectCore::initialize();
  57. }
  58. const SamplerProperties& SamplerStateCore::getProperties() const
  59. {
  60. return mProperties;
  61. }
  62. SPtr<SamplerStateCore> SamplerStateCore::create(const SAMPLER_STATE_DESC& desc)
  63. {
  64. return RenderStateCoreManager::instance()._createSamplerState(desc);
  65. }
  66. const SPtr<SamplerStateCore>& SamplerStateCore::getDefault()
  67. {
  68. return RenderStateCoreManager::instance().getDefaultSamplerState();
  69. }
  70. SamplerState::SamplerState(const SAMPLER_STATE_DESC& desc)
  71. :mProperties(desc)
  72. {
  73. }
  74. SamplerState::~SamplerState()
  75. {
  76. }
  77. SPtr<SamplerStateCore> SamplerState::getCore() const
  78. {
  79. return std::static_pointer_cast<SamplerStateCore>(mCoreSpecific);
  80. }
  81. SPtr<CoreObjectCore> SamplerState::createCore() const
  82. {
  83. return RenderStateCoreManager::instance()._createSamplerState(mProperties.mData);
  84. }
  85. SPtr<SamplerState> SamplerState::create(const SAMPLER_STATE_DESC& desc)
  86. {
  87. return RenderStateManager::instance().createSamplerState(desc);
  88. }
  89. const SPtr<SamplerState>& SamplerState::getDefault()
  90. {
  91. return RenderStateManager::instance().getDefaultSamplerState();
  92. }
  93. UINT64 SamplerState::generateHash(const SAMPLER_STATE_DESC& desc)
  94. {
  95. size_t hash = 0;
  96. hash_combine(hash, (UINT32)desc.addressMode.u);
  97. hash_combine(hash, (UINT32)desc.addressMode.v);
  98. hash_combine(hash, (UINT32)desc.addressMode.w);
  99. hash_combine(hash, (UINT32)desc.minFilter);
  100. hash_combine(hash, (UINT32)desc.magFilter);
  101. hash_combine(hash, (UINT32)desc.mipFilter);
  102. hash_combine(hash, desc.maxAniso);
  103. hash_combine(hash, desc.mipmapBias);
  104. hash_combine(hash, desc.mipMin);
  105. hash_combine(hash, desc.mipMax);
  106. hash_combine(hash, desc.borderColor);
  107. hash_combine(hash, (UINT32)desc.comparisonFunc);
  108. return (UINT64)hash;
  109. }
  110. const SamplerProperties& SamplerState::getProperties() const
  111. {
  112. return mProperties;
  113. }
  114. /************************************************************************/
  115. /* RTTI */
  116. /************************************************************************/
  117. RTTITypeBase* SamplerState::getRTTIStatic()
  118. {
  119. return SamplerStateRTTI::instance();
  120. }
  121. RTTITypeBase* SamplerState::getRTTI() const
  122. {
  123. return SamplerState::getRTTIStatic();
  124. }
  125. }