mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +01:00
Delete a texture when deleting the render target
This commit is contained in:
parent
92b2e0d948
commit
a9711cd509
@ -65,7 +65,7 @@ func (i *ids) CreateTexture(img image.Image, filter graphics.Filter) (
|
||||
|
||||
func (i *ids) CreateRenderTarget(width, height int, filter graphics.Filter) (
|
||||
graphics.RenderTargetId, error) {
|
||||
|
||||
|
||||
texture, err := texture.Create(width, height, filter)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@ -85,13 +85,17 @@ func (i *ids) CreateRenderTarget(width, height int, filter graphics.Filter) (
|
||||
}
|
||||
|
||||
func (i *ids) DeleteRenderTarget(id graphics.RenderTargetId) {
|
||||
renderTarget := i.renderTargets[id]
|
||||
renderTarget.Dispose()
|
||||
|
||||
i.lock.Lock()
|
||||
defer i.lock.Unlock()
|
||||
|
||||
renderTarget := i.renderTargets[id]
|
||||
textureId := i.renderTargetToTexture[id]
|
||||
texture := i.textures[textureId]
|
||||
|
||||
renderTarget.Dispose()
|
||||
texture.Dispose()
|
||||
|
||||
delete(i.renderTargets, id)
|
||||
|
||||
// TODO: Remove the related texture
|
||||
delete(i.renderTargetToTexture, id)
|
||||
delete(i.textures, textureId)
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ func (o *Offscreen) SetMainFramebuffer() {
|
||||
func (o *Offscreen) DrawTexture(texture *texture.Texture,
|
||||
geometryMatrix matrix.Geometry, colorMatrix matrix.Color) {
|
||||
projectionMatrix := o.projectionMatrix()
|
||||
texture.Draw(projectionMatrix, geometryMatrix, colorMatrix)
|
||||
texture.Draw(projectionMatrix, geometryMatrix, colorMatrix)
|
||||
}
|
||||
|
||||
func (o *Offscreen) DrawTextureParts(texture *texture.Texture,
|
||||
|
@ -77,6 +77,5 @@ func (r *RenderTarget) ProjectionMatrix() [4][4]float64 {
|
||||
}
|
||||
|
||||
func (r *RenderTarget) Dispose() {
|
||||
f := C.GLuint(r.framebuffer)
|
||||
C.glDeleteFramebuffers(1, &f)
|
||||
C.glDeleteFramebuffers(1, &r.framebuffer)
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ func createNativeTexture(textureWidth, textureHeight int, pixels []uint8,
|
||||
filter graphics.Filter) C.GLuint {
|
||||
nativeTexture := C.GLuint(0)
|
||||
|
||||
C.glGenTextures(1, (*C.GLuint)(&nativeTexture))
|
||||
C.glGenTextures(1, &nativeTexture)
|
||||
if nativeTexture < 0 {
|
||||
panic("glGenTexture failed")
|
||||
}
|
||||
@ -87,3 +87,7 @@ func (t *Texture) DrawParts(parts []graphics.TexturePart, projectionMatrix [16]f
|
||||
projectionMatrix, quads,
|
||||
geometryMatrix, colorMatrix)
|
||||
}
|
||||
|
||||
func (t *Texture) Dispose() {
|
||||
C.glDeleteTextures(1, &t.native)
|
||||
}
|
||||
|
@ -83,9 +83,9 @@ func TextureQuadsForTextureParts(parts []TexturePart, width, height int) []Textu
|
||||
y1 := float32(part.LocationY)
|
||||
y2 := float32(part.LocationY + part.Source.Height)
|
||||
u1 := u(part.Source.X, width)
|
||||
u2 := u(part.Source.X + part.Source.Width, width)
|
||||
u2 := u(part.Source.X+part.Source.Width, width)
|
||||
v1 := v(part.Source.Y, height)
|
||||
v2 := v(part.Source.Y + part.Source.Height, height)
|
||||
v2 := v(part.Source.Y+part.Source.Height, height)
|
||||
quad := TextureQuad{x1, x2, y1, y2, u1, u2, v1, v2}
|
||||
quads = append(quads, quad)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user