internal/restorable: integrate some functions into internal/atlas

Updates #805
This commit is contained in:
Hajime Hoshi 2024-01-13 18:04:48 +09:00
parent 21ef462c37
commit c5d0ec3de7
2 changed files with 8 additions and 21 deletions

View File

@ -385,7 +385,7 @@ func (i *Image) drawTriangles(srcs [graphics.ShaderImageCount]*Image, vertices [
vertices[i+3] += oyf
}
if shader.ir.Unit == shaderir.Texels {
sw, sh := srcs[0].backend.restorable.InternalSize()
sw, sh := srcs[0].backend.restorable.Image.InternalSize()
swf, shf := float32(sw), float32(sh)
for i := 0; i < n; i += graphics.VertexFloatCount {
vertices[i+2] /= swf
@ -584,7 +584,8 @@ func (i *Image) deallocate() {
}
if !i.isOnAtlas() {
i.backend.restorable.Dispose()
i.backend.restorable.Image.Dispose()
i.backend.restorable.Image = nil
return
}
@ -596,7 +597,8 @@ func (i *Image) deallocate() {
return
}
i.backend.restorable.Dispose()
i.backend.restorable.Image.Dispose()
i.backend.restorable.Image = nil
for idx, sh := range theBackends {
if sh == i.backend {
@ -736,7 +738,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.Dump(graphicsDriver, path, blackbg, image.Rect(0, 0, i.width, i.height))
return i.backend.restorable.Image.Dump(graphicsDriver, path, blackbg, image.Rect(0, 0, i.width, i.height))
}
func EndFrame() error {

View File

@ -72,7 +72,8 @@ 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.ShaderImageCount]image.Rectangle{}, NearestFilterShader, nil, graphicsdriver.FillAll)
i.Dispose()
i.Image.Dispose()
i.Image = nil
return newImg
}
@ -155,19 +156,3 @@ 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()
}