mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 03:58:55 +01:00
Revert "internal/restorable: move DumpImages to internal/atlas"
This reverts commit 7c9266d8b6
.
Updates #3083
This commit is contained in:
parent
a9d8f374c8
commit
169b9fe51e
@ -23,7 +23,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicscommand"
|
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/packing"
|
"github.com/hajimehoshi/ebiten/v2/internal/packing"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/restorable"
|
"github.com/hajimehoshi/ebiten/v2/internal/restorable"
|
||||||
@ -840,12 +839,5 @@ func DumpImages(graphicsDriver graphicsdriver.Graphics, dir string) (string, err
|
|||||||
panic("atlas: DumpImages must be called in between BeginFrame and EndFrame")
|
panic("atlas: DumpImages must be called in between BeginFrame and EndFrame")
|
||||||
}
|
}
|
||||||
|
|
||||||
images := make([]*graphicscommand.Image, 0, len(theBackends))
|
return restorable.DumpImages(graphicsDriver, dir)
|
||||||
for _, backend := range theBackends {
|
|
||||||
if backend.restorable == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
images = append(images, backend.restorable.Image)
|
|
||||||
}
|
|
||||||
return graphicscommand.DumpImages(images, graphicsDriver, dir)
|
|
||||||
}
|
}
|
||||||
|
@ -35,10 +35,7 @@ const (
|
|||||||
|
|
||||||
// Image represents an image.
|
// Image represents an image.
|
||||||
type Image struct {
|
type Image struct {
|
||||||
// Image is the underlying image.
|
image *graphicscommand.Image
|
||||||
// This member is exported on purpose.
|
|
||||||
// TODO: Move the implementation to internal/atlas package (#805).
|
|
||||||
Image *graphicscommand.Image
|
|
||||||
|
|
||||||
width int
|
width int
|
||||||
height int
|
height int
|
||||||
@ -57,7 +54,7 @@ func NewImage(width, height int, imageType ImageType) *Image {
|
|||||||
}
|
}
|
||||||
|
|
||||||
i := &Image{
|
i := &Image{
|
||||||
Image: graphicscommand.NewImage(width, height, imageType == ImageTypeScreen),
|
image: graphicscommand.NewImage(width, height, imageType == ImageTypeScreen),
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
imageType: imageType,
|
imageType: imageType,
|
||||||
@ -65,8 +62,8 @@ func NewImage(width, height int, imageType ImageType) *Image {
|
|||||||
|
|
||||||
// This needs to use 'InternalSize' to render the whole region, or edges are unexpectedly cleared on some
|
// This needs to use 'InternalSize' to render the whole region, or edges are unexpectedly cleared on some
|
||||||
// devices.
|
// devices.
|
||||||
iw, ih := i.Image.InternalSize()
|
iw, ih := i.image.InternalSize()
|
||||||
clearImage(i.Image, image.Rect(0, 0, iw, ih))
|
clearImage(i.image, image.Rect(0, 0, iw, ih))
|
||||||
theImages.add(i)
|
theImages.add(i)
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
@ -84,7 +81,7 @@ func (i *Image) Extend(width, height int) *Image {
|
|||||||
// Use DrawTriangles instead of WritePixels because the image i might be stale and not have its pixels
|
// Use DrawTriangles instead of WritePixels because the image i might be stale and not have its pixels
|
||||||
// information.
|
// information.
|
||||||
srcs := [graphics.ShaderSrcImageCount]*Image{i}
|
srcs := [graphics.ShaderSrcImageCount]*Image{i}
|
||||||
sw, sh := i.Image.InternalSize()
|
sw, sh := i.image.InternalSize()
|
||||||
vs := make([]float32, 4*graphics.VertexFloatCount)
|
vs := make([]float32, 4*graphics.VertexFloatCount)
|
||||||
graphics.QuadVerticesFromDstAndSrc(vs, 0, 0, float32(sw), float32(sh), 0, 0, float32(sw), float32(sh), 1, 1, 1, 1)
|
graphics.QuadVerticesFromDstAndSrc(vs, 0, 0, float32(sw), float32(sh), 0, 0, float32(sw), float32(sh), 1, 1, 1, 1)
|
||||||
is := graphics.QuadIndices()
|
is := graphics.QuadIndices()
|
||||||
@ -120,9 +117,9 @@ func (i *Image) WritePixels(pixels *graphics.ManagedBytes, region image.Rectangl
|
|||||||
}
|
}
|
||||||
|
|
||||||
if pixels != nil {
|
if pixels != nil {
|
||||||
i.Image.WritePixels(pixels, region)
|
i.image.WritePixels(pixels, region)
|
||||||
} else {
|
} else {
|
||||||
clearImage(i.Image, region)
|
clearImage(i.image, region)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,13 +145,13 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderSrcImageCount]*Image, vertice
|
|||||||
if src == nil {
|
if src == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
imgs[i] = src.Image
|
imgs[i] = src.image
|
||||||
}
|
}
|
||||||
i.Image.DrawTriangles(imgs, vertices, indices, blend, dstRegion, srcRegions, shader.shader, uniforms, fillRule)
|
i.image.DrawTriangles(imgs, vertices, indices, blend, dstRegion, srcRegions, shader.shader, uniforms, fillRule)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) ReadPixels(graphicsDriver graphicsdriver.Graphics, pixels []byte, region image.Rectangle) error {
|
func (i *Image) ReadPixels(graphicsDriver graphicsdriver.Graphics, pixels []byte, region image.Rectangle) error {
|
||||||
if err := i.Image.ReadPixels(graphicsDriver, []graphicsdriver.PixelsArgs{
|
if err := i.image.ReadPixels(graphicsDriver, []graphicsdriver.PixelsArgs{
|
||||||
{
|
{
|
||||||
Pixels: pixels,
|
Pixels: pixels,
|
||||||
Region: region,
|
Region: region,
|
||||||
@ -170,14 +167,14 @@ func (i *Image) ReadPixels(graphicsDriver graphicsdriver.Graphics, pixels []byte
|
|||||||
// After disposing, calling the function of the image causes unexpected results.
|
// After disposing, calling the function of the image causes unexpected results.
|
||||||
func (i *Image) Dispose() {
|
func (i *Image) Dispose() {
|
||||||
theImages.remove(i)
|
theImages.remove(i)
|
||||||
i.Image.Dispose()
|
i.image.Dispose()
|
||||||
i.Image = nil
|
i.image = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) Dump(graphicsDriver graphicsdriver.Graphics, path string, blackbg bool, rect image.Rectangle) (string, error) {
|
func (i *Image) Dump(graphicsDriver graphicsdriver.Graphics, path string, blackbg bool, rect image.Rectangle) (string, error) {
|
||||||
return i.Image.Dump(graphicsDriver, path, blackbg, rect)
|
return i.image.Dump(graphicsDriver, path, blackbg, rect)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) InternalSize() (int, int) {
|
func (i *Image) InternalSize() (int, int) {
|
||||||
return i.Image.InternalSize()
|
return i.image.InternalSize()
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ func SwapBuffers(graphicsDriver graphicsdriver.Graphics) error {
|
|||||||
debug.FrameLogf("Internal image sizes:\n")
|
debug.FrameLogf("Internal image sizes:\n")
|
||||||
imgs := make([]*graphicscommand.Image, 0, len(theImages.images))
|
imgs := make([]*graphicscommand.Image, 0, len(theImages.images))
|
||||||
for i := range theImages.images {
|
for i := range theImages.images {
|
||||||
imgs = append(imgs, i.Image)
|
imgs = append(imgs, i.image)
|
||||||
}
|
}
|
||||||
graphicscommand.LogImagesInfo(imgs)
|
graphicscommand.LogImagesInfo(imgs)
|
||||||
}
|
}
|
||||||
@ -45,6 +45,18 @@ func SwapBuffers(graphicsDriver graphicsdriver.Graphics) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DumpImages dumps all the current images to the specified directory.
|
||||||
|
//
|
||||||
|
// This is for testing usage.
|
||||||
|
func DumpImages(graphicsDriver graphicsdriver.Graphics, dir string) (string, error) {
|
||||||
|
images := make([]*graphicscommand.Image, 0, len(theImages.images))
|
||||||
|
for img := range theImages.images {
|
||||||
|
images = append(images, img.image)
|
||||||
|
}
|
||||||
|
|
||||||
|
return graphicscommand.DumpImages(images, graphicsDriver, dir)
|
||||||
|
}
|
||||||
|
|
||||||
// add adds img to the images.
|
// add adds img to the images.
|
||||||
func (i *images) add(img *Image) {
|
func (i *images) add(img *Image) {
|
||||||
i.images[img] = struct{}{}
|
i.images[img] = struct{}{}
|
||||||
|
Loading…
Reference in New Issue
Block a user