mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
parent
7c9266d8b6
commit
f610cb5724
@ -21,6 +21,7 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/hajimehoshi/ebiten/v2/internal/debug"
|
||||||
"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/graphicscommand"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||||
@ -762,7 +763,18 @@ func SwapBuffers(graphicsDriver graphicsdriver.Graphics) error {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if err := restorable.SwapBuffers(graphicsDriver); err != nil {
|
if debug.IsDebug {
|
||||||
|
debug.Logf("Internal image sizes:\n")
|
||||||
|
imgs := make([]*graphicscommand.Image, 0, len(theBackends))
|
||||||
|
for _, backend := range theBackends {
|
||||||
|
if backend.restorable == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
imgs = append(imgs, backend.restorable.Image)
|
||||||
|
}
|
||||||
|
graphicscommand.LogImagesInfo(imgs)
|
||||||
|
}
|
||||||
|
if err := graphicscommand.FlushCommands(graphicsDriver, true); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -67,7 +67,6 @@ func NewImage(width, height int, imageType ImageType) *Image {
|
|||||||
// 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)
|
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,7 +176,6 @@ 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)
|
|
||||||
i.Image.Dispose()
|
i.Image.Dispose()
|
||||||
i.Image = nil
|
i.Image = nil
|
||||||
}
|
}
|
||||||
|
@ -15,46 +15,10 @@
|
|||||||
package restorable
|
package restorable
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/debug"
|
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicscommand"
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicscommand"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||||
)
|
)
|
||||||
|
|
||||||
// images is a set of Image objects.
|
|
||||||
type images struct {
|
|
||||||
images map[*Image]struct{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// theImages represents the images for the current process.
|
|
||||||
var theImages = &images{
|
|
||||||
images: map[*Image]struct{}{},
|
|
||||||
}
|
|
||||||
|
|
||||||
func SwapBuffers(graphicsDriver graphicsdriver.Graphics) error {
|
|
||||||
if debug.IsDebug {
|
|
||||||
debug.Logf("Internal image sizes:\n")
|
|
||||||
imgs := make([]*graphicscommand.Image, 0, len(theImages.images))
|
|
||||||
for i := range theImages.images {
|
|
||||||
imgs = append(imgs, i.Image)
|
|
||||||
}
|
|
||||||
graphicscommand.LogImagesInfo(imgs)
|
|
||||||
}
|
|
||||||
if err := graphicscommand.FlushCommands(graphicsDriver, true); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// add adds img to the images.
|
|
||||||
func (i *images) add(img *Image) {
|
|
||||||
i.images[img] = struct{}{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove removes img from the images.
|
|
||||||
func (i *images) remove(img *Image) {
|
|
||||||
delete(i.images, img)
|
|
||||||
}
|
|
||||||
|
|
||||||
var graphicsDriverInitialized bool
|
var graphicsDriverInitialized bool
|
||||||
|
|
||||||
// InitializeGraphicsDriverState initializes the graphics driver state.
|
// InitializeGraphicsDriverState initializes the graphics driver state.
|
||||||
|
Loading…
Reference in New Issue
Block a user