hajimehoshi / ebiten

Ebitengine - A dead simple 2D game engine for Go
https://ebitengine.org
Apache License 2.0
11.12k stars 664 forks source link

ebiten: don't create a Vertex copy in DrawTriangles() / DrawTrianglesShader() #3104

Closed SolarLune closed 2 months ago

SolarLune commented 2 months ago

What issue is this addressing?

This is a performance patch to remove extra variable copying when looping through vertices in Image.DrawTriangles() and Image.DrawTrianglesShader().

What type of issue is this addressing?

Performance

What this PR does | solves

This PR replaces for i, v := range vertices with for i := range vertices and indexes the vertices slice to allow the functions to behave the same while avoiding unnecessarily allocating an extra ebiten.Vertex in each loop iteration.

This PR should resolve issue #3103.