From 12c24215b1c6e52ba930e5ac25d4c149fcc95dbc Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 24 Aug 2017 00:11:08 +0900 Subject: [PATCH] graphics: Bug fix: Flush after filling (#419) --- image_test.go | 24 +++++++++++++++++++++++- internal/graphics/command.go | 8 +++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/image_test.go b/image_test.go index 70382843a..1ed9a7e13 100644 --- a/image_test.go +++ b/image_test.go @@ -490,7 +490,7 @@ func TestImageFill(t *testing.T) { } } -// Issue 317 +// Issue #317 func TestImageEdge(t *testing.T) { const ( img0Width = 16 @@ -561,6 +561,28 @@ func TestImageEdge(t *testing.T) { } } +// Issue #419 +func TestImageTooManyFill(t *testing.T) { + const width = 256 + + src, _ := NewImage(1, 1, FilterNearest) + dst, _ := NewImage(width, 1, FilterNearest) + for i := 0; i < width; i++ { + src.Fill(color.RGBA{uint8(i), uint8(i), uint8(i), 0xff}) + op := &DrawImageOptions{} + op.GeoM.Translate(float64(i), 0) + dst.DrawImage(src, op) + } + + for i := 0; i < width; i++ { + got := color.RGBAModel.Convert(dst.At(i, 0)) + want := color.RGBA{uint8(i), uint8(i), uint8(i), 0xff} + if got != want { + t.Errorf("src At(%d, %d): got %#v, want: %#v", i, 0, got, want) + } + } +} + func BenchmarkDrawImage(b *testing.B) { img0, _ := NewImage(16, 16, FilterNearest) img1, _ := NewImage(16, 16, FilterNearest) diff --git a/internal/graphics/command.go b/internal/graphics/command.go index 0f5eb3a11..666276625 100644 --- a/internal/graphics/command.go +++ b/internal/graphics/command.go @@ -181,7 +181,13 @@ func (c *fillCommand) Exec(indexOffsetInBytes int) error { g := float64(cg) / max b := float64(cb) / max a := float64(ca) / max - return opengl.GetContext().FillFramebuffer(r, g, b, a) + if err := opengl.GetContext().FillFramebuffer(r, g, b, a); err != nil { + return err + } + + // Flush is needed after filling (#419) + opengl.GetContext().Flush() + return nil } type drawImageCommand struct {