mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
parent
fdf36026ae
commit
7c9266d8b6
@ -22,6 +22,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"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/packing"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/restorable"
|
||||
@ -830,5 +831,12 @@ func DumpImages(graphicsDriver graphicsdriver.Graphics, dir string) (string, err
|
||||
panic("atlas: DumpImages must be called in between BeginFrame and EndFrame")
|
||||
}
|
||||
|
||||
return restorable.DumpImages(graphicsDriver, dir)
|
||||
images := make([]*graphicscommand.Image, 0, len(theBackends))
|
||||
for _, backend := range theBackends {
|
||||
if backend.restorable == nil {
|
||||
continue
|
||||
}
|
||||
images = append(images, backend.restorable.Image)
|
||||
}
|
||||
return graphicscommand.DumpImages(images, graphicsDriver, dir)
|
||||
}
|
||||
|
@ -35,7 +35,10 @@ const (
|
||||
|
||||
// Image represents an image.
|
||||
type Image struct {
|
||||
image *graphicscommand.Image
|
||||
// Image is the underlying image.
|
||||
// This member is exported on purpose.
|
||||
// TODO: Move the implementation to internal/atlas package (#805).
|
||||
Image *graphicscommand.Image
|
||||
|
||||
width int
|
||||
height int
|
||||
@ -54,7 +57,7 @@ func NewImage(width, height int, imageType ImageType) *Image {
|
||||
}
|
||||
|
||||
i := &Image{
|
||||
image: graphicscommand.NewImage(width, height, imageType == ImageTypeScreen),
|
||||
Image: graphicscommand.NewImage(width, height, imageType == ImageTypeScreen),
|
||||
width: width,
|
||||
height: height,
|
||||
imageType: imageType,
|
||||
@ -62,8 +65,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
|
||||
// devices.
|
||||
iw, ih := i.image.InternalSize()
|
||||
clearImage(i.image, image.Rect(0, 0, iw, ih))
|
||||
iw, ih := i.Image.InternalSize()
|
||||
clearImage(i.Image, image.Rect(0, 0, iw, ih))
|
||||
theImages.add(i)
|
||||
return i
|
||||
}
|
||||
@ -81,7 +84,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
|
||||
// information.
|
||||
srcs := [graphics.ShaderImageCount]*Image{i}
|
||||
sw, sh := i.image.InternalSize()
|
||||
sw, sh := i.Image.InternalSize()
|
||||
vs := quadVertices(0, 0, float32(sw), float32(sh), 0, 0, float32(sw), float32(sh), 1, 1, 1, 1)
|
||||
is := graphics.QuadIndices()
|
||||
dr := image.Rect(0, 0, sw, sh)
|
||||
@ -125,9 +128,9 @@ func (i *Image) WritePixels(pixels *graphics.ManagedBytes, region image.Rectangl
|
||||
}
|
||||
|
||||
if pixels != nil {
|
||||
i.image.WritePixels(pixels, region)
|
||||
i.Image.WritePixels(pixels, region)
|
||||
} else {
|
||||
clearImage(i.image, region)
|
||||
clearImage(i.Image, region)
|
||||
}
|
||||
}
|
||||
|
||||
@ -153,13 +156,13 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageCount]*Image, vertices [
|
||||
if src == nil {
|
||||
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 {
|
||||
if err := i.image.ReadPixels(graphicsDriver, []graphicsdriver.PixelsArgs{
|
||||
if err := i.Image.ReadPixels(graphicsDriver, []graphicsdriver.PixelsArgs{
|
||||
{
|
||||
Pixels: pixels,
|
||||
Region: region,
|
||||
@ -175,14 +178,14 @@ func (i *Image) ReadPixels(graphicsDriver graphicsdriver.Graphics, pixels []byte
|
||||
// After disposing, calling the function of the image causes unexpected results.
|
||||
func (i *Image) Dispose() {
|
||||
theImages.remove(i)
|
||||
i.image.Dispose()
|
||||
i.image = nil
|
||||
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)
|
||||
return i.Image.Dump(graphicsDriver, path, blackbg, rect)
|
||||
}
|
||||
|
||||
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.Logf("Internal image sizes:\n")
|
||||
imgs := make([]*graphicscommand.Image, 0, len(theImages.images))
|
||||
for i := range theImages.images {
|
||||
imgs = append(imgs, i.image)
|
||||
imgs = append(imgs, i.Image)
|
||||
}
|
||||
graphicscommand.LogImagesInfo(imgs)
|
||||
}
|
||||
@ -45,18 +45,6 @@ func SwapBuffers(graphicsDriver graphicsdriver.Graphics) error {
|
||||
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.
|
||||
func (i *images) add(img *Image) {
|
||||
i.images[img] = struct{}{}
|
||||
|
Loading…
Reference in New Issue
Block a user