BsRenderBeast.h 7.5 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. public:
  52. RenderBeast();
  53. ~RenderBeast() { }
  54. /** @copydoc Renderer::getName */
  55. const StringID& getName() const override;
  56. /** @copydoc Renderer::renderAll */
  57. void renderAll() override;
  58. /** Sets options used for controlling the rendering. */
  59. void setOptions(const SPtr<CoreRendererOptions>& options) override;
  60. /** Returns current set of options used for controlling the rendering. */
  61. SPtr<CoreRendererOptions> getOptions() const override;
  62. /** @copydoc Renderer::initialize */
  63. void initialize() override;
  64. /** @copydoc Renderer::destroy */
  65. void destroy() override;
  66. private:
  67. /** @copydoc Renderer::notifyCameraAdded */
  68. void notifyCameraAdded(const CameraCore* camera) override;
  69. /** @copydoc Renderer::notifyCameraUpdated */
  70. void notifyCameraUpdated(const CameraCore* camera, UINT32 updateFlag) override;
  71. /** @copydocRenderer::notifyCameraRemoved */
  72. void notifyCameraRemoved(const CameraCore* camera) override;
  73. /** @copydoc Renderer::notifyLightAdded */
  74. void notifyLightAdded(LightCore* light) override;
  75. /** @copydoc Renderer::notifyLightUpdated */
  76. void notifyLightUpdated(LightCore* light) override;
  77. /** @copydoc Renderer::notifyLightRemoved */
  78. void notifyLightRemoved(LightCore* light) override;
  79. /** @copydoc Renderer::notifyRenderableAdded */
  80. void notifyRenderableAdded(RenderableCore* renderable) override;
  81. /** @copydoc Renderer::notifyRenderableUpdated */
  82. void notifyRenderableUpdated(RenderableCore* renderable) override;
  83. /** @copydoc Renderer::notifyRenderableRemoved */
  84. void notifyRenderableRemoved(RenderableCore* renderable) override;
  85. /**
  86. * Updates (or adds) renderer specific data for the specified camera. Should be called whenever camera properties
  87. * change.
  88. *
  89. * @param[in] camera Camera whose data to update.
  90. * @param[in] forceRemove If true, the camera data will be removed instead of updated.
  91. */
  92. void updateCameraData(const CameraCore* camera, bool forceRemove = false);
  93. /**
  94. * Updates the render options on the core thread.
  95. *
  96. * @note Core thread only.
  97. */
  98. void syncOptions(const RenderBeastOptions& options);
  99. /**
  100. * Performs rendering over all camera proxies.
  101. *
  102. * @param[in] time Current frame time in milliseconds.
  103. * @param[in] delta Time elapsed since the last frame.
  104. *
  105. * @note Core thread only.
  106. */
  107. void renderAllCore(float time, float delta);
  108. /**
  109. * Renders all objects visible by the provided camera.
  110. *
  111. * @param[in] frameInfo Renderer information specific to this frame.
  112. * @param[in] rtInfo Render target information containing the camera to render.
  113. * @param[in] camIdx Index of the camera to render.
  114. *
  115. * @note Core thread only.
  116. */
  117. void render(const RendererFrame& frameInfo, RendererRenderTarget& rtInfo, UINT32 camIdx);
  118. /**
  119. * Renders all overlay callbacks attached to the provided camera.
  120. *
  121. * @param[in] frameInfo Renderer information specific to this frame.
  122. * @param[in] rtInfo Render target information containing the camera to render.
  123. * @param[in] camIdx Index of the camera to render.
  124. *
  125. * @note Core thread only.
  126. */
  127. void renderOverlay(const RendererFrame& frameInfo, RendererRenderTarget& rtInfo, UINT32 camIdx);
  128. /**
  129. * Renders a single element of a renderable object.
  130. *
  131. * @param[in] element Element to render.
  132. * @param[in] passIdx Index of the material pass to render the element with.
  133. * @param[in] bindPass If true the material pass will be bound for rendering, if false it is assumed it is
  134. * already bound.
  135. * @param[in] frameInfo Renderer information specific to this frame.
  136. * @param[in] viewProj View projection matrix of the camera the element is being rendered with.
  137. */
  138. void renderElement(const BeastRenderableElement& element, UINT32 passIdx, bool bindPass,
  139. const RendererFrame& frameInfo, const Matrix4& viewProj);
  140. /** Creates data used by the renderer on the core thread. */
  141. void initializeCore();
  142. /** Destroys data used by the renderer on the core thread. */
  143. void destroyCore();
  144. /**
  145. * Checks all sampler overrides in case material sampler states changed, and updates them.
  146. *
  147. * @param[in] force If true, all sampler overrides will be updated, regardless of a change in the material
  148. * was detected or not.
  149. */
  150. void refreshSamplerOverrides(bool force = false);
  151. /**
  152. * Sets parameters (textures, samplers, buffers) for the currently active pass.
  153. *
  154. * @param[in] passParams Structure containing parameters for all stages of the pass.
  155. * @param[in] samplerOverrides Optional samplers to use instead of the those in the pass parameters. Number of
  156. * samplers must match number in pass parameters.
  157. *
  158. * @note Core thread.
  159. */
  160. static void setPassParams(const SPtr<PassParametersCore>& passParams, const PassSamplerOverrides* samplerOverrides);
  161. // Core thread only fields
  162. Vector<RendererRenderTarget> mRenderTargets;
  163. UnorderedMap<const CameraCore*, RendererCamera> mCameras;
  164. UnorderedMap<SPtr<MaterialCore>, MaterialSamplerOverrides*> mSamplerOverrides;
  165. Vector<RendererObject> mRenderables;
  166. Vector<RenderableShaderData> mRenderableShaderData;
  167. Vector<Bounds> mWorldBounds;
  168. Vector<RendererLight> mDirectionalLights;
  169. Vector<RendererLight> mPointLights;
  170. Vector<Sphere> mLightWorldBounds;
  171. SPtr<RenderBeastOptions> mCoreOptions;
  172. DefaultMaterial* mDefaultMaterial;
  173. PointLightInMat* mPointLightInMat;
  174. PointLightOutMat* mPointLightOutMat;
  175. DirectionalLightMat* mDirLightMat;
  176. ObjectRenderer* mObjectRenderer;
  177. // Sim thread only fields
  178. SPtr<RenderBeastOptions> mOptions;
  179. bool mOptionsDirty;
  180. };
  181. /** @} */
  182. }