BsPass.h 6.2 KB

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