diff --git a/image.go b/image.go index f0c917387..e98c1a22c 100644 --- a/image.go +++ b/image.go @@ -327,8 +327,7 @@ func (i *Image) DrawTriangles(vertices []Vertex, indices []uint16, img *Image, o filter := driver.Filter(options.Filter) - // TODO: Use the same backend as graphics.QuadVertices. - vs := make([]float32, len(vertices)*graphics.VertexFloatNum) + vs := graphics.Vertices(len(vertices)) for i, v := range vertices { vs[i*graphics.VertexFloatNum] = v.DstX vs[i*graphics.VertexFloatNum+1] = v.DstY @@ -417,7 +416,7 @@ func (i *Image) DrawTrianglesShader(vertices []Vertex, indices []uint16, shader mode := driver.CompositeMode(options.CompositeMode) - vs := make([]float32, len(vertices)*graphics.VertexFloatNum) + vs := graphics.Vertices(len(vertices)) for i, v := range vertices { vs[i*graphics.VertexFloatNum] = v.DstX vs[i*graphics.VertexFloatNum+1] = v.DstY diff --git a/internal/graphics/vertex.go b/internal/graphics/vertex.go index e6bc71148..7c845706c 100644 --- a/internal/graphics/vertex.go +++ b/internal/graphics/vertex.go @@ -63,9 +63,6 @@ type verticesBackend struct { m sync.Mutex } -// slice returns a float32 slice for n vertices. -// slice returns a slice that never overlaps with other slices returned this function, -// and users can do optimization based on this fact. func (v *verticesBackend) slice(n int) []float32 { v.m.Lock() defer v.m.Unlock() @@ -88,6 +85,16 @@ func (v *verticesBackend) slice(n int) []float32 { return s } +// Vertices returns a float32 slice for n vertices. +// Vertices returns a slice that never overlaps with other slices returned this function, +// and users can do optimization based on this fact. +func Vertices(n int) []float32 { + return theVerticesBackend.slice(n) +} + +// QuadVertices returns a float32 slice for a quadrangle. +// QuadVertices returns a slice that never overlaps with other slices returned this function, +// and users can do optimization based on this fact. func QuadVertices(sx0, sy0, sx1, sy1 float32, a, b, c, d, tx, ty float32, cr, cg, cb, ca float32) []float32 { x := sx1 - sx0 y := sy1 - sy0