BsTechnique.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. /**
  27. * @brief Checks if this technique is supported based on current
  28. * render and other systems.
  29. */
  30. bool isSupported() const;
  31. protected:
  32. StringID mRenderAPI;
  33. StringID mRenderer;
  34. };
  35. /**
  36. * @copydoc TechniqueBase
  37. *
  38. * @note Templated version that is used for implementing
  39. * both sim and core versions of Technique.
  40. */
  41. template<bool Core>
  42. class BS_CORE_EXPORT TTechnique : public TechniqueBase
  43. {
  44. public:
  45. template<bool Core> struct TPassType { };
  46. template<> struct TPassType < false > { typedef Pass Type; };
  47. template<> struct TPassType < true > { typedef PassCore Type; };
  48. typedef typename TPassType<Core>::Type PassType;
  49. TTechnique();
  50. TTechnique(const StringID& renderAPI, const StringID& renderer, const Vector<SPtr<PassType>>& passes);
  51. virtual ~TTechnique() { }
  52. /** Returns a pass with the specified index. */
  53. SPtr<PassType> getPass(UINT32 idx) const;
  54. /** Returns total number of passes. */
  55. UINT32 getNumPasses() const { return (UINT32)mPasses.size(); }
  56. protected:
  57. Vector<SPtr<PassType>> mPasses;
  58. };
  59. /** @} */
  60. /** @addtogroup Material
  61. * @{
  62. */
  63. /** @cond INTERNAL */
  64. /**
  65. * @copydoc TechniqueBase
  66. *
  67. * @note Core thread.
  68. */
  69. class BS_CORE_EXPORT TechniqueCore : public CoreObjectCore, public TTechnique<true>
  70. {
  71. public:
  72. TechniqueCore(const StringID& renderAPI, const StringID& renderer, const Vector<SPtr<PassCore>>& passes);
  73. /** Creates a new technique. */
  74. static SPtr<TechniqueCore> create(const StringID& renderAPI, const StringID& renderer, const Vector<SPtr<PassCore>>& passes);
  75. };
  76. /** @endcond */
  77. /**
  78. * @copydoc TechniqueBase
  79. *
  80. * @note Sim thread.
  81. */
  82. class BS_CORE_EXPORT Technique : public IReflectable, public CoreObject, public TTechnique<false>
  83. {
  84. public:
  85. Technique(const StringID& renderAPI, const StringID& renderer, const Vector<SPtr<Pass>>& passes);
  86. /** Retrieves an implementation of a technique usable only from the core thread. */
  87. SPtr<TechniqueCore> getCore() const;
  88. /** Creates a new technique. */
  89. static TechniquePtr create(const StringID& renderAPI, const StringID& renderer, const Vector<SPtr<Pass>>& passes);
  90. protected:
  91. /** @copydoc CoreObject::createCore */
  92. SPtr<CoreObjectCore> createCore() const override;
  93. /** @copydoc CoreObject::getCoreDependencies */
  94. void getCoreDependencies(Vector<CoreObject*>& dependencies) override;
  95. /** Creates a new technique but doesn't initialize it. */
  96. static TechniquePtr createEmpty();
  97. private:
  98. /************************************************************************/
  99. /* RTTI */
  100. /************************************************************************/
  101. /** Serialization only constructor. */
  102. Technique();
  103. public:
  104. friend class TechniqueRTTI;
  105. static RTTITypeBase* getRTTIStatic();
  106. virtual RTTITypeBase* getRTTI() const override;
  107. };
  108. /** @} */
  109. }