BsSamplerState.cpp 3.6 KB

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