BsSamplerState.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. const SPtr<SamplerStateCore>& SamplerStateCore::getDefault()
  63. {
  64. return RenderStateCoreManager::instance().getDefaultSamplerState();
  65. }
  66. SamplerState::SamplerState(const SAMPLER_STATE_DESC& desc)
  67. :mProperties(desc)
  68. {
  69. }
  70. SamplerState::~SamplerState()
  71. {
  72. }
  73. SPtr<SamplerStateCore> SamplerState::getCore() const
  74. {
  75. return std::static_pointer_cast<SamplerStateCore>(mCoreSpecific);
  76. }
  77. SPtr<CoreObjectCore> SamplerState::createCore() const
  78. {
  79. return RenderStateCoreManager::instance()._createSamplerState(mProperties.mData);
  80. }
  81. SamplerStatePtr SamplerState::create(const SAMPLER_STATE_DESC& desc)
  82. {
  83. return RenderStateManager::instance().createSamplerState(desc);
  84. }
  85. const SamplerStatePtr& SamplerState::getDefault()
  86. {
  87. return RenderStateManager::instance().getDefaultSamplerState();
  88. }
  89. UINT64 SamplerState::generateHash(const SAMPLER_STATE_DESC& desc)
  90. {
  91. size_t hash = 0;
  92. hash_combine(hash, (UINT32)desc.addressMode.u);
  93. hash_combine(hash, (UINT32)desc.addressMode.v);
  94. hash_combine(hash, (UINT32)desc.addressMode.w);
  95. hash_combine(hash, (UINT32)desc.minFilter);
  96. hash_combine(hash, (UINT32)desc.magFilter);
  97. hash_combine(hash, (UINT32)desc.mipFilter);
  98. hash_combine(hash, desc.maxAniso);
  99. hash_combine(hash, desc.mipmapBias);
  100. hash_combine(hash, desc.mipMin);
  101. hash_combine(hash, desc.mipMax);
  102. hash_combine(hash, desc.borderColor);
  103. hash_combine(hash, (UINT32)desc.comparisonFunc);
  104. return (UINT64)hash;
  105. }
  106. const SamplerProperties& SamplerState::getProperties() const
  107. {
  108. return mProperties;
  109. }
  110. /************************************************************************/
  111. /* RTTI */
  112. /************************************************************************/
  113. RTTITypeBase* SamplerState::getRTTIStatic()
  114. {
  115. return SamplerStateRTTI::instance();
  116. }
  117. RTTITypeBase* SamplerState::getRTTI() const
  118. {
  119. return SamplerState::getRTTIStatic();
  120. }
  121. }