From e537cb2c27a8f6ae9f875ce6cda3d0a6f09df096 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 1 Dec 2018 20:44:06 +0100 Subject: [PATCH] graphics: Bug fix: render source might not be initialized --- image_test.go | 30 ++++++++++++++++++++++++++++++ internal/graphicscommand/image.go | 15 +++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/image_test.go b/image_test.go index 34f73fc0f..2d64bbf6e 100644 --- a/image_test.go +++ b/image_test.go @@ -1095,3 +1095,33 @@ func TestImageSubImageSize(t *testing.T) { t.Errorf("got: %v, want: %v", got, want) } } + +func TestImageDrawImmediately(t *testing.T) { + const w, h = 16, 16 + img0, _ := NewImage(w, h, FilterDefault) + img1, _ := NewImage(w, h, FilterDefault) + // Do not manipulate img0 here. + + img0.Fill(color.RGBA{0xff, 0, 0, 0xff}) + for j := 0; j < h; j++ { + for i := 0; i < w; i++ { + got := img0.At(i, j).(color.RGBA) + want := color.RGBA{0xff, 0, 0, 0xff} + if got != want { + t.Errorf("img0.At(%d, %d): got %v, want: %v", i, j, got, want) + } + } + } + + img0.DrawImage(img1, nil) + + for j := 0; j < h; j++ { + for i := 0; i < w; i++ { + got := img0.At(i, j).(color.RGBA) + want := color.RGBA{0xff, 0, 0, 0xff} + if got != want { + t.Errorf("img0.At(%d, %d): got %v, want: %v", i, j, got, want) + } + } + } +} diff --git a/internal/graphicscommand/image.go b/internal/graphicscommand/image.go index cbf3e6ddb..e5a699981 100644 --- a/internal/graphicscommand/image.go +++ b/internal/graphicscommand/image.go @@ -143,6 +143,21 @@ func (i *Image) DrawImage(src *Image, vertices []float32, indices []uint16, clr default: panic("not reached") } + + switch src.state { + case imageStateInit: + src.clearByReplacingPixels() + case imageStateReplacePixelsOnly: + // Do nothing + // TODO: Check the region. + case imageStateDrawable: + // Do nothing + case imageStateScreen: + panic("not reached") + default: + panic("not reached") + } + theCommandQueue.EnqueueDrawImageCommand(i, src, vertices, indices, clr, mode, filter) }