BsRenderBeast.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. /** Semantics that may be used for signaling the renderer for what is a certain shader parameter used for. */
  20. static StringID RPS_GBufferA = "GBufferA";
  21. static StringID RPS_GBufferB = "GBufferB";
  22. static StringID RPS_GBufferDepth = "GBufferDepth";
  23. /**
  24. * Default renderer for Banshee. Performs frustum culling, sorting and renders objects in custom ways determine by
  25. * renderable handlers.
  26. *
  27. * @note Sim thread unless otherwise noted.
  28. */
  29. class RenderBeast : public Renderer
  30. {
  31. /** Render data for a single render target. */
  32. struct RenderTargetData
  33. {
  34. SPtr<RenderTargetCore> target;
  35. Vector<const CameraCore*> cameras;
  36. };
  37. /** Data used by the renderer for lights. */
  38. struct LightData
  39. {
  40. LightCore* internal;
  41. };
  42. public:
  43. RenderBeast();
  44. ~RenderBeast() { }
  45. /** @copydoc Renderer::getName */
  46. const StringID& getName() const override;
  47. /** @copydoc Renderer::renderAll */
  48. void renderAll() override;
  49. /** Sets options used for controlling the rendering. */
  50. void setOptions(const SPtr<CoreRendererOptions>& options) override;
  51. /** Returns current set of options used for controlling the rendering. */
  52. SPtr<CoreRendererOptions> getOptions() const override;
  53. /** @copydoc Renderer::initialize */
  54. void initialize() override;
  55. /** @copydoc Renderer::destroy */
  56. void destroy() override;
  57. private:
  58. /** @copydoc Renderer::notifyCameraAdded */
  59. void notifyCameraAdded(const CameraCore* camera) override;
  60. /** @copydoc Renderer::notifyCameraUpdated */
  61. void notifyCameraUpdated(const CameraCore* camera, UINT32 updateFlag) override;
  62. /** @copydocRenderer::notifyCameraRemoved */
  63. void notifyCameraRemoved(const CameraCore* camera) override;
  64. /** @copydoc Renderer::notifyLightAdded */
  65. void notifyLightAdded(LightCore* light) override;
  66. /** @copydoc Renderer::notifyLightUpdated */
  67. void notifyLightUpdated(LightCore* light) override;
  68. /** @copydoc Renderer::notifyLightRemoved */
  69. void notifyLightRemoved(LightCore* light) override;
  70. /** @copydoc Renderer::notifyRenderableAdded */
  71. void notifyRenderableAdded(RenderableCore* renderable) override;
  72. /** @copydoc Renderer::notifyRenderableUpdated */
  73. void notifyRenderableUpdated(RenderableCore* renderable) override;
  74. /** @copydoc Renderer::notifyRenderableRemoved */
  75. void notifyRenderableRemoved(RenderableCore* renderable) override;
  76. /**
  77. * Updates (or adds) renderer specific data for the specified camera. Should be called whenever camera properties
  78. * change.
  79. *
  80. * @param[in] camera Camera whose data to update.
  81. * @param[in] forceRemove If true, the camera data will be removed instead of updated.
  82. */
  83. void updateCameraData(const CameraCore* camera, bool forceRemove = false);
  84. /**
  85. * Updates the render options on the core thread.
  86. *
  87. * @note Core thread only.
  88. */
  89. void syncOptions(const RenderBeastOptions& options);
  90. /**
  91. * Performs rendering over all camera proxies.
  92. *
  93. * @param[in] time Current frame time in milliseconds.
  94. * @param[in] delta Time elapsed since the last frame.
  95. *
  96. * @note Core thread only.
  97. */
  98. void renderAllCore(float time, float delta);
  99. /**
  100. * Renders all objects visible by the provided camera.
  101. *
  102. * @param[in] rtData Render target data containing the camera to render.
  103. * @param[in] camIdx Index of the camera to render.
  104. * @param[in] delta Time elapsed since the last frame.
  105. *
  106. * @note Core thread only.
  107. */
  108. void render(RenderTargetData& rtData, UINT32 camIdx, float delta);
  109. /**
  110. * Renders all overlay callbacks attached to the provided camera.
  111. *
  112. * @param[in] rtData Render target data containing the camera to render.
  113. * @param[in] camIdx Index of the camera to render.
  114. * @param[in] delta Time elapsed since the last frame.
  115. *
  116. * @note Core thread only.
  117. */
  118. void renderOverlay(RenderTargetData& rtData, UINT32 camIdx, float delta);
  119. /**
  120. * Renders a single element of a renderable object.
  121. *
  122. * @param[in] element Element to render.
  123. * @param[in] passIdx Index of the material pass to render the element with.
  124. * @param[in] bindPass If true the material pass will be bound for rendering, if false it is assumed it is
  125. * already bound.
  126. * @param[in] viewProj View projection matrix of the camera the element is being rendered with.
  127. */
  128. void renderElement(const BeastRenderableElement& element, UINT32 passIdx, bool bindPass, const Matrix4& viewProj);
  129. /** Creates data used by the renderer on the core thread. */
  130. void initializeCore();
  131. /** Destroys data used by the renderer on the core thread. */
  132. void destroyCore();
  133. /**
  134. * Checks all sampler overrides in case material sampler states changed, and updates them.
  135. *
  136. * @param[in] force If true, all sampler overrides will be updated, regardless of a change in the material
  137. * was detected or not.
  138. */
  139. void refreshSamplerOverrides(bool force = false);
  140. /**
  141. * Sets parameters (textures, samplers, buffers) for the currently active pass.
  142. *
  143. * @param[in] passParams Structure containing parameters for all stages of the pass.
  144. * @param[in] samplerOverrides Optional samplers to use instead of the those in the pass parameters. Number of
  145. * samplers must match number in pass parameters.
  146. *
  147. * @note Core thread.
  148. */
  149. static void setPassParams(const SPtr<PassParametersCore>& passParams, const PassSamplerOverrides* samplerOverrides);
  150. // Core thread only fields
  151. Vector<RenderTargetData> mRenderTargets;
  152. UnorderedMap<const CameraCore*, RendererCamera> mCameras;
  153. UnorderedMap<SPtr<MaterialCore>, MaterialSamplerOverrides*> mSamplerOverrides;
  154. Vector<RendererObject> mRenderables;
  155. Vector<RenderableShaderData> mRenderableShaderData;
  156. Vector<Bounds> mWorldBounds;
  157. Vector<LightData> mDirectionalLights;
  158. Vector<LightData> mPointLights;
  159. Vector<Sphere> mLightWorldBounds;
  160. SPtr<RenderBeastOptions> mCoreOptions;
  161. DefaultMaterial* mDefaultMaterial;
  162. PointLightInMat* mPointLightInMat;
  163. PointLightOutMat* mPointLightOutMat;
  164. DirectionalLightMat* mDirLightMat;
  165. ObjectRenderer* mObjectRenderer;
  166. // Sim thread only fields
  167. SPtr<RenderBeastOptions> mOptions;
  168. bool mOptionsDirty;
  169. };
  170. /** @} */
  171. }