BsRendererScene.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 "BsObjectRendering.h"
  6. #include "BsSamplerOverrides.h"
  7. #include "BsLightRendering.h"
  8. #include "BsRendererView.h"
  9. #include "BsLight.h"
  10. namespace bs
  11. {
  12. struct RendererAnimationData;
  13. namespace ct
  14. {
  15. struct FrameInfo;
  16. /** @addtogroup RenderBeast
  17. * @{
  18. */
  19. /** Contains most scene objects relevant to the renderer. */
  20. struct SceneInfo
  21. {
  22. // Cameras and render targets
  23. Vector<RendererRenderTarget> renderTargets;
  24. Vector<RendererView*> views;
  25. UnorderedMap<const Camera*, UINT32> cameraToView;
  26. // Renderables
  27. Vector<RendererObject*> renderables;
  28. Vector<CullInfo> renderableCullInfos;
  29. // Lights
  30. Vector<RendererLight> directionalLights;
  31. Vector<RendererLight> radialLights;
  32. Vector<RendererLight> spotLights;
  33. Vector<Sphere> radialLightWorldBounds;
  34. Vector<Sphere> spotLightWorldBounds;
  35. // Reflection probes
  36. Vector<RendererReflectionProbe> reflProbes;
  37. Vector<Sphere> reflProbeWorldBounds;
  38. // Buffers for various transient data that gets rebuilt every frame
  39. //// Rebuilt every frame
  40. mutable Vector<bool> renderableReady;
  41. };
  42. /** Contains information about the scene (e.g. renderables, lights, cameras) required by the renderer. */
  43. class RendererScene
  44. {
  45. public:
  46. RendererScene(const SPtr<RenderBeastOptions>& options);
  47. ~RendererScene();
  48. /** Registers a new camera in the scene. */
  49. void registerCamera(Camera* camera);
  50. /** Updates information about a previously registered camera. */
  51. void updateCamera(Camera* camera, UINT32 updateFlag);
  52. /** Removes a camera from the scene. */
  53. void unregisterCamera(Camera* camera);
  54. /** Registers a new light in the scene. */
  55. void registerLight(Light* light);
  56. /** Updates information about a previously registered light. */
  57. void updateLight(Light* light);
  58. /** Removes a light from the scene. */
  59. void unregisterLight(Light* light);
  60. /** Registers a new renderable object in the scene. */
  61. void registerRenderable(Renderable* renderable);
  62. /** Updates information about a previously registered renderable object. */
  63. void updateRenderable(Renderable* renderable);
  64. /** Removes a renderable object from the scene. */
  65. void unregisterRenderable(Renderable* renderable);
  66. /** Registers a new reflection probe in the scene. */
  67. void registerReflectionProbe(ReflectionProbe* probe);
  68. /** Updates information about a previously registered reflection probe. */
  69. void updateReflectionProbe(ReflectionProbe* probe);
  70. /** Removes a reflection probe from the scene. */
  71. void unregisterReflectionProbe(ReflectionProbe* probe);
  72. /** Updates or replaces the filtered reflection texture of the probe at the specified index. */
  73. void setReflectionProbeTexture(UINT32 probeIdx, const SPtr<Texture>& texture);
  74. /** Updates the index at which the reflection probe's texture is stored at, in the global array. */
  75. void setReflectionProbeArrayIndex(UINT32 probeIdx, UINT32 arrayIdx, bool markAsClean);
  76. /** Returns a container with all relevant scene objects. */
  77. const SceneInfo& getSceneInfo() const { return mInfo; }
  78. /** Updates scene according to the newly provided renderer options. */
  79. void setOptions(const SPtr<RenderBeastOptions>& options);
  80. /**
  81. * Checks all sampler overrides in case material sampler states changed, and updates them.
  82. *
  83. * @param[in] force If true, all sampler overrides will be updated, regardless of a change in the material
  84. * was detected or not.
  85. */
  86. void refreshSamplerOverrides(bool force = false);
  87. /**
  88. * Performs necessary steps to make a renderable ready for rendering. This must be called at least once every frame,
  89. * for every renderable that will be drawn. Multiple calls for the same renderable during a single frame will result
  90. * in a no-op.
  91. *
  92. * @param[in] idx Index of the renderable to prepare.
  93. * @param[in] frameInfo Global information describing the current frame.
  94. */
  95. void prepareRenderable(UINT32 idx, const FrameInfo& frameInfo);
  96. private:
  97. /** Creates a renderer view descriptor for the particular camera. */
  98. RENDERER_VIEW_DESC createViewDesc(Camera* camera) const;
  99. /**
  100. * Find the render target the camera belongs to and adds it to the relevant list. If the camera was previously
  101. * registered with some other render target it will be removed from it and added to the new target.
  102. */
  103. void updateCameraRenderTargets(Camera* camera);
  104. SceneInfo mInfo;
  105. UnorderedMap<SamplerOverrideKey, MaterialSamplerOverrides*> mSamplerOverrides;
  106. DefaultMaterial* mDefaultMaterial = nullptr;
  107. SPtr<RenderBeastOptions> mOptions;
  108. };
  109. /** @} */
  110. }}