BsRenderBeast.h 7.8 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 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. /** Technique tags. */
  26. static StringID RTag_Animated = "Animated";
  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<RenderTargetCore> target;
  46. Vector<const CameraCore*> cameras;
  47. };
  48. /** Renderer information specific to a single light. */
  49. struct RendererLight
  50. {
  51. LightCore* internal;
  52. };
  53. /** Renderer information for a single material. */
  54. struct RendererMaterial
  55. {
  56. Vector<SPtr<GpuParamsSetCore>> 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. 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. /**
  160. * Sets parameters (textures, samplers, buffers) for the currently active pass.
  161. *
  162. * @param[in] paramsSet Structure containing parameters for a material.
  163. * @param[in] samplerOverrides Optional samplers to use instead of the those in the pass parameters. Number of
  164. * samplers must match number in pass parameters.
  165. * @param[in] passIdx Index of the pass whose parameters to bind.
  166. *
  167. * @note Core thread.
  168. */
  169. static void setPassParams(const SPtr<GpuParamsSetCore>& paramsSet, const MaterialSamplerOverrides* samplerOverrides,
  170. UINT32 passIdx);
  171. // Core thread only fields
  172. Vector<RendererRenderTarget> mRenderTargets;
  173. UnorderedMap<const CameraCore*, RendererCamera> mCameras;
  174. UnorderedMap<SamplerOverrideKey, MaterialSamplerOverrides*> mSamplerOverrides;
  175. Vector<RendererObject> mRenderables;
  176. Vector<RenderableShaderData> mRenderableShaderData;
  177. Vector<Bounds> mWorldBounds;
  178. Vector<RendererLight> mDirectionalLights;
  179. Vector<RendererLight> mPointLights;
  180. Vector<Sphere> mLightWorldBounds;
  181. SPtr<RenderBeastOptions> mCoreOptions;
  182. DefaultMaterial* mDefaultMaterial;
  183. PointLightInMat* mPointLightInMat;
  184. PointLightOutMat* mPointLightOutMat;
  185. DirectionalLightMat* mDirLightMat;
  186. ObjectRenderer* mObjectRenderer;
  187. // Sim thread only fields
  188. SPtr<RenderBeastOptions> mOptions;
  189. bool mOptionsDirty;
  190. };
  191. /** @} */
  192. }