mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 19:28:57 +01:00
graphics: Refactoring: Rename functions
This commit is contained in:
parent
32ac3840a7
commit
2853895e6b
@ -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.
|
||||
|
@ -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]
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user