BsRenderBeast.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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 bs
  15. {
  16. struct RendererAnimationData;
  17. namespace ct
  18. {
  19. /** @addtogroup RenderBeast
  20. * @{
  21. */
  22. /** Semantics that may be used for signaling the renderer for what is a certain shader parameter used for. */
  23. static StringID RPS_GBufferA = "GBufferA";
  24. static StringID RPS_GBufferB = "GBufferB";
  25. static StringID RPS_GBufferDepth = "GBufferDepth";
  26. static StringID RPS_BoneMatrices = "BoneMatrices";
  27. /**
  28. * Default renderer for Banshee. Performs frustum culling, sorting and renders all scene objects while applying
  29. * lighting, shadowing, special effects and post-processing.
  30. *
  31. * @note Sim thread unless otherwise noted.
  32. */
  33. class RenderBeast : public Renderer
  34. {
  35. /** Renderer information specific to a single render target. */
  36. struct RendererRenderTarget
  37. {
  38. SPtr<RenderTarget> target;
  39. Vector<const Camera*> cameras;
  40. };
  41. /** Renderer information for a single material. */
  42. struct RendererMaterial
  43. {
  44. Vector<SPtr<GpuParamsSet>> params;
  45. UINT32 matVersion;
  46. };
  47. /** Contains information global to an entire frame. */
  48. struct FrameInfo
  49. {
  50. FrameInfo(float timeDelta, const RendererAnimationData& animData)
  51. :timeDelta(timeDelta), animData(animData)
  52. { }
  53. float timeDelta;
  54. const RendererAnimationData& animData;
  55. };
  56. public:
  57. RenderBeast();
  58. ~RenderBeast() { }
  59. /** @copydoc Renderer::getName */
  60. const StringID& getName() const override;
  61. /** @copydoc Renderer::renderAll */
  62. void renderAll() override;
  63. /** Sets options used for controlling the rendering. */
  64. void setOptions(const SPtr<CoreRendererOptions>& options) override;
  65. /** Returns current set of options used for controlling the rendering. */
  66. SPtr<CoreRendererOptions> getOptions() const override;
  67. /** @copydoc Renderer::initialize */
  68. void initialize() override;
  69. /** @copydoc Renderer::destroy */
  70. void destroy() override;
  71. /** @copydoc Renderer::createPostProcessSettings */
  72. SPtr<PostProcessSettings> createPostProcessSettings() const override;
  73. private:
  74. /** @copydoc Renderer::notifyCameraAdded */
  75. void notifyCameraAdded(const Camera* camera) override;
  76. /** @copydoc Renderer::notifyCameraUpdated */
  77. void notifyCameraUpdated(const Camera* camera, UINT32 updateFlag) override;
  78. /** @copydocRenderer::notifyCameraRemoved */
  79. void notifyCameraRemoved(const Camera* camera) override;
  80. /** @copydoc Renderer::notifyLightAdded */
  81. void notifyLightAdded(Light* light) override;
  82. /** @copydoc Renderer::notifyLightUpdated */
  83. void notifyLightUpdated(Light* light) override;
  84. /** @copydoc Renderer::notifyLightRemoved */
  85. void notifyLightRemoved(Light* light) override;
  86. /** @copydoc Renderer::notifyRenderableAdded */
  87. void notifyRenderableAdded(Renderable* renderable) override;
  88. /** @copydoc Renderer::notifyRenderableUpdated */
  89. void notifyRenderableUpdated(Renderable* renderable) override;
  90. /** @copydoc Renderer::notifyRenderableRemoved */
  91. void notifyRenderableRemoved(Renderable* renderable) override;
  92. /**
  93. * Updates (or adds) renderer specific data for the specified camera. Should be called whenever camera properties
  94. * change.
  95. *
  96. * @param[in] camera Camera whose data to update.
  97. * @param[in] forceRemove If true, the camera data will be removed instead of updated.
  98. * @return Renderer camera object that represents the camera. Null if camera was removed.
  99. */
  100. RendererCamera* updateCameraData(const Camera* camera, bool forceRemove = false);
  101. /**
  102. * Updates the render options on the core thread.
  103. *
  104. * @note Core thread only.
  105. */
  106. void syncOptions(const RenderBeastOptions& options);
  107. /**
  108. * Performs rendering over all camera proxies.
  109. *
  110. * @param[in] time Current frame time in milliseconds.
  111. * @param[in] delta Time elapsed since the last frame.
  112. *
  113. * @note Core thread only.
  114. */
  115. void renderAllCore(float time, float delta);
  116. /**
  117. * Renders all provided views.
  118. *
  119. * @note Core thread only.
  120. */
  121. void renderViews(RendererCamera** views, UINT32 numViews, const FrameInfo& frameInfo);
  122. /**
  123. * Renders all objects visible by the provided view.
  124. *
  125. * @note Core thread only.
  126. */
  127. void renderView(RendererCamera* viewInfo, float frameDelta);
  128. /**
  129. * Renders all overlay callbacks of the provided view.
  130. *
  131. * @note Core thread only.
  132. */
  133. void renderOverlay(RendererCamera* viewInfo);
  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] viewProj View projection matrix of the camera the element is being rendered with.
  142. */
  143. void renderElement(const BeastRenderableElement& element, UINT32 passIdx, bool bindPass, const Matrix4& viewProj);
  144. /**
  145. * Captures the scene at the specified location into a cubemap.
  146. *
  147. * @param[in] position Position to capture the scene at.
  148. * @param[in] hdr If true scene will be captured in a format that supports high dynamic range.
  149. * @param[in] size Cubemap face width/height in pixels.
  150. * @param[in] frameInfo Global information about the the frame currently being rendered.
  151. */
  152. SPtr<Texture> captureSceneCubeMap(const Vector3& position, bool hdr, UINT32 size, const FrameInfo& frameInfo);
  153. /** Creates data used by the renderer on the core thread. */
  154. void initializeCore();
  155. /** Destroys data used by the renderer on the core thread. */
  156. void destroyCore();
  157. /**
  158. * Checks all sampler overrides in case material sampler states changed, and updates them.
  159. *
  160. * @param[in] force If true, all sampler overrides will be updated, regardless of a change in the material
  161. * was detected or not.
  162. */
  163. void refreshSamplerOverrides(bool force = false);
  164. // Core thread only fields
  165. Vector<RendererRenderTarget> mRenderTargets;
  166. UnorderedMap<const Camera*, RendererCamera*> mCameras;
  167. UnorderedMap<SamplerOverrideKey, MaterialSamplerOverrides*> mSamplerOverrides;
  168. Vector<RendererObject*> mRenderables;
  169. Vector<CullInfo> mRenderableCullInfos;
  170. Vector<bool> mRenderableVisibility; // Transient
  171. Vector<RendererLight> mDirectionalLights;
  172. Vector<RendererLight> mRadialLights;
  173. Vector<RendererLight> mSpotLights;
  174. Vector<Sphere> mPointLightWorldBounds;
  175. Vector<Sphere> mSpotLightWorldBounds;
  176. SPtr<RenderBeastOptions> mCoreOptions;
  177. DefaultMaterial* mDefaultMaterial;
  178. TiledDeferredLightingMat* mTiledDeferredLightingMat;
  179. SkyboxMat* mSkyboxMat;
  180. ObjectRenderer* mObjectRenderer;
  181. // Sim thread only fields
  182. SPtr<RenderBeastOptions> mOptions;
  183. bool mOptionsDirty;
  184. // Helpers to avoid memory allocations
  185. Vector<LightData> mLightDataTemp;
  186. Vector<bool> mLightVisibilityTemp;
  187. };
  188. /** @} */
  189. }}