ebiten: refactoring: reduce local variables

This commit is contained in:
Hajime Hoshi 2023-08-27 18:14:50 +09:00
parent 3678b20c5d
commit 4b9875295c

View File

@ -659,11 +659,8 @@ func (i *Image) DrawTrianglesShader(vertices []Vertex, indices []uint16, shader
imgs[i] = img.image imgs[i] = img.image
} }
var sx, sy int
var sr graphicsdriver.Region var sr graphicsdriver.Region
if img := options.Images[0]; img != nil { if img := options.Images[0]; img != nil {
b := img.Bounds()
sx, sy = img.adjustPosition(b.Min.X, b.Min.Y)
sr = img.adjustedRegion() sr = img.adjustedRegion()
} }
@ -674,10 +671,10 @@ func (i *Image) DrawTrianglesShader(vertices []Vertex, indices []uint16, shader
} }
b := img.Bounds() b := img.Bounds()
x, y := img.adjustPosition(b.Min.X, b.Min.Y) x, y := img.adjustPosition(b.Min.X, b.Min.Y)
// (sx, sy) is the upper-left position of the first image. // (sr.X, sr.Y) is the upper-left position of the first image.
// Calculate the distance between the current image's upper-left position and the first one's. // Calculate the distance between the current image's upper-left position and the first one's.
offsets[i][0] = float32(x - sx) offsets[i][0] = float32(x) - sr.X
offsets[i][1] = float32(y - sy) offsets[i][1] = float32(y) - sr.Y
} }
i.tmpUniforms = i.tmpUniforms[:0] i.tmpUniforms = i.tmpUniforms[:0]
@ -778,11 +775,8 @@ func (i *Image) DrawRectShader(width, height int, shader *Shader, options *DrawR
imgs[i] = img.image imgs[i] = img.image
} }
var sx, sy int
var sr graphicsdriver.Region var sr graphicsdriver.Region
if img := options.Images[0]; img != nil { if img := options.Images[0]; img != nil {
b := img.Bounds()
sx, sy = img.adjustPosition(b.Min.X, b.Min.Y)
sr = img.adjustedRegion() sr = img.adjustedRegion()
} else if shader.unit == shaderir.Pixels { } else if shader.unit == shaderir.Pixels {
// Give the source size as pixels only when the unit is pixels so that users can get the source size via imageSrcRegionOnTexture (#2166). // Give the source size as pixels only when the unit is pixels so that users can get the source size via imageSrcRegionOnTexture (#2166).
@ -800,7 +794,8 @@ func (i *Image) DrawRectShader(width, height int, shader *Shader, options *DrawR
a, b, c, d, tx, ty := geoM.elements32() a, b, c, d, tx, ty := geoM.elements32()
cr, cg, cb, ca := options.ColorScale.elements() cr, cg, cb, ca := options.ColorScale.elements()
vs := i.ensureTmpVertices(4 * graphics.VertexFloatCount) vs := i.ensureTmpVertices(4 * graphics.VertexFloatCount)
graphics.QuadVertices(vs, float32(sx), float32(sy), float32(sx+width), float32(sy+height), a, b, c, d, tx, ty, cr, cg, cb, ca) // Do not use sr.Width and sr.Height as these might be empty.
graphics.QuadVertices(vs, sr.X, sr.Y, sr.X+float32(width), sr.Y+float32(height), a, b, c, d, tx, ty, cr, cg, cb, ca)
is := graphics.QuadIndices() is := graphics.QuadIndices()
var offsets [graphics.ShaderImageCount - 1][2]float32 var offsets [graphics.ShaderImageCount - 1][2]float32
@ -810,10 +805,10 @@ func (i *Image) DrawRectShader(width, height int, shader *Shader, options *DrawR
} }
b := img.Bounds() b := img.Bounds()
x, y := img.adjustPosition(b.Min.X, b.Min.Y) x, y := img.adjustPosition(b.Min.X, b.Min.Y)
// (sx, sy) is the upper-left position of the first image. // (sr.X, sr.Y) is the upper-left position of the first image.
// Calculate the distance between the current image's upper-left position and the first one's. // Calculate the distance between the current image's upper-left position and the first one's.
offsets[i][0] = float32(x - sx) offsets[i][0] = float32(x) - sr.X
offsets[i][1] = float32(y - sy) offsets[i][1] = float32(y) - sr.Y
} }
i.tmpUniforms = i.tmpUniforms[:0] i.tmpUniforms = i.tmpUniforms[:0]