ebiten: Use the common vertices backend at DrawTriangles

This commit is contained in:
Hajime Hoshi 2021-03-20 20:24:32 +09:00
parent 15a0c53918
commit 41f060b1d2
2 changed files with 12 additions and 6 deletions

View File

@ -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

View File

@ -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