Delete a texture when deleting the render target

This commit is contained in:
Hajime Hoshi 2014-01-08 18:58:15 +09:00
parent 92b2e0d948
commit a9711cd509
5 changed files with 20 additions and 13 deletions

View File

@ -85,13 +85,17 @@ func (i *ids) CreateRenderTarget(width, height int, filter graphics.Filter) (
} }
func (i *ids) DeleteRenderTarget(id graphics.RenderTargetId) { func (i *ids) DeleteRenderTarget(id graphics.RenderTargetId) {
renderTarget := i.renderTargets[id]
renderTarget.Dispose()
i.lock.Lock() i.lock.Lock()
defer i.lock.Unlock() defer i.lock.Unlock()
renderTarget := i.renderTargets[id]
textureId := i.renderTargetToTexture[id]
texture := i.textures[textureId]
renderTarget.Dispose()
texture.Dispose()
delete(i.renderTargets, id) delete(i.renderTargets, id)
delete(i.renderTargetToTexture, id)
// TODO: Remove the related texture delete(i.textures, textureId)
} }

View File

@ -77,6 +77,5 @@ func (r *RenderTarget) ProjectionMatrix() [4][4]float64 {
} }
func (r *RenderTarget) Dispose() { func (r *RenderTarget) Dispose() {
f := C.GLuint(r.framebuffer) C.glDeleteFramebuffers(1, &r.framebuffer)
C.glDeleteFramebuffers(1, &f)
} }

View File

@ -23,7 +23,7 @@ func createNativeTexture(textureWidth, textureHeight int, pixels []uint8,
filter graphics.Filter) C.GLuint { filter graphics.Filter) C.GLuint {
nativeTexture := C.GLuint(0) nativeTexture := C.GLuint(0)
C.glGenTextures(1, (*C.GLuint)(&nativeTexture)) C.glGenTextures(1, &nativeTexture)
if nativeTexture < 0 { if nativeTexture < 0 {
panic("glGenTexture failed") panic("glGenTexture failed")
} }
@ -87,3 +87,7 @@ func (t *Texture) DrawParts(parts []graphics.TexturePart, projectionMatrix [16]f
projectionMatrix, quads, projectionMatrix, quads,
geometryMatrix, colorMatrix) geometryMatrix, colorMatrix)
} }
func (t *Texture) Dispose() {
C.glDeleteTextures(1, &t.native)
}