candlewick 0.9.0
A tiny cross-platform renderer based on SDL3
Loading...
Searching...
No Matches
DebugScene.h
Go to the documentation of this file.
1#pragma once
2
3#include "Scene.h"
4#include "Mesh.h"
5#include "RenderContext.h"
6#include "math_types.h"
7
8#include <entt/entity/registry.hpp>
9#include <entt/signal/sigh.hpp>
10
11namespace candlewick {
12
17
18class DebugScene;
19
25
31 virtual void update() = 0;
32 virtual ~IDebugSubSystem() = default;
33
34protected:
36 explicit IDebugSubSystem(DebugScene &scene) : m_scene(scene) {}
37};
38
42struct DebugMeshComponent;
43
51 entt::registry &m_registry;
52 const RenderContext &m_renderer;
53 SDL_GPUGraphicsPipeline *m_trianglePipeline{nullptr};
54 SDL_GPUGraphicsPipeline *m_linePipeline{nullptr};
55 std::vector<std::unique_ptr<IDebugSubSystem>> m_subsystems;
56 std::unordered_map<DebugMeshType, Mesh> m_sharedMeshes;
57 inline static const std::array<Float4, 3> m_triadColors = {
58 Float4{1., 0., 0., 1.},
59 Float4{0., 1., 0., 1.},
60 Float4{0., 0., 1., 1.},
61 };
62
63 void initializeSharedMeshes();
64
65 void setupPipelines(const MeshLayout &layout);
66
67public:
68 enum : Uint32 { TRANSFORM_SLOT = 0 };
69 enum : Uint32 { COLOR_SLOT = 0 };
70 using enum DebugMeshType;
71
72 const Mesh &getMesh(DebugMeshType type) const {
73 return m_sharedMeshes.at(type);
74 }
75
76 DebugScene(entt::registry &registry, const RenderContext &renderer);
77 DebugScene(const DebugScene &) = delete;
78 DebugScene &operator=(const DebugScene &) = delete;
81
82 const Device &device() const noexcept { return m_renderer.device; }
83 entt::registry &registry() { return m_registry; }
84 const entt::registry &registry() const { return m_registry; }
85
87 template <std::derived_from<IDebugSubSystem> System, typename... Args>
88 System &addSystem(Args &&...args) {
89 auto sys = std::make_unique<System>(*this, std::forward<Args>(args)...);
90 auto &p = m_subsystems.emplace_back(std::move(sys));
91 return static_cast<System &>(*p);
92 }
93
95 std::tuple<entt::entity, DebugMeshComponent &>
96 addTriad(const Float3 &scale = Float3::Ones());
97
100 std::tuple<entt::entity, DebugMeshComponent &>
101 addLineGrid(const Float4 &color = Float4::Ones());
102
104 entt::entity addArrow(const Float4 &color = 0xf351ff_rgbaf);
105
106 void update() {
107 for (auto &system : m_subsystems) {
108 system->update();
109 }
110 }
111
112 void render(CommandBuffer &cmdBuf, const Camera &camera) const;
113
114 void release();
115
117};
118static_assert(Scene<DebugScene>);
119
123 std::vector<Float4> colors;
124 bool enable = true;
125 Float3 scale = Float3::Ones();
126};
127
128} // namespace candlewick
Definition CommandBuffer.h:17
Scene for organizing debug entities and render systems.
Definition DebugScene.h:50
entt::registry & registry()
Definition DebugScene.h:83
entt::entity addArrow(const Float4 &color=0xf351ff_rgbaf)
Add an arrow debug entity.
DebugScene & operator=(const DebugScene &)=delete
const Mesh & getMesh(DebugMeshType type) const
Definition DebugScene.h:72
const entt::registry & registry() const
Definition DebugScene.h:84
std::tuple< entt::entity, DebugMeshComponent & > addLineGrid(const Float4 &color=Float4::Ones())
Add a basic line grid.
DebugScene(entt::registry &registry, const RenderContext &renderer)
void render(CommandBuffer &cmdBuf, const Camera &camera) const
System & addSystem(Args &&...args)
Add a subsystem (IDebugSubSystem) to the scene.
Definition DebugScene.h:88
std::tuple< entt::entity, DebugMeshComponent & > addTriad(const Float3 &scale=Float3::Ones())
Just the basic 3D triad.
DebugScene(DebugScene &&other)
@ TRANSFORM_SLOT
Definition DebugScene.h:68
void update()
Definition DebugScene.h:106
@ COLOR_SLOT
Definition DebugScene.h:69
DebugScene & operator=(DebugScene &&)=delete
DebugScene(const DebugScene &)=delete
~DebugScene()
Definition DebugScene.h:116
const Device & device() const noexcept
Definition DebugScene.h:82
This class defines the layout of a mesh's vertices.
Definition MeshLayout.h:122
Handle class for meshes (vertex buffers and an optional index buffer) on the GPU.
Definition Mesh.h:57
Definition Camera.h:8
Eigen::Vector3f Float3
Definition math_types.h:8
DebugPipelines
Definition DebugScene.h:13
@ TRIANGLE_FILL
Definition DebugScene.h:14
@ TRIANGLE_LINE
Definition DebugScene.h:15
Eigen::Vector4f Float4
Definition math_types.h:9
DebugMeshType
Definition DebugScene.h:20
@ TRIAD
Definition DebugScene.h:21
@ GRID
Definition DebugScene.h:22
@ ARROW
Definition DebugScene.h:23
The main way of using a camera to render things.
Definition Camera.h:19
Definition DebugScene.h:120
std::vector< Float4 > colors
Definition DebugScene.h:123
DebugMeshType meshType
Definition DebugScene.h:122
DebugPipelines pipeline_type
Definition DebugScene.h:121
Float3 scale
Definition DebugScene.h:125
bool enable
Definition DebugScene.h:124
RAII wrapper for SDL_GPUDevice.
Definition Device.h:17
IDebugSubSystem(DebugScene &scene)
Definition DebugScene.h:36
DebugScene & m_scene
Definition DebugScene.h:35
virtual ~IDebugSubSystem()=default
The RenderContext class provides a rendering context for a graphical application.
Definition RenderContext.h:20