-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathView.hpp
More file actions
294 lines (209 loc) · 8.56 KB
/
View.hpp
File metadata and controls
294 lines (209 loc) · 8.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/* Copyright (c) 2016-2026 Andrew J. MacDonald. All rights reserved. */
#pragma once
#include <Core/Constants.hpp>
#include <Core/Types.hpp>
#include <Core/reflection/ObjectBase.hpp>
#include <Core/reflection/Handle.hpp>
#include <Core/math/Ray.hpp>
#include <Core/utilities/EnumFlags.hpp>
#include <Core/functional/Delegate.hpp>
#include <Core/memory/resource/Resource.hpp>
#include <Core/math/Frustum.hpp>
#include <rendering/Shared.hpp>
#include <rendering/RenderableAttributes.hpp>
#include <rendering/RenderObject.hpp>
namespace Hyperion {
class Scene;
class Camera;
class Light;
class LightmapVolume;
class EnvGrid;
class EnvProbe;
class Texture;
class GBuffer;
class EntityBatchAllocatorBase;
class RenderProxyList;
namespace threading {
class TaskBatch;
} // namespace threading
using threading::TaskBatch;
HYP_ENUM()
enum class ViewFlags : uint32
{
NONE = 0x0,
GBUFFER = 0x1,
ALL_WORLD_SCENES = 0x2, //!< If set, all scenes added to the world will be added view, and removed when removed from the world. Otherwise, the View itself manages the scenes it contains.
COLLECT_STATIC_ENTITIES = 0x4, //!< If set, the view will collect static entities (those that are not dynamic). Dynamic entities are those that move or are animated.
COLLECT_DYNAMIC_ENTITIES = 0x8, //!< If set, the view will collect dynamic entities (those that are not static). Static entities are those that do not move and are not animated.
COLLECT_ALL_ENTITIES = COLLECT_STATIC_ENTITIES | COLLECT_DYNAMIC_ENTITIES,
NO_FRUSTUM_CULLING = 0x10, //!< If set, the view will not perform frustum culling. This is useful for debugging or when you want to render everything regardless of visibility.
SKIP_ENV_PROBES = 0x20, //!< If set, the view will not collect EnvProbes
SKIP_ENV_GRIDS = 0x40, //!< If set, the view will not collect EnvGrids.
SKIP_LIGHTS = 0x80, //!< If set, the view will not collect Lights.
SKIP_LIGHTMAP_VOLUMES = 0x100, //!< If set, the view will not collect LightmapVolumes.
SKIP_PARTICLE_VOLUMES = 0x200, //!< If set, the view will not collect ParticleVolumes.
SKIP_FOG_VOLUMES = 0x400, //!< If set, the view will not collect FogVolumes.
SKIP_CAMERAS = 0x800, //!< If set, the view will not collect Cameras.
NOT_MULTI_BUFFERED = 0x1000, //!< Disables double / triple buffering for the RenderProxyList this View writes to.
// --- Use ONLY for Views that are not written to every frame, and instead are written to and read once (or infrequently); e.g EnvProbes.
// --- Use of these is still threadsafe, however it uses a spinlock instead of multiple buffering so contentions will eat up cpu cycles.
NO_DRAW_CALLS = 0x2000, //!< If set, no draw calls will be built for any mesh entities that this View collects.
// enable flags
RAY_TRACING = 0x100000, //!< Does this View contain rayTracing data (acceleration structures)? (RayTracing must be enabled in the global config and must have RT hardware support)
MATCH_CAMERA_DIMENSIONS = 0x200000, //!< If set, the Viewport dimensions will always match the associated Camera's dimensions.
SHADOW_VIEW = 0x400000, //!< This View is for a rendering a shadow map slice or cascade
EXTERNAL_RENDERTARGET = 0x800000,
UI = 0x1000000,
DEFAULT = ALL_WORLD_SCENES | COLLECT_ALL_ENTITIES
};
HYP_MAKE_ENUM_FLAGS(ViewFlags)
struct ViewDesc
{
EnumFlags<ViewFlags> flags = ViewFlags::DEFAULT;
RenderTargetDesc renderTargetDesc;
Array<Scene*> scenes;
Camera* camera = nullptr;
BoundingBox bounds = BoundingBox::Empty();
int priority = 0;
float resolutionScale = 1.0f;
Optional<RenderableAttributeSet> overrideAttributes;
const Class* entityBatchClass = nullptr;
};
class ViewOutputTarget
{
public:
ViewOutputTarget();
ViewOutputTarget(const FramebufferRef& framebuffer);
ViewOutputTarget(const Handle<GBuffer>& gbuffer);
ViewOutputTarget(const ViewOutputTarget& other) = delete;
ViewOutputTarget& operator=(const ViewOutputTarget& other) = delete;
ViewOutputTarget(ViewOutputTarget&& other) noexcept = default;
ViewOutputTarget& operator=(ViewOutputTarget&& other) noexcept = default;
~ViewOutputTarget();
HYP_FORCE_INLINE bool IsValid() const
{
return bool(m_impl);
}
const Handle<GBuffer>& GetGBuffer() const;
const FramebufferRef& GetFramebuffer() const;
const FramebufferRef& GetFramebuffer(RenderBucket rb) const;
Span<const FramebufferRef> GetFramebuffers() const;
private:
Handle<ObjectBase> m_impl;
};
HYP_CLASS()
class HYP_API View final : public ObjectBase
{
HYP_OBJECT_BODY(View);
friend class World;
public:
View();
explicit View(const ViewDesc& viewDesc, Name name = Name::Invalid());
View(const View& other) = delete;
View& operator=(const View& other) = delete;
View(View&& other) noexcept = delete;
View& operator=(View&& other) noexcept = delete;
~View();
HYP_FORCE_INLINE const ViewDesc& GetViewDesc() const
{
return m_viewDesc;
}
HYP_FORCE_INLINE Name GetName() const
{
return m_name;
}
HYP_FORCE_INLINE void SetName(Name name)
{
m_name = name;
}
HYP_FORCE_INLINE EnumFlags<ViewFlags> GetFlags() const
{
return m_flags;
}
HYP_METHOD()
const Array<Scene*>& GetScenes() const
{
return m_scenes;
}
HYP_METHOD()
void AddScene(Scene* scene);
HYP_METHOD()
void RemoveScene(Scene* scene);
HYP_METHOD()
const Handle<Camera>& GetCamera() const
{
return m_camera;
}
HYP_FORCE_INLINE const ViewOutputTarget& GetOutputTarget() const
{
return m_outputTarget;
}
HYP_METHOD()
int GetPriority() const
{
return m_priority;
}
HYP_METHOD()
void SetPriority(int priority);
HYP_FORCE_INLINE const Optional<RenderableAttributeSet>& GetOverrideAttributes() const
{
return m_overrideAttributes;
}
HYP_FORCE_INLINE RenderProxyList* GetRenderProxyList(uint32 index) const
{
return m_renderProxyLists[index];
}
HYP_FORCE_INLINE const WeakHandle<View>& GetRayTracingView() const
{
return m_rayTracingView;
}
HYP_FORCE_INLINE const Frustum& GetSubFrustum() const
{
return m_subFrustum;
}
HYP_FORCE_INLINE const ProcRef<void(RenderProxyList&)>& GetOverrideCollectFunctor() const
{
return m_overrideCollectFunctor;
}
HYP_FORCE_INLINE void SetOverrideCollectFunctor(const ProcRef<void(RenderProxyList&)>& ref)
{
m_overrideCollectFunctor = ref;
}
bool TestRay(const Ray& ray, RayTestResults& outResults, EnumFlags<RayTestFlags> flags = RayTestFlags::TestBVH) const;
/*! \brief Sync changes to the Viewport so the render thread can see updates to it for the next frame */
void UpdateViewport();
/*! \brief Computes visibility states for all Scenes this View has using the Camera */
void UpdateVisibility();
void PrepareShadowViews(Array<View*, SceneTempAllocator>& outShadowViews);
/*! \brief Enqueue tasks to `batch` to asynchronously collect entities and other scene resources for the current View. */
void BeginAsyncCollection(TaskBatch& batch);
/*! \brief End asynchronous scene collection tasks */
void EndAsyncCollection();
/*! \brief Synchronously collect scene resources for the View, blocks the current thread until complete. */
void CollectSync();
protected:
void Init() override;
void CollectCameras(RenderProxyList& rpl);
void CollectLights(RenderProxyList& rpl);
void CollectLightmapVolumes(RenderProxyList& rpl);
void CollectParticleVolumes(RenderProxyList& rpl);
void CollectFogVolumes(RenderProxyList& rpl);
void CollectEnvGrids(RenderProxyList& rpl);
void CollectEnvProbes(RenderProxyList& rpl);
void CollectMeshEntities(RenderProxyList& rpl);
ViewDesc m_viewDesc;
Name m_name;
EnumFlags<ViewFlags> m_flags;
Array<Scene*> m_scenes;
Handle<Camera> m_camera;
ViewOutputTarget m_outputTarget;
// optional rayTracing View set by the world
WeakHandle<View> m_rayTracingView;
RenderProxyList* m_renderProxyLists[RingBufferDepth];
Frustum m_subFrustum;
int m_priority;
Optional<RenderableAttributeSet> m_overrideAttributes;
ProcRef<void(RenderProxyList&)> m_overrideCollectFunctor;
TaskBatch* m_collectionTaskBatch;
};
} // namespace Hyperion