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
19
image.go
19
image.go
@ -302,18 +302,10 @@ func (i *imageImpl) restorePixels(context *opengl.Context) error {
|
||||
if i.disposed {
|
||||
return nil
|
||||
}
|
||||
if i.texture != nil {
|
||||
// TODO: As the texture is already disposed, is it correct to delete it here?
|
||||
if err := i.texture.Dispose(context); err != nil {
|
||||
if err := graphics.Dispose(i.texture, i.framebuffer); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if i.framebuffer != nil {
|
||||
// TODO: Ditto
|
||||
if err := i.framebuffer.Dispose(context); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// TODO: Recalc i.pixels here
|
||||
img := image.NewRGBA(image.Rect(0, 0, i.width, i.height))
|
||||
for j := 0; j < i.height; j++ {
|
||||
@ -338,18 +330,11 @@ func (i *imageImpl) Dispose() error {
|
||||
if i.isDisposed() {
|
||||
return errors.New("ebiten: image is already disposed")
|
||||
}
|
||||
if i.framebuffer != nil {
|
||||
if err := i.framebuffer.Dispose(ui.GLContext()); err != nil {
|
||||
if err := graphics.Dispose(i.texture, i.framebuffer); err != nil {
|
||||
return err
|
||||
}
|
||||
i.framebuffer = nil
|
||||
}
|
||||
if i.texture != nil {
|
||||
if err := i.texture.Dispose(ui.GLContext()); err != nil {
|
||||
return err
|
||||
}
|
||||
i.texture = nil
|
||||
}
|
||||
i.disposed = true
|
||||
i.pixels = 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)
|
||||
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
|
||||
}
|
||||
|
||||
func (f *Framebuffer) Dispose(c *opengl.Context) error {
|
||||
// Don't delete the default framebuffer.
|
||||
if f.native == opengl.ZeroFramebuffer {
|
||||
return nil
|
||||
func Dispose(texture *Texture, framebuffer *Framebuffer) error {
|
||||
c := &disposeCommand{
|
||||
framebuffer: framebuffer,
|
||||
texture: texture,
|
||||
}
|
||||
c.DeleteFramebuffer(f.native)
|
||||
theCommandQueue.Enqueue(c)
|
||||
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
|
||||
}
|
||||
|
||||
func (t *Texture) Dispose(c *opengl.Context) error {
|
||||
c.DeleteTexture(t.native)
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user