diff --git a/image.go b/image.go index 9d2367cba2e6..fc124faaa823 100644 --- a/image.go +++ b/image.go @@ -239,10 +239,11 @@ func (i *Image) DrawImage(img *Image, options *DrawImageOptions) { } filter := builtinshader.Filter(options.Filter) + geoM := options.GeoM if offsetX, offsetY := i.adjustPosition(0, 0); offsetX != 0 || offsetY != 0 { - options.GeoM.Translate(float64(offsetX), float64(offsetY)) + geoM.Translate(float64(offsetX), float64(offsetY)) } - a, b, c, d, tx, ty := options.GeoM.elements32() + a, b, c, d, tx, ty := geoM.elements32() bounds := img.Bounds() sx0, sy0 := img.adjustPosition(bounds.Min.X, bounds.Min.Y) @@ -268,7 +269,7 @@ func (i *Image) DrawImage(img *Image, options *DrawImageOptions) { }) } - i.image.DrawTriangles(srcs, vs, is, blend, i.adjustedRegion(), img.adjustedRegion(), [graphics.ShaderImageCount - 1][2]float32{}, shader.shader, i.tmpUniforms, false, canSkipMipmap(options.GeoM, filter), false) + i.image.DrawTriangles(srcs, vs, is, blend, i.adjustedRegion(), img.adjustedRegion(), [graphics.ShaderImageCount - 1][2]float32{}, shader.shader, i.tmpUniforms, false, canSkipMipmap(geoM, filter), false) } // Vertex represents a vertex passed to DrawTriangles. @@ -740,10 +741,11 @@ func (i *Image) DrawRectShader(width, height int, shader *Shader, options *DrawR sr = img.adjustedRegion() } + geoM := options.GeoM if offsetX, offsetY := i.adjustPosition(0, 0); offsetX != 0 || offsetY != 0 { - options.GeoM.Translate(float64(offsetX), float64(offsetY)) + geoM.Translate(float64(offsetX), float64(offsetY)) } - a, b, c, d, tx, ty := options.GeoM.elements32() + a, b, c, d, tx, ty := geoM.elements32() cr, cg, cb, ca := options.ColorScale.elements() 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) diff --git a/image_test.go b/image_test.go index 4f8e2341fb63..b4d98b4fda76 100644 --- a/image_test.go +++ b/image_test.go @@ -4080,3 +4080,31 @@ func TestImageSetAndSubImage(t *testing.T) { t.Errorf("got: %v, want: %v", got, want) } } + +// Issue #2733 +func TestImageGeoMAfterDraw(t *testing.T) { + src := ebiten.NewImage(1, 1) + dst := ebiten.NewImageWithOptions(image.Rect(-1, -1, 0, 0), nil) + op0 := &ebiten.DrawImageOptions{} + dst.DrawImage(src, op0) + if x, y := op0.GeoM.Apply(0, 0); x != 0 || y != 0 { + t.Errorf("got: (%0.2f, %0.2f), want: (0, 0)", x, y) + } + + s, err := ebiten.NewShader([]byte(`//kage:unit pixels + +package main + +func Fragment(position vec4, texCoord vec2, color vec4) vec4 { + return vec4(1) +} +`)) + if err != nil { + t.Fatal(err) + } + op1 := &ebiten.DrawRectShaderOptions{} + dst.DrawRectShader(1, 1, s, op1) + if x, y := op1.GeoM.Apply(0, 0); x != 0 || y != 0 { + t.Errorf("got: (%0.2f, %0.2f), want: (0, 0)", x, y) + } +}