BsPass.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsColor.h"
  4. #include "BsIReflectable.h"
  5. #include "BsCoreObject.h"
  6. namespace BansheeEngine
  7. {
  8. /** @addtogroup Material
  9. * @{
  10. */
  11. /** Descriptor structure used for initializing a shader pass. */
  12. struct PASS_DESC
  13. {
  14. BlendStatePtr blendState;
  15. RasterizerStatePtr rasterizerState;
  16. DepthStencilStatePtr depthStencilState;
  17. UINT32 stencilRefValue;
  18. GpuProgramPtr vertexProgram;
  19. GpuProgramPtr fragmentProgram;
  20. GpuProgramPtr geometryProgram;
  21. GpuProgramPtr hullProgram;
  22. GpuProgramPtr domainProgram;
  23. GpuProgramPtr computeProgram;
  24. };
  25. /** Descriptor structure used for initializing a core thread variant of a shader pass. */
  26. struct PASS_DESC_CORE
  27. {
  28. SPtr<BlendStateCore> blendState;
  29. SPtr<RasterizerStateCore> rasterizerState;
  30. SPtr<DepthStencilStateCore> depthStencilState;
  31. UINT32 stencilRefValue;
  32. SPtr<GpuProgramCore> vertexProgram;
  33. SPtr<GpuProgramCore> fragmentProgram;
  34. SPtr<GpuProgramCore> geometryProgram;
  35. SPtr<GpuProgramCore> hullProgram;
  36. SPtr<GpuProgramCore> domainProgram;
  37. SPtr<GpuProgramCore> computeProgram;
  38. };
  39. /** Contains all data used by a pass, templated so it may contain both core and sim thread data. */
  40. template<bool Core>
  41. struct TPassTypes
  42. { };
  43. template<>
  44. struct TPassTypes < false >
  45. {
  46. typedef BlendStatePtr BlendStateType;
  47. typedef RasterizerStatePtr RasterizerStateType;
  48. typedef DepthStencilStatePtr DepthStencilStateType;
  49. typedef GpuProgramPtr GpuProgramType;
  50. typedef PASS_DESC PassDescType;
  51. };
  52. template<>
  53. struct TPassTypes < true >
  54. {
  55. typedef SPtr<BlendStateCore> BlendStateType;
  56. typedef SPtr<RasterizerStateCore> RasterizerStateType;
  57. typedef SPtr<DepthStencilStateCore> DepthStencilStateType;
  58. typedef SPtr<GpuProgramCore> GpuProgramType;
  59. typedef PASS_DESC_CORE PassDescType;
  60. };
  61. /**
  62. * Class defining a single pass of a technique (of a material), i.e. a single rendering call.
  63. *
  64. * Pass may contain multiple GPU programs (vertex, fragment, geometry, etc.), and a set of pipeline states (blend,
  65. * rasterizer, etc.).
  66. *
  67. * @note Templated so it can be used for both core and non-core versions of a pass.
  68. */
  69. template<bool Core>
  70. class BS_CORE_EXPORT TPass
  71. {
  72. public:
  73. typedef typename TPassTypes<Core>::BlendStateType BlendStateType;
  74. typedef typename TPassTypes<Core>::RasterizerStateType RasterizerStateType;
  75. typedef typename TPassTypes<Core>::DepthStencilStateType DepthStencilStateType;
  76. typedef typename TPassTypes<Core>::GpuProgramType GpuProgramType;
  77. typedef typename TPassTypes<Core>::PassDescType PassDescType;
  78. virtual ~TPass() { }
  79. bool hasVertexProgram() const { return mData.vertexProgram != nullptr; }
  80. bool hasFragmentProgram() const { return mData.fragmentProgram != nullptr; }
  81. bool hasGeometryProgram() const { return mData.geometryProgram != nullptr; }
  82. bool hasHullProgram() const { return mData.hullProgram != nullptr; }
  83. bool hasDomainProgram() const { return mData.domainProgram != nullptr; }
  84. bool hasComputeProgram() const { return mData.computeProgram != nullptr; }
  85. /** Returns true if this pass has some element of transparency. */
  86. bool hasBlending() const;
  87. BlendStateType getBlendState() const { return mData.blendState; }
  88. RasterizerStateType getRasterizerState() const { return mData.rasterizerState; }
  89. DepthStencilStateType getDepthStencilState() const { return mData.depthStencilState; }
  90. /** Gets the stencil reference value that is used when performing operations using the stencil buffer. */
  91. UINT32 getStencilRefValue() const { return mData.stencilRefValue; }
  92. const GpuProgramType& getVertexProgram() const { return mData.vertexProgram; }
  93. const GpuProgramType& getFragmentProgram() const { return mData.fragmentProgram; }
  94. const GpuProgramType& getGeometryProgram() const { return mData.geometryProgram; }
  95. const GpuProgramType& getHullProgram(void) const { return mData.hullProgram; }
  96. const GpuProgramType& getDomainProgram(void) const { return mData.domainProgram; }
  97. const GpuProgramType& getComputeProgram(void) const { return mData.computeProgram; }
  98. protected:
  99. TPass();
  100. TPass(const PassDescType& desc);
  101. PassDescType mData;
  102. };
  103. /**
  104. * @copydoc PassBase
  105. *
  106. * @note Core thread.
  107. */
  108. class BS_CORE_EXPORT PassCore : public CoreObjectCore, public TPass<true>
  109. {
  110. public:
  111. virtual ~PassCore() { }
  112. /** Creates a new empty pass. */
  113. static SPtr<PassCore> create(const PASS_DESC_CORE& desc);
  114. protected:
  115. friend class Pass;
  116. friend class TechniqueCore;
  117. PassCore() { }
  118. PassCore(const PASS_DESC_CORE& desc);
  119. /** @copydoc CoreObjectCore::syncToCore */
  120. void syncToCore(const CoreSyncData& data) override;
  121. };
  122. /**
  123. * @copydoc PassBase
  124. *
  125. * @note Sim thread.
  126. */
  127. class BS_CORE_EXPORT Pass : public IReflectable, public CoreObject, public TPass<false>
  128. {
  129. public:
  130. virtual ~Pass() { }
  131. /** Retrieves an implementation of a pass usable only from the core thread. */
  132. SPtr<PassCore> getCore() const;
  133. /** Creates a new empty pass. */
  134. static PassPtr create(const PASS_DESC& desc);
  135. protected:
  136. friend class Technique;
  137. Pass() { }
  138. Pass(const PASS_DESC& desc);
  139. /** @copydoc CoreObject::syncToCore */
  140. CoreSyncData syncToCore(FrameAlloc* allocator) override;
  141. /** @copydoc CoreObject::createCore */
  142. SPtr<CoreObjectCore> createCore() const override;
  143. /** @copydoc CoreObject::syncToCore */
  144. void getCoreDependencies(Vector<CoreObject*>& dependencies) override;
  145. /** Creates a new empty pass but doesn't initialize it. */
  146. static PassPtr createEmpty();
  147. /************************************************************************/
  148. /* RTTI */
  149. /************************************************************************/
  150. public:
  151. friend class PassRTTI;
  152. static RTTITypeBase* getRTTIStatic();
  153. virtual RTTITypeBase* getRTTI() const override;
  154. };
  155. /** @} */
  156. }