candlewick 0.6.0
A tiny cross-platform renderer based on SDL3
Loading...
Searching...
No Matches
Frustum.h
Go to the documentation of this file.
1#pragma once
2
3#include "../Core.h"
4#include "../Device.h"
5#include "../Collision.h"
6#include "../math_types.h"
7
8#include <entt/entity/registry.hpp>
9#include <SDL3/SDL_gpu.h>
10#include <variant>
11
12namespace candlewick {
13namespace frustum_debug {
14
15 SDL_GPUGraphicsPipeline *
17
18 void renderFrustum(CommandBuffer &cmdBuf, SDL_GPURenderPass *render_pass,
19 const Camera &mainCamera, const Camera &otherCam,
20 const Float4 &color = 0x40FF00CC_rgbaf);
21
22 void renderAABB(CommandBuffer &cmdBuf, SDL_GPURenderPass *render_pass,
23 const Camera &camera, const AABB &aabb,
24 const Float4 &color = 0x00BFFFff_rgbaf);
25
26 void renderOBB(CommandBuffer &cmdBuf, SDL_GPURenderPass *render_pass,
27 const Camera &camera, const coal::OBB &obb,
28 const Float4 &color = 0x00BFFFff_rgbaf);
29
30 void renderFrustum(CommandBuffer &cmdBuf, SDL_GPURenderPass *render_pass,
31 const Mat4f &invProj, const Mat4f &mvp,
32 const Float3 eyePos, const Float4 &color);
33
34} // namespace frustum_debug
35
40
42 std::variant<AABB, coal::OBB> bounds;
43 GpuVec4 color = 0xA03232FF_rgbaf;
44};
45
47 const RenderContext &renderer;
48 const Device &device;
49 SDL_GPUGraphicsPipeline *pipeline;
50 entt::registry &_registry;
51
52public:
54 const RenderContext &renderer);
55
56 entt::registry &registry() { return _registry; }
57 const entt::registry &registry() const { return _registry; }
58
59 std::tuple<entt::entity, DebugFrustumComponent &>
60 addFrustum(const Camera &otherCam, Float4 color = 0x00BFFFff_rgbaf) {
61 auto entity = registry().create();
62 auto &item =
63 registry().emplace<DebugFrustumComponent>(entity, &otherCam, color);
64 return {entity, item};
65 }
66
67 template <typename BoundsType>
68 std::tuple<entt::entity, DebugBoundsComponent &>
69 addBounds(const BoundsType &bounds) {
70 auto entity = registry().create();
71 auto &item = registry().emplace<DebugBoundsComponent>(entity, bounds);
72 return {entity, item};
73 }
74
75 void render(CommandBuffer &cmdBuf, const Camera &camera);
76
77 void release() noexcept {
78 if (pipeline)
79 SDL_ReleaseGPUGraphicsPipeline(device, pipeline);
80 }
81
83};
84
85} // namespace candlewick
Definition CommandBuffer.h:17
std::tuple< entt::entity, DebugFrustumComponent & > addFrustum(const Camera &otherCam, Float4 color=0x00BFFFff_rgbaf)
Definition Frustum.h:60
FrustumBoundsDebugSystem(entt::registry &registry, const RenderContext &renderer)
~FrustumBoundsDebugSystem()
Definition Frustum.h:82
std::tuple< entt::entity, DebugBoundsComponent & > addBounds(const BoundsType &bounds)
Definition Frustum.h:69
void render(CommandBuffer &cmdBuf, const Camera &camera)
const entt::registry & registry() const
Definition Frustum.h:57
void release() noexcept
Definition Frustum.h:77
entt::registry & registry()
Definition Frustum.h:56
Definition Frustum.h:13
void renderFrustum(CommandBuffer &cmdBuf, SDL_GPURenderPass *render_pass, const Camera &mainCamera, const Camera &otherCam, const Float4 &color=0x40FF00CC_rgbaf)
void renderOBB(CommandBuffer &cmdBuf, SDL_GPURenderPass *render_pass, const Camera &camera, const coal::OBB &obb, const Float4 &color=0x00BFFFff_rgbaf)
SDL_GPUGraphicsPipeline * createFrustumDebugPipeline(const RenderContext &renderer)
void renderAABB(CommandBuffer &cmdBuf, SDL_GPURenderPass *render_pass, const Camera &camera, const AABB &aabb, const Float4 &color=0x00BFFFff_rgbaf)
Definition Camera.h:8
Eigen::Vector3f Float3
Definition math_types.h:8
Eigen::Vector4f Float4
Definition math_types.h:9
Eigen::Matrix< float, 4, 1, Eigen::DontAlign > GpuVec4
Definition math_types.h:19
Eigen::Matrix4f Mat4f
Definition math_types.h:11
The main way of using a camera to render things.
Definition Camera.h:19
Definition Frustum.h:41
GpuVec4 color
Definition Frustum.h:43
std::variant< AABB, coal::OBB > bounds
Definition Frustum.h:42
Definition Frustum.h:36
Camera const * otherCam
Definition Frustum.h:37
GpuVec4 color
Definition Frustum.h:38
RAII wrapper for SDL_GPUDevice.
Definition Device.h:17
The RenderContext class provides a rendering context for a graphical application.
Definition RenderContext.h:20