Hymn to Beauty
C++ 3D Engine
DebugDrawing.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <glm/glm.hpp>
4#include <vector>
6
7namespace Video {
8class Renderer;
9class LowLevelRenderer;
10class CommandBuffer;
11class Buffer;
12class Shader;
13class ShaderProgram;
14class GraphicsPipeline;
15class VertexDescription;
16class GeometryBinding;
17
20 public:
22 struct Point {
24 glm::vec3 position;
25
27 glm::vec3 color;
28
30 float size;
31
33 float duration;
34
37 };
38
40 struct Line {
42 glm::vec3 startPosition;
43
45 glm::vec3 endPosition;
46
48 glm::vec3 color;
49
51 float width;
52
54 float duration;
55
58 };
59
61 struct Cuboid {
63 glm::vec3 dimensions;
64
66 glm::mat4 matrix;
67
69 glm::vec3 color;
70
72 float lineWidth;
73
75 float duration;
76
79 };
80
82 struct Plane {
84 glm::vec3 position;
85
87 glm::vec3 normal;
88
90 glm::vec2 size;
91
93 glm::vec3 color;
94
96 float lineWidth;
97
99 float duration;
100
103 };
104
106 struct Circle {
108 glm::vec3 position;
109
111 glm::vec3 normal;
112
114 float radius;
115
117 glm::vec3 color;
118
121
123 float duration;
124
127 };
128
130 struct Sphere {
132 glm::vec3 position;
133
135 float radius;
136
138 glm::vec3 color;
139
142
144 float duration;
145
148 };
149
151 struct Cylinder {
153 float radius;
154
156 float length;
157
159 glm::mat4 matrix;
160
162 glm::vec3 color;
163
166
168 float duration;
169
172 };
173
175 struct Cone {
177 float radius;
178
180 float height;
181
183 glm::mat4 matrix;
184
186 glm::vec3 color;
187
190
192 float duration;
193
196 };
197
199 struct Mesh {
201 glm::mat4 matrix;
202
204 glm::vec3 color;
205
208
210 float duration;
211
214
216 unsigned int indexCount = 0;
217
220 };
221
223
226 explicit DebugDrawing(Renderer* renderer);
227
230
232
237 void StartDebugDrawing(CommandBuffer* commandBuffer, const glm::mat4& viewProjectionMatrix);
238
240
243 void DrawPoint(const Point& point);
244
246
249 void DrawLine(const Line& line);
250
252
255 void DrawCuboid(const Cuboid& cuboid);
256
258
261 void DrawPlane(const Plane& plane);
262
264
267 void DrawCircle(const Circle& circle);
268
270
273 void DrawSphere(const Sphere& sphere);
274
276
279 void DrawCylinder(const Cylinder& cylinder);
280
282
285 void DrawCone(const Cone& cone);
286
288
291 void DrawMesh(const Mesh& mesh);
292
294 void EndDebugDrawing();
295
296 private:
297 DebugDrawing(const DebugDrawing& other) = delete;
298
299 void CreateVertexBuffer(const glm::vec3* positions, unsigned int positionCount, Buffer*& vertexBuffer, GeometryBinding*& geometryBinding);
300 void BindGraphicsPipeline(GraphicsPipeline* graphicsPipeline);
301 void BindGeometry(GeometryBinding* geometryBinding);
302 void CreateCircle(glm::vec3*& positions, unsigned int& vertexCount, unsigned int detail);
303 void CreateSphere(glm::vec3*& positions, unsigned int& vertexCount, unsigned int detail);
304 void CreateCylinder(glm::vec3*& positions, unsigned int& vertexCount, unsigned int detail);
305 void CreateCone(glm::vec3*& positions, unsigned int& vertexCount, unsigned int detail);
306
307 Renderer* renderer;
308 LowLevelRenderer* lowLevelRenderer;
309 CommandBuffer* commandBuffer = nullptr;
310 Shader* vertexShader;
311 Shader* fragmentShader;
312 ShaderProgram* shaderProgram;
313 Shader* pointVertexShader;
314 ShaderProgram* pointShaderProgram;
315
316 GraphicsPipeline* pointGraphicsPipeline[2];
317 GraphicsPipeline* lineGraphicsPipeline[2];
318 GraphicsPipeline* lineTriangleGraphicsPipeline[2];
319 GraphicsPipeline* fillTriangleGraphicsPipeline[2];
320
321 // Shader resources.
322 Buffer* matricesBuffer;
323 struct PushConstantData {
324 glm::mat4 modelMatrix;
325 glm::vec4 colorSize;
326 };
327 struct PointPushConstantData {
328 glm::vec4 position;
329 glm::vec4 colorSize;
330 glm::vec2 screenSize;
331 };
332
333 // Geometry.
334 Buffer* pointVertexBuffer;
335 GeometryBinding* pointGeometryBinding;
336
337 Buffer* lineVertexBuffer;
338 GeometryBinding* lineGeometryBinding;
339
340 Buffer* cuboidVertexBuffer;
341 GeometryBinding* cuboidGeometryBinding;
342
343 Buffer* planeVertexBuffer;
344 GeometryBinding* planeGeometryBinding;
345
346 Buffer* sphereVertexBuffer;
347 GeometryBinding* sphereGeometryBinding;
348 unsigned int sphereVertexCount;
349
350 Buffer* circleVertexBuffer;
351 GeometryBinding* circleGeometryBinding;
352 unsigned int circleVertexCount;
353
354 Buffer* cylinderVertexBuffer;
355 GeometryBinding* cylinderGeometryBinding;
356 unsigned int cylinderVertexCount;
357
358 Buffer* coneVertexBuffer;
359 GeometryBinding* coneGeometryBinding;
360 unsigned int coneVertexCount;
361
362 VertexDescription* vertexDescription;
363 VertexDescription* meshVertexDescription;
364 GraphicsPipeline* boundGraphicsPipeline = nullptr;
365 const GeometryBinding* boundGeometry = nullptr;
366};
367} // namespace Video
A buffer containing GPU accessible data.
Definition: Buffer.hpp:8
A buffer into which rendering commands are recorded.
Definition: CommandBuffer.hpp:24
Draws debug primitives.
Definition: DebugDrawing.hpp:19
void DrawPoint(const Point &point)
Draw a point.
Definition: DebugDrawing.cpp:195
void DrawCircle(const Circle &circle)
Draw a circle.
Definition: DebugDrawing.cpp:265
void DrawMesh(const Mesh &mesh)
Draw a mesh.
Definition: DebugDrawing.cpp:341
DebugDrawing(Renderer *renderer)
Create new debug primitive renderer.
Definition: DebugDrawing.cpp:21
void DrawLine(const Line &line)
Draw a line.
Definition: DebugDrawing.cpp:209
void DrawPlane(const Plane &plane)
Draw a plane.
Definition: DebugDrawing.cpp:243
void DrawSphere(const Sphere &sphere)
Draw a sphere.
Definition: DebugDrawing.cpp:287
~DebugDrawing()
Destructor.
Definition: DebugDrawing.cpp:143
void DrawCone(const Cone &cone)
Draw a cone.
Definition: DebugDrawing.cpp:323
void EndDebugDrawing()
Stop debug drawing.
Definition: DebugDrawing.cpp:361
void DrawCylinder(const Cylinder &cylinder)
Draw a cylinder.
Definition: DebugDrawing.cpp:305
void DrawCuboid(const Cuboid &cuboid)
Draw a cuboid.
Definition: DebugDrawing.cpp:226
void StartDebugDrawing(CommandBuffer *commandBuffer, const glm::mat4 &viewProjectionMatrix)
Start rendering debug primitives.
Definition: DebugDrawing.cpp:188
Binds together a vertex description with buffers.
Definition: GeometryBinding.hpp:8
A graphics pipeline.
Definition: GraphicsPipeline.hpp:11
Low level renderer abstracting the underlaying graphics API (OpenGL or Vulkan).
Definition: LowLevelRenderer.hpp:27
Handles rendering using a low-level renderer.
Definition: Renderer.hpp:32
Compiles and handles a shader. Shaders should be linked together into a ShaderProgram.
Definition: Shader.hpp:8
A shader program.
Definition: ShaderProgram.hpp:11
Definition: Editor.hpp:18
A debug drawing circle.
Definition: DebugDrawing.hpp:106
float lineWidth
Line width.
Definition: DebugDrawing.hpp:120
float duration
Duration (in seconds).
Definition: DebugDrawing.hpp:123
float radius
Radius.
Definition: DebugDrawing.hpp:114
glm::vec3 position
The center position of the circle.
Definition: DebugDrawing.hpp:108
bool depthTesting
Whether to enable depth testing.
Definition: DebugDrawing.hpp:126
glm::vec3 color
Color.
Definition: DebugDrawing.hpp:117
glm::vec3 normal
The circle normal.
Definition: DebugDrawing.hpp:111
A debug drawing cone.
Definition: DebugDrawing.hpp:175
glm::vec3 color
Color.
Definition: DebugDrawing.hpp:186
float height
Height.
Definition: DebugDrawing.hpp:180
glm::mat4 matrix
The matrix used to transform the cone.
Definition: DebugDrawing.hpp:183
bool depthTesting
Whether to enable depth testing.
Definition: DebugDrawing.hpp:195
float duration
Duration (in seconds).
Definition: DebugDrawing.hpp:192
float radius
Radius.
Definition: DebugDrawing.hpp:177
float lineWidth
Line width.
Definition: DebugDrawing.hpp:189
A debug drawing cuboid.
Definition: DebugDrawing.hpp:61
glm::mat4 matrix
The matrix used to transform the cuboid.
Definition: DebugDrawing.hpp:66
float duration
Duration (in seconds).
Definition: DebugDrawing.hpp:75
float lineWidth
Line width.
Definition: DebugDrawing.hpp:72
glm::vec3 dimensions
The dimensions of the cuboid.
Definition: DebugDrawing.hpp:63
bool depthTesting
Whether to enable depth testing.
Definition: DebugDrawing.hpp:78
glm::vec3 color
Color.
Definition: DebugDrawing.hpp:69
A debug drawing cylinder.
Definition: DebugDrawing.hpp:151
float radius
Radius.
Definition: DebugDrawing.hpp:153
glm::vec3 color
Color.
Definition: DebugDrawing.hpp:162
glm::mat4 matrix
The matrix used to transform the cylinder.
Definition: DebugDrawing.hpp:159
bool depthTesting
Whether to enable depth testing.
Definition: DebugDrawing.hpp:171
float duration
Duration (in seconds).
Definition: DebugDrawing.hpp:168
float length
Length.
Definition: DebugDrawing.hpp:156
float lineWidth
Line width.
Definition: DebugDrawing.hpp:165
A debug drawing line.
Definition: DebugDrawing.hpp:40
float width
Line width.
Definition: DebugDrawing.hpp:51
glm::vec3 endPosition
End position of the line.
Definition: DebugDrawing.hpp:45
glm::vec3 color
Color.
Definition: DebugDrawing.hpp:48
glm::vec3 startPosition
Starting position of the line.
Definition: DebugDrawing.hpp:42
float duration
Duration (in seconds).
Definition: DebugDrawing.hpp:54
bool depthTesting
Whether to enable depth testing.
Definition: DebugDrawing.hpp:57
A debug drawing mesh.
Definition: DebugDrawing.hpp:199
bool depthTesting
Whether to enable depth testing.
Definition: DebugDrawing.hpp:213
float duration
Duration (in seconds).
Definition: DebugDrawing.hpp:210
unsigned int indexCount
Index count.
Definition: DebugDrawing.hpp:216
glm::mat4 matrix
The matrix used to transform the cone.
Definition: DebugDrawing.hpp:201
GeometryBinding * geometryBinding
Geometry binding.
Definition: DebugDrawing.hpp:219
glm::vec3 color
Color.
Definition: DebugDrawing.hpp:204
bool wireFrame
Draw wire framed.
Definition: DebugDrawing.hpp:207
A debug drawing plane.
Definition: DebugDrawing.hpp:82
glm::vec2 size
Size.
Definition: DebugDrawing.hpp:90
bool depthTesting
Whether to enable depth testing.
Definition: DebugDrawing.hpp:102
float lineWidth
Line width.
Definition: DebugDrawing.hpp:96
glm::vec3 position
The center position of the plane.
Definition: DebugDrawing.hpp:84
glm::vec3 color
Color.
Definition: DebugDrawing.hpp:93
glm::vec3 normal
The plane normal.
Definition: DebugDrawing.hpp:87
float duration
Duration (in seconds).
Definition: DebugDrawing.hpp:99
A debug drawing point.
Definition: DebugDrawing.hpp:22
float size
Size.
Definition: DebugDrawing.hpp:30
glm::vec3 color
Color.
Definition: DebugDrawing.hpp:27
glm::vec3 position
World position.
Definition: DebugDrawing.hpp:24
bool depthTesting
Whether to enable depth testing.
Definition: DebugDrawing.hpp:36
float duration
Duration (in seconds).
Definition: DebugDrawing.hpp:33
A debug drawing sphere.
Definition: DebugDrawing.hpp:130
glm::vec3 color
Color.
Definition: DebugDrawing.hpp:138
glm::vec3 position
The center position of the sphere.
Definition: DebugDrawing.hpp:132
float duration
Duration (in seconds).
Definition: DebugDrawing.hpp:144
float lineWidth
Line width.
Definition: DebugDrawing.hpp:141
bool depthTesting
Whether to enable depth testing.
Definition: DebugDrawing.hpp:147
float radius
Radius.
Definition: DebugDrawing.hpp:135