diff --git a/Source/Editor/Cooker/Steps/DeployDataStep.cpp b/Source/Editor/Cooker/Steps/DeployDataStep.cpp index 96f8bfad2..f90658cab 100644 --- a/Source/Editor/Cooker/Steps/DeployDataStep.cpp +++ b/Source/Editor/Cooker/Steps/DeployDataStep.cpp @@ -97,6 +97,8 @@ bool DeployDataStep::Perform(CookingData& data) data.AddRootEngineAsset(PRE_INTEGRATED_GF_ASSET_NAME); data.AddRootEngineAsset(SMAA_AREA_TEX); data.AddRootEngineAsset(SMAA_SEARCH_TEX); + if (data.Configuration != BuildConfiguration::Release) + data.AddRootEngineAsset(TEXT("Editor/Fonts/Roboto-Regular")); // Register game assets data.StepProgress(TEXT("Deploying game data"), 50); diff --git a/Source/Engine/Debug/DebugDraw.cpp b/Source/Engine/Debug/DebugDraw.cpp index 7a6444a89..729148bac 100644 --- a/Source/Engine/Debug/DebugDraw.cpp +++ b/Source/Engine/Debug/DebugDraw.cpp @@ -20,6 +20,8 @@ #include "Engine/Animations/AnimationUtils.h" #include "Engine/Profiler/Profiler.h" #include "Engine/Debug/DebugLog.h" +#include "Engine/Render2D/Render2D.h" +#include "Engine/Render2D/FontAsset.h" // Debug draw service configuration #define DEBUG_DRAW_INITIAL_VB_CAPACITY (4 * 1024) @@ -54,6 +56,15 @@ struct DebugTriangle float TimeLeft; }; +struct DebugText2D +{ + Array> Text; + Vector2 Position; + int32 Size; + Color Color; + float TimeLeft; +}; + PACK_STRUCT(struct Vertex { Vector3 Position; Color32 Color; @@ -133,10 +144,12 @@ struct DebugDrawData Array OneFrameTriangles; Array DefaultWireTriangles; Array OneFrameWireTriangles; + Array DefaultText2D; + Array OneFrameText2D; inline int32 Count() const { - return LinesCount() + TrianglesCount(); + return LinesCount() + TrianglesCount() + Text2DCount(); } inline int32 LinesCount() const @@ -149,6 +162,11 @@ struct DebugDrawData return DefaultTriangles.Count() + OneFrameTriangles.Count() + DefaultWireTriangles.Count() + OneFrameWireTriangles.Count(); } + inline int32 Text2DCount() const + { + return DefaultText2D.Count() + OneFrameText2D.Count(); + } + inline void Add(const DebugLine& l) { if (l.TimeLeft > 0) @@ -178,10 +196,12 @@ struct DebugDrawData UpdateList(deltaTime, DefaultLines); UpdateList(deltaTime, DefaultTriangles); UpdateList(deltaTime, DefaultWireTriangles); + UpdateList(deltaTime, DefaultText2D); OneFrameLines.Clear(); OneFrameTriangles.Clear(); OneFrameWireTriangles.Clear(); + OneFrameText2D.Clear(); } inline void Clear() @@ -192,6 +212,8 @@ struct DebugDrawData OneFrameTriangles.Clear(); DefaultWireTriangles.Clear(); OneFrameWireTriangles.Clear(); + DefaultText2D.Clear(); + OneFrameText2D.Clear(); } inline void Release() @@ -202,6 +224,8 @@ struct DebugDrawData OneFrameTriangles.Resize(0); DefaultWireTriangles.Resize(0); OneFrameWireTriangles.Resize(0); + DefaultText2D.Resize(0); + OneFrameText2D.Resize(0); } }; @@ -216,6 +240,7 @@ namespace DebugDrawContext GlobalContext; DebugDrawContext* Context; AssetReference DebugDrawShader; + AssetReference DebugDrawFont; PsData DebugDrawPsLinesDefault; PsData DebugDrawPsLinesDepthTest; PsData DebugDrawPsWireTrianglesDefault; @@ -601,8 +626,6 @@ void DebugDraw::Draw(RenderContext& renderContext, GPUTextureView* target, GPUTe context->BindCB(0, cb); auto vb = DebugDrawVB->GetBuffer(); -#define DRAW(drawCall) if (drawCall.VertexCount) - // Draw with depth test if (depthTestLines.VertexCount + depthTestTriangles.VertexCount + depthTestWireTriangles.VertexCount > 0) { @@ -673,7 +696,30 @@ void DebugDraw::Draw(RenderContext& renderContext, GPUTextureView* target, GPUTe } } -#undef DRAW + // Text 2D + if (Context->DebugDrawDefault.TrianglesCount()) + { + PROFILE_GPU_CPU_NAMED("2D"); + + if (!DebugDrawFont) + { + DebugDrawFont = Content::LoadAsyncInternal(TEXT("Editor/Fonts/Roboto-Regular")); + } + if (DebugDrawFont && DebugDrawFont->IsLoaded()) + { + Viewport viewport = renderContext.Task->GetViewport(); + Render2D::Begin(context, target, nullptr, viewport); + for (auto& t : Context->DebugDrawDefault.DefaultText2D) + { + } + for (auto& t : Context->DebugDrawDefault.OneFrameText2D) + { + const StringView text(t.Text.Get(), t.Text.Count() - 1); + Render2D::DrawText(DebugDrawFont->CreateFont(t.Size), text, t.Color, t.Position); + } + Render2D::End(); + } + } } void DebugDraw::DrawActors(Actor** selectedActors, int32 selectedActorsCount, bool drawScenes) @@ -1276,4 +1322,19 @@ void DebugDraw::DrawBox(const OrientedBoundingBox& box, const Color& color, floa } } +void DebugDraw::DrawText(const StringView& text, const Vector2& position, const Color& color, int32 size, float duration) +{ + if (text.Length() == 0 || size < 4) + return; + Array* list = duration > 0 ? &Context->DebugDrawDefault.DefaultText2D : &Context->DebugDrawDefault.OneFrameText2D; + auto& t = list->AddOne(); + t.Text.Resize(text.Length() + 1); + Platform::MemoryCopy(t.Text.Get(), text.Get(), text.Length() * sizeof(Char)); + t.Text[text.Length()] = 0; + t.Position = position; + t.Size = size; + t.Color = color; + t.TimeLeft = duration; +} + #endif diff --git a/Source/Engine/Debug/DebugDraw.h b/Source/Engine/Debug/DebugDraw.h index a2681e1f2..6b77d09dd 100644 --- a/Source/Engine/Debug/DebugDraw.h +++ b/Source/Engine/Debug/DebugDraw.h @@ -307,6 +307,16 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(DebugDraw); /// The duration (in seconds). Use 0 to draw it only once. /// If set to true depth test will be performed, otherwise depth will be ignored. API_FUNCTION() static void DrawBox(const OrientedBoundingBox& box, const Color& color, float duration = 0.0f, bool depthTest = true); + + /// + /// Draws the text on a screen (2D). + /// + /// The text. + /// The position of the text on the screen (in screen-space coordinates). + /// The color. + /// The font size. + /// The duration (in seconds). Use 0 to draw it only once. + API_FUNCTION() static void DrawText(const StringView& text, const Vector2& position, const Color& color, int32 size = 20, float duration = 0.0f); }; #define DEBUG_DRAW_LINE(start, end, color, duration, depthTest) DebugDraw::DrawLine(start, end, color, duration, depthTest) @@ -326,7 +336,8 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(DebugDraw); #define DEBUG_DRAW_WIRE_SPHERE(sphere, color, duration, depthTest) DebugDraw::DrawWireSphere(sphere, color, duration, depthTest) #define DEBUG_DRAW_WIRE_TUBE(position, orientation, radius, length, color, duration, depthTest) DebugDraw::DrawWireTube(position, orientation, radius, length, color, duration, depthTest) #define DEBUG_DRAW_WIRE_CYLINDER(position, orientation, radius, height, color, duration, depthTest) DebugDraw::DrawWireTube(position, orientation, radius, height, color, duration, depthTest) -#define DEBUG_DRAW_WIRE_ARROW(position, orientation, scale, color, duration, depthTest) DebugDraw::DrawWireTube(position, orientation, scale, color, duration, depthTest) +#define DEBUG_DRAW_WIRE_ARROW(position, orientation, scale, color, duration, depthTest) DebugDraw::DrawWireArrow(position, orientation, scale, color, duration, depthTest) +#define DEBUG_DRAW_TEXT(text, position, color, size, duration) DebugDraw::DrawText(text, position, color, size, duration) #else @@ -348,5 +359,6 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(DebugDraw); #define DEBUG_DRAW_WIRE_TUBE(position, orientation, radius, length, color, duration, depthTest) #define DEBUG_DRAW_WIRE_CYLINDER(position, orientation, radius, height, color, duration, depthTest) #define DEBUG_DRAW_WIRE_ARROW(position, orientation, scale, color, duration, depthTest) +#define DEBUG_DRAW_TEXT(text, position, color, size, duration) #endif