BsRenderBeast.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 bs
  15. {
  16. struct RendererAnimationData;
  17. namespace ct
  18. {
  19. /** @addtogroup RenderBeast
  20. * @{
  21. */
  22. /** Semantics that may be used for signaling the renderer for what is a certain shader parameter used for. */
  23. static StringID RPS_GBufferA = "GBufferA";
  24. static StringID RPS_GBufferB = "GBufferB";
  25. static StringID RPS_GBufferDepth = "GBufferDepth";
  26. static StringID RPS_BoneMatrices = "BoneMatrices";
  27. /**
  28. * Default renderer for Banshee. Performs frustum culling, sorting and renders all scene objects while applying
  29. * lighting, shadowing, special effects and post-processing.
  30. *
  31. * @note Sim thread unless otherwise noted.
  32. */
  33. class RenderBeast : public Renderer
  34. {
  35. /** Renderer information specific to a single render target. */
  36. struct RendererRenderTarget
  37. {
  38. SPtr<RenderTarget> target;
  39. Vector<const Camera*> cameras;
  40. };
  41. /** Renderer information specific to a single light. */
  42. struct RendererLight
  43. {
  44. Light* internal;
  45. };
  46. /** Renderer information for a single material. */
  47. struct RendererMaterial
  48. {
  49. Vector<SPtr<GpuParamsSet>> params;
  50. UINT32 matVersion;
  51. };
  52. public:
  53. RenderBeast();
  54. ~RenderBeast() { }
  55. /** @copydoc Renderer::getName */
  56. const StringID& getName() const override;
  57. /** @copydoc Renderer::renderAll */
  58. void renderAll() override;
  59. /** Sets options used for controlling the rendering. */
  60. void setOptions(const SPtr<CoreRendererOptions>& options) override;
  61. /** Returns current set of options used for controlling the rendering. */
  62. SPtr<CoreRendererOptions> getOptions() const override;
  63. /** @copydoc Renderer::initialize */
  64. void initialize() override;
  65. /** @copydoc Renderer::destroy */
  66. void destroy() override;
  67. /** @copydoc Renderer::createPostProcessSettings */
  68. SPtr<PostProcessSettings> createPostProcessSettings() const override;
  69. private:
  70. /** @copydoc Renderer::notifyCameraAdded */
  71. void notifyCameraAdded(const Camera* camera) override;
  72. /** @copydoc Renderer::notifyCameraUpdated */
  73. void notifyCameraUpdated(const Camera* camera, UINT32 updateFlag) override;
  74. /** @copydocRenderer::notifyCameraRemoved */
  75. void notifyCameraRemoved(const Camera* camera) override;
  76. /** @copydoc Renderer::notifyLightAdded */
  77. void notifyLightAdded(Light* light) override;
  78. /** @copydoc Renderer::notifyLightUpdated */
  79. void notifyLightUpdated(Light* light) override;
  80. /** @copydoc Renderer::notifyLightRemoved */
  81. void notifyLightRemoved(Light* light) override;
  82. /** @copydoc Renderer::notifyRenderableAdded */
  83. void notifyRenderableAdded(Renderable* renderable) override;
  84. /** @copydoc Renderer::notifyRenderableUpdated */
  85. void notifyRenderableUpdated(Renderable* renderable) override;
  86. /** @copydoc Renderer::notifyRenderableRemoved */
  87. void notifyRenderableRemoved(Renderable* renderable) override;
  88. /**
  89. * Updates (or adds) renderer specific data for the specified camera. Should be called whenever camera properties
  90. * change.
  91. *
  92. * @param[in] camera Camera whose data to update.
  93. * @param[in] forceRemove If true, the camera data will be removed instead of updated.
  94. * @return Renderer camera object that represents the camera. Null if camera was removed.
  95. */
  96. RendererCamera* updateCameraData(const Camera* camera, bool forceRemove = false);
  97. /**
  98. * Updates the render options on the core thread.
  99. *
  100. * @note Core thread only.
  101. */
  102. void syncOptions(const RenderBeastOptions& options);
  103. /**
  104. * Performs rendering over all camera proxies.
  105. *
  106. * @param[in] time Current frame time in milliseconds.
  107. * @param[in] delta Time elapsed since the last frame.
  108. *
  109. * @note Core thread only.
  110. */
  111. void renderAllCore(float time, float delta);
  112. /**
  113. * Renders all objects visible by the provided view.
  114. *
  115. * @note Core thread only.
  116. */
  117. void render(RendererCamera* viewInfo, float frameDelta);
  118. /**
  119. * Renders all overlay callbacks attached to the provided camera.
  120. *
  121. * @note Core thread only.
  122. */
  123. void renderOverlay(const Camera* camera, bool clear);
  124. /**
  125. * Renders a single element of a renderable object.
  126. *
  127. * @param[in] element Element to render.
  128. * @param[in] passIdx Index of the material pass to render the element with.
  129. * @param[in] bindPass If true the material pass will be bound for rendering, if false it is assumed it is
  130. * already bound.
  131. * @param[in] viewProj View projection matrix of the camera the element is being rendered with.
  132. */
  133. void renderElement(const BeastRenderableElement& element, UINT32 passIdx, bool bindPass, const Matrix4& viewProj);
  134. /**
  135. * Captures the scene at the specified location into a cubemap.
  136. *
  137. * @param[in] position Position to capture the scene at.
  138. * @param[in] hdr If true scene will be captured in a format that supports high dynamic range.
  139. * @param[in] size Cubemap face width/height in pixels.
  140. */
  141. SPtr<Texture> captureSceneCubeMap(const Vector3& position, bool hdr, UINT32 size);
  142. /** Creates data used by the renderer on the core thread. */
  143. void initializeCore();
  144. /** Destroys data used by the renderer on the core thread. */
  145. void destroyCore();
  146. /**
  147. * Checks all sampler overrides in case material sampler states changed, and updates them.
  148. *
  149. * @param[in] force If true, all sampler overrides will be updated, regardless of a change in the material
  150. * was detected or not.
  151. */
  152. void refreshSamplerOverrides(bool force = false);
  153. // Core thread only fields
  154. Vector<RendererRenderTarget> mRenderTargets;
  155. UnorderedMap<const Camera*, RendererCamera*> mCameras;
  156. UnorderedMap<SamplerOverrideKey, MaterialSamplerOverrides*> mSamplerOverrides;
  157. Vector<RendererObject*> mRenderables;
  158. Vector<Bounds> mWorldBounds;
  159. Vector<bool> mVisibility; // Transient
  160. Vector<RendererLight> mDirectionalLights;
  161. Vector<RendererLight> mPointLights;
  162. Vector<Sphere> mLightWorldBounds;
  163. SPtr<RenderBeastOptions> mCoreOptions;
  164. DefaultMaterial* mDefaultMaterial;
  165. PointLightInMat* mPointLightInMat;
  166. PointLightOutMat* mPointLightOutMat;
  167. DirectionalLightMat* mDirLightMat;
  168. SkyboxMat* mSkyboxMat;
  169. ObjectRenderer* mObjectRenderer;
  170. // Sim thread only fields
  171. SPtr<RenderBeastOptions> mOptions;
  172. bool mOptionsDirty;
  173. };
  174. /** @} */
  175. }}