diff --git a/image.go b/image.go index 5e44c85c0..c780646ed 100644 --- a/image.go +++ b/image.go @@ -140,6 +140,9 @@ func (i *Image) DrawImage(img *Image, options *DrawImageOptions) error { } } vs := vertices(sx0, sy0, sx1, sy1, w, h, &options.GeoM.impl) + if vs == nil { + return nil + } mode := opengl.CompositeMode(options.CompositeMode) i.restorable.DrawImage(img.restorable, vs, &options.ColorM.impl, mode) return nil diff --git a/internal/graphics/shader.go b/internal/graphics/shader.go index 18cd9a5b6..f98206ada 100644 --- a/internal/graphics/shader.go +++ b/internal/graphics/shader.go @@ -83,9 +83,6 @@ highp vec2 roundTexel(highp vec2 p) { } vec4 getColorAt(highp vec2 pos) { - if (pos.x < 0.0 || pos.y < 0.0) { - return vec4(0, 0, 0, 0); - } if (pos.x < varying_tex_coord_min.x || pos.y < varying_tex_coord_min.y || varying_tex_coord_max.x <= pos.x || diff --git a/vertices.go b/vertices.go index 305921941..793f57879 100644 --- a/vertices.go +++ b/vertices.go @@ -47,8 +47,30 @@ func vertices(sx0, sy0, sx1, sy1 int, width, height int, geo *affine.GeoM) []flo if sx0 >= sx1 || sy0 >= sy1 { return nil } + if sx1 <= 0 || sy1 <= 0 { + return nil + } + // TODO: This function should be in graphics package? vs := theVerticesBackend.get() + + if sx0 < 0 || sy0 < 0 { + dx := 0.0 + dy := 0.0 + if sx0 < 0 { + dx = -float64(sx0) + sx0 = 0 + } + if sy0 < 0 { + dy = -float64(sy0) + sy0 = 0 + } + g := affine.GeoM{} + g.Translate(dx, dy) + g.Concat(geo) + geo = &g + } + a, b, c, d, tx, ty := geo.Elements() g0 := float32(a) g1 := float32(b)