diff --git a/internal/graphics/command.go b/internal/graphics/command.go index 961c48e57..9ed70f2cb 100644 --- a/internal/graphics/command.go +++ b/internal/graphics/command.go @@ -209,9 +209,9 @@ type drawImageCommand struct { filter Filter } -// QuadVertexSizeInBytes returns the size in bytes of vertices for a quadrangle. -func QuadVertexSizeInBytes() int { - return 4 * theArrayBufferLayout.totalBytes() +// VertexSizeInBytes returns the size in bytes of one vertex. +func VertexSizeInBytes() int { + return theArrayBufferLayout.totalBytes() } // Exec executes the drawImageCommand. diff --git a/internal/graphics/image.go b/internal/graphics/image.go index 275312dab..c8a0b940e 100644 --- a/internal/graphics/image.go +++ b/internal/graphics/image.go @@ -89,10 +89,10 @@ func (i *Image) Size() (int, int) { func (i *Image) DrawImage(src *Image, vertices []float32, clr *affine.ColorM, mode opengl.CompositeMode, filter Filter) { for len(vertices) > 0 { var next []float32 - nq := len(vertices) * opengl.Float.SizeInBytes() / QuadVertexSizeInBytes() + nq := len(vertices) * opengl.Float.SizeInBytes() / VertexSizeInBytes() / 4 if nq > maxQuads { nq = maxQuads - i := nq * QuadVertexSizeInBytes() / opengl.Float.SizeInBytes() + i := 4 * nq * VertexSizeInBytes() / opengl.Float.SizeInBytes() next = vertices[i:] vertices = vertices[:i] } diff --git a/internal/restorable/vertices.go b/internal/restorable/vertices.go index 6cbdc0c18..136240c58 100644 --- a/internal/restorable/vertices.go +++ b/internal/restorable/vertices.go @@ -17,10 +17,10 @@ package restorable import ( "github.com/hajimehoshi/ebiten/internal/affine" "github.com/hajimehoshi/ebiten/internal/graphics" + "github.com/hajimehoshi/ebiten/internal/opengl" ) var ( - quadFloat32Num = graphics.QuadVertexSizeInBytes() / 4 theVerticesBackend = &verticesBackend{} ) @@ -29,14 +29,15 @@ type verticesBackend struct { head int } -func (v *verticesBackend) get() []float32 { +func (v *verticesBackend) sliceForOneQuad() []float32 { const num = 256 + size := 4 * graphics.VertexSizeInBytes() / opengl.Float.SizeInBytes() if v.backend == nil { - v.backend = make([]float32, quadFloat32Num*num) + v.backend = make([]float32, size*num) } - s := v.backend[v.head : v.head+quadFloat32Num] - v.head += quadFloat32Num - if v.head+quadFloat32Num > len(v.backend) { + s := v.backend[v.head : v.head+size] + v.head += size + if v.head+size > len(v.backend) { v.backend = nil v.head = 0 } @@ -51,7 +52,7 @@ func vertices(width, height int, sx0, sy0, sx1, sy1 int, geo *affine.GeoM) []flo return nil } - vs := theVerticesBackend.get() + vs := theVerticesBackend.sliceForOneQuad() x0, y0 := 0.0, 0.0 x1, y1 := float64(sx1-sx0), float64(sy1-sy0)