BsRendererScene.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. // Limited by max number of array elements in texture for DX11 hardware
  20. constexpr UINT32 MaxReflectionCubemaps = 2048 / 6;
  21. /** Contains most scene objects relevant to the renderer. */
  22. struct SceneInfo
  23. {
  24. // Cameras and render targets
  25. Vector<RendererRenderTarget> renderTargets;
  26. Vector<RendererView*> views;
  27. UnorderedMap<const Camera*, UINT32> cameraToView;
  28. // Renderables
  29. Vector<RendererObject*> renderables;
  30. Vector<CullInfo> renderableCullInfos;
  31. // Lights
  32. Vector<RendererLight> directionalLights;
  33. Vector<RendererLight> radialLights;
  34. Vector<RendererLight> spotLights;
  35. Vector<Sphere> radialLightWorldBounds;
  36. Vector<Sphere> spotLightWorldBounds;
  37. // Reflection probes
  38. Vector<RendererReflectionProbe> reflProbes;
  39. Vector<Sphere> reflProbeWorldBounds;
  40. Vector<bool> reflProbeCubemapArrayUsedSlots;
  41. SPtr<Texture> reflProbeCubemapsTex;
  42. // Sky
  43. Skybox* skybox = nullptr;
  44. // Buffers for various transient data that gets rebuilt every frame
  45. //// Rebuilt every frame
  46. mutable Vector<bool> renderableReady;
  47. };
  48. /** Contains information about the scene (e.g. renderables, lights, cameras) required by the renderer. */
  49. class RendererScene
  50. {
  51. public:
  52. RendererScene(const SPtr<RenderBeastOptions>& options);
  53. ~RendererScene();
  54. /** Registers a new camera in the scene. */
  55. void registerCamera(Camera* camera);
  56. /** Updates information about a previously registered camera. */
  57. void updateCamera(Camera* camera, UINT32 updateFlag);
  58. /** Removes a camera from the scene. */
  59. void unregisterCamera(Camera* camera);
  60. /** Registers a new light in the scene. */
  61. void registerLight(Light* light);
  62. /** Updates information about a previously registered light. */
  63. void updateLight(Light* light);
  64. /** Removes a light from the scene. */
  65. void unregisterLight(Light* light);
  66. /** Registers a new renderable object in the scene. */
  67. void registerRenderable(Renderable* renderable);
  68. /** Updates information about a previously registered renderable object. */
  69. void updateRenderable(Renderable* renderable);
  70. /** Removes a renderable object from the scene. */
  71. void unregisterRenderable(Renderable* renderable);
  72. /** Registers a new reflection probe in the scene. */
  73. void registerReflectionProbe(ReflectionProbe* probe);
  74. /** Updates information about a previously registered reflection probe. */
  75. void updateReflectionProbe(ReflectionProbe* probe, bool texture);
  76. /** Removes a reflection probe from the scene. */
  77. void unregisterReflectionProbe(ReflectionProbe* probe);
  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. /** Registers a new sky texture in the scene. */
  81. void registerSkybox(Skybox* skybox);
  82. /** Removes a skybox from the scene. */
  83. void unregisterSkybox(Skybox* skybox);
  84. /** Returns a container with all relevant scene objects. */
  85. const SceneInfo& getSceneInfo() const { return mInfo; }
  86. /** Updates scene according to the newly provided renderer options. */
  87. void setOptions(const SPtr<RenderBeastOptions>& options);
  88. /**
  89. * Checks all sampler overrides in case material sampler states changed, and updates them.
  90. *
  91. * @param[in] force If true, all sampler overrides will be updated, regardless of a change in the material
  92. * was detected or not.
  93. */
  94. void refreshSamplerOverrides(bool force = false);
  95. /**
  96. * Performs necessary steps to make a renderable ready for rendering. This must be called at least once every frame,
  97. * for every renderable that will be drawn. Multiple calls for the same renderable during a single frame will result
  98. * in a no-op.
  99. *
  100. * @param[in] idx Index of the renderable to prepare.
  101. * @param[in] frameInfo Global information describing the current frame.
  102. */
  103. void prepareRenderable(UINT32 idx, const FrameInfo& frameInfo);
  104. /** Returns a modifiable version of SceneInfo. Only to be used by friends who know what they are doing. */
  105. SceneInfo& _getSceneInfo() { return mInfo; }
  106. private:
  107. /** Creates a renderer view descriptor for the particular camera. */
  108. RENDERER_VIEW_DESC createViewDesc(Camera* camera) const;
  109. /**
  110. * Find the render target the camera belongs to and adds it to the relevant list. If the camera was previously
  111. * registered with some other render target it will be removed from it and added to the new target.
  112. */
  113. void updateCameraRenderTargets(Camera* camera, bool remove = false);
  114. SceneInfo mInfo;
  115. UnorderedMap<SamplerOverrideKey, MaterialSamplerOverrides*> mSamplerOverrides;
  116. SPtr<RenderBeastOptions> mOptions;
  117. };
  118. /** @} */
  119. }}