candlewick 0.6.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 <optional>
9#include <entt/entity/registry.hpp>
10#include <entt/signal/sigh.hpp>
11
12namespace candlewick {
13
18
19class DebugScene;
20
26 virtual void update(DebugScene & /*scene*/) = 0;
27 virtual ~IDebugSubSystem() = default;
28};
29
36 std::vector<GpuVec4> colors;
37 bool enable = true;
38 Float3 scale = Float3::Ones();
39};
40
45 entt::registry &m_registry;
46 const RenderContext &m_renderer;
47 SDL_GPUGraphicsPipeline *m_trianglePipeline{nullptr};
48 SDL_GPUGraphicsPipeline *m_linePipeline{nullptr};
49 std::vector<std::unique_ptr<IDebugSubSystem>> m_subsystems;
50
51public:
52 enum { TRANSFORM_SLOT = 0 };
53 enum { COLOR_SLOT = 0 };
54
55 DebugScene(entt::registry &registry, const RenderContext &renderer);
56 DebugScene(const DebugScene &) = delete;
57 DebugScene &operator=(const DebugScene &) = delete;
60
61 const Device &device() const noexcept { return m_renderer.device; }
62 entt::registry &registry() { return m_registry; }
63 const entt::registry &registry() const { return m_registry; }
64
66 template <std::derived_from<IDebugSubSystem> System, typename... Args>
67 System &addSystem(Args &&...args) {
68 auto sys = std::make_unique<System>(std::forward<Args>(args)...);
69 auto &p = m_subsystems.emplace_back(std::move(sys));
70 return static_cast<System &>(*p);
71 }
72
74 void setupPipelines(const MeshLayout &layout);
75
77 std::tuple<entt::entity, DebugMeshComponent &>
78 addTriad(const Float3 &scale = Float3::Ones());
80 std::tuple<entt::entity, DebugMeshComponent &>
81 addLineGrid(std::optional<Float4> color = std::nullopt);
82
83 void update() {
84 for (auto &system : m_subsystems) {
85 system->update(*this);
86 }
87 }
88
89 void render(CommandBuffer &cmdBuf, const Camera &camera) const;
90
91 void release();
92
94};
95static_assert(Scene<DebugScene>);
96
97} // namespace candlewick
Definition CommandBuffer.h:17
Scene for organizing debug entities and render systems.
Definition DebugScene.h:44
entt::registry & registry()
Definition DebugScene.h:62
DebugScene & operator=(const DebugScene &)=delete
void setupPipelines(const MeshLayout &layout)
Setup pipelines; this will only have an effect ONCE.
const entt::registry & registry() const
Definition DebugScene.h:63
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:67
std::tuple< entt::entity, DebugMeshComponent & > addTriad(const Float3 &scale=Float3::Ones())
Just the basic 3D triad.
DebugScene(DebugScene &&other)
@ COLOR_SLOT
Definition DebugScene.h:53
void update()
Definition DebugScene.h:83
DebugScene & operator=(DebugScene &&)=delete
DebugScene(const DebugScene &)=delete
~DebugScene()
Definition DebugScene.h:93
std::tuple< entt::entity, DebugMeshComponent & > addLineGrid(std::optional< Float4 > color=std::nullopt)
Add a basic line grid.
const Device & device() const noexcept
Definition DebugScene.h:61
@ TRANSFORM_SLOT
Definition DebugScene.h:52
This class defines the layout of a mesh's vertices.
Definition MeshLayout.h:98
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:14
@ LINE
Definition DebugScene.h:16
@ TRIANGLE_FILL
Definition DebugScene.h:15
The main way of using a camera to render things.
Definition Camera.h:19
Component for simple mesh with colors.
Definition DebugScene.h:33
std::vector< GpuVec4 > colors
Definition DebugScene.h:36
DebugPipelines pipeline_type
Definition DebugScene.h:34
Float3 scale
Definition DebugScene.h:38
bool enable
Definition DebugScene.h:37
Mesh mesh
Definition DebugScene.h:35
RAII wrapper for SDL_GPUDevice.
Definition Device.h:17
A subsystem for the DebugScene.
Definition DebugScene.h:25
virtual void update(DebugScene &)=0
virtual ~IDebugSubSystem()=default
The RenderContext class provides a rendering context for a graphical application.
Definition RenderContext.h:20