Brunot
Loading...
Searching...
No Matches
DebugDraw.h
Go to the documentation of this file.
1// DebugDraw.h
2// File: DebugDraw.h
3// Description: A system to collect lines and render them all at once each frame for debug information. recommended uses
4// are hitboxes, paths, relationships, grids, and vectors.
5// Author(s): Aidan Hartman (aidan.hartman@digipen.edu)
6// 2025 / 11 / 07
7// (C) Digipen 2025
8// ____ __ __ __
9// /\__ _\/\ \ /\ \/\ \
10// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
11// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
12// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
13// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
14// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
15
16#pragma once
17
18// true or false
19#ifdef _DEBUG
20#define DEBUG_DRAW_START_ACTIVE true
21#else
22#define DEBUG_DRAW_START_ACTIVE false
23#endif
24
25#include "Framework/System.h"
26#include "Graphics/VAO.h"
27
28class Line;
29
30
32// namespace gfx
33// {
34// struct Vertex;
35// }
36#include "Graphics/Vertex.h"
37
38namespace sys
39{
40class DebugDraw : public System
41{
42public:
43#pragma region static_functions
44
48 static auto getEnum() -> Type
49 {
50 return Type::DebugDraw;
51 }
52
58 static auto drawLine(const Line& line) -> void;
59
60
61#pragma endregion
62
63 DebugDraw();
64 ~DebugDraw() override = default;
65 DebugDraw(const DebugDraw& other) = default;
66 DebugDraw(DebugDraw&& other) noexcept;
67 auto operator=(const DebugDraw& other) -> DebugDraw&;
68 auto operator=(DebugDraw&& other) noexcept -> DebugDraw& = default;
69
70
71#pragma region overridden_functions
72
73 auto clone() const -> std::unique_ptr<GameObject> override
74 {
75 return std::make_unique<DebugDraw>(*this);
76 }
77
78 auto onUpdate(float dt) -> void override;
79 auto onRender() -> void override;
80
81protected:
82 auto systemShowMenu() -> void override;
83
84public:
85 auto load(Stream& stream) -> void override;
86 auto save(Stream& stream) const -> void override;
87 auto endWindow() -> void override;
88
89#pragma endregion
90
91#pragma region DebugDraw_Functions
92
93
98 auto addLine(const Line& line) -> void;
99
100
101#pragma endregion
102
103private:
104#pragma region member_variables
105
106 std::shared_ptr<VertexBuffer> vertexBuffer;
107 std::vector<std::pair<gfx::Vertex, gfx::Vertex>> lines;
109
110 int lineWidth{2};
111
112
113#pragma endregion
114
115#pragma region helper_functions
116 auto setupMesh() -> GLuint;
117
118#pragma endregion
119
120#pragma region static_variables
121
122#pragma endregion
123
124
125};
126}
127
135auto operator<<(sys::DebugDraw* debug, const Line& line) -> sys::DebugDraw*;
136
137#undef DEBUG_DRAW_START_ACTIVE
sys::Json Stream
Definition AudioObject.h:20
auto operator<<(sys::DebugDraw *debug, const Line &line) -> sys::DebugDraw *
stream insertion operator for adding lines to the debug draw system Uses DebugDraw pointer instead of...
Definition DebugDraw.cpp:190
#define DEBUG_DRAW_START_ACTIVE
Definition DebugDraw.h:22
unsigned int GLuint
Definition IndexBuffer.h:17
A struct for stroing vertexes and handing them to opengl.
GameObject(std::string typeName, gobj::Type parentType, gobj::Type type)
constructor for gameobject.
Definition GameObject.cpp:23
Definition Line.h:30
Type
Definition System.h:20
@ DebugDraw
Definition System.h:34
System(const std::string &typeName, Type systemType)
Definition System.cpp:75
Definition DebugDraw.h:41
int lineWidth
Definition DebugDraw.h:110
auto operator=(const DebugDraw &other) -> DebugDraw &
Definition DebugDraw.cpp:51
auto operator=(DebugDraw &&other) noexcept -> DebugDraw &=default
auto addLine(const Line &line) -> void
add a line to the debug renderer.
Definition DebugDraw.cpp:178
DebugDraw(const DebugDraw &other)=default
auto onUpdate(float dt) -> void override
called once every frame.
Definition DebugDraw.cpp:65
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition DebugDraw.h:73
static auto getEnum() -> Type
function required by all systems
Definition DebugDraw.h:48
bool active
Definition DebugDraw.h:108
auto onRender() -> void override
called every frame after update has been called for every object.
Definition DebugDraw.cpp:99
static auto drawLine(const Line &line) -> void
add a line to the debug renderer.
Definition DebugDraw.cpp:36
std::vector< std::pair< gfx::Vertex, gfx::Vertex > > lines
Definition DebugDraw.h:107
DebugDraw()
Definition DebugDraw.cpp:41
auto systemShowMenu() -> void override
Specific systems should override this function to show their specific menu for the system.
Definition DebugDraw.cpp:150
auto load(Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition DebugDraw.cpp:163
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition DebugDraw.cpp:168
auto setupMesh() -> GLuint
Definition DebugDraw.cpp:70
~DebugDraw() override=default
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition DebugDraw.cpp:173
std::shared_ptr< VertexBuffer > vertexBuffer
Definition DebugDraw.h:106
the type of elements in a basic_json container
Definition GameObject.h:32