BsTechnique.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "Material/BsTechnique.h"
  4. #include "Error/BsException.h"
  5. #include "RenderAPI/BsRenderAPI.h"
  6. #include "Renderer/BsRendererManager.h"
  7. #include "Material/BsPass.h"
  8. #include "Renderer/BsRenderer.h"
  9. #include "Managers/BsGpuProgramManager.h"
  10. #include "RTTI/BsTechniqueRTTI.h"
  11. namespace bs
  12. {
  13. TechniqueBase::TechniqueBase(const String& language, const Vector<StringID>& tags, const ShaderVariation& variation)
  14. :mLanguage(language), mTags(tags), mVariation(variation)
  15. {
  16. }
  17. bool TechniqueBase::isSupported() const
  18. {
  19. if (ct::GpuProgramManager::instance().isLanguageSupported(mLanguage) || mLanguage == "Any")
  20. return true;
  21. return false;
  22. }
  23. bool TechniqueBase::hasTag(const StringID& tag)
  24. {
  25. for(auto& entry : mTags)
  26. {
  27. if (entry == tag)
  28. return true;
  29. }
  30. return false;
  31. }
  32. template<bool Core>
  33. TTechnique<Core>::TTechnique(const String& language, const Vector<StringID>& tags,
  34. const ShaderVariation& variation, const Vector<SPtr<PassType>>& passes)
  35. : TechniqueBase(language, tags, variation), mPasses(passes)
  36. { }
  37. template<bool Core>
  38. TTechnique<Core>::TTechnique()
  39. : TechniqueBase("", {}, ShaderVariation())
  40. { }
  41. template<bool Core>
  42. SPtr<typename TTechnique<Core>::PassType> TTechnique<Core>::getPass(UINT32 idx) const
  43. {
  44. if (idx < 0 || idx >= (UINT32)mPasses.size())
  45. BS_EXCEPT(InvalidParametersException, "Index out of range: " + toString(idx));
  46. return mPasses[idx];
  47. }
  48. template class TTechnique < false > ;
  49. template class TTechnique < true >;
  50. Technique::Technique(const String& language, const Vector<StringID>& tags,
  51. const ShaderVariation& variation, const Vector<SPtr<Pass>>& passes)
  52. :TTechnique(language, tags, variation, passes)
  53. { }
  54. Technique::Technique()
  55. : TTechnique()
  56. { }
  57. SPtr<ct::Technique> Technique::getCore() const
  58. {
  59. return std::static_pointer_cast<ct::Technique>(mCoreSpecific);
  60. }
  61. SPtr<ct::CoreObject> Technique::createCore() const
  62. {
  63. Vector<SPtr<ct::Pass>> passes;
  64. for (auto& pass : mPasses)
  65. passes.push_back(pass->getCore());
  66. ct::Technique* technique = new(bs_alloc<ct::Technique>()) ct::Technique(
  67. mLanguage,
  68. mTags,
  69. mVariation,
  70. passes);
  71. SPtr<ct::Technique> techniquePtr = bs_shared_ptr<ct::Technique>(technique);
  72. techniquePtr->_setThisPtr(techniquePtr);
  73. return techniquePtr;
  74. }
  75. void Technique::getCoreDependencies(Vector<CoreObject*>& dependencies)
  76. {
  77. for (auto& pass : mPasses)
  78. dependencies.push_back(pass.get());
  79. }
  80. SPtr<Technique> Technique::create(const String& language, const Vector<SPtr<Pass>>& passes)
  81. {
  82. Technique* technique = new (bs_alloc<Technique>()) Technique(language, {}, ShaderVariation(), passes);
  83. SPtr<Technique> techniquePtr = bs_core_ptr<Technique>(technique);
  84. techniquePtr->_setThisPtr(techniquePtr);
  85. techniquePtr->initialize();
  86. return techniquePtr;
  87. }
  88. SPtr<Technique> Technique::create(const String& language, const Vector<StringID>& tags,
  89. const ShaderVariation& variation, const Vector<SPtr<Pass>>& passes)
  90. {
  91. Technique* technique = new (bs_alloc<Technique>()) Technique(language, tags, variation, passes);
  92. SPtr<Technique> techniquePtr = bs_core_ptr<Technique>(technique);
  93. techniquePtr->_setThisPtr(techniquePtr);
  94. techniquePtr->initialize();
  95. return techniquePtr;
  96. }
  97. SPtr<Technique> Technique::createEmpty()
  98. {
  99. Technique* technique = new (bs_alloc<Technique>()) Technique();
  100. SPtr<Technique> techniquePtr = bs_core_ptr<Technique>(technique);
  101. techniquePtr->_setThisPtr(techniquePtr);
  102. return techniquePtr;
  103. }
  104. RTTITypeBase* Technique::getRTTIStatic()
  105. {
  106. return TechniqueRTTI::instance();
  107. }
  108. RTTITypeBase* Technique::getRTTI() const
  109. {
  110. return Technique::getRTTIStatic();
  111. }
  112. namespace ct
  113. {
  114. Technique::Technique(const String& language, const Vector<StringID>& tags, const ShaderVariation& variation,
  115. const Vector<SPtr<Pass>>& passes)
  116. :TTechnique(language, tags, variation, passes)
  117. { }
  118. SPtr<Technique> Technique::create(const String& language, const Vector<SPtr<Pass>>& passes)
  119. {
  120. Technique* technique = new (bs_alloc<Technique>()) Technique(language, {}, ShaderVariation(), passes);
  121. SPtr<Technique> techniquePtr = bs_shared_ptr<Technique>(technique);
  122. techniquePtr->_setThisPtr(techniquePtr);
  123. techniquePtr->initialize();
  124. return techniquePtr;
  125. }
  126. SPtr<Technique> Technique::create(const String& language, const Vector<StringID>& tags,
  127. const ShaderVariation& variation, const Vector<SPtr<Pass>>& passes)
  128. {
  129. Technique* technique = new (bs_alloc<Technique>()) Technique(language, tags, variation, passes);
  130. SPtr<Technique> techniquePtr = bs_shared_ptr<Technique>(technique);
  131. techniquePtr->_setThisPtr(techniquePtr);
  132. techniquePtr->initialize();
  133. return techniquePtr;
  134. }
  135. }
  136. }