mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
graphicsutil: Don't allow nil GeoM
This commit is contained in:
parent
f6b7a6be73
commit
4c2fc30311
@ -74,10 +74,7 @@ func QuadVertices(width, height int, sx0, sy0, sx1, sy1 int, geom GeoM) []float3
|
||||
hf := float32(h)
|
||||
u0, v0, u1, v1 := float32(sx0)/wf, float32(sy0)/hf, float32(sx1)/wf, float32(sy1)/hf
|
||||
|
||||
x, y := x0, y0
|
||||
if geom != nil {
|
||||
x, y = geom.Apply(x, y)
|
||||
}
|
||||
x, y := geom.Apply(x0, y0)
|
||||
// Vertex coordinates
|
||||
vs[0] = float32(x)
|
||||
vs[1] = float32(y)
|
||||
@ -91,10 +88,7 @@ func QuadVertices(width, height int, sx0, sy0, sx1, sy1 int, geom GeoM) []float3
|
||||
vs[5] = v1
|
||||
|
||||
// and the same for the other three coordinates
|
||||
x, y = x1, y0
|
||||
if geom != nil {
|
||||
x, y = geom.Apply(x, y)
|
||||
}
|
||||
x, y = geom.Apply(x1, y0)
|
||||
vs[6] = float32(x)
|
||||
vs[7] = float32(y)
|
||||
vs[8] = u1
|
||||
@ -102,10 +96,7 @@ func QuadVertices(width, height int, sx0, sy0, sx1, sy1 int, geom GeoM) []float3
|
||||
vs[10] = u0
|
||||
vs[11] = v1
|
||||
|
||||
x, y = x0, y1
|
||||
if geom != nil {
|
||||
x, y = geom.Apply(x, y)
|
||||
}
|
||||
x, y = geom.Apply(x0, y1)
|
||||
vs[12] = float32(x)
|
||||
vs[13] = float32(y)
|
||||
vs[14] = u0
|
||||
@ -113,10 +104,7 @@ func QuadVertices(width, height int, sx0, sy0, sx1, sy1 int, geom GeoM) []float3
|
||||
vs[16] = u1
|
||||
vs[17] = v0
|
||||
|
||||
x, y = x1, y1
|
||||
if geom != nil {
|
||||
x, y = geom.Apply(x, y)
|
||||
}
|
||||
x, y = geom.Apply(x1, y1)
|
||||
vs[18] = float32(x)
|
||||
vs[19] = float32(y)
|
||||
vs[20] = u1
|
||||
|
@ -105,6 +105,12 @@ var (
|
||||
quadIndices = []uint16{0, 1, 2, 1, 2, 3}
|
||||
)
|
||||
|
||||
type idGeoM struct{}
|
||||
|
||||
func (idGeoM) Apply(x, y float64) (x2, y2 float64) {
|
||||
return x, y
|
||||
}
|
||||
|
||||
func TestRestoreChain(t *testing.T) {
|
||||
const num = 10
|
||||
imgs := []*Image{}
|
||||
@ -122,7 +128,7 @@ func TestRestoreChain(t *testing.T) {
|
||||
fill(imgs[0], clr.R, clr.G, clr.B, clr.A)
|
||||
for i := 0; i < num-1; i++ {
|
||||
w, h := imgs[i].Size()
|
||||
vs := graphicsutil.QuadVertices(w, h, 0, 0, 1, 1, nil)
|
||||
vs := graphicsutil.QuadVertices(w, h, 0, 0, 1, 1, idGeoM{})
|
||||
imgs[i+1].DrawImage(imgs[i], vs, quadIndices, nil, opengl.CompositeModeCopy, graphics.FilterNearest)
|
||||
}
|
||||
if err := ResolveStaleImages(); err != nil {
|
||||
@ -165,7 +171,7 @@ func TestRestoreChain2(t *testing.T) {
|
||||
clr8 := color.RGBA{0x00, 0x00, 0xff, 0xff}
|
||||
fill(imgs[8], clr8.R, clr8.G, clr8.B, clr8.A)
|
||||
|
||||
vs := graphicsutil.QuadVertices(w, h, 0, 0, w, h, nil)
|
||||
vs := graphicsutil.QuadVertices(w, h, 0, 0, w, h, idGeoM{})
|
||||
imgs[8].DrawImage(imgs[7], vs, quadIndices, nil, opengl.CompositeModeCopy, graphics.FilterNearest)
|
||||
imgs[9].DrawImage(imgs[8], vs, quadIndices, nil, opengl.CompositeModeCopy, graphics.FilterNearest)
|
||||
for i := 0; i < 7; i++ {
|
||||
@ -212,7 +218,7 @@ func TestRestoreOverrideSource(t *testing.T) {
|
||||
clr0 := color.RGBA{0x00, 0x00, 0x00, 0xff}
|
||||
clr1 := color.RGBA{0x00, 0x00, 0x01, 0xff}
|
||||
fill(img1, clr0.R, clr0.G, clr0.B, clr0.A)
|
||||
vs := graphicsutil.QuadVertices(w, h, 0, 0, w, h, nil)
|
||||
vs := graphicsutil.QuadVertices(w, h, 0, 0, w, h, idGeoM{})
|
||||
img2.DrawImage(img1, vs, quadIndices, nil, opengl.CompositeModeSourceOver, graphics.FilterNearest)
|
||||
img3.DrawImage(img2, vs, quadIndices, nil, opengl.CompositeModeSourceOver, graphics.FilterNearest)
|
||||
fill(img0, clr1.R, clr1.G, clr1.B, clr1.A)
|
||||
@ -513,7 +519,7 @@ func TestDrawImageAndReplacePixels(t *testing.T) {
|
||||
img1 := NewImage(2, 1, false)
|
||||
defer img1.Dispose()
|
||||
|
||||
vs := graphicsutil.QuadVertices(1, 1, 0, 0, 1, 1, nil)
|
||||
vs := graphicsutil.QuadVertices(1, 1, 0, 0, 1, 1, idGeoM{})
|
||||
img1.DrawImage(img0, vs, quadIndices, nil, opengl.CompositeModeCopy, graphics.FilterNearest)
|
||||
img1.ReplacePixels([]byte{0xff, 0xff, 0xff, 0xff}, 1, 0, 1, 1)
|
||||
|
||||
@ -549,7 +555,7 @@ func TestDispose(t *testing.T) {
|
||||
img2 := newImageFromImage(base2)
|
||||
defer img2.Dispose()
|
||||
|
||||
vs := graphicsutil.QuadVertices(1, 1, 0, 0, 1, 1, nil)
|
||||
vs := graphicsutil.QuadVertices(1, 1, 0, 0, 1, 1, idGeoM{})
|
||||
img1.DrawImage(img2, vs, quadIndices, nil, opengl.CompositeModeCopy, graphics.FilterNearest)
|
||||
img0.DrawImage(img1, vs, quadIndices, nil, opengl.CompositeModeCopy, graphics.FilterNearest)
|
||||
img1.Dispose()
|
||||
@ -581,7 +587,7 @@ func TestDoubleResolve(t *testing.T) {
|
||||
base.Pix[3] = 0xff
|
||||
img1 := newImageFromImage(base)
|
||||
|
||||
vs := graphicsutil.QuadVertices(1, 1, 0, 0, 1, 1, nil)
|
||||
vs := graphicsutil.QuadVertices(1, 1, 0, 0, 1, 1, idGeoM{})
|
||||
img0.DrawImage(img1, vs, quadIndices, nil, opengl.CompositeModeCopy, graphics.FilterNearest)
|
||||
img0.ReplacePixels([]uint8{0x00, 0xff, 0x00, 0xff}, 1, 1, 1, 1)
|
||||
// Now img0 is stale.
|
||||
|
@ -67,7 +67,7 @@ func (b *backend) TryAlloc(width, height int) (*packing.Node, bool) {
|
||||
newImg := restorable.NewImage(s, s, false)
|
||||
oldImg := b.restorable
|
||||
w, h := oldImg.Size()
|
||||
vs := graphicsutil.QuadVertices(w, h, 0, 0, w, h, nil)
|
||||
vs := graphicsutil.QuadVertices(w, h, 0, 0, w, h, idGeoM{})
|
||||
newImg.DrawImage(oldImg, vs, quadIndices, nil, opengl.CompositeModeCopy, graphics.FilterNearest)
|
||||
oldImg.Dispose()
|
||||
b.restorable = newImg
|
||||
@ -98,6 +98,12 @@ type Image struct {
|
||||
node *packing.Node
|
||||
}
|
||||
|
||||
type idGeoM struct{}
|
||||
|
||||
func (idGeoM) Apply(x, y float64) (x2, y2 float64) {
|
||||
return x, y
|
||||
}
|
||||
|
||||
func (i *Image) ensureNotShared() {
|
||||
if i.backend == nil {
|
||||
i.allocate(false)
|
||||
@ -111,7 +117,7 @@ func (i *Image) ensureNotShared() {
|
||||
x, y, w, h := i.region()
|
||||
newImg := restorable.NewImage(w, h, false)
|
||||
vw, vh := i.backend.restorable.Size()
|
||||
vs := graphicsutil.QuadVertices(vw, vh, x, y, x+w, y+h, nil)
|
||||
vs := graphicsutil.QuadVertices(vw, vh, x, y, x+w, y+h, idGeoM{})
|
||||
newImg.DrawImage(i.backend.restorable, vs, quadIndices, nil, opengl.CompositeModeCopy, graphics.FilterNearest)
|
||||
|
||||
i.dispose(false)
|
||||
|
Loading…
Reference in New Issue
Block a user