BsTechnique.h 4.2 KB

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