BsTechnique.h 3.7 KB

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