BsRenderBeast.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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 objects in custom ways determine by
  29. * renderable handlers.
  30. *
  31. * @note Sim thread unless otherwise noted.
  32. */
  33. class RenderBeast : public Renderer
  34. {
  35. /** Renderer information specific to a single frame. */
  36. struct RendererFrame
  37. {
  38. RendererFrame(float delta, const RendererAnimationData& animData);
  39. float delta;
  40. const RendererAnimationData& animData;
  41. };
  42. /** Renderer information specific to a single render target. */
  43. struct RendererRenderTarget
  44. {
  45. SPtr<RenderTarget> target;
  46. Vector<const Camera*> cameras;
  47. };
  48. /** Renderer information specific to a single light. */
  49. struct RendererLight
  50. {
  51. Light* internal;
  52. };
  53. /** Renderer information for a single material. */
  54. struct RendererMaterial
  55. {
  56. Vector<SPtr<GpuParamsSet>> params;
  57. UINT32 matVersion;
  58. };
  59. public:
  60. RenderBeast();
  61. ~RenderBeast() { }
  62. /** @copydoc Renderer::getName */
  63. const StringID& getName() const override;
  64. /** @copydoc Renderer::renderAll */
  65. void renderAll() override;
  66. /** Sets options used for controlling the rendering. */
  67. void setOptions(const SPtr<CoreRendererOptions>& options) override;
  68. /** Returns current set of options used for controlling the rendering. */
  69. SPtr<CoreRendererOptions> getOptions() const override;
  70. /** @copydoc Renderer::initialize */
  71. void initialize() override;
  72. /** @copydoc Renderer::destroy */
  73. void destroy() override;
  74. /** @copydoc Renderer::createPostProcessSettings */
  75. SPtr<PostProcessSettings> createPostProcessSettings() const override;
  76. private:
  77. /** @copydoc Renderer::notifyCameraAdded */
  78. void notifyCameraAdded(const Camera* camera) override;
  79. /** @copydoc Renderer::notifyCameraUpdated */
  80. void notifyCameraUpdated(const Camera* camera, UINT32 updateFlag) override;
  81. /** @copydocRenderer::notifyCameraRemoved */
  82. void notifyCameraRemoved(const Camera* camera) override;
  83. /** @copydoc Renderer::notifyLightAdded */
  84. void notifyLightAdded(Light* light) override;
  85. /** @copydoc Renderer::notifyLightUpdated */
  86. void notifyLightUpdated(Light* light) override;
  87. /** @copydoc Renderer::notifyLightRemoved */
  88. void notifyLightRemoved(Light* light) override;
  89. /** @copydoc Renderer::notifyRenderableAdded */
  90. void notifyRenderableAdded(Renderable* renderable) override;
  91. /** @copydoc Renderer::notifyRenderableUpdated */
  92. void notifyRenderableUpdated(Renderable* renderable) override;
  93. /** @copydoc Renderer::notifyRenderableRemoved */
  94. void notifyRenderableRemoved(Renderable* renderable) override;
  95. /**
  96. * Updates (or adds) renderer specific data for the specified camera. Should be called whenever camera properties
  97. * change.
  98. *
  99. * @param[in] camera Camera whose data to update.
  100. * @param[in] forceRemove If true, the camera data will be removed instead of updated.
  101. * @return Renderer camera object that represents the camera. Null if camera was removed.
  102. */
  103. RendererCamera* updateCameraData(const Camera* camera, bool forceRemove = false);
  104. /**
  105. * Updates the render options on the core thread.
  106. *
  107. * @note Core thread only.
  108. */
  109. void syncOptions(const RenderBeastOptions& options);
  110. /**
  111. * Performs rendering over all camera proxies.
  112. *
  113. * @param[in] time Current frame time in milliseconds.
  114. * @param[in] delta Time elapsed since the last frame.
  115. *
  116. * @note Core thread only.
  117. */
  118. void renderAllCore(float time, float delta);
  119. /**
  120. * Renders all objects visible by the provided camera.
  121. *
  122. * @param[in] frameInfo Renderer information specific to this frame.
  123. * @param[in] rtInfo Render target information containing the camera to render.
  124. * @param[in] camIdx Index of the camera to render.
  125. *
  126. * @note Core thread only.
  127. */
  128. void render(const RendererFrame& frameInfo, RendererRenderTarget& rtInfo, UINT32 camIdx);
  129. /**
  130. * Renders all overlay callbacks attached to the provided camera.
  131. *
  132. * @param[in] frameInfo Renderer information specific to this frame.
  133. * @param[in] rtInfo Render target information containing the camera to render.
  134. * @param[in] camIdx Index of the camera to render.
  135. *
  136. * @note Core thread only.
  137. */
  138. void renderOverlay(const RendererFrame& frameInfo, RendererRenderTarget& rtInfo, UINT32 camIdx);
  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] frameInfo Renderer information specific to this frame.
  147. * @param[in] viewProj View projection matrix of the camera the element is being rendered with.
  148. */
  149. void renderElement(const BeastRenderableElement& element, UINT32 passIdx, bool bindPass,
  150. const RendererFrame& frameInfo, const Matrix4& viewProj);
  151. /** Creates data used by the renderer on the core thread. */
  152. void initializeCore();
  153. /** Destroys data used by the renderer on the core thread. */
  154. void destroyCore();
  155. /**
  156. * Checks all sampler overrides in case material sampler states changed, and updates them.
  157. *
  158. * @param[in] force If true, all sampler overrides will be updated, regardless of a change in the material
  159. * was detected or not.
  160. */
  161. void refreshSamplerOverrides(bool force = false);
  162. // Core thread only fields
  163. Vector<RendererRenderTarget> mRenderTargets;
  164. UnorderedMap<const Camera*, RendererCamera*> mCameras;
  165. UnorderedMap<SamplerOverrideKey, MaterialSamplerOverrides*> mSamplerOverrides;
  166. Vector<RendererObject*> mRenderables;
  167. Vector<Bounds> mWorldBounds;
  168. Vector<bool> mVisibility; // Transient
  169. Vector<RendererLight> mDirectionalLights;
  170. Vector<RendererLight> mPointLights;
  171. Vector<Sphere> mLightWorldBounds;
  172. SPtr<RenderBeastOptions> mCoreOptions;
  173. DefaultMaterial* mDefaultMaterial;
  174. PointLightInMat* mPointLightInMat;
  175. PointLightOutMat* mPointLightOutMat;
  176. DirectionalLightMat* mDirLightMat;
  177. SkyboxMat* mSkyboxMat;
  178. ObjectRenderer* mObjectRenderer;
  179. // Sim thread only fields
  180. SPtr<RenderBeastOptions> mOptions;
  181. bool mOptionsDirty;
  182. };
  183. /** @} */
  184. }}