BsTechnique.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 "Reflection/BsIReflectable.h"
  6. #include "CoreThread/BsCoreObject.h"
  7. namespace bs
  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 String& language, 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. String mLanguage;
  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 ct::Pass Type; };
  32. template<bool Core> struct TTechniqueType {};
  33. template<> struct TTechniqueType < false > { typedef Technique Type; };
  34. template<> struct TTechniqueType < true > { typedef ct::Technique 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 String& language, 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
  54. * @{
  55. */
  56. /**
  57. * Technique is a set of shading passes bindable to the GPU pipeline. Each technique can also have a set of properties
  58. * that help the engine to determine which technique should be used under which circumstances (if more than one
  59. * technique is available).
  60. *
  61. * @note
  62. * Normally you want to have a separate technique for every render system and renderer your application supports.
  63. * For example, if you are supporting DirectX11 and OpenGL you will want to have two techniques, one using HLSL based
  64. * GPU programs, other using GLSL. Those techniques should try to mirror each other's end results.
  65. */
  66. class BS_CORE_EXPORT Technique : public IReflectable, public CoreObject, public TTechnique<false>
  67. {
  68. public:
  69. Technique(const String& language, const StringID& renderer, const Vector<StringID>& tags,
  70. const Vector<SPtr<Pass>>& passes);
  71. /** Retrieves an implementation of a technique usable only from the core thread. */
  72. SPtr<ct::Technique> getCore() const;
  73. /**
  74. * Creates a new technique.
  75. *
  76. * @param[in] language Shading language used by the technique. The engine will not use this technique unless
  77. * this language is supported by the render API.
  78. * @param[in] renderer Renderer the technique supports. Under normal circumstances the engine will not use
  79. * this technique unless this renderer is enabled.
  80. * @param[in] passes A set of passes that define the technique.
  81. * @return Newly creted technique.
  82. */
  83. static SPtr<Technique> create(const String& language, const StringID& renderer, const Vector<SPtr<Pass>>& passes);
  84. /**
  85. * Creates a new technique.
  86. *
  87. * @param[in] language Shading language used by the technique. The engine will not use this technique unless
  88. * this language is supported by the render API.
  89. * @param[in] renderer Renderer the technique supports. Under normal circumstances the engine will not use
  90. * this technique unless this renderer is enabled.
  91. * @param[in] tags An optional set of tags that can be used for further identifying under which
  92. * circumstances should a technique be used.
  93. * @param[in] passes A set of passes that define the technique.
  94. * @return Newly creted technique.
  95. */
  96. static SPtr<Technique> create(const String& language, const StringID& renderer, const Vector<StringID>& tags,
  97. const Vector<SPtr<Pass>>& passes);
  98. protected:
  99. /** @copydoc CoreObject::createCore */
  100. SPtr<ct::CoreObject> createCore() const override;
  101. /** @copydoc CoreObject::getCoreDependencies */
  102. void getCoreDependencies(Vector<CoreObject*>& dependencies) override;
  103. /** Creates a new technique but doesn't initialize it. */
  104. static SPtr<Technique> createEmpty();
  105. private:
  106. /************************************************************************/
  107. /* RTTI */
  108. /************************************************************************/
  109. /** Serialization only constructor. */
  110. Technique();
  111. public:
  112. friend class TechniqueRTTI;
  113. static RTTITypeBase* getRTTIStatic();
  114. RTTITypeBase* getRTTI() const override;
  115. };
  116. /** @} */
  117. namespace ct
  118. {
  119. /** @addtogroup Material-Internal
  120. * @{
  121. */
  122. /** Core thread version of bs::Technique. */
  123. class BS_CORE_EXPORT Technique : public CoreObject, public TTechnique<true>
  124. {
  125. public:
  126. Technique(const String& language, const StringID& renderer, const Vector<StringID>& tags,
  127. const Vector<SPtr<Pass>>& passes);
  128. /** @copydoc bs::Technique::create(const String&, const StringID&, const Vector<SPtr<Pass>>&) */
  129. static SPtr<Technique> create(const String& language, const StringID& renderer,
  130. const Vector<SPtr<Pass>>& passes);
  131. /** @copydoc bs::Technique::create(const String&, const StringID&, const Vector<StringID>&, const Vector<SPtr<Pass>>&) */
  132. static SPtr<Technique> create(const String& language, const StringID& renderer, const Vector<StringID>& tags,
  133. const Vector<SPtr<Pass>>& passes);
  134. };
  135. /** @} */
  136. }
  137. }