BsPass.h 6.4 KB

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