From 044e141848d139149cef10a697676b460d4a588d Mon Sep 17 00:00:00 2001 From: Wojciech Figat Date: Tue, 25 Oct 2022 15:06:52 +0200 Subject: [PATCH] Add `Render2D.DrawTexturedTriangles` with index buffer --- Source/Engine/Render2D/Render2D.cpp | 21 +++++++++++++++++++++ Source/Engine/Render2D/Render2D.h | 10 ++++++++++ 2 files changed, 31 insertions(+) diff --git a/Source/Engine/Render2D/Render2D.cpp b/Source/Engine/Render2D/Render2D.cpp index 1105920ba..d929bdb5c 100644 --- a/Source/Engine/Render2D/Render2D.cpp +++ b/Source/Engine/Render2D/Render2D.cpp @@ -1963,6 +1963,27 @@ void Render2D::DrawTexturedTriangles(GPUTexture* t, const Span& vertices WriteTri(vertices[i], vertices[i + 1], vertices[i + 2], uvs[i], uvs[i + 1], uvs[i + 2], colors[i], colors[i + 1], colors[i + 2]); } +void Render2D::DrawTexturedTriangles(GPUTexture* t, const Span& indices, const Span& vertices, const Span& uvs, const Span& colors) +{ + RENDER2D_CHECK_RENDERING_STATE; + CHECK(vertices.Length() == uvs.Length()); + CHECK(vertices.Length() == colors.Length()); + + Render2DDrawCall& drawCall = DrawCalls.AddOne(); + drawCall.Type = DrawCallType::FillTexture; + drawCall.StartIB = IBIndex; + drawCall.CountIB = indices.Length(); + drawCall.AsTexture.Ptr = t; + + for (int32 i = 0; i < indices.Length();) + { + const uint16 i0 = indices.Get()[i++]; + const uint16 i1 = indices.Get()[i++]; + const uint16 i2 = indices.Get()[i++]; + WriteTri(vertices[i0], vertices[i1], vertices[i2], uvs[i0], uvs[i1], uvs[i2], colors[i0], colors[i1], colors[i2]); + } +} + void Render2D::FillTriangles(const Span& vertices, const Span& colors, bool useAlpha) { CHECK(vertices.Length() == colors.Length()); diff --git a/Source/Engine/Render2D/Render2D.h b/Source/Engine/Render2D/Render2D.h index 55f450e87..ba95c8a85 100644 --- a/Source/Engine/Render2D/Render2D.h +++ b/Source/Engine/Render2D/Render2D.h @@ -425,6 +425,16 @@ public: /// The colors array. API_FUNCTION() static void DrawTexturedTriangles(GPUTexture* t, const Span& vertices, const Span& uvs, const Span& colors); + /// + /// Draws indexed vertices array. + /// + /// The texture. + /// The indices array. + /// The vertices array. + /// The uvs array. + /// The colors array. + API_FUNCTION() static void DrawTexturedTriangles(GPUTexture* t, const Span& indices, const Span& vertices, const Span& uvs, const Span& colors); + /// /// Draws vertices array. ///