From d5fbd2001b0ad3591a7f969dfd75c809ab55b40e Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Fri, 30 Jun 2023 04:34:10 +1000 Subject: RenderPrimitive micro-optimizations --- source/rendering/StarDrawablePainter.cpp | 35 +++++++++++++++++--------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'source/rendering/StarDrawablePainter.cpp') diff --git a/source/rendering/StarDrawablePainter.cpp b/source/rendering/StarDrawablePainter.cpp index 647d209..8c50b2b 100644 --- a/source/rendering/StarDrawablePainter.cpp +++ b/source/rendering/StarDrawablePainter.cpp @@ -9,24 +9,25 @@ DrawablePainter::DrawablePainter(RendererPtr renderer, AssetTextureGroupPtr text void DrawablePainter::drawDrawable(Drawable const& drawable) { Vec4B color = drawable.color.toRgba(); + auto& primitives = m_renderer->immediatePrimitives(); if (auto linePart = drawable.part.ptr()) { auto line = linePart->line; line.translate(drawable.position); - Vec2F left = Vec2F(vnorm(line.diff())).rot90() * linePart->width / 2.0f; - m_renderer->render(RenderQuad{{}, - RenderVertex{Vec2F(line.min()) + left, Vec2F(), color, drawable.fullbright ? 0.0f : 1.0f}, - RenderVertex{Vec2F(line.min()) - left, Vec2F(), color, drawable.fullbright ? 0.0f : 1.0f}, - RenderVertex{Vec2F(line.max()) - left, Vec2F(), color, drawable.fullbright ? 0.0f : 1.0f}, - RenderVertex{Vec2F(line.max()) + left, Vec2F(), color, drawable.fullbright ? 0.0f : 1.0f} - }); - + + float fullbright = drawable.fullbright ? 0.0f : 1.0f; + primitives.emplace_back(std::in_place_type_t(), + line.min() + left, + line.min() - left, + line.max() - left, + line.max() + left, + color, fullbright); } else if (auto polyPart = drawable.part.ptr()) { - auto poly = polyPart->poly; + PolyF poly = polyPart->poly; poly.translate(drawable.position); - m_renderer->render(renderFlatPoly(poly, color, 0.0f)); + primitives.emplace_back(std::in_place_type_t(), poly.vertexes(), color, 0.0f); } else if (auto imagePart = drawable.part.ptr()) { TexturePtr texture = m_textureGroup->loadTexture(imagePart->image); @@ -41,12 +42,14 @@ void DrawablePainter::drawDrawable(Drawable const& drawable) { Vec2F upperRight = transformation.transformVec2(Vec2F(imageRect.xMax(), imageRect.yMax())); Vec2F upperLeft = transformation.transformVec2(Vec2F(imageRect.xMin(), imageRect.yMax())); - m_renderer->render(RenderQuad{move(texture), - {lowerLeft, {0, 0}, color, drawable.fullbright ? 0.0f : 1.0f}, - {lowerRight, {textureSize[0], 0}, color, drawable.fullbright ? 0.0f : 1.0f}, - {upperRight, {textureSize[0], textureSize[1]}, color, drawable.fullbright ? 0.0f : 1.0f}, - {upperLeft, {0, textureSize[1]}, color, drawable.fullbright ? 0.0f : 1.0f} - }); + float param1 = drawable.fullbright ? 0.0f : 1.0f; + + primitives.emplace_back(std::in_place_type_t(), move(texture), + lowerLeft, Vec2F{0, 0}, + lowerRight, Vec2F{textureSize[0], 0}, + upperRight, Vec2F{textureSize[0], textureSize[1]}, + upperLeft, Vec2F{0, textureSize[1]}, + color, param1); } } -- cgit v1.2.3