Plasma Engine  2.0
Loading...
Searching...
No Matches
DebugRenderer.h
1#pragma once
2
3#include <Foundation/Math/Color.h>
4#include <Foundation/Math/Transform.h>
5#include <RendererCore/Debug/DebugRendererContext.h>
6#include <RendererCore/Declarations.h>
7#include <RendererCore/RendererCoreDLL.h>
8#include <RendererFoundation/Descriptors/Descriptors.h>
9
10template <typename Type>
11class plRectTemplate;
13
14class plFormatString;
15class plFrustum;
17
20{
21 using StorageType = plUInt8;
22
23 enum Enum
24 {
25 Left,
26 Center,
27 Right,
28
29 Default = Left
30 };
31};
32
33PL_DECLARE_REFLECTABLE_TYPE(PL_RENDERERCORE_DLL, plDebugTextHAlign);
34
37{
38 using StorageType = plUInt8;
39
40 enum Enum
41 {
42 Top,
43 Center,
44 Bottom,
45
46 Default = Top
47 };
48};
49
50PL_DECLARE_REFLECTABLE_TYPE(PL_RENDERERCORE_DLL, plDebugTextVAlign);
51
54{
55 using StorageType = plUInt8;
56
57 enum Enum
58 {
59 TopLeft,
60 TopCenter,
61 TopRight,
62 BottomLeft,
63 BottomCenter,
64 BottomRight,
65
66 ENUM_COUNT,
67
68 Default = TopLeft
69 };
70};
71
72PL_DECLARE_REFLECTABLE_TYPE(PL_RENDERERCORE_DLL, plDebugTextPlacement);
73
80class PL_RENDERERCORE_DLL plDebugRenderer
81{
82public:
83 struct Line
84 {
85 PL_DECLARE_POD_TYPE();
86
87 Line();
88 Line(const plVec3& vStart, const plVec3& vEnd);
89 Line(const plVec3& vStart, const plVec3& vEnd, const plColor& color);
90
91 plVec3 m_start;
92 plVec3 m_end;
93
94 plColor m_startColor = plColor::White;
95 plColor m_endColor = plColor::White;
96 };
97
98 struct Triangle
99 {
100 PL_DECLARE_POD_TYPE();
101
102 Triangle();
103 Triangle(const plVec3& v0, const plVec3& v1, const plVec3& v2);
104
105 plVec3 m_position[3];
106 plColor m_color = plColor::White;
107 };
108
110 {
111 PL_DECLARE_POD_TYPE();
112
113 plVec3 m_position[3];
114 plVec2 m_texcoord[3];
115 plColor m_color = plColor::White;
116 };
117
119 static void DrawLines(const plDebugRendererContext& context, plArrayPtr<const Line> lines, const plColor& color, const plTransform& transform = plTransform::MakeIdentity());
120
122 static void Draw2DLines(const plDebugRendererContext& context, plArrayPtr<const Line> lines, const plColor& color);
123
125 static void DrawCross(const plDebugRendererContext& context, const plVec3& vGlobalPosition, float fLineLength, const plColor& color, const plTransform& transform = plTransform::MakeIdentity());
126
128 static void DrawLineBox(const plDebugRendererContext& context, const plBoundingBox& box, const plColor& color, const plTransform& transform = plTransform::MakeIdentity());
129
131 static void DrawLineBoxCorners(const plDebugRendererContext& context, const plBoundingBox& box, float fCornerFraction, const plColor& color, const plTransform& transform = plTransform::MakeIdentity());
132
134 static void DrawLineSphere(const plDebugRendererContext& context, const plBoundingSphere& sphere, const plColor& color, const plTransform& transform = plTransform::MakeIdentity());
135
137 static void DrawLineCapsuleZ(const plDebugRendererContext& context, float fLength, float fRadius, const plColor& color, const plTransform& transform = plTransform::MakeIdentity());
138
140 static void DrawLineCylinderZ(const plDebugRendererContext& context, float fLength, float fRadius, const plColor& color, const plTransform& transform = plTransform::MakeIdentity());
141
143 static void DrawLineFrustum(const plDebugRendererContext& context, const plFrustum& frustum, const plColor& color, bool bDrawPlaneNormals = false);
144
146 static void DrawSolidBox(const plDebugRendererContext& context, const plBoundingBox& box, const plColor& color, const plTransform& transform = plTransform::MakeIdentity());
147
149 static void DrawSolidTriangles(const plDebugRendererContext& context, plArrayPtr<Triangle> triangles, const plColor& color);
150
152 static void DrawTexturedTriangles(const plDebugRendererContext& context, plArrayPtr<TexturedTriangle> triangles, const plColor& color, const plTexture2DResourceHandle& hTexture);
153
155 static void Draw2DRectangle(const plDebugRendererContext& context, const plRectFloat& rectInPixel, float fDepth, const plColor& color);
156
158 static void Draw2DRectangle(const plDebugRendererContext& context, const plRectFloat& rectInPixel, float fDepth, const plColor& color, const plTexture2DResourceHandle& hTexture, plVec2 vScale = plVec2(1, 1));
159
161 static void Draw2DRectangle(const plDebugRendererContext& context, const plRectFloat& rectInPixel, float fDepth, const plColor& color, plGALTextureResourceViewHandle hResourceView, plVec2 vScale = plVec2(1, 1));
162
173 static plUInt32 Draw2DText(const plDebugRendererContext& context, const plFormatString& text, const plVec2I32& vPositionInPixel, const plColor& color, plUInt32 uiSizeInPixel = 16, plDebugTextHAlign::Enum horizontalAlignment = plDebugTextHAlign::Left, plDebugTextVAlign::Enum verticalAlignment = plDebugTextVAlign::Top);
174
186 static void DrawInfoText(const plDebugRendererContext& context, plDebugTextPlacement::Enum placement, plStringView sGroupName, const plFormatString& text, const plColor& color = plColor::White);
187
189 static plUInt32 Draw3DText(const plDebugRendererContext& context, const plFormatString& text, const plVec3& vGlobalPosition, const plColor& color, plUInt32 uiSizeInPixel = 16, plDebugTextHAlign::Enum horizontalAlignment = plDebugTextHAlign::Center, plDebugTextVAlign::Enum verticalAlignment = plDebugTextVAlign::Bottom);
190
192 static void AddPersistentCross(const plDebugRendererContext& context, float fSize, const plColor& color, const plTransform& transform, plTime duration);
193
195 static void AddPersistentLineSphere(const plDebugRendererContext& context, float fRadius, const plColor& color, const plTransform& transform, plTime duration);
196
198 static void AddPersistentLineBox(const plDebugRendererContext& context, const plVec3& vHalfSize, const plColor& color, const plTransform& transform, plTime duration);
199
205 static void DrawAngle(const plDebugRendererContext& context, plAngle startAngle, plAngle endAngle, const plColor& solidColor, const plColor& lineColor, const plTransform& transform, plVec3 vForwardAxis = plVec3::MakeAxisX(), plVec3 vRotationAxis = plVec3::MakeAxisZ());
206
208 static void DrawOpeningCone(const plDebugRendererContext& context, plAngle halfAngle, const plColor& colorInside, const plColor& colorOutside, const plTransform& transform, plVec3 vForwardAxis = plVec3::MakeAxisX());
209
215 static void DrawLimitCone(const plDebugRendererContext& context, plAngle halfAngle1, plAngle halfAngle2, const plColor& solidColor, const plColor& lineColor, const plTransform& transform);
216
220 static void DrawCylinder(const plDebugRendererContext& context, float fRadiusStart, float fRadiusEnd, float fLength, const plColor& solidColor, const plColor& lineColor, const plTransform& transform, bool bCapStart = false, bool bCapEnd = false);
221
223 static void DrawArrow(const plDebugRendererContext& context, float fSize, const plColor& color, const plTransform& transform, plVec3 vForwardAxis = plVec3::MakeAxisX());
224
226 static float GetTextGlyphWidth(plUInt32 uiSizeInPixel = 16);
227
229 static float GetTextLineHeight(plUInt32 uiSizeInPixel = 16);
230
232 static float GetTextScale();
233
235 static void SetTextScale(float fScale);
236
237private:
238 friend class plSimpleRenderPass;
239
240 static void RenderScreenSpace(const plRenderViewContext& renderViewContext);
241 static void RenderInternalScreenSpace(const plDebugRendererContext& context, const plRenderViewContext& renderViewContext);
242
243 static void RenderWorldSpace(const plRenderViewContext& renderViewContext);
244 static void RenderInternalWorldSpace(const plDebugRendererContext& context, const plRenderViewContext& renderViewContext);
245
246 static void OnEngineStartup();
247 static void OnEngineShutdown();
248
249 PL_MAKE_SUBSYSTEM_STARTUP_FRIEND(RendererCore, DebugRenderer);
250};
251
253class PL_RENDERERCORE_DLL plScriptExtensionClass_Debug
254{
255public:
256 static void DrawCross(const plWorld* pWorld, const plVec3& vPosition, float fSize, const plColor& color, const plTransform& transform);
257 static void DrawLineBox(const plWorld* pWorld, const plVec3& vPosition, const plVec3& vHalfExtents, const plColor& color, const plTransform& transform);
258 static void DrawLineSphere(const plWorld* pWorld, const plVec3& vPosition, float fRadius, const plColor& color, const plTransform& transform);
259
260 static void DrawSolidBox(const plWorld* pWorld, const plVec3& vPosition, const plVec3& vHalfExtents, const plColor& color, const plTransform& transform);
261
262 static void Draw2DText(const plWorld* pWorld, plStringView sText, const plVec3& vPositionInPixel, const plColor& color, plUInt32 uiSizeInPixel, plEnum<plDebugTextHAlign> horizontalAlignment);
263 static void Draw3DText(const plWorld* pWorld, plStringView sText, const plVec3& vPosition, const plColor& color, plUInt32 uiSizeInPixel);
264 static void DrawInfoText(const plWorld* pWorld, plStringView sText, plEnum<plDebugTextPlacement> placement, plStringView sGroupName, const plColor& color);
265
266 static void AddPersistentCross(const plWorld* pWorld, const plVec3& vPosition, float fSize, const plColor& color, const plTransform& transform, plTime duration);
267 static void AddPersistentLineBox(const plWorld* pWorld, const plVec3& vPosition, const plVec3& vHalfExtents, const plColor& color, const plTransform& transform, plTime duration);
268 static void AddPersistentLineSphere(const plWorld* pWorld, const plVec3& vPosition, float fRadius, const plColor& color, const plTransform& transform, plTime duration);
269};
270
271PL_DECLARE_REFLECTABLE_TYPE(PL_RENDERERCORE_DLL, plScriptExtensionClass_Debug);
272
273#include <RendererCore/Debug/Implementation/DebugRenderer_inl.h>
Float wrapper struct for a safe usage and conversions of angles.
Definition Angle.h:10
This class encapsulates an array and it's size. It is recommended to use this class instead of plain ...
Definition ArrayPtr.h:37
plColor represents an RGBA color in linear color space. Values are stored as float,...
Definition Color.h:44
static const plColor White
#FFFFFF
Definition Color.h:194
Used in plDebugRenderer to determine where debug geometry should be rendered.
Definition DebugRendererContext.h:11
Draws simple shapes into the scene or view.
Definition DebugRenderer.h:81
Implements formating of strings with placeholders and formatting options.
Definition FormatString.h:59
Represents the frustum of some camera and can be used for culling objects.
Definition Frustum.h:32
Definition RendererFoundationDLL.h:425
A simple rectangle class templated on the type for x, y and width, height.
Definition Rect.h:10
Helper class to expose debug rendering to scripting.
Definition DebugRenderer.h:254
A very basic render pass that renders into the color target.
Definition SimpleRenderPass.h:11
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
static plTransformTemplate< float > MakeIdentity()
Definition Transform_inl.h:25
static plVec3Template< float > MakeAxisX()
Definition Vec3.h:41
static plVec3Template< float > MakeAxisZ()
Definition Vec3.h:47
A world encapsulates a scene graph of game objects and various component managers and their component...
Definition World.h:22
Definition DebugRenderer.h:84
Definition DebugRenderer.h:110
Definition DebugRenderer.h:99
Horizontal alignment of debug text.
Definition DebugRenderer.h:20
Screen placement of debug text.
Definition DebugRenderer.h:54
Vertical alignment of debug text.
Definition DebugRenderer.h:37
A custom enum implementation that allows to define the underlying storage type to control its memory ...
Definition Enum.h:37
Definition Declarations.h:51
The time class encapsulates a double value storing the time in seconds.
Definition Time.h:12