From db738676cebe2dbd33e46ae0063c5756e75daf7f Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 1 Mar 2018 23:13:23 +0900 Subject: [PATCH] restorable: Refactoring: clearIfVolatile --- internal/graphics/image.go | 4 ---- internal/restorable/image.go | 14 +++++++------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/internal/graphics/image.go b/internal/graphics/image.go index 38b8f7925..300dc1ea2 100644 --- a/internal/graphics/image.go +++ b/internal/graphics/image.go @@ -115,7 +115,3 @@ func (i *Image) createFramebufferIfNeeded() (*framebuffer, error) { i.framebuffer = f return i.framebuffer, nil } - -func (i *Image) ViewportSize() (int, int) { - return i.framebuffer.viewportSize() -} diff --git a/internal/restorable/image.go b/internal/restorable/image.go index 90c923fa1..0fe36368b 100644 --- a/internal/restorable/image.go +++ b/internal/restorable/image.go @@ -116,12 +116,13 @@ func (i *Image) makeStale() { } var ( - dummyImage = graphics.NewImage(16, 16) - clearColorM *affine.ColorM + emptyImage = graphics.NewImage(16, 16) ) func init() { - clearColorM = clearColorM.Scale(0, 0, 0, 0) + w, h := emptyImage.Size() + pix := make([]byte, 4*w*h) + emptyImage.ReplacePixels(pix, 0, 0, w, h) } // clearIfVolatile clears the image if the image is volatile. @@ -136,11 +137,10 @@ func (i *Image) clearIfVolatile() { panic("not reached") } - w, h := i.image.ViewportSize() x0 := float32(0) y0 := float32(0) - x1 := float32(w) - y1 := float32(h) + x1 := float32(graphics.MaxImageSize) + y1 := float32(graphics.MaxImageSize) // For the rule of values, see vertices.go. clearVertices := []float32{ x0, y0, 0, 0, 1, 1, @@ -148,7 +148,7 @@ func (i *Image) clearIfVolatile() { x0, y1, 0, 1, 1, 0, x1, y1, 1, 1, 0, 0, } - i.image.DrawImage(dummyImage, clearVertices, clearColorM, opengl.CompositeModeCopy, graphics.FilterNearest) + i.image.DrawImage(emptyImage, clearVertices, nil, opengl.CompositeModeCopy, graphics.FilterNearest) } // ReplacePixels replaces the image pixels with the given pixels slice.