From 2583f6fe36db282b36f5e93b96f4e219f34de8eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kapu=C5=9Bci=C5=84ski?= Date: Sun, 12 Dec 2021 21:17:39 +0100 Subject: [PATCH] Removed UIRenderer's DrawPrimitive() via CDevice --- src/graphics/core/device.h | 2 -- src/graphics/engine/engine.cpp | 11 +++++++---- src/graphics/engine/text.cpp | 4 +++- src/graphics/opengl/gl33device.cpp | 5 ----- src/graphics/opengl/gl33device.h | 2 -- src/ui/controls/color.cpp | 7 ++++--- src/ui/controls/control.cpp | 18 +++++++++--------- src/ui/controls/edit.cpp | 5 ++++- src/ui/controls/map.cpp | 13 +++++++------ src/ui/controls/shortcut.cpp | 7 ++++--- 10 files changed, 38 insertions(+), 36 deletions(-) diff --git a/src/graphics/core/device.h b/src/graphics/core/device.h index 0a42d1b9..45659986 100644 --- a/src/graphics/core/device.h +++ b/src/graphics/core/device.h @@ -503,8 +503,6 @@ public: Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) = 0; //! Renders primitive composed of vertices with solid color virtual void DrawPrimitive(PrimitiveType type, const VertexCol *vertices , int vertexCount) = 0; - //! Renders primitive using UI renderer - virtual void DrawPrimitive(PrimitiveType type, const Vertex2D* vertices, int vertexCount) = 0; //! Renders 3D primitive virtual void DrawPrimitive(PrimitiveType type, const Vertex3D* vertices, int vertexCount) = 0; diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 2e727500..b39f3014 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -5008,7 +5008,8 @@ void CEngine::DrawBackgroundImage() { { p2.x, p2.y }, { u2, v1 } } }; - m_device->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, vertices, 4); + auto renderer = m_device->GetUIRenderer(); + renderer->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, 4, vertices); AddStatisticTriangle(2); } @@ -5261,7 +5262,8 @@ void CEngine::DrawMouseSprite(Math::IntPoint pos, Math::IntPoint size, int icon) { { p2.x, p1.y }, { u2, v1 } } }; - m_device->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, vertex, 4); + auto renderer = m_device->GetUIRenderer(); + renderer->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, 4, vertex); AddStatisticTriangle(2); } @@ -5277,7 +5279,8 @@ void CEngine::DrawStats() Math::Point pos(0.05f * m_size.x/m_size.y, 0.05f + TOTAL_LINES * height); SetState(ENG_RSTATE_TCOLOR_ALPHA); - SetUITexture(Texture{}); + auto renderer = m_device->GetUIRenderer(); + renderer->SetTexture(Texture{}); glm::u8vec4 black = { 0, 0, 0, 192 }; @@ -5291,7 +5294,7 @@ void CEngine::DrawStats() { { pos.x + width + margin.x, pos.y + height + margin.y }, {}, black } }; - m_device->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, vertex, 4); + renderer->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, 4, vertex); SetState(ENG_RSTATE_TEXT); diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index 83018e74..ee91bed0 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -151,9 +151,11 @@ public: } } + auto renderer = m_engine.GetDevice()->GetUIRenderer(); + for (const auto& quad : m_quads) { - m_engine.GetDevice()->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, quad.vertices, 4); + renderer->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, 4, quad.vertices); } m_engine.GetDevice()->GetUIRenderer()->Flush(); diff --git a/src/graphics/opengl/gl33device.cpp b/src/graphics/opengl/gl33device.cpp index 8963a4d0..bdffcf6a 100644 --- a/src/graphics/opengl/gl33device.cpp +++ b/src/graphics/opengl/gl33device.cpp @@ -1143,11 +1143,6 @@ void CGL33Device::DrawPrimitive(PrimitiveType type, const Vertex3D* vertices, in glDrawArrays(TranslateGfxPrimitive(type), 0, vertexCount); } -void CGL33Device::DrawPrimitive(PrimitiveType type, const Vertex2D* vertices, int vertexCount) -{ - m_uiRenderer->DrawPrimitive(type, vertexCount, vertices); -} - void CGL33Device::DrawPrimitives(PrimitiveType type, const Vertex *vertices, int first[], int count[], int drawCount, Color color) { diff --git a/src/graphics/opengl/gl33device.h b/src/graphics/opengl/gl33device.h index b038d4ee..d89c67e8 100644 --- a/src/graphics/opengl/gl33device.h +++ b/src/graphics/opengl/gl33device.h @@ -154,8 +154,6 @@ public: Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) override; virtual void DrawPrimitive(PrimitiveType type, const VertexCol *vertices , int vertexCount) override; - virtual void DrawPrimitive(PrimitiveType type, const Vertex2D* vertices, int vertexCount) override; - virtual void DrawPrimitive(PrimitiveType type, const Vertex3D* vertices, int vertexCount) override; virtual void DrawPrimitives(PrimitiveType type, const Vertex *vertices, diff --git a/src/ui/controls/color.cpp b/src/ui/controls/color.cpp index 7915b4fb..2210e8b3 100644 --- a/src/ui/controls/color.cpp +++ b/src/ui/controls/color.cpp @@ -24,6 +24,7 @@ #include "common/restext.h" #include "graphics/core/device.h" +#include "graphics/core/renderers.h" #include "graphics/engine/engine.h" @@ -151,14 +152,14 @@ void CColor::Draw() m_engine->SetUITexture(Gfx::Texture{0}); // no texture m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); - auto device = m_engine->GetDevice(); - vertex[0] = { { p1.x, p1.y }, {}, col }; vertex[1] = { { p1.x, p2.y }, {}, col }; vertex[2] = { { p2.x, p1.y }, {}, col }; vertex[3] = { { p2.x, p2.y }, {}, col }; - device->DrawPrimitive(Gfx::PrimitiveType::TRIANGLE_STRIP, vertex, 4); + auto renderer = m_engine->GetDevice()->GetUIRenderer(); + + renderer->DrawPrimitive(Gfx::PrimitiveType::TRIANGLE_STRIP, 4, vertex); m_engine->AddStatisticTriangle(2); } diff --git a/src/ui/controls/control.cpp b/src/ui/controls/control.cpp index aeaefde8..4714bf24 100644 --- a/src/ui/controls/control.cpp +++ b/src/ui/controls/control.cpp @@ -28,7 +28,7 @@ #include "level/robotmain.h" - +#include "graphics/core/renderers.h" namespace Ui { @@ -610,7 +610,7 @@ void CControl::DrawIcon(Math::Point pos, Math::Point dim, Math::Point uv1, Math: Gfx::Vertex2D vertex[8]; // 6 triangles glm::vec2 p1, p2, p3, p4; - auto device = m_engine->GetDevice(); + auto renderer = m_engine->GetDevice()->GetUIRenderer(); p1.x = pos.x; p1.y = pos.y; @@ -624,7 +624,7 @@ void CControl::DrawIcon(Math::Point pos, Math::Point dim, Math::Point uv1, Math: vertex[2] = { { p2.x, p1.y }, { uv2.x, uv2.y } }; vertex[3] = { { p2.x, p2.y }, { uv2.x, uv1.y } }; - device->DrawPrimitive(Gfx::PrimitiveType::TRIANGLE_STRIP, vertex, 4); + renderer->DrawPrimitive(Gfx::PrimitiveType::TRIANGLE_STRIP, 4, vertex); m_engine->AddStatisticTriangle(2); } else // 3 pieces? @@ -643,7 +643,7 @@ void CControl::DrawIcon(Math::Point pos, Math::Point dim, Math::Point uv1, Math: vertex[6] = { { p2.x, p1.y }, { uv2.x, uv2.y } }; vertex[7] = { { p2.x, p2.y }, { uv2.x, uv1.y } }; - device->DrawPrimitive(Gfx::PrimitiveType::TRIANGLE_STRIP, vertex, 8); + renderer->DrawPrimitive(Gfx::PrimitiveType::TRIANGLE_STRIP, 8, vertex); m_engine->AddStatisticTriangle(6); } else @@ -660,7 +660,7 @@ void CControl::DrawIcon(Math::Point pos, Math::Point dim, Math::Point uv1, Math: vertex[6] = { { p2.x, p2.y }, { uv2.x, uv1.y } }; vertex[7] = { { p1.x, p2.y }, { uv1.x, uv1.y } }; - device->DrawPrimitive(Gfx::PrimitiveType::TRIANGLE_STRIP, vertex, 8); + renderer->DrawPrimitive(Gfx::PrimitiveType::TRIANGLE_STRIP, 8, vertex); m_engine->AddStatisticTriangle(6); } } @@ -674,7 +674,7 @@ void CControl::DrawIcon(Math::Point pos, Math::Point dim, Math::Point uv1, Math: Gfx::Vertex2D vertices[8]; // 6 triangles glm::vec2 p1, p2, p3, p4; - auto device = m_engine->GetDevice(); + auto renderer = m_engine->GetDevice()->GetUIRenderer(); p1.x = pos.x; p1.y = pos.y; @@ -703,7 +703,7 @@ void CControl::DrawIcon(Math::Point pos, Math::Point dim, Math::Point uv1, Math: vertices[6] = { { p2.x, p1.y }, { uv2.x, uv2.y } }; vertices[7] = { { p2.x, p3.y }, { uv2.x, uv2.y - ex } }; - device->DrawPrimitive(Gfx::PrimitiveType::TRIANGLE_STRIP, vertices, 8); + renderer->DrawPrimitive(Gfx::PrimitiveType::TRIANGLE_STRIP, 8, vertices); m_engine->AddStatisticTriangle(6); // Central horizontal band. @@ -716,7 +716,7 @@ void CControl::DrawIcon(Math::Point pos, Math::Point dim, Math::Point uv1, Math: vertices[6] = { { p2.x, p3.y }, { uv2.x, uv2.y - ex } }; vertices[7] = { { p2.x, p4.y }, { uv2.x, uv1.y + ex } }; - device->DrawPrimitive(Gfx::PrimitiveType::TRIANGLE_STRIP, vertices, 8); + renderer->DrawPrimitive(Gfx::PrimitiveType::TRIANGLE_STRIP, 8, vertices); m_engine->AddStatisticTriangle(6); // Top horizontal band. @@ -729,7 +729,7 @@ void CControl::DrawIcon(Math::Point pos, Math::Point dim, Math::Point uv1, Math: vertices[6] = { { p2.x, p4.y }, { uv2.x, uv1.y + ex } }; vertices[7] = { { p2.x, p2.y }, { uv2.x, uv1.y } }; - device->DrawPrimitive(Gfx::PrimitiveType::TRIANGLE_STRIP, vertices, 8); + renderer->DrawPrimitive(Gfx::PrimitiveType::TRIANGLE_STRIP, 8, vertices); m_engine->AddStatisticTriangle(6); } diff --git a/src/ui/controls/edit.cpp b/src/ui/controls/edit.cpp index 57bee1a1..22ce14d8 100644 --- a/src/ui/controls/edit.cpp +++ b/src/ui/controls/edit.cpp @@ -31,6 +31,7 @@ #include "common/resources/inputstream.h" #include "common/resources/outputstream.h" +#include "graphics/core/renderers.h" #include "graphics/engine/engine.h" #include "level/parser/parser.h" @@ -1278,7 +1279,9 @@ void CEdit::DrawHorizontalGradient(Math::Point pos, Math::Point dim, Gfx::Color { { p2.x, p2.y }, {}, col2 } }; - m_engine->GetDevice()->DrawPrimitive(Gfx::PrimitiveType::TRIANGLE_STRIP, quad, 4); + auto renderer = m_engine->GetDevice()->GetUIRenderer(); + + renderer->DrawPrimitive(Gfx::PrimitiveType::TRIANGLE_STRIP, 4, quad); m_engine->AddStatisticTriangle(2); } diff --git a/src/ui/controls/map.cpp b/src/ui/controls/map.cpp index 33217adb..386dae49 100644 --- a/src/ui/controls/map.cpp +++ b/src/ui/controls/map.cpp @@ -23,6 +23,7 @@ #include "common/image.h" #include "graphics/core/device.h" +#include "graphics/core/renderers.h" #include "graphics/engine/terrain.h" #include "graphics/engine/water.h" @@ -959,13 +960,13 @@ void CMap::DrawTriangle(Math::Point p1, Math::Point p2, Math::Point p3, Math::Po { Gfx::Vertex2D vertex[3]; // 1 triangle - auto device = m_engine->GetDevice(); + auto renderer = m_engine->GetDevice()->GetUIRenderer(); vertex[0] = { { p1.x, p1.y }, { uv1.x, uv1.y } }; vertex[1] = { { p2.x, p2.y }, { uv1.x, uv2.y } }; vertex[2] = { { p3.x, p3.y }, { uv2.x, uv2.y } }; - device->DrawPrimitive(Gfx::PrimitiveType::TRIANGLES, vertex, 3); + renderer->DrawPrimitive(Gfx::PrimitiveType::TRIANGLES, 3, vertex); m_engine->AddStatisticTriangle(1); } @@ -975,7 +976,7 @@ void CMap::DrawPenta(Math::Point p1, Math::Point p2, Math::Point p3, Math::Point { Gfx::Vertex2D vertex[5]; // 1 pentagon - auto device = m_engine->GetDevice(); + auto renderer = m_engine->GetDevice()->GetUIRenderer(); vertex[0] = { { p1.x, p1.y }, { uv1.x, uv1.y } }; vertex[1] = { { p2.x, p2.y }, { uv1.x, uv2.y } }; @@ -983,7 +984,7 @@ void CMap::DrawPenta(Math::Point p1, Math::Point p2, Math::Point p3, Math::Point vertex[3] = { { p3.x, p3.y }, { uv2.x, uv2.y } }; vertex[4] = { { p4.x, p4.y }, { uv2.x, uv2.y } }; - device->DrawPrimitive(Gfx::PrimitiveType::TRIANGLE_STRIP, vertex, 5); + renderer->DrawPrimitive(Gfx::PrimitiveType::TRIANGLE_STRIP, 5, vertex); m_engine->AddStatisticTriangle(3); } @@ -994,7 +995,7 @@ void CMap::DrawVertex(Math::Point uv1, Math::Point uv2, float zoom) Gfx::Vertex2D vertex[4]; // 2 triangles Math::Point p1, p2, c; - auto device = m_engine->GetDevice(); + auto renderer = m_engine->GetDevice()->GetUIRenderer(); p1.x = m_pos.x; p1.y = m_pos.y; @@ -1019,7 +1020,7 @@ void CMap::DrawVertex(Math::Point uv1, Math::Point uv2, float zoom) vertex[2] = { { p2.x, p1.y }, { uv2.x, uv2.y } }; vertex[3] = { { p2.x, p2.y }, { uv2.x, uv1.y } }; - device->DrawPrimitive(Gfx::PrimitiveType::TRIANGLE_STRIP, vertex, 4); + renderer->DrawPrimitive(Gfx::PrimitiveType::TRIANGLE_STRIP, 4, vertex); m_engine->AddStatisticTriangle(2); } diff --git a/src/ui/controls/shortcut.cpp b/src/ui/controls/shortcut.cpp index 2838c72d..2f2b9284 100644 --- a/src/ui/controls/shortcut.cpp +++ b/src/ui/controls/shortcut.cpp @@ -23,6 +23,7 @@ #include "common/event.h" #include "graphics/core/device.h" +#include "graphics/core/renderers.h" #include "graphics/engine/engine.h" @@ -226,8 +227,6 @@ void CShortcut::DrawVertex(int icon, float zoom) Math::Point p1, p2, c; float u1, u2, v1, v2, dp; - auto device = m_engine->GetDevice(); - p1.x = m_pos.x; p1.y = m_pos.y; p2.x = m_pos.x + m_dim.x; @@ -258,7 +257,9 @@ void CShortcut::DrawVertex(int icon, float zoom) vertex[2] = { { p2.x, p1.y }, { u2, v2 } }; vertex[3] = { { p2.x, p2.y }, { u2, v1 } }; - device->DrawPrimitive(Gfx::PrimitiveType::TRIANGLE_STRIP, vertex, 4); + auto renderer = m_engine->GetDevice()->GetUIRenderer(); + + renderer->DrawPrimitive(Gfx::PrimitiveType::TRIANGLE_STRIP, 4, vertex); m_engine->AddStatisticTriangle(2); }