BsSamplerState.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "RenderAPI/BsSamplerState.h"
  4. #include "RTTI/BsSamplerStateRTTI.h"
  5. #include "Managers/BsRenderStateManager.h"
  6. namespace bs
  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. SamplerState::SamplerState(const SAMPLER_STATE_DESC& desc)
  42. :mProperties(desc)
  43. {
  44. }
  45. SamplerState::~SamplerState()
  46. {
  47. }
  48. SPtr<ct::SamplerState> SamplerState::getCore() const
  49. {
  50. return std::static_pointer_cast<ct::SamplerState>(mCoreSpecific);
  51. }
  52. SPtr<ct::CoreObject> SamplerState::createCore() const
  53. {
  54. return ct::RenderStateManager::instance()._createSamplerState(mProperties.mData);
  55. }
  56. SPtr<SamplerState> SamplerState::create(const SAMPLER_STATE_DESC& desc)
  57. {
  58. return RenderStateManager::instance().createSamplerState(desc);
  59. }
  60. const SPtr<SamplerState>& SamplerState::getDefault()
  61. {
  62. return RenderStateManager::instance().getDefaultSamplerState();
  63. }
  64. UINT64 SamplerState::generateHash(const SAMPLER_STATE_DESC& desc)
  65. {
  66. size_t hash = 0;
  67. hash_combine(hash, (UINT32)desc.addressMode.u);
  68. hash_combine(hash, (UINT32)desc.addressMode.v);
  69. hash_combine(hash, (UINT32)desc.addressMode.w);
  70. hash_combine(hash, (UINT32)desc.minFilter);
  71. hash_combine(hash, (UINT32)desc.magFilter);
  72. hash_combine(hash, (UINT32)desc.mipFilter);
  73. hash_combine(hash, desc.maxAniso);
  74. hash_combine(hash, desc.mipmapBias);
  75. hash_combine(hash, desc.mipMin);
  76. hash_combine(hash, desc.mipMax);
  77. hash_combine(hash, desc.borderColor);
  78. hash_combine(hash, (UINT32)desc.comparisonFunc);
  79. return (UINT64)hash;
  80. }
  81. const SamplerProperties& SamplerState::getProperties() const
  82. {
  83. return mProperties;
  84. }
  85. /************************************************************************/
  86. /* RTTI */
  87. /************************************************************************/
  88. RTTITypeBase* SamplerState::getRTTIStatic()
  89. {
  90. return SamplerStateRTTI::instance();
  91. }
  92. RTTITypeBase* SamplerState::getRTTI() const
  93. {
  94. return SamplerState::getRTTIStatic();
  95. }
  96. namespace ct
  97. {
  98. SamplerState::SamplerState(const SAMPLER_STATE_DESC& desc, GpuDeviceFlags deviceMask)
  99. :mProperties(desc)
  100. {
  101. }
  102. SamplerState::~SamplerState()
  103. {
  104. RenderStateManager::instance().notifySamplerStateDestroyed(mProperties.mData);
  105. }
  106. void SamplerState::initialize()
  107. {
  108. // Since we cache states it's possible this object was already initialized
  109. // (i.e. multiple sim-states can share a single core-state)
  110. if (isInitialized())
  111. return;
  112. createInternal();
  113. CoreObject::initialize();
  114. }
  115. const SamplerProperties& SamplerState::getProperties() const
  116. {
  117. return mProperties;
  118. }
  119. SPtr<SamplerState> SamplerState::create(const SAMPLER_STATE_DESC& desc, GpuDeviceFlags deviceMask)
  120. {
  121. return RenderStateManager::instance().createSamplerState(desc, deviceMask);
  122. }
  123. const SPtr<SamplerState>& SamplerState::getDefault()
  124. {
  125. return RenderStateManager::instance().getDefaultSamplerState();
  126. }
  127. }
  128. }