From 62ed5bed4b166ecf294f3479a43bd47f81dee649 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 6 Sep 2024 14:25:20 +0900 Subject: [PATCH] Revert "internal/restorable: integrate some functions into internal/atlas" This reverts commit c5d0ec3de741ab5fc842d5bbb0530a428286ff8d. Updates #3803 --- internal/atlas/image.go | 7 +++---- internal/restorable/image.go | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/internal/atlas/image.go b/internal/atlas/image.go index 9a874b8af..ca8add1c6 100644 --- a/internal/atlas/image.go +++ b/internal/atlas/image.go @@ -414,7 +414,7 @@ func (i *Image) drawTriangles(srcs [graphics.ShaderSrcImageCount]*Image, vertice vertices[i+3] += oyf } if shader.ir.Unit == shaderir.Texels { - sw, sh := srcs[0].backend.restorable.Image.InternalSize() + sw, sh := srcs[0].backend.restorable.InternalSize() swf, shf := float32(sw), float32(sh) for i := 0; i < n; i += graphics.VertexFloatCount { vertices[i+2] /= swf @@ -613,8 +613,7 @@ func (i *Image) deallocate() { } } - i.backend.restorable.Image.Dispose() - i.backend.restorable.Image = nil + i.backend.restorable.Dispose() for idx, sh := range theBackends { if sh == i.backend { @@ -756,7 +755,7 @@ func (i *Image) DumpScreenshot(graphicsDriver graphicsdriver.Graphics, path stri panic("atlas: DumpScreenshots must be called in between BeginFrame and EndFrame") } - return i.backend.restorable.Image.Dump(graphicsDriver, path, blackbg, image.Rect(0, 0, i.width, i.height)) + return i.backend.restorable.Dump(graphicsDriver, path, blackbg, image.Rect(0, 0, i.width, i.height)) } func EndFrame() error { diff --git a/internal/restorable/image.go b/internal/restorable/image.go index 34643661c..3d533585f 100644 --- a/internal/restorable/image.go +++ b/internal/restorable/image.go @@ -73,8 +73,7 @@ func (i *Image) Extend(width, height int) *Image { is := graphics.QuadIndices() dr := image.Rect(0, 0, sw, sh) newImg.DrawTriangles(srcs, vs, is, graphicsdriver.BlendCopy, dr, [graphics.ShaderSrcImageCount]image.Rectangle{}, NearestFilterShader, nil, graphicsdriver.FillRuleFillAll) - i.Image.Dispose() - i.Image = nil + i.Dispose() return newImg } @@ -148,3 +147,19 @@ func (i *Image) ReadPixels(graphicsDriver graphicsdriver.Graphics, pixels []byte } return nil } + +// Dispose disposes the image. +// +// After disposing, calling the function of the image causes unexpected results. +func (i *Image) Dispose() { + i.Image.Dispose() + i.Image = nil +} + +func (i *Image) Dump(graphicsDriver graphicsdriver.Graphics, path string, blackbg bool, rect image.Rectangle) (string, error) { + return i.Image.Dump(graphicsDriver, path, blackbg, rect) +} + +func (i *Image) InternalSize() (int, int) { + return i.Image.InternalSize() +}