BsRendererScene.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. //// Rebuilt for every set of views
  42. mutable Vector<bool> renderableVisibility;
  43. mutable Vector<bool> radialLightVisibility;
  44. mutable Vector<bool> spotLightVisibility;
  45. };
  46. /** Contains information about the scene (e.g. renderables, lights, cameras) required by the renderer. */
  47. class RendererScene
  48. {
  49. public:
  50. RendererScene(const SPtr<RenderBeastOptions>& options);
  51. ~RendererScene();
  52. /** Registers a new camera in the scene. */
  53. void registerCamera(Camera* camera);
  54. /** Updates information about a previously registered camera. */
  55. void updateCamera(Camera* camera, UINT32 updateFlag);
  56. /** Removes a camera from the scene. */
  57. void unregisterCamera(Camera* camera);
  58. /** Registers a new light in the scene. */
  59. void registerLight(Light* light);
  60. /** Updates information about a previously registered light. */
  61. void updateLight(Light* light);
  62. /** Removes a light from the scene. */
  63. void unregisterLight(Light* light);
  64. /** Registers a new renderable object in the scene. */
  65. void registerRenderable(Renderable* renderable);
  66. /** Updates information about a previously registered renderable object. */
  67. void updateRenderable(Renderable* renderable);
  68. /** Removes a renderable object from the scene. */
  69. void unregisterRenderable(Renderable* renderable);
  70. /** Registers a new reflection probe in the scene. */
  71. void registerReflectionProbe(ReflectionProbe* probe);
  72. /** Updates information about a previously registered reflection probe. */
  73. void updateReflectionProbe(ReflectionProbe* probe);
  74. /** Removes a reflection probe from the scene. */
  75. void unregisterReflectionProbe(ReflectionProbe* probe);
  76. /** Updates or replaces the filtered reflection texture of the probe at the specified index. */
  77. void setReflectionProbeTexture(UINT32 probeIdx, const SPtr<Texture>& texture);
  78. /** Updates the index at which the reflection probe's texture is stored at, in the global array. */
  79. void setReflectionProbeArrayIndex(UINT32 probeIdx, UINT32 arrayIdx, bool markAsClean);
  80. /** Returns a container with all relevant scene objects. */
  81. const SceneInfo& getSceneInfo() const { return mInfo; }
  82. /** Updates scene according to the newly provided renderer options. */
  83. void setOptions(const SPtr<RenderBeastOptions>& options);
  84. /**
  85. * Checks all sampler overrides in case material sampler states changed, and updates them.
  86. *
  87. * @param[in] force If true, all sampler overrides will be updated, regardless of a change in the material
  88. * was detected or not.
  89. */
  90. void refreshSamplerOverrides(bool force = false);
  91. /**
  92. * Performs necessary steps to make a renderable ready for rendering. This must be called at least once every frame,
  93. * for every renderable that will be drawn. Multiple calls for the same renderable during a single frame will result
  94. * in a no-op.
  95. *
  96. * @param[in] idx Index of the renderable to prepare.
  97. * @param[in] frameInfo Global information describing the current frame.
  98. */
  99. void prepareRenderable(UINT32 idx, const FrameInfo& frameInfo);
  100. private:
  101. /** Creates a renderer view descriptor for the particular camera. */
  102. RENDERER_VIEW_DESC createViewDesc(Camera* camera) const;
  103. /**
  104. * Find the render target the camera belongs to and adds it to the relevant list. If the camera was previously
  105. * registered with some other render target it will be removed from it and added to the new target.
  106. */
  107. void updateCameraRenderTargets(Camera* camera);
  108. SceneInfo mInfo;
  109. UnorderedMap<SamplerOverrideKey, MaterialSamplerOverrides*> mSamplerOverrides;
  110. DefaultMaterial* mDefaultMaterial = nullptr;
  111. SPtr<RenderBeastOptions> mOptions;
  112. };
  113. /** @} */
  114. }}