From def82fd5d30e576134b057c26db84278afa1b66a Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 30 Jun 2024 18:40:13 +0900 Subject: [PATCH] internal/atlas: refactoring: remove ImageTypeVolatile ImageTypeVolatile was meaningful when Ebitengine had `restorable` package, but now this doesn't make sense. --- gameforui.go | 4 ---- internal/atlas/image.go | 1 - internal/atlas/image_test.go | 6 +++--- internal/ui/context.go | 6 ------ internal/ui/image.go | 12 +----------- 5 files changed, 4 insertions(+), 25 deletions(-) diff --git a/gameforui.go b/gameforui.go index d86e4fda8..e496e7843 100644 --- a/gameforui.go +++ b/gameforui.go @@ -66,10 +66,6 @@ func (g *gameForUI) NewOffscreenImage(width, height int) *ui.Image { // An image on an atlas is surrounded by a transparent edge, // and the shader program unexpectedly picks the pixel on the edges. imageType := atlas.ImageTypeUnmanaged - if ui.Get().IsScreenClearedEveryFrame() { - // A volatile image is also always isolated. - imageType = atlas.ImageTypeVolatile - } g.offscreen = newImage(image.Rect(0, 0, width, height), imageType) return g.offscreen.image } diff --git a/internal/atlas/image.go b/internal/atlas/image.go index c1bf42268..d52681f99 100644 --- a/internal/atlas/image.go +++ b/internal/atlas/image.go @@ -225,7 +225,6 @@ type ImageType int const ( ImageTypeRegular ImageType = iota ImageTypeScreen - ImageTypeVolatile ImageTypeUnmanaged ) diff --git a/internal/atlas/image_test.go b/internal/atlas/image_test.go index 3bc0d796f..ab17d5cd0 100644 --- a/internal/atlas/image_test.go +++ b/internal/atlas/image_test.go @@ -177,8 +177,8 @@ func TestReputOnSourceBackend(t *testing.T) { } img2.WritePixels(pix, image.Rect(0, 0, size, size)) - // Create a volatile image. This should always be on a non-source backend. - img3 := atlas.NewImage(size, size, atlas.ImageTypeVolatile) + // Create an unmanaged image. This should always be on a non-source backend. + img3 := atlas.NewImage(size, size, atlas.ImageTypeUnmanaged) defer img3.Deallocate() img3.WritePixels(make([]byte, 4*size*size), image.Rect(0, 0, size, size)) if got, want := img3.IsOnSourceBackendForTesting(), false; got != want { @@ -688,7 +688,7 @@ func TestImageIsNotReputOnSourceBackendWithoutUsingAsSource(t *testing.T) { } func TestImageWritePixelsModify(t *testing.T) { - for _, typ := range []atlas.ImageType{atlas.ImageTypeRegular, atlas.ImageTypeVolatile, atlas.ImageTypeUnmanaged} { + for _, typ := range []atlas.ImageType{atlas.ImageTypeRegular, atlas.ImageTypeRegular, atlas.ImageTypeUnmanaged} { const size = 16 img := atlas.NewImage(size, size, typ) defer img.Deallocate() diff --git a/internal/ui/context.go b/internal/ui/context.go index 48274c171..9af591f6f 100644 --- a/internal/ui/context.go +++ b/internal/ui/context.go @@ -178,12 +178,6 @@ func (c *context) newOffscreenImage(w, h int) *Image { } func (c *context) drawGame(graphicsDriver graphicsdriver.Graphics, ui *UserInterface, forceDraw bool) error { - if (c.offscreen.imageType == atlas.ImageTypeVolatile) != ui.IsScreenClearedEveryFrame() { - w, h := c.offscreen.width, c.offscreen.height - c.offscreen.Deallocate() - c.offscreen = c.newOffscreenImage(w, h) - } - // isOffscreenModified is updated when an offscreen's modifyCallback. c.isOffscreenModified = false diff --git a/internal/ui/image.go b/internal/ui/image.go index d0a63ec37..c49d854cd 100644 --- a/internal/ui/image.go +++ b/internal/ui/image.go @@ -15,7 +15,6 @@ package ui import ( - "fmt" "image" "math" @@ -86,16 +85,7 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderSrcImageCount]*Image, vertice if antialias { if i.bigOffscreenBuffer == nil { - var imageType atlas.ImageType - switch i.imageType { - case atlas.ImageTypeRegular, atlas.ImageTypeUnmanaged: - imageType = atlas.ImageTypeUnmanaged - case atlas.ImageTypeScreen, atlas.ImageTypeVolatile: - imageType = atlas.ImageTypeVolatile - default: - panic(fmt.Sprintf("ui: unexpected image type: %d", imageType)) - } - i.bigOffscreenBuffer = i.ui.newBigOffscreenImage(i, imageType) + i.bigOffscreenBuffer = i.ui.newBigOffscreenImage(i, atlas.ImageTypeUnmanaged) } i.bigOffscreenBuffer.drawTriangles(srcs, vertices, indices, blend, dstRegion, srcRegions, shader, uniforms, fillRule, canSkipMipmap)