graphics: Refactoring: Rename functions

This commit is contained in:
Hajime Hoshi 2018-06-10 17:53:57 +09:00
parent 32ac3840a7
commit 2853895e6b
3 changed files with 13 additions and 12 deletions

View File

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

View File

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

View File

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