BsRenderBeast.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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 specific to a single light. */
  42. struct RendererLight
  43. {
  44. Light* internal;
  45. };
  46. /** Renderer information for a single material. */
  47. struct RendererMaterial
  48. {
  49. Vector<SPtr<GpuParamsSet>> params;
  50. UINT32 matVersion;
  51. };
  52. /** Contains information global to an entire frame. */
  53. struct FrameInfo
  54. {
  55. FrameInfo(float timeDelta, const RendererAnimationData& animData)
  56. :timeDelta(timeDelta), animData(animData)
  57. { }
  58. float timeDelta;
  59. const RendererAnimationData& animData;
  60. };
  61. public:
  62. RenderBeast();
  63. ~RenderBeast() { }
  64. /** @copydoc Renderer::getName */
  65. const StringID& getName() const override;
  66. /** @copydoc Renderer::renderAll */
  67. void renderAll() override;
  68. /** Sets options used for controlling the rendering. */
  69. void setOptions(const SPtr<CoreRendererOptions>& options) override;
  70. /** Returns current set of options used for controlling the rendering. */
  71. SPtr<CoreRendererOptions> getOptions() const override;
  72. /** @copydoc Renderer::initialize */
  73. void initialize() override;
  74. /** @copydoc Renderer::destroy */
  75. void destroy() override;
  76. /** @copydoc Renderer::createPostProcessSettings */
  77. SPtr<PostProcessSettings> createPostProcessSettings() const override;
  78. private:
  79. /** @copydoc Renderer::notifyCameraAdded */
  80. void notifyCameraAdded(const Camera* camera) override;
  81. /** @copydoc Renderer::notifyCameraUpdated */
  82. void notifyCameraUpdated(const Camera* camera, UINT32 updateFlag) override;
  83. /** @copydocRenderer::notifyCameraRemoved */
  84. void notifyCameraRemoved(const Camera* camera) override;
  85. /** @copydoc Renderer::notifyLightAdded */
  86. void notifyLightAdded(Light* light) override;
  87. /** @copydoc Renderer::notifyLightUpdated */
  88. void notifyLightUpdated(Light* light) override;
  89. /** @copydoc Renderer::notifyLightRemoved */
  90. void notifyLightRemoved(Light* light) override;
  91. /** @copydoc Renderer::notifyRenderableAdded */
  92. void notifyRenderableAdded(Renderable* renderable) override;
  93. /** @copydoc Renderer::notifyRenderableUpdated */
  94. void notifyRenderableUpdated(Renderable* renderable) override;
  95. /** @copydoc Renderer::notifyRenderableRemoved */
  96. void notifyRenderableRemoved(Renderable* renderable) override;
  97. /**
  98. * Updates (or adds) renderer specific data for the specified camera. Should be called whenever camera properties
  99. * change.
  100. *
  101. * @param[in] camera Camera whose data to update.
  102. * @param[in] forceRemove If true, the camera data will be removed instead of updated.
  103. * @return Renderer camera object that represents the camera. Null if camera was removed.
  104. */
  105. RendererCamera* updateCameraData(const Camera* camera, bool forceRemove = false);
  106. /**
  107. * Updates the render options on the core thread.
  108. *
  109. * @note Core thread only.
  110. */
  111. void syncOptions(const RenderBeastOptions& options);
  112. /**
  113. * Performs rendering over all camera proxies.
  114. *
  115. * @param[in] time Current frame time in milliseconds.
  116. * @param[in] delta Time elapsed since the last frame.
  117. *
  118. * @note Core thread only.
  119. */
  120. void renderAllCore(float time, float delta);
  121. /**
  122. * Renders all provided views.
  123. *
  124. * @note Core thread only.
  125. */
  126. void renderViews(RendererCamera** views, UINT32 numViews, const FrameInfo& frameInfo);
  127. /**
  128. * Renders all objects visible by the provided view.
  129. *
  130. * @note Core thread only.
  131. */
  132. void renderView(RendererCamera* viewInfo, float frameDelta);
  133. /**
  134. * Renders all overlay callbacks of the provided view.
  135. *
  136. * @note Core thread only.
  137. */
  138. void renderOverlay(RendererCamera* viewInfo);
  139. /**
  140. * Renders a single element of a renderable object.
  141. *
  142. * @param[in] element Element to render.
  143. * @param[in] passIdx Index of the material pass to render the element with.
  144. * @param[in] bindPass If true the material pass will be bound for rendering, if false it is assumed it is
  145. * already bound.
  146. * @param[in] viewProj View projection matrix of the camera the element is being rendered with.
  147. */
  148. void renderElement(const BeastRenderableElement& element, UINT32 passIdx, bool bindPass, const Matrix4& viewProj);
  149. /**
  150. * Captures the scene at the specified location into a cubemap.
  151. *
  152. * @param[in] position Position to capture the scene at.
  153. * @param[in] hdr If true scene will be captured in a format that supports high dynamic range.
  154. * @param[in] size Cubemap face width/height in pixels.
  155. * @param[in] frameInfo Global information about the the frame currently being rendered.
  156. */
  157. SPtr<Texture> captureSceneCubeMap(const Vector3& position, bool hdr, UINT32 size, const FrameInfo& frameInfo);
  158. /** Creates data used by the renderer on the core thread. */
  159. void initializeCore();
  160. /** Destroys data used by the renderer on the core thread. */
  161. void destroyCore();
  162. /**
  163. * Checks all sampler overrides in case material sampler states changed, and updates them.
  164. *
  165. * @param[in] force If true, all sampler overrides will be updated, regardless of a change in the material
  166. * was detected or not.
  167. */
  168. void refreshSamplerOverrides(bool force = false);
  169. // Core thread only fields
  170. Vector<RendererRenderTarget> mRenderTargets;
  171. UnorderedMap<const Camera*, RendererCamera*> mCameras;
  172. UnorderedMap<SamplerOverrideKey, MaterialSamplerOverrides*> mSamplerOverrides;
  173. Vector<RendererObject*> mRenderables;
  174. Vector<CullInfo> mRenderableCullInfos;
  175. Vector<bool> mRenderableVisibility; // Transient
  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. SkyboxMat* mSkyboxMat;
  185. ObjectRenderer* mObjectRenderer;
  186. // Sim thread only fields
  187. SPtr<RenderBeastOptions> mOptions;
  188. bool mOptionsDirty;
  189. };
  190. /** @} */
  191. }}