1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
3 | #pragma once |
4 | |
5 | #include "BsRenderBeastPrerequisites.h" |
6 | #include "Renderer/BsRenderer.h" |
7 | #include "Renderer/BsRendererMaterial.h" |
8 | #include "BsRendererView.h" |
9 | #include "BsRendererScene.h" |
10 | |
11 | namespace bs |
12 | { |
13 | struct EvaluatedAnimationData; |
14 | |
15 | namespace ct |
16 | { |
17 | class LightGrid; |
18 | |
19 | /** @addtogroup RenderBeast |
20 | * @{ |
21 | */ |
22 | |
23 | /** Information about current time and frame index. */ |
24 | struct FrameTimings |
25 | { |
26 | float time; |
27 | float timeDelta; |
28 | UINT64 frameIdx; |
29 | }; |
30 | |
31 | /** Contains information global to an entire frame. */ |
32 | struct FrameInfo |
33 | { |
34 | FrameInfo(const FrameTimings& timings, PerFrameData perFrameData) |
35 | :timeDelta(timings.timeDelta), frameIdx(timings.frameIdx), perFrameData(perFrameData) |
36 | { } |
37 | |
38 | float timeDelta; |
39 | UINT64 frameIdx; |
40 | PerFrameData perFrameData; |
41 | }; |
42 | |
43 | /** |
44 | * Default framework renderer. Performs frustum culling, sorting and renders all scene objects while applying |
45 | * lighting, shadowing, special effects and post-processing. |
46 | */ |
47 | class RenderBeast : public Renderer |
48 | { |
49 | /** Renderer information for a single material. */ |
50 | struct RendererMaterial |
51 | { |
52 | Vector<SPtr<GpuParamsSet>> params; |
53 | UINT32 matVersion; |
54 | }; |
55 | |
56 | public: |
57 | RenderBeast(); |
58 | ~RenderBeast() = default; |
59 | |
60 | /** @copydoc Renderer::getName */ |
61 | const StringID& getName() const override; |
62 | |
63 | /** @copydoc Renderer::renderAll */ |
64 | void renderAll(PerFrameData perFrameData) override; |
65 | |
66 | /** Sets options used for controlling the rendering. */ |
67 | void setOptions(const SPtr<RendererOptions>& options) override; |
68 | |
69 | /** Returns current set of options used for controlling the rendering. */ |
70 | SPtr<RendererOptions> getOptions() const override; |
71 | |
72 | /** Returns the feature set the renderer is operating on. Core thread only. */ |
73 | RenderBeastFeatureSet getFeatureSet() const { return mFeatureSet; } |
74 | |
75 | /** @copydoc Renderer::initialize */ |
76 | void initialize() override; |
77 | |
78 | /** @copydoc Renderer::destroy */ |
79 | void destroy() override; |
80 | |
81 | /** @copydoc Renderer::captureSceneCubeMap */ |
82 | void captureSceneCubeMap(const SPtr<Texture>& cubemap, const Vector3& position, |
83 | const CaptureSettings& settings) override; |
84 | |
85 | /** @copydoc Renderer::getShaderExtensionPointInfo */ |
86 | ShaderExtensionPointInfo getShaderExtensionPointInfo(const String& name) override; |
87 | |
88 | /** @copydoc Renderer::setGlobalShaderOverride */ |
89 | void setGlobalShaderOverride(const String& name, const SPtr<bs::Shader>& shader) override; |
90 | |
91 | private: |
92 | /** @copydoc Renderer::notifyCameraAdded */ |
93 | void notifyCameraAdded(Camera* camera) override; |
94 | |
95 | /** @copydoc Renderer::notifyCameraUpdated */ |
96 | void notifyCameraUpdated(Camera* camera, UINT32 updateFlag) override; |
97 | |
98 | /** @copydocRenderer::notifyCameraRemoved */ |
99 | void notifyCameraRemoved(Camera* camera) override; |
100 | |
101 | /** @copydoc Renderer::notifyLightAdded */ |
102 | void notifyLightAdded(Light* light) override; |
103 | |
104 | /** @copydoc Renderer::notifyLightUpdated */ |
105 | void notifyLightUpdated(Light* light) override; |
106 | |
107 | /** @copydoc Renderer::notifyLightRemoved */ |
108 | void notifyLightRemoved(Light* light) override; |
109 | |
110 | /** @copydoc Renderer::notifyRenderableAdded */ |
111 | void notifyRenderableAdded(Renderable* renderable) override; |
112 | |
113 | /** @copydoc Renderer::notifyRenderableUpdated */ |
114 | void notifyRenderableUpdated(Renderable* renderable) override; |
115 | |
116 | /** @copydoc Renderer::notifyRenderableRemoved */ |
117 | void notifyRenderableRemoved(Renderable* renderable) override; |
118 | |
119 | /** @copydoc Renderer::notifyReflectionProbeAdded */ |
120 | void notifyReflectionProbeAdded(ReflectionProbe* probe) override; |
121 | |
122 | /** @copydoc Renderer::notifyReflectionProbeUpdated */ |
123 | void notifyReflectionProbeUpdated(ReflectionProbe* probe, bool texture) override; |
124 | |
125 | /** @copydoc Renderer::notifyReflectionProbeRemoved */ |
126 | void notifyReflectionProbeRemoved(ReflectionProbe* probe) override; |
127 | |
128 | /** @copydoc Renderer::notifyLightProbeVolumeAdded */ |
129 | void notifyLightProbeVolumeAdded(LightProbeVolume* volume) override; |
130 | |
131 | /** @copydoc Renderer::notifyLightProbeVolumeUpdated */ |
132 | void notifyLightProbeVolumeUpdated(LightProbeVolume* volume) override; |
133 | |
134 | /** @copydoc Renderer::notifyLightProbeVolumeRemoved */ |
135 | void notifyLightProbeVolumeRemoved(LightProbeVolume* volume) override; |
136 | |
137 | /** @copydoc Renderer::notifySkyboxAdded */ |
138 | void notifySkyboxAdded(Skybox* skybox) override; |
139 | |
140 | /** @copydoc Renderer::notifySkyboxRemoved */ |
141 | void notifySkyboxRemoved(Skybox* skybox) override; |
142 | |
143 | /** @copydoc Renderer::notifyParticleSystemAdded */ |
144 | void notifyParticleSystemAdded(ParticleSystem* particleSystem) override; |
145 | |
146 | /** @copydoc Renderer::notifyParticleSystemUpdated */ |
147 | void notifyParticleSystemUpdated(ParticleSystem* particleSystem, bool tfrmOnly) override; |
148 | |
149 | /** @copydoc Renderer::notifyParticleSystemRemoved */ |
150 | void notifyParticleSystemRemoved(ParticleSystem* particleSystem) override; |
151 | |
152 | /** @copydoc Renderer::notifyDecalAdded */ |
153 | void notifyDecalAdded(Decal* decal) override; |
154 | |
155 | /** @copydoc Renderer::notifyDecalUpdated */ |
156 | void notifyDecalUpdated(Decal* decal) override; |
157 | |
158 | /** @copydoc Renderer::notifyDecalRemoved */ |
159 | void notifyDecalRemoved(Decal* decal) override; |
160 | |
161 | /** |
162 | * Updates the render options on the core thread. |
163 | * |
164 | * @note Core thread only. |
165 | */ |
166 | void syncOptions(const RenderBeastOptions& options); |
167 | |
168 | /** |
169 | * Performs rendering over all camera proxies. |
170 | * |
171 | * @param[in] timings Information about frame time and frame index. |
172 | * @param[in] perFrameData Per-frame data provided by external systems. |
173 | * |
174 | * @note Core thread only. |
175 | */ |
176 | void renderAllCore(FrameTimings timings, PerFrameData perFrameData); |
177 | |
178 | /** |
179 | * Renders all views in the provided view group. |
180 | * |
181 | * @note Core thread only. |
182 | */ |
183 | void renderViews(RendererViewGroup& viewGroup, const FrameInfo& frameInfo); |
184 | |
185 | /** |
186 | * Renders all objects visible by the provided view. |
187 | * |
188 | * @note Core thread only. |
189 | */ |
190 | void renderView(const RendererViewGroup& viewGroup, RendererView& view, const FrameInfo& frameInfo); |
191 | |
192 | /** |
193 | * Renders all overlay callbacks of the provided view. |
194 | * |
195 | * @note Core thread only. |
196 | */ |
197 | void renderOverlay(RendererView& view); |
198 | |
199 | /** Creates data used by the renderer on the core thread. */ |
200 | void initializeCore(); |
201 | |
202 | /** Destroys data used by the renderer on the core thread. */ |
203 | void destroyCore(); |
204 | |
205 | /** Updates the global reflection probe cubemap array with changed probe textures. */ |
206 | void updateReflProbeArray(); |
207 | |
208 | // Core thread only fields |
209 | RenderBeastFeatureSet mFeatureSet = RenderBeastFeatureSet::Desktop; |
210 | |
211 | // Scene data |
212 | SPtr<RendererScene> mScene; |
213 | |
214 | SPtr<RenderBeastOptions> mCoreOptions; |
215 | |
216 | // Helpers to avoid memory allocations |
217 | RendererViewGroup* mMainViewGroup = nullptr; |
218 | |
219 | // Sim thread only fields |
220 | SPtr<RenderBeastOptions> mOptions; |
221 | bool mOptionsDirty = true; |
222 | }; |
223 | |
224 | /** Provides easy access to the RenderBeast renderer. */ |
225 | SPtr<RenderBeast> gRenderBeast(); |
226 | |
227 | /** @} */ |
228 | }} |