mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
graphics: Add disposeCommand
This commit is contained in:
parent
b59206b777
commit
2a58c095b8
29
image.go
29
image.go
@ -302,17 +302,9 @@ func (i *imageImpl) restorePixels(context *opengl.Context) error {
|
|||||||
if i.disposed {
|
if i.disposed {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if i.texture != nil {
|
// TODO: As the texture is already disposed, is it correct to delete it here?
|
||||||
// TODO: As the texture is already disposed, is it correct to delete it here?
|
if err := graphics.Dispose(i.texture, i.framebuffer); err != nil {
|
||||||
if err := i.texture.Dispose(context); err != nil {
|
return err
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if i.framebuffer != nil {
|
|
||||||
// TODO: Ditto
|
|
||||||
if err := i.framebuffer.Dispose(context); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// TODO: Recalc i.pixels here
|
// TODO: Recalc i.pixels here
|
||||||
img := image.NewRGBA(image.Rect(0, 0, i.width, i.height))
|
img := image.NewRGBA(image.Rect(0, 0, i.width, i.height))
|
||||||
@ -338,18 +330,11 @@ func (i *imageImpl) Dispose() error {
|
|||||||
if i.isDisposed() {
|
if i.isDisposed() {
|
||||||
return errors.New("ebiten: image is already disposed")
|
return errors.New("ebiten: image is already disposed")
|
||||||
}
|
}
|
||||||
if i.framebuffer != nil {
|
if err := graphics.Dispose(i.texture, i.framebuffer); err != nil {
|
||||||
if err := i.framebuffer.Dispose(ui.GLContext()); err != nil {
|
return err
|
||||||
return err
|
|
||||||
}
|
|
||||||
i.framebuffer = nil
|
|
||||||
}
|
|
||||||
if i.texture != nil {
|
|
||||||
if err := i.texture.Dispose(ui.GLContext()); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
i.texture = nil
|
|
||||||
}
|
}
|
||||||
|
i.framebuffer = nil
|
||||||
|
i.texture = nil
|
||||||
i.disposed = true
|
i.disposed = true
|
||||||
i.pixels = nil
|
i.pixels = nil
|
||||||
runtime.SetFinalizer(i, nil)
|
runtime.SetFinalizer(i, nil)
|
||||||
|
@ -144,3 +144,18 @@ func (c *replacePixelsCommand) Exec(context *opengl.Context) error {
|
|||||||
context.TexSubImage2D(c.pixels, c.texture.width, c.texture.height)
|
context.TexSubImage2D(c.pixels, c.texture.width, c.texture.height)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type disposeCommand struct {
|
||||||
|
framebuffer *Framebuffer
|
||||||
|
texture *Texture
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *disposeCommand) Exec(context *opengl.Context) error {
|
||||||
|
if c.framebuffer != nil && c.framebuffer.native != opengl.ZeroFramebuffer {
|
||||||
|
context.DeleteFramebuffer(c.framebuffer.native)
|
||||||
|
}
|
||||||
|
if c.texture != nil {
|
||||||
|
context.DeleteTexture(c.texture.native)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -64,12 +64,12 @@ func NewFramebufferFromTexture(c *opengl.Context, texture *Texture) (*Framebuffe
|
|||||||
return f, nil
|
return f, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Framebuffer) Dispose(c *opengl.Context) error {
|
func Dispose(texture *Texture, framebuffer *Framebuffer) error {
|
||||||
// Don't delete the default framebuffer.
|
c := &disposeCommand{
|
||||||
if f.native == opengl.ZeroFramebuffer {
|
framebuffer: framebuffer,
|
||||||
return nil
|
texture: texture,
|
||||||
}
|
}
|
||||||
c.DeleteFramebuffer(f.native)
|
theCommandQueue.Enqueue(c)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,8 +82,3 @@ func NewTextureFromImage(c *opengl.Context, img *image.RGBA, filter opengl.Filte
|
|||||||
}
|
}
|
||||||
return &Texture{native, origSize.X, origSize.Y}, nil
|
return &Texture{native, origSize.X, origSize.Y}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Texture) Dispose(c *opengl.Context) error {
|
|
||||||
c.DeleteTexture(t.native)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user