candlewick 0.7.0-59-g23c6
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 virtual void update() = 0;
26 virtual ~IDebugSubSystem() = default;
27
28protected:
30 explicit IDebugSubSystem(DebugScene &scene) : m_scene(scene) {}
31};
32
39 std::vector<Float4> colors;
40 bool enable = true;
41 Float3 scale = Float3::Ones();
42};
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
57 void setupPipelines(const MeshLayout &layout);
58
59public:
60 enum { TRANSFORM_SLOT = 0 };
61 enum { COLOR_SLOT = 0 };
62
63 DebugScene(entt::registry &registry, const RenderContext &renderer);
64 DebugScene(const DebugScene &) = delete;
65 DebugScene &operator=(const DebugScene &) = delete;
68
69 const Device &device() const noexcept { return m_renderer.device; }
70 entt::registry &registry() { return m_registry; }
71 const entt::registry &registry() const { return m_registry; }
72
74 template <std::derived_from<IDebugSubSystem> System, typename... Args>
75 System &addSystem(Args &&...args) {
76 auto sys = std::make_unique<System>(*this, std::forward<Args>(args)...);
77 auto &p = m_subsystems.emplace_back(std::move(sys));
78 return static_cast<System &>(*p);
79 }
80
82 std::tuple<entt::entity, DebugMeshComponent &>
83 addTriad(const Float3 &scale = Float3::Ones());
84
87 std::tuple<entt::entity, DebugMeshComponent &>
88 addLineGrid(const Float4 &color = Float4::Ones());
89
90 void update() {
91 for (auto &system : m_subsystems) {
92 system->update();
93 }
94 }
95
96 void render(CommandBuffer &cmdBuf, const Camera &camera) const;
97
98 void release();
99
101};
102static_assert(Scene<DebugScene>);
103
104} // namespace candlewick
Definition CommandBuffer.h:17
Scene for organizing debug entities and render systems.
Definition DebugScene.h:50
entt::registry & registry()
Definition DebugScene.h:70
DebugScene & operator=(const DebugScene &)=delete
const entt::registry & registry() const
Definition DebugScene.h:71
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:75
std::tuple< entt::entity, DebugMeshComponent & > addTriad(const Float3 &scale=Float3::Ones())
Just the basic 3D triad.
DebugScene(DebugScene &&other)
@ COLOR_SLOT
Definition DebugScene.h:61
void update()
Definition DebugScene.h:90
DebugScene & operator=(DebugScene &&)=delete
DebugScene(const DebugScene &)=delete
~DebugScene()
Definition DebugScene.h:100
const Device & device() const noexcept
Definition DebugScene.h:69
@ TRANSFORM_SLOT
Definition DebugScene.h:60
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
The main way of using a camera to render things.
Definition Camera.h:19
Component for simple mesh with colors.
Definition DebugScene.h:36
std::vector< Float4 > colors
Definition DebugScene.h:39
DebugPipelines pipeline_type
Definition DebugScene.h:37
Float3 scale
Definition DebugScene.h:41
bool enable
Definition DebugScene.h:40
Mesh mesh
Definition DebugScene.h:38
RAII wrapper for SDL_GPUDevice.
Definition Device.h:17
IDebugSubSystem(DebugScene &scene)
Definition DebugScene.h:30
DebugScene & m_scene
Definition DebugScene.h:29
virtual ~IDebugSubSystem()=default
The RenderContext class provides a rendering context for a graphical application.
Definition RenderContext.h:20