BsRenderBeast.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. /** @copydoc Renderer::createPostProcessSettings */
  75. SPtr<PostProcessSettings> createPostProcessSettings() const override;
  76. private:
  77. /** @copydoc Renderer::notifyCameraAdded */
  78. void notifyCameraAdded(const CameraCore* camera) override;
  79. /** @copydoc Renderer::notifyCameraUpdated */
  80. void notifyCameraUpdated(const CameraCore* camera, UINT32 updateFlag) override;
  81. /** @copydocRenderer::notifyCameraRemoved */
  82. void notifyCameraRemoved(const CameraCore* camera) override;
  83. /** @copydoc Renderer::notifyLightAdded */
  84. void notifyLightAdded(LightCore* light) override;
  85. /** @copydoc Renderer::notifyLightUpdated */
  86. void notifyLightUpdated(LightCore* light) override;
  87. /** @copydoc Renderer::notifyLightRemoved */
  88. void notifyLightRemoved(LightCore* light) override;
  89. /** @copydoc Renderer::notifyRenderableAdded */
  90. void notifyRenderableAdded(RenderableCore* renderable) override;
  91. /** @copydoc Renderer::notifyRenderableUpdated */
  92. void notifyRenderableUpdated(RenderableCore* renderable) override;
  93. /** @copydoc Renderer::notifyRenderableRemoved */
  94. void notifyRenderableRemoved(RenderableCore* 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. */
  102. void updateCameraData(const CameraCore* camera, bool forceRemove = false);
  103. /**
  104. * Updates the render options on the core thread.
  105. *
  106. * @note Core thread only.
  107. */
  108. void syncOptions(const RenderBeastOptions& options);
  109. /**
  110. * Performs rendering over all camera proxies.
  111. *
  112. * @param[in] time Current frame time in milliseconds.
  113. * @param[in] delta Time elapsed since the last frame.
  114. *
  115. * @note Core thread only.
  116. */
  117. void renderAllCore(float time, float delta);
  118. /**
  119. * Renders all objects visible by 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 render(const RendererFrame& frameInfo, RendererRenderTarget& rtInfo, UINT32 camIdx);
  128. /**
  129. * Renders all overlay callbacks attached to the provided camera.
  130. *
  131. * @param[in] frameInfo Renderer information specific to this frame.
  132. * @param[in] rtInfo Render target information containing the camera to render.
  133. * @param[in] camIdx Index of the camera to render.
  134. *
  135. * @note Core thread only.
  136. */
  137. void renderOverlay(const RendererFrame& frameInfo, RendererRenderTarget& rtInfo, UINT32 camIdx);
  138. /**
  139. * Renders a single element of a renderable object.
  140. *
  141. * @param[in] element Element to render.
  142. * @param[in] passIdx Index of the material pass to render the element with.
  143. * @param[in] bindPass If true the material pass will be bound for rendering, if false it is assumed it is
  144. * already bound.
  145. * @param[in] frameInfo Renderer information specific to this frame.
  146. * @param[in] viewProj View projection matrix of the camera the element is being rendered with.
  147. */
  148. void renderElement(const BeastRenderableElement& element, UINT32 passIdx, bool bindPass,
  149. const RendererFrame& frameInfo, const Matrix4& viewProj);
  150. /** Creates data used by the renderer on the core thread. */
  151. void initializeCore();
  152. /** Destroys data used by the renderer on the core thread. */
  153. void destroyCore();
  154. /**
  155. * Checks all sampler overrides in case material sampler states changed, and updates them.
  156. *
  157. * @param[in] force If true, all sampler overrides will be updated, regardless of a change in the material
  158. * was detected or not.
  159. */
  160. void refreshSamplerOverrides(bool force = false);
  161. /**
  162. * Sets parameters (textures, samplers, buffers) for the currently active pass.
  163. *
  164. * @param[in] paramsSet Structure containing parameters for a material.
  165. * @param[in] samplerOverrides Optional samplers to use instead of the those in the pass parameters. Number of
  166. * samplers must match number in pass parameters.
  167. * @param[in] passIdx Index of the pass whose parameters to bind.
  168. *
  169. * @note Core thread.
  170. */
  171. static void setPassParams(const SPtr<GpuParamsSetCore>& paramsSet, const MaterialSamplerOverrides* samplerOverrides,
  172. UINT32 passIdx);
  173. // Core thread only fields
  174. Vector<RendererRenderTarget> mRenderTargets;
  175. UnorderedMap<const CameraCore*, RendererCamera> mCameras;
  176. UnorderedMap<SamplerOverrideKey, MaterialSamplerOverrides*> mSamplerOverrides;
  177. Vector<RendererObject> mRenderables;
  178. Vector<RenderableShaderData> mRenderableShaderData;
  179. Vector<Bounds> mWorldBounds;
  180. Vector<RendererLight> mDirectionalLights;
  181. Vector<RendererLight> mPointLights;
  182. Vector<Sphere> mLightWorldBounds;
  183. SPtr<RenderBeastOptions> mCoreOptions;
  184. DefaultMaterial* mDefaultMaterial;
  185. PointLightInMat* mPointLightInMat;
  186. PointLightOutMat* mPointLightOutMat;
  187. DirectionalLightMat* mDirLightMat;
  188. ObjectRenderer* mObjectRenderer;
  189. // Sim thread only fields
  190. SPtr<RenderBeastOptions> mOptions;
  191. bool mOptionsDirty;
  192. };
  193. /** @} */
  194. }