BsRenderBeast.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsRenderBeastPrerequisites.h"
  5. #include "BsRenderer.h"
  6. #include "BsBounds.h"
  7. #include "BsSamplerOverrides.h"
  8. #include "BsRendererMaterial.h"
  9. #include "BsLightRendering.h"
  10. #include "BsObjectRendering.h"
  11. #include "BsPostProcessing.h"
  12. #include "BsRendererCamera.h"
  13. #include "BsRendererObject.h"
  14. namespace BansheeEngine
  15. {
  16. /** @addtogroup RenderBeast
  17. * @{
  18. */
  19. struct RendererAnimationData;
  20. /** Semantics that may be used for signaling the renderer for what is a certain shader parameter used for. */
  21. static StringID RPS_GBufferA = "GBufferA";
  22. static StringID RPS_GBufferB = "GBufferB";
  23. static StringID RPS_GBufferDepth = "GBufferDepth";
  24. static StringID RPS_BoneMatrices = "BoneMatrices";
  25. /**
  26. * Default renderer for Banshee. Performs frustum culling, sorting and renders objects in custom ways determine by
  27. * renderable handlers.
  28. *
  29. * @note Sim thread unless otherwise noted.
  30. */
  31. class RenderBeast : public Renderer
  32. {
  33. /** Renderer information specific to a single frame. */
  34. struct RendererFrame
  35. {
  36. RendererFrame(float delta, const RendererAnimationData& animData);
  37. float delta;
  38. const RendererAnimationData& animData;
  39. };
  40. /** Renderer information specific to a single render target. */
  41. struct RendererRenderTarget
  42. {
  43. SPtr<RenderTargetCore> target;
  44. Vector<const CameraCore*> cameras;
  45. };
  46. /** Renderer information specific to a single light. */
  47. struct RendererLight
  48. {
  49. LightCore* internal;
  50. };
  51. /** Renderer information for a single material. */
  52. struct RendererMaterial
  53. {
  54. Vector<SPtr<GpuParamsSetCore>> params;
  55. UINT32 matVersion;
  56. };
  57. public:
  58. RenderBeast();
  59. ~RenderBeast() { }
  60. /** @copydoc Renderer::getName */
  61. const StringID& getName() const override;
  62. /** @copydoc Renderer::renderAll */
  63. void renderAll() override;
  64. /** Sets options used for controlling the rendering. */
  65. void setOptions(const SPtr<CoreRendererOptions>& options) override;
  66. /** Returns current set of options used for controlling the rendering. */
  67. SPtr<CoreRendererOptions> getOptions() const override;
  68. /** @copydoc Renderer::initialize */
  69. void initialize() override;
  70. /** @copydoc Renderer::destroy */
  71. void destroy() override;
  72. private:
  73. /** @copydoc Renderer::notifyCameraAdded */
  74. void notifyCameraAdded(const CameraCore* camera) override;
  75. /** @copydoc Renderer::notifyCameraUpdated */
  76. void notifyCameraUpdated(const CameraCore* camera, UINT32 updateFlag) override;
  77. /** @copydocRenderer::notifyCameraRemoved */
  78. void notifyCameraRemoved(const CameraCore* camera) override;
  79. /** @copydoc Renderer::notifyLightAdded */
  80. void notifyLightAdded(LightCore* light) override;
  81. /** @copydoc Renderer::notifyLightUpdated */
  82. void notifyLightUpdated(LightCore* light) override;
  83. /** @copydoc Renderer::notifyLightRemoved */
  84. void notifyLightRemoved(LightCore* light) override;
  85. /** @copydoc Renderer::notifyRenderableAdded */
  86. void notifyRenderableAdded(RenderableCore* renderable) override;
  87. /** @copydoc Renderer::notifyRenderableUpdated */
  88. void notifyRenderableUpdated(RenderableCore* renderable) override;
  89. /** @copydoc Renderer::notifyRenderableRemoved */
  90. void notifyRenderableRemoved(RenderableCore* renderable) override;
  91. /**
  92. * Updates (or adds) renderer specific data for the specified camera. Should be called whenever camera properties
  93. * change.
  94. *
  95. * @param[in] camera Camera whose data to update.
  96. * @param[in] forceRemove If true, the camera data will be removed instead of updated.
  97. */
  98. void updateCameraData(const CameraCore* camera, bool forceRemove = false);
  99. /**
  100. * Updates the render options on the core thread.
  101. *
  102. * @note Core thread only.
  103. */
  104. void syncOptions(const RenderBeastOptions& options);
  105. /**
  106. * Performs rendering over all camera proxies.
  107. *
  108. * @param[in] time Current frame time in milliseconds.
  109. * @param[in] delta Time elapsed since the last frame.
  110. *
  111. * @note Core thread only.
  112. */
  113. void renderAllCore(float time, float delta);
  114. /**
  115. * Renders all objects visible by the provided camera.
  116. *
  117. * @param[in] frameInfo Renderer information specific to this frame.
  118. * @param[in] rtInfo Render target information containing the camera to render.
  119. * @param[in] camIdx Index of the camera to render.
  120. *
  121. * @note Core thread only.
  122. */
  123. void render(const RendererFrame& frameInfo, RendererRenderTarget& rtInfo, UINT32 camIdx);
  124. /**
  125. * Renders all overlay callbacks attached to the provided camera.
  126. *
  127. * @param[in] frameInfo Renderer information specific to this frame.
  128. * @param[in] rtInfo Render target information containing the camera to render.
  129. * @param[in] camIdx Index of the camera to render.
  130. *
  131. * @note Core thread only.
  132. */
  133. void renderOverlay(const RendererFrame& frameInfo, RendererRenderTarget& rtInfo, UINT32 camIdx);
  134. /**
  135. * Renders a single element of a renderable object.
  136. *
  137. * @param[in] element Element to render.
  138. * @param[in] passIdx Index of the material pass to render the element with.
  139. * @param[in] bindPass If true the material pass will be bound for rendering, if false it is assumed it is
  140. * already bound.
  141. * @param[in] frameInfo Renderer information specific to this frame.
  142. * @param[in] viewProj View projection matrix of the camera the element is being rendered with.
  143. */
  144. void renderElement(const BeastRenderableElement& element, UINT32 passIdx, bool bindPass,
  145. const RendererFrame& frameInfo, const Matrix4& viewProj);
  146. /** Creates data used by the renderer on the core thread. */
  147. void initializeCore();
  148. /** Destroys data used by the renderer on the core thread. */
  149. void destroyCore();
  150. /**
  151. * Checks all sampler overrides in case material sampler states changed, and updates them.
  152. *
  153. * @param[in] force If true, all sampler overrides will be updated, regardless of a change in the material
  154. * was detected or not.
  155. */
  156. void refreshSamplerOverrides(bool force = false);
  157. /**
  158. * Sets parameters (textures, samplers, buffers) for the currently active pass.
  159. *
  160. * @param[in] paramsSet Structure containing parameters for a material.
  161. * @param[in] samplerOverrides Optional samplers to use instead of the those in the pass parameters. Number of
  162. * samplers must match number in pass parameters.
  163. * @param[in] passIdx Index of the pass whose parameters to bind.
  164. *
  165. * @note Core thread.
  166. */
  167. static void setPassParams(const SPtr<GpuParamsSetCore>& paramsSet, const MaterialSamplerOverrides* samplerOverrides,
  168. UINT32 passIdx);
  169. // Core thread only fields
  170. Vector<RendererRenderTarget> mRenderTargets;
  171. UnorderedMap<const CameraCore*, RendererCamera> mCameras;
  172. UnorderedMap<SPtr<MaterialCore>, MaterialSamplerOverrides*> mSamplerOverrides;
  173. Vector<RendererObject> mRenderables;
  174. Vector<RenderableShaderData> mRenderableShaderData;
  175. Vector<Bounds> mWorldBounds;
  176. Vector<RendererLight> mDirectionalLights;
  177. Vector<RendererLight> mPointLights;
  178. Vector<Sphere> mLightWorldBounds;
  179. SPtr<RenderBeastOptions> mCoreOptions;
  180. DefaultMaterial* mDefaultMaterial;
  181. PointLightInMat* mPointLightInMat;
  182. PointLightOutMat* mPointLightOutMat;
  183. DirectionalLightMat* mDirLightMat;
  184. ObjectRenderer* mObjectRenderer;
  185. // Sim thread only fields
  186. SPtr<RenderBeastOptions> mOptions;
  187. bool mOptionsDirty;
  188. };
  189. /** @} */
  190. }