From 6987834b2dd8343ed13f63c0bfd51614af6048bf Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 15 Feb 2021 10:53:49 +0100 Subject: [PATCH 1/7] Fix default actor bounds --- Source/Engine/Level/Actor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Engine/Level/Actor.cpp b/Source/Engine/Level/Actor.cpp index e88791442..f558f25a0 100644 --- a/Source/Engine/Level/Actor.cpp +++ b/Source/Engine/Level/Actor.cpp @@ -44,7 +44,7 @@ Actor::Actor(const SpawnParams& params) , _localTransform(Transform::Identity) , _transform(Transform::Identity) , _sphere(BoundingSphere::Empty) - , _box(BoundingBox::Empty) + , _box(BoundingBox::Zero) , HideFlags(HideFlags::None) { } From 674e09e72b387f5ca149b64cecffd03b81d47e00 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Mon, 15 Feb 2021 19:32:43 +0100 Subject: [PATCH 2/7] Add WriteTri helpers funcs. --- Source/Engine/Render2D/Render2D.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Source/Engine/Render2D/Render2D.cpp b/Source/Engine/Render2D/Render2D.cpp index c956566ca..e834c5939 100644 --- a/Source/Engine/Render2D/Render2D.cpp +++ b/Source/Engine/Render2D/Render2D.cpp @@ -270,6 +270,34 @@ FORCE_INLINE Render2DVertex MakeVertex(const Vector2& point, const Vector2& uv, }; } +void WriteTri(const Vector2& p0, const Vector2& p1, const Vector2& p2, const Vector2& uv0, const Vector2& uv1, const Vector2& uv2, const Color& color0, const Color& color1, const Color& color2) +{ + Render2DVertex tris[3]; + tris[0] = MakeVertex(p0, uv0, color0); + tris[1] = MakeVertex(p1, uv1, color1); + tris[2] = MakeVertex(p2, uv2, color2); + VB.Write(tris, sizeof(tris)); + + uint32 indices[3]; + indices[0] = VBIndex + 0; + indices[1] = VBIndex + 1; + indices[2] = VBIndex + 2; + IB.Write(indices, sizeof(indices)); + + VBIndex += 3; + IBIndex += 3; +} + +void WriteTri(const Vector2& p0, const Vector2& p1, const Vector2& p2, const Color& color0, const Color& color1, const Color& color2) +{ + WriteTri(p0, p1, p2, Vector2::Zero, Vector2::Zero, Vector2::Zero, color0, color1, color2); +} + +void WriteTri(const Vector2& p0, const Vector2& p1, const Vector2& p2, const Vector2& uv0, const Vector2& uv1, const Vector2& uv2) +{ + WriteTri(p0, p1, p2, uv0, uv1, uv2, Color::Black, Color::Black, Color::Black); +} + void WriteRect(const Rectangle& rect, const Color& color1, const Color& color2, const Color& color3, const Color& color4) { const Vector2 uvUpperLeft = Vector2::Zero; From b1f867f1072d68978e0de3a006987084cf7822c0 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Mon, 15 Feb 2021 19:33:25 +0100 Subject: [PATCH 3/7] Add DrawVertices & FillTriangle funcs. --- Source/Engine/Render2D/Render2D.cpp | 38 +++++++++++++++++++++++++++++ Source/Engine/Render2D/Render2D.h | 26 ++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/Source/Engine/Render2D/Render2D.cpp b/Source/Engine/Render2D/Render2D.cpp index e834c5939..818265551 100644 --- a/Source/Engine/Render2D/Render2D.cpp +++ b/Source/Engine/Render2D/Render2D.cpp @@ -1744,3 +1744,41 @@ void Render2D::DrawBlur(const Rectangle& rect, float blurStrength) drawCall.AsBlur.BottomRightY = p.Y; WriteRect(rect, Color::White); } + +void Render2D::DrawVertices(GPUTexture* t, const Array vertices, const Array uvs) +{ + RENDER2D_CHECK_RENDERING_STATE; + + Render2DDrawCall& drawCall = DrawCalls.AddOne(); + drawCall.Type = DrawCallType::FillTexture; + drawCall.StartIB = IBIndex; + drawCall.CountIB = vertices.Count(); + drawCall.AsTexture.Ptr = t; + + for (int32 i = 0; i < vertices.Count(); i += 3) + WriteTri(vertices[i], vertices[i + 1], vertices[i + 2], uvs[i], uvs[i + 1], uvs[i + 2]); +} + +void Render2D::DrawVertices(const Array vertices, const Array colors, bool useAlpha) +{ + RENDER2D_CHECK_RENDERING_STATE; + + Render2DDrawCall& drawCall = DrawCalls.AddOne(); + drawCall.Type = useAlpha ? DrawCallType::FillRect : DrawCallType::FillRectNoAlpha; + drawCall.StartIB = IBIndex; + drawCall.CountIB = vertices.Count(); + + for (int32 i = 0; i < vertices.Count(); i += 3) + WriteTri(vertices[i], vertices[i + 1], vertices[i + 2], colors[i], colors[i + 1], colors[i + 2]); +} + +void Render2D::FillTriangle(const Vector2& p0, const Vector2& p1, const Vector2& p2, const Color& color) +{ + RENDER2D_CHECK_RENDERING_STATE; + + Render2DDrawCall& drawCall = DrawCalls.AddOne(); + drawCall.Type = color.A < 1.0f ? DrawCallType::FillRect : DrawCallType::FillRectNoAlpha; + drawCall.StartIB = IBIndex; + drawCall.CountIB = 3; + WriteTri(p0, p1, p2, color, color, color); +} diff --git a/Source/Engine/Render2D/Render2D.h b/Source/Engine/Render2D/Render2D.h index a421c56a6..1cf32a886 100644 --- a/Source/Engine/Render2D/Render2D.h +++ b/Source/Engine/Render2D/Render2D.h @@ -4,6 +4,7 @@ #include "Engine/Core/Math/Color.h" #include "Engine/Scripting/ScriptingType.h" +#include "Engine/Core/Collections/Array.h" struct SpriteHandle; struct TextLayoutOptions; @@ -339,4 +340,29 @@ public: /// The target rectangle to draw (blurs its background). /// The blur strength defines how blurry the background is. Larger numbers increase blur, resulting in a larger runtime cost on the GPU. API_FUNCTION() static void DrawBlur(const Rectangle& rect, float blurStrength); + + /// + /// Draws vertices array. + /// + /// The texture. + /// The vertices array. + /// The uvs array. + API_FUNCTION() static void DrawVertices(GPUTexture* t, Array vertices, Array uvs); + + /// + /// Draws vertices array. + /// + /// The vertices array. + /// The colors array. + /// If true alpha blending will be enabled. + API_FUNCTION() static void DrawVertices(Array vertices, Array colors, bool useAlpha); + + /// + /// Fills a triangular area. + /// + /// The first point. + /// The second point. + /// The third point. + /// The color. + API_FUNCTION() static void FillTriangle(const Vector2& p0, const Vector2& p1, const Vector2& p2, const Color& color); }; From 653e9609e4b29116b410e443852bbbd5708bd510 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Tue, 16 Feb 2021 10:14:42 +0100 Subject: [PATCH 4/7] Span + Naming --- Source/Engine/Render2D/Render2D.cpp | 4 ++-- Source/Engine/Render2D/Render2D.h | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Source/Engine/Render2D/Render2D.cpp b/Source/Engine/Render2D/Render2D.cpp index 818265551..cd91430bf 100644 --- a/Source/Engine/Render2D/Render2D.cpp +++ b/Source/Engine/Render2D/Render2D.cpp @@ -1745,7 +1745,7 @@ void Render2D::DrawBlur(const Rectangle& rect, float blurStrength) WriteRect(rect, Color::White); } -void Render2D::DrawVertices(GPUTexture* t, const Array vertices, const Array uvs) +void Render2D::DrawTexturedTriangles(GPUTexture* t, const Span& vertices, const Span& uvs) { RENDER2D_CHECK_RENDERING_STATE; @@ -1759,7 +1759,7 @@ void Render2D::DrawVertices(GPUTexture* t, const Array vertices, const WriteTri(vertices[i], vertices[i + 1], vertices[i + 2], uvs[i], uvs[i + 1], uvs[i + 2]); } -void Render2D::DrawVertices(const Array vertices, const Array colors, bool useAlpha) +void Render2D::FillTriangles(const Span& vertices, const Span& colors, bool useAlpha) { RENDER2D_CHECK_RENDERING_STATE; diff --git a/Source/Engine/Render2D/Render2D.h b/Source/Engine/Render2D/Render2D.h index 1cf32a886..bd73fa137 100644 --- a/Source/Engine/Render2D/Render2D.h +++ b/Source/Engine/Render2D/Render2D.h @@ -5,6 +5,7 @@ #include "Engine/Core/Math/Color.h" #include "Engine/Scripting/ScriptingType.h" #include "Engine/Core/Collections/Array.h" +#include "Engine/Core/Types/Span.h" struct SpriteHandle; struct TextLayoutOptions; @@ -347,7 +348,7 @@ public: /// The texture. /// The vertices array. /// The uvs array. - API_FUNCTION() static void DrawVertices(GPUTexture* t, Array vertices, Array uvs); + API_FUNCTION() static void DrawTexturedTriangles(GPUTexture* t, const Span& vertices, const Span& uvs); /// /// Draws vertices array. @@ -355,7 +356,7 @@ public: /// The vertices array. /// The colors array. /// If true alpha blending will be enabled. - API_FUNCTION() static void DrawVertices(Array vertices, Array colors, bool useAlpha); + API_FUNCTION() static void FillTriangles(const Span& vertices, const Span& colors, bool useAlpha); /// /// Fills a triangular area. From 588ad86f8ed0328dbab5e462bfc90b4d6f867d6d Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Tue, 16 Feb 2021 16:05:34 +0100 Subject: [PATCH 5/7] Fix Span Count -> length. --- Source/Engine/Render2D/Render2D.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Engine/Render2D/Render2D.cpp b/Source/Engine/Render2D/Render2D.cpp index cd91430bf..a2e72eeb7 100644 --- a/Source/Engine/Render2D/Render2D.cpp +++ b/Source/Engine/Render2D/Render2D.cpp @@ -1752,10 +1752,10 @@ void Render2D::DrawTexturedTriangles(GPUTexture* t, const Span& vertice Render2DDrawCall& drawCall = DrawCalls.AddOne(); drawCall.Type = DrawCallType::FillTexture; drawCall.StartIB = IBIndex; - drawCall.CountIB = vertices.Count(); + drawCall.CountIB = vertices.Length(); drawCall.AsTexture.Ptr = t; - for (int32 i = 0; i < vertices.Count(); i += 3) + for (int32 i = 0; i < vertices.Length(); i += 3) WriteTri(vertices[i], vertices[i + 1], vertices[i + 2], uvs[i], uvs[i + 1], uvs[i + 2]); } @@ -1766,9 +1766,9 @@ void Render2D::FillTriangles(const Span& vertices, const Span& c Render2DDrawCall& drawCall = DrawCalls.AddOne(); drawCall.Type = useAlpha ? DrawCallType::FillRect : DrawCallType::FillRectNoAlpha; drawCall.StartIB = IBIndex; - drawCall.CountIB = vertices.Count(); + drawCall.CountIB = vertices.Length(); - for (int32 i = 0; i < vertices.Count(); i += 3) + for (int32 i = 0; i < vertices.Length(); i += 3) WriteTri(vertices[i], vertices[i + 1], vertices[i + 2], colors[i], colors[i + 1], colors[i + 2]); } From bc073b73cc33e1b6bbfb9cba27893434a846bc18 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Tue, 16 Feb 2021 16:05:48 +0100 Subject: [PATCH 6/7] Add check. --- Source/Engine/Render2D/Render2D.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Source/Engine/Render2D/Render2D.cpp b/Source/Engine/Render2D/Render2D.cpp index a2e72eeb7..fe1c71c3c 100644 --- a/Source/Engine/Render2D/Render2D.cpp +++ b/Source/Engine/Render2D/Render2D.cpp @@ -1747,6 +1747,8 @@ void Render2D::DrawBlur(const Rectangle& rect, float blurStrength) void Render2D::DrawTexturedTriangles(GPUTexture* t, const Span& vertices, const Span& uvs) { + CHECK(vertices.Length() == uvs.Length()) + RENDER2D_CHECK_RENDERING_STATE; Render2DDrawCall& drawCall = DrawCalls.AddOne(); @@ -1761,6 +1763,8 @@ void Render2D::DrawTexturedTriangles(GPUTexture* t, const Span& vertice void Render2D::FillTriangles(const Span& vertices, const Span& colors, bool useAlpha) { + CHECK(vertices.Length() == colors.Length()); + RENDER2D_CHECK_RENDERING_STATE; Render2DDrawCall& drawCall = DrawCalls.AddOne(); From 9144f6dcc92d75c005ddc06bd6844e2ef8ee8997 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Tue, 16 Feb 2021 16:08:20 +0100 Subject: [PATCH 7/7] Remove Array include. --- Source/Engine/Render2D/Render2D.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/Engine/Render2D/Render2D.h b/Source/Engine/Render2D/Render2D.h index bd73fa137..a6eba94e4 100644 --- a/Source/Engine/Render2D/Render2D.h +++ b/Source/Engine/Render2D/Render2D.h @@ -4,7 +4,6 @@ #include "Engine/Core/Math/Color.h" #include "Engine/Scripting/ScriptingType.h" -#include "Engine/Core/Collections/Array.h" #include "Engine/Core/Types/Span.h" struct SpriteHandle;