Removed UIRenderer's DrawPrimitive() via CDevice

dev
Tomasz Kapuściński 2021-12-12 21:17:39 +01:00
parent d1489a1fb1
commit 2583f6fe36
10 changed files with 38 additions and 36 deletions

View File

@ -503,8 +503,6 @@ public:
Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) = 0; Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) = 0;
//! Renders primitive composed of vertices with solid color //! Renders primitive composed of vertices with solid color
virtual void DrawPrimitive(PrimitiveType type, const VertexCol *vertices , int vertexCount) = 0; 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 //! Renders 3D primitive
virtual void DrawPrimitive(PrimitiveType type, const Vertex3D* vertices, int vertexCount) = 0; virtual void DrawPrimitive(PrimitiveType type, const Vertex3D* vertices, int vertexCount) = 0;

View File

@ -5008,7 +5008,8 @@ void CEngine::DrawBackgroundImage()
{ { p2.x, p2.y }, { u2, v1 } } { { 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); AddStatisticTriangle(2);
} }
@ -5261,7 +5262,8 @@ void CEngine::DrawMouseSprite(Math::IntPoint pos, Math::IntPoint size, int icon)
{ { p2.x, p1.y }, { u2, v1 } } { { 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); 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); Math::Point pos(0.05f * m_size.x/m_size.y, 0.05f + TOTAL_LINES * height);
SetState(ENG_RSTATE_TCOLOR_ALPHA); SetState(ENG_RSTATE_TCOLOR_ALPHA);
SetUITexture(Texture{}); auto renderer = m_device->GetUIRenderer();
renderer->SetTexture(Texture{});
glm::u8vec4 black = { 0, 0, 0, 192 }; 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 } { { 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); SetState(ENG_RSTATE_TEXT);

View File

@ -151,9 +151,11 @@ public:
} }
} }
auto renderer = m_engine.GetDevice()->GetUIRenderer();
for (const auto& quad : m_quads) 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(); m_engine.GetDevice()->GetUIRenderer()->Flush();

View File

@ -1143,11 +1143,6 @@ void CGL33Device::DrawPrimitive(PrimitiveType type, const Vertex3D* vertices, in
glDrawArrays(TranslateGfxPrimitive(type), 0, vertexCount); 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, void CGL33Device::DrawPrimitives(PrimitiveType type, const Vertex *vertices,
int first[], int count[], int drawCount, Color color) int first[], int count[], int drawCount, Color color)
{ {

View File

@ -154,8 +154,6 @@ public:
Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) override; 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 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 DrawPrimitive(PrimitiveType type, const Vertex3D* vertices, int vertexCount) override;
virtual void DrawPrimitives(PrimitiveType type, const Vertex *vertices, virtual void DrawPrimitives(PrimitiveType type, const Vertex *vertices,

View File

@ -24,6 +24,7 @@
#include "common/restext.h" #include "common/restext.h"
#include "graphics/core/device.h" #include "graphics/core/device.h"
#include "graphics/core/renderers.h"
#include "graphics/engine/engine.h" #include "graphics/engine/engine.h"
@ -151,14 +152,14 @@ void CColor::Draw()
m_engine->SetUITexture(Gfx::Texture{0}); // no texture m_engine->SetUITexture(Gfx::Texture{0}); // no texture
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
auto device = m_engine->GetDevice();
vertex[0] = { { p1.x, p1.y }, {}, col }; vertex[0] = { { p1.x, p1.y }, {}, col };
vertex[1] = { { p1.x, p2.y }, {}, col }; vertex[1] = { { p1.x, p2.y }, {}, col };
vertex[2] = { { p2.x, p1.y }, {}, col }; vertex[2] = { { p2.x, p1.y }, {}, col };
vertex[3] = { { p2.x, p2.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); m_engine->AddStatisticTriangle(2);
} }

View File

@ -28,7 +28,7 @@
#include "level/robotmain.h" #include "level/robotmain.h"
#include "graphics/core/renderers.h"
namespace Ui 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 Gfx::Vertex2D vertex[8]; // 6 triangles
glm::vec2 p1, p2, p3, p4; glm::vec2 p1, p2, p3, p4;
auto device = m_engine->GetDevice(); auto renderer = m_engine->GetDevice()->GetUIRenderer();
p1.x = pos.x; p1.x = pos.x;
p1.y = pos.y; 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[2] = { { p2.x, p1.y }, { uv2.x, uv2.y } };
vertex[3] = { { p2.x, p2.y }, { uv2.x, uv1.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); m_engine->AddStatisticTriangle(2);
} }
else // 3 pieces? 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[6] = { { p2.x, p1.y }, { uv2.x, uv2.y } };
vertex[7] = { { p2.x, p2.y }, { uv2.x, uv1.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); m_engine->AddStatisticTriangle(6);
} }
else 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[6] = { { p2.x, p2.y }, { uv2.x, uv1.y } };
vertex[7] = { { p1.x, p2.y }, { uv1.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); 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 Gfx::Vertex2D vertices[8]; // 6 triangles
glm::vec2 p1, p2, p3, p4; glm::vec2 p1, p2, p3, p4;
auto device = m_engine->GetDevice(); auto renderer = m_engine->GetDevice()->GetUIRenderer();
p1.x = pos.x; p1.x = pos.x;
p1.y = pos.y; 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[6] = { { p2.x, p1.y }, { uv2.x, uv2.y } };
vertices[7] = { { p2.x, p3.y }, { uv2.x, uv2.y - ex } }; 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); m_engine->AddStatisticTriangle(6);
// Central horizontal band. // 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[6] = { { p2.x, p3.y }, { uv2.x, uv2.y - ex } };
vertices[7] = { { p2.x, p4.y }, { uv2.x, uv1.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); m_engine->AddStatisticTriangle(6);
// Top horizontal band. // 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[6] = { { p2.x, p4.y }, { uv2.x, uv1.y + ex } };
vertices[7] = { { p2.x, p2.y }, { uv2.x, uv1.y } }; 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); m_engine->AddStatisticTriangle(6);
} }

View File

@ -31,6 +31,7 @@
#include "common/resources/inputstream.h" #include "common/resources/inputstream.h"
#include "common/resources/outputstream.h" #include "common/resources/outputstream.h"
#include "graphics/core/renderers.h"
#include "graphics/engine/engine.h" #include "graphics/engine/engine.h"
#include "level/parser/parser.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 } { { 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); m_engine->AddStatisticTriangle(2);
} }

View File

@ -23,6 +23,7 @@
#include "common/image.h" #include "common/image.h"
#include "graphics/core/device.h" #include "graphics/core/device.h"
#include "graphics/core/renderers.h"
#include "graphics/engine/terrain.h" #include "graphics/engine/terrain.h"
#include "graphics/engine/water.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 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[0] = { { p1.x, p1.y }, { uv1.x, uv1.y } };
vertex[1] = { { p2.x, p2.y }, { uv1.x, uv2.y } }; vertex[1] = { { p2.x, p2.y }, { uv1.x, uv2.y } };
vertex[2] = { { p3.x, p3.y }, { uv2.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); 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 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[0] = { { p1.x, p1.y }, { uv1.x, uv1.y } };
vertex[1] = { { p2.x, p2.y }, { uv1.x, uv2.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[3] = { { p3.x, p3.y }, { uv2.x, uv2.y } };
vertex[4] = { { p4.x, p4.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); 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 Gfx::Vertex2D vertex[4]; // 2 triangles
Math::Point p1, p2, c; Math::Point p1, p2, c;
auto device = m_engine->GetDevice(); auto renderer = m_engine->GetDevice()->GetUIRenderer();
p1.x = m_pos.x; p1.x = m_pos.x;
p1.y = m_pos.y; 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[2] = { { p2.x, p1.y }, { uv2.x, uv2.y } };
vertex[3] = { { p2.x, p2.y }, { uv2.x, uv1.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); m_engine->AddStatisticTriangle(2);
} }

View File

@ -23,6 +23,7 @@
#include "common/event.h" #include "common/event.h"
#include "graphics/core/device.h" #include "graphics/core/device.h"
#include "graphics/core/renderers.h"
#include "graphics/engine/engine.h" #include "graphics/engine/engine.h"
@ -226,8 +227,6 @@ void CShortcut::DrawVertex(int icon, float zoom)
Math::Point p1, p2, c; Math::Point p1, p2, c;
float u1, u2, v1, v2, dp; float u1, u2, v1, v2, dp;
auto device = m_engine->GetDevice();
p1.x = m_pos.x; p1.x = m_pos.x;
p1.y = m_pos.y; p1.y = m_pos.y;
p2.x = m_pos.x + m_dim.x; 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[2] = { { p2.x, p1.y }, { u2, v2 } };
vertex[3] = { { p2.x, p2.y }, { u2, v1 } }; 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); m_engine->AddStatisticTriangle(2);
} }