BsTechnique.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "BsIReflectable.h"
  6. #include "BsCoreObject.h"
  7. namespace BansheeEngine
  8. {
  9. /** @addtogroup Implementation
  10. * @{
  11. */
  12. /** Base class that is used for implementing both sim and core versions of Technique. */
  13. class BS_CORE_EXPORT TechniqueBase
  14. {
  15. public:
  16. TechniqueBase(const StringID& renderAPI, const StringID& renderer, const Vector<StringID>& tags);
  17. virtual ~TechniqueBase() { }
  18. /** Checks if this technique is supported based on current render and other systems. */
  19. bool isSupported() const;
  20. /** Checks if the technique has the specified tag. */
  21. bool hasTag(const StringID& tag);
  22. /** Checks if the technique has any tags. */
  23. UINT32 hasTags() const { return !mTags.empty(); }
  24. protected:
  25. StringID mRenderAPI;
  26. StringID mRenderer;
  27. Vector<StringID> mTags;
  28. };
  29. template<bool Core> struct TPassType { };
  30. template<> struct TPassType < false > { typedef Pass Type; };
  31. template<> struct TPassType < true > { typedef PassCore Type; };
  32. template<bool Core> struct TTechniqueType {};
  33. template<> struct TTechniqueType < false > { typedef Technique Type; };
  34. template<> struct TTechniqueType < true > { typedef TechniqueCore Type; };
  35. /** Templated class that is used for implementing both sim and core versions of Technique. */
  36. template<bool Core>
  37. class BS_CORE_EXPORT TTechnique : public TechniqueBase
  38. {
  39. public:
  40. typedef typename TPassType<Core>::Type PassType;
  41. TTechnique();
  42. TTechnique(const StringID& renderAPI, const StringID& renderer, const Vector<StringID>& tags,
  43. const Vector<SPtr<PassType>>& passes);
  44. virtual ~TTechnique() { }
  45. /** Returns a pass with the specified index. */
  46. SPtr<PassType> getPass(UINT32 idx) const;
  47. /** Returns total number of passes. */
  48. UINT32 getNumPasses() const { return (UINT32)mPasses.size(); }
  49. protected:
  50. Vector<SPtr<PassType>> mPasses;
  51. };
  52. /** @} */
  53. /** @addtogroup Material-Internal
  54. * @{
  55. */
  56. /** Core thread version of Technique. */
  57. class BS_CORE_EXPORT TechniqueCore : public CoreObjectCore, public TTechnique<true>
  58. {
  59. public:
  60. TechniqueCore(const StringID& renderAPI, const StringID& renderer, const Vector<StringID>& tags,
  61. const Vector<SPtr<PassCore>>& passes);
  62. /** @copydoc Technique::create(const StringID&, const StringID&, const Vector<SPtr<Pass>>&) */
  63. static SPtr<TechniqueCore> create(const StringID& renderAPI, const StringID& renderer,
  64. const Vector<SPtr<PassCore>>& passes);
  65. /** @copydoc Technique::create(const StringID&, const StringID&, const Vector<StringID>&, const Vector<SPtr<Pass>>&) */
  66. static SPtr<TechniqueCore> create(const StringID& renderAPI, const StringID& renderer, const Vector<StringID>& tags,
  67. const Vector<SPtr<PassCore>>& passes);
  68. };
  69. /** @} */
  70. /** @addtogroup Material
  71. * @{
  72. */
  73. /**
  74. * Technique is a set of shading passes bindable to the GPU pipeline. Each technique can also have a set of properties
  75. * that help the engine to determine which technique should be used under which circumstances (if more than one
  76. * technique is available).
  77. *
  78. * @note
  79. * Normally you want to have a separate technique for every render system and renderer your application supports.
  80. * For example, if you are supporting DirectX11 and OpenGL you will want to have two techniques, one using HLSL based
  81. * GPU programs, other using GLSL. Those techniques should try to mirror each other's end results.
  82. */
  83. class BS_CORE_EXPORT Technique : public IReflectable, public CoreObject, public TTechnique<false>
  84. {
  85. public:
  86. Technique(const StringID& renderAPI, const StringID& renderer, const Vector<StringID>& tags,
  87. const Vector<SPtr<Pass>>& passes);
  88. /** Retrieves an implementation of a technique usable only from the core thread. */
  89. SPtr<TechniqueCore> getCore() const;
  90. /**
  91. * Creates a new technique.
  92. *
  93. * @param[in] renderAPI Render API the technique supports. Under normal circumstances the engine will not use
  94. * this technique unless this API is enabled.
  95. * @param[in] renderer Renderer the technique supports. Under normal circumstances the engine will not use
  96. * this technique unless this renderer is enabled.
  97. * @param[in] passes A set of passes that define the technique.
  98. * @return Newly creted technique.
  99. */
  100. static SPtr<Technique> create(const StringID& renderAPI, const StringID& renderer, const Vector<SPtr<Pass>>& passes);
  101. /**
  102. * Creates a new technique.
  103. *
  104. * @param[in] renderAPI Render API the technique supports. Under normal circumstances the engine will not use
  105. * this technique unless this API is enabled.
  106. * @param[in] renderer Renderer the technique supports. Under normal circumstances the engine will not use
  107. * this technique unless this renderer is enabled.
  108. * @param[in] tags An optional set of tags that can be used for further identifying under which
  109. * circumstances should a technique be used.
  110. * @param[in] passes A set of passes that define the technique.
  111. * @return Newly creted technique.
  112. */
  113. static SPtr<Technique> create(const StringID& renderAPI, const StringID& renderer, const Vector<StringID>& tags,
  114. const Vector<SPtr<Pass>>& passes);
  115. protected:
  116. /** @copydoc CoreObject::createCore */
  117. SPtr<CoreObjectCore> createCore() const override;
  118. /** @copydoc CoreObject::getCoreDependencies */
  119. void getCoreDependencies(Vector<CoreObject*>& dependencies) override;
  120. /** Creates a new technique but doesn't initialize it. */
  121. static SPtr<Technique> createEmpty();
  122. private:
  123. /************************************************************************/
  124. /* RTTI */
  125. /************************************************************************/
  126. /** Serialization only constructor. */
  127. Technique();
  128. public:
  129. friend class TechniqueRTTI;
  130. static RTTITypeBase* getRTTIStatic();
  131. RTTITypeBase* getRTTI() const override;
  132. };
  133. /** @} */
  134. }