BsRenderBeast.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. /** @copydoc Renderer::createPostProcessSettings */
  73. SPtr<PostProcessSettings> createPostProcessSettings() const override;
  74. private:
  75. /** @copydoc Renderer::notifyCameraAdded */
  76. void notifyCameraAdded(const CameraCore* camera) override;
  77. /** @copydoc Renderer::notifyCameraUpdated */
  78. void notifyCameraUpdated(const CameraCore* camera, UINT32 updateFlag) override;
  79. /** @copydocRenderer::notifyCameraRemoved */
  80. void notifyCameraRemoved(const CameraCore* camera) override;
  81. /** @copydoc Renderer::notifyLightAdded */
  82. void notifyLightAdded(LightCore* light) override;
  83. /** @copydoc Renderer::notifyLightUpdated */
  84. void notifyLightUpdated(LightCore* light) override;
  85. /** @copydoc Renderer::notifyLightRemoved */
  86. void notifyLightRemoved(LightCore* light) override;
  87. /** @copydoc Renderer::notifyRenderableAdded */
  88. void notifyRenderableAdded(RenderableCore* renderable) override;
  89. /** @copydoc Renderer::notifyRenderableUpdated */
  90. void notifyRenderableUpdated(RenderableCore* renderable) override;
  91. /** @copydoc Renderer::notifyRenderableRemoved */
  92. void notifyRenderableRemoved(RenderableCore* renderable) override;
  93. /**
  94. * Updates (or adds) renderer specific data for the specified camera. Should be called whenever camera properties
  95. * change.
  96. *
  97. * @param[in] camera Camera whose data to update.
  98. * @param[in] forceRemove If true, the camera data will be removed instead of updated.
  99. */
  100. void updateCameraData(const CameraCore* 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 objects visible by the provided camera.
  118. *
  119. * @param[in] frameInfo Renderer information specific to this frame.
  120. * @param[in] rtInfo Render target information containing the camera to render.
  121. * @param[in] camIdx Index of the camera to render.
  122. *
  123. * @note Core thread only.
  124. */
  125. void render(const RendererFrame& frameInfo, RendererRenderTarget& rtInfo, UINT32 camIdx);
  126. /**
  127. * Renders all overlay callbacks attached to the provided camera.
  128. *
  129. * @param[in] frameInfo Renderer information specific to this frame.
  130. * @param[in] rtInfo Render target information containing the camera to render.
  131. * @param[in] camIdx Index of the camera to render.
  132. *
  133. * @note Core thread only.
  134. */
  135. void renderOverlay(const RendererFrame& frameInfo, RendererRenderTarget& rtInfo, UINT32 camIdx);
  136. /**
  137. * Renders a single element of a renderable object.
  138. *
  139. * @param[in] element Element to render.
  140. * @param[in] passIdx Index of the material pass to render the element with.
  141. * @param[in] bindPass If true the material pass will be bound for rendering, if false it is assumed it is
  142. * already bound.
  143. * @param[in] frameInfo Renderer information specific to this frame.
  144. * @param[in] viewProj View projection matrix of the camera the element is being rendered with.
  145. */
  146. void renderElement(const BeastRenderableElement& element, UINT32 passIdx, bool bindPass,
  147. const RendererFrame& frameInfo, const Matrix4& viewProj);
  148. /** Creates data used by the renderer on the core thread. */
  149. void initializeCore();
  150. /** Destroys data used by the renderer on the core thread. */
  151. void destroyCore();
  152. /**
  153. * Checks all sampler overrides in case material sampler states changed, and updates them.
  154. *
  155. * @param[in] force If true, all sampler overrides will be updated, regardless of a change in the material
  156. * was detected or not.
  157. */
  158. void refreshSamplerOverrides(bool force = false);
  159. // Core thread only fields
  160. Vector<RendererRenderTarget> mRenderTargets;
  161. UnorderedMap<const CameraCore*, RendererCamera> mCameras;
  162. UnorderedMap<SamplerOverrideKey, MaterialSamplerOverrides*> mSamplerOverrides;
  163. Vector<RendererObject> mRenderables;
  164. Vector<RenderableShaderData> mRenderableShaderData;
  165. Vector<Bounds> mWorldBounds;
  166. Vector<bool> mVisibility; // Transient
  167. Vector<RendererLight> mDirectionalLights;
  168. Vector<RendererLight> mPointLights;
  169. Vector<Sphere> mLightWorldBounds;
  170. SPtr<RenderBeastOptions> mCoreOptions;
  171. DefaultMaterial* mDefaultMaterial;
  172. PointLightInMat* mPointLightInMat;
  173. PointLightOutMat* mPointLightOutMat;
  174. DirectionalLightMat* mDirLightMat;
  175. ObjectRenderer* mObjectRenderer;
  176. // Sim thread only fields
  177. SPtr<RenderBeastOptions> mOptions;
  178. bool mOptionsDirty;
  179. };
  180. /** @} */
  181. }