BsRendererScene.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. UnorderedMap<const Camera*, RendererView*> views;
  25. // Renderables
  26. Vector<RendererObject*> renderables;
  27. Vector<CullInfo> renderableCullInfos;
  28. // Lights
  29. Vector<RendererLight> directionalLights;
  30. Vector<RendererLight> radialLights;
  31. Vector<RendererLight> spotLights;
  32. Vector<Sphere> radialLightWorldBounds;
  33. Vector<Sphere> spotLightWorldBounds;
  34. // Reflection probes
  35. Vector<RendererReflectionProbe> reflProbes;
  36. Vector<Sphere> reflProbeWorldBounds;
  37. // Buffers for various transient data that gets rebuilt every frame
  38. //// Rebuilt every frame
  39. mutable Vector<bool> renderableReady;
  40. //// Rebuilt for every set of views
  41. mutable Vector<bool> renderableVisibility;
  42. mutable Vector<bool> radialLightVisibility;
  43. mutable Vector<bool> spotLightVisibility;
  44. };
  45. /** Contains information about the scene (e.g. renderables, lights, cameras) required by the renderer. */
  46. class RendererScene
  47. {
  48. public:
  49. RendererScene(const SPtr<RenderBeastOptions>& options);
  50. ~RendererScene();
  51. /** Registers a new camera in the scene. */
  52. void registerCamera(const Camera* camera);
  53. /** Updates information about a previously registered camera. */
  54. void updateCamera(const Camera* camera, UINT32 updateFlag);
  55. /** Removes a camera from the scene. */
  56. void unregisterCamera(const Camera* camera);
  57. /** Registers a new light in the scene. */
  58. void registerLight(Light* light);
  59. /** Updates information about a previously registered light. */
  60. void updateLight(Light* light);
  61. /** Removes a light from the scene. */
  62. void unregisterLight(Light* light);
  63. /** Registers a new renderable object in the scene. */
  64. void registerRenderable(Renderable* renderable);
  65. /** Updates information about a previously registered renderable object. */
  66. void updateRenderable(Renderable* renderable);
  67. /** Removes a renderable object from the scene. */
  68. void unregisterRenderable(Renderable* renderable);
  69. /** Registers a new reflection probe in the scene. */
  70. void registerReflectionProbe(ReflectionProbe* probe);
  71. /** Updates information about a previously registered reflection probe. */
  72. void updateReflectionProbe(ReflectionProbe* probe);
  73. /** Removes a reflection probe from the scene. */
  74. void unregisterReflectionProbe(ReflectionProbe* probe);
  75. /** Updates the index which maps the light to a particular shadow map in ShadowRendering. */
  76. void setLightShadowMapIdx(UINT32 lightIdx, LightType lightType, UINT32 shadowMapIndex);
  77. /** Updates or replaces the filtered reflection texture of the probe at the specified index. */
  78. void setReflectionProbeTexture(UINT32 probeIdx, const SPtr<Texture>& texture);
  79. /** Updates the index at which the reflection probe's texture is stored at, in the global array. */
  80. void setReflectionProbeArrayIndex(UINT32 probeIdx, UINT32 arrayIdx, bool markAsClean);
  81. /** Returns a container with all relevant scene objects. */
  82. const SceneInfo& getSceneInfo() const { return mInfo; }
  83. /** Updates scene according to the newly provided renderer options. */
  84. void setOptions(const SPtr<RenderBeastOptions>& options);
  85. /**
  86. * Checks all sampler overrides in case material sampler states changed, and updates them.
  87. *
  88. * @param[in] force If true, all sampler overrides will be updated, regardless of a change in the material
  89. * was detected or not.
  90. */
  91. void refreshSamplerOverrides(bool force = false);
  92. /**
  93. * Performs necessary steps to make a renderable ready for rendering. This must be called at least once every frame,
  94. * for every renderable that will be drawn. Multiple calls for the same renderable during a single frame will result
  95. * in a no-op.
  96. *
  97. * @param[in] idx Index of the renderable to prepare.
  98. * @param[in] frameInfo Global information describing the current frame.
  99. */
  100. void prepareRenderable(UINT32 idx, const FrameInfo& frameInfo);
  101. private:
  102. /**
  103. * Updates (or adds) renderer specific data for the specified camera. Should be called whenever camera properties
  104. * change.
  105. *
  106. * @param[in] camera Camera whose data to update.
  107. * @param[in] forceRemove If true, the camera data will be removed instead of updated.
  108. * @return Renderer view object that represents the camera. Null if camera was removed.
  109. */
  110. RendererView* updateCameraData(const Camera* camera, bool forceRemove = false);
  111. SceneInfo mInfo;
  112. UnorderedMap<SamplerOverrideKey, MaterialSamplerOverrides*> mSamplerOverrides;
  113. DefaultMaterial* mDefaultMaterial = nullptr;
  114. SPtr<RenderBeastOptions> mOptions;
  115. };
  116. /** @} */
  117. }}