mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
image: Add image.Dipose and image.IsDisposed
This commit is contained in:
parent
d1ff3701a6
commit
e8c2e5f3d6
@ -61,10 +61,10 @@ func (c *graphicsContext) postUpdate() error {
|
|||||||
|
|
||||||
func (c *graphicsContext) setSize(screenWidth, screenHeight, screenScale int) error {
|
func (c *graphicsContext) setSize(screenWidth, screenHeight, screenScale int) error {
|
||||||
if c.defaultRenderTarget != nil {
|
if c.defaultRenderTarget != nil {
|
||||||
c.defaultRenderTarget.dispose()
|
c.defaultRenderTarget.Dispose()
|
||||||
}
|
}
|
||||||
if c.screen != nil {
|
if c.screen != nil {
|
||||||
c.screen.dispose()
|
c.screen.Dispose()
|
||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
18
image.go
18
image.go
@ -128,18 +128,26 @@ func (i *Image) At(x, y int) color.Color {
|
|||||||
return color.RGBA{r, g, b, a}
|
return color.RGBA{r, g, b, a}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) dispose() {
|
// Dispose disposes the image data. After disposing, the image becomes invalid.
|
||||||
|
// This is useful to save memory.
|
||||||
|
func (i *Image) Dispose() {
|
||||||
|
if i.isDisposed() {
|
||||||
|
panic("the image is already disposed")
|
||||||
|
}
|
||||||
useGLContext(func(c *opengl.Context) {
|
useGLContext(func(c *opengl.Context) {
|
||||||
if i.framebuffer != nil {
|
|
||||||
i.framebuffer.Dispose(c)
|
i.framebuffer.Dispose(c)
|
||||||
}
|
i.framebuffer = nil
|
||||||
if i.texture != nil {
|
|
||||||
i.texture.Dispose(c)
|
i.texture.Dispose(c)
|
||||||
}
|
i.texture = nil
|
||||||
})
|
})
|
||||||
i.pixels = nil
|
i.pixels = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsDisposed returns a boolean indicating wheather the image is disposed.
|
||||||
|
func (i *Image) IsDisposed() bool {
|
||||||
|
return i.texture == nil
|
||||||
|
}
|
||||||
|
|
||||||
// ReplacePixels replaces the pixels of the image with p.
|
// ReplacePixels replaces the pixels of the image with p.
|
||||||
//
|
//
|
||||||
// The given p must represent RGBA pre-multiplied alpha values. len(p) must equal to 4 * (image width) * (image height).
|
// The given p must represent RGBA pre-multiplied alpha values. len(p) must equal to 4 * (image width) * (image height).
|
||||||
|
Loading…
Reference in New Issue
Block a user