BsTechnique.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsIReflectable.h"
  4. #include "BsCoreObject.h"
  5. namespace BansheeEngine
  6. {
  7. /**
  8. * @brief Technique represents a specific implementation of a shader. Contains
  9. * a number of passes that will be executed when rendering objects using this technique.
  10. *
  11. * @note Normally you want to have a separate technique for every render system and renderer your
  12. * application supports. For example, if you are supporting DirectX11 and OpenGL you will
  13. * want to have two techniques, one using HLSL based GPU programs, other using GLSL. Those
  14. * techniques should try to mirror each others end results.
  15. */
  16. class BS_CORE_EXPORT TechniqueBase
  17. {
  18. public:
  19. TechniqueBase(const StringID& renderAPI, const StringID& renderer);
  20. virtual ~TechniqueBase() { }
  21. /**
  22. * @brief Checks if this technique is supported based on current
  23. * render and other systems.
  24. */
  25. bool isSupported() const;
  26. protected:
  27. StringID mRenderAPI;
  28. StringID mRenderer;
  29. };
  30. /**
  31. * @copydoc TechniqueBase
  32. *
  33. * @note Templated version that is used for implementing
  34. * both sim and core versions of Technique.
  35. */
  36. template<bool Core>
  37. class BS_CORE_EXPORT TTechnique : public TechniqueBase
  38. {
  39. public:
  40. template<bool Core> struct TPassType { };
  41. template<> struct TPassType < false > { typedef Pass Type; };
  42. template<> struct TPassType < true > { typedef PassCore Type; };
  43. typedef typename TPassType<Core>::Type PassType;
  44. TTechnique();
  45. TTechnique(const StringID& renderAPI, const StringID& renderer, const Vector<SPtr<PassType>>& passes);
  46. virtual ~TTechnique() { }
  47. /**
  48. * @brief Returns a pass with the specified index.
  49. */
  50. SPtr<PassType> getPass(UINT32 idx) const;
  51. /**
  52. * @brief Returns total number of passes.
  53. */
  54. UINT32 getNumPasses() const { return (UINT32)mPasses.size(); }
  55. protected:
  56. Vector<SPtr<PassType>> mPasses;
  57. };
  58. /**
  59. * @copydoc TechniqueBase
  60. *
  61. * @note Core thread.
  62. */
  63. class BS_CORE_EXPORT TechniqueCore : public CoreObjectCore, public TTechnique<true>
  64. {
  65. public:
  66. TechniqueCore(const StringID& renderAPI, const StringID& renderer, const Vector<SPtr<PassCore>>& passes);
  67. /**
  68. * @brief Creates a new technique.
  69. */
  70. static SPtr<TechniqueCore> create(const StringID& renderAPI, const StringID& renderer, const Vector<SPtr<PassCore>>& passes);
  71. };
  72. /**
  73. * @copydoc TechniqueBase
  74. *
  75. * @note Sim thread.
  76. */
  77. class BS_CORE_EXPORT Technique : public IReflectable, public CoreObject, public TTechnique<false>
  78. {
  79. public:
  80. Technique(const StringID& renderAPI, const StringID& renderer, const Vector<SPtr<Pass>>& passes);
  81. /**
  82. * @brief Retrieves an implementation of a technique usable only from the
  83. * core thread.
  84. */
  85. SPtr<TechniqueCore> getCore() const;
  86. /**
  87. * @brief Creates a new technique.
  88. */
  89. static TechniquePtr create(const StringID& renderAPI, const StringID& renderer, const Vector<SPtr<Pass>>& passes);
  90. protected:
  91. /**
  92. * @copydoc CoreObject::createCore
  93. */
  94. SPtr<CoreObjectCore> createCore() const override;
  95. /**
  96. * @copydoc CoreObject::getCoreDependencies
  97. */
  98. void getCoreDependencies(FrameVector<SPtr<CoreObject>>& dependencies);
  99. /**
  100. * @brief Creates a new technique but doesn't initialize it.
  101. */
  102. static TechniquePtr createEmpty();
  103. private:
  104. /************************************************************************/
  105. /* RTTI */
  106. /************************************************************************/
  107. /**
  108. * @brief Serialization only constructor.
  109. */
  110. Technique();
  111. public:
  112. friend class TechniqueRTTI;
  113. static RTTITypeBase* getRTTIStatic();
  114. virtual RTTITypeBase* getRTTI() const;
  115. };
  116. }