opengl: Check texture/framebuffer is valid before deleting it

This commit is contained in:
Hajime Hoshi 2016-06-12 23:19:01 +09:00
parent 854fa6f32c
commit 5fbbb6dc6a
3 changed files with 18 additions and 0 deletions

View File

@ -187,6 +187,9 @@ func (c *Context) BindTexture(t Texture) {
func (c *Context) DeleteTexture(t Texture) { func (c *Context) DeleteTexture(t Texture) {
c.RunOnContextThread(func() error { c.RunOnContextThread(func() error {
tt := uint32(t) tt := uint32(t)
if !gl.IsTexture(tt) {
return nil
}
gl.DeleteTextures(1, &tt) gl.DeleteTextures(1, &tt)
return nil return nil
}) })
@ -259,6 +262,9 @@ func (c *Context) FillFramebuffer(r, g, b, a float64) error {
func (c *Context) DeleteFramebuffer(f Framebuffer) { func (c *Context) DeleteFramebuffer(f Framebuffer) {
c.RunOnContextThread(func() error { c.RunOnContextThread(func() error {
ff := uint32(f) ff := uint32(f)
if !gl.IsFramebuffer(ff) {
return nil
}
// If a framebuffer to be delted is bound, a newly bound framebuffer // If a framebuffer to be delted is bound, a newly bound framebuffer
// will be a default framebuffer. // will be a default framebuffer.
// https://www.khronos.org/opengles/sdk/docs/man/xhtml/glDeleteFramebuffers.xml // https://www.khronos.org/opengles/sdk/docs/man/xhtml/glDeleteFramebuffers.xml

View File

@ -190,6 +190,9 @@ func (c *Context) BindTexture(t Texture) {
func (c *Context) DeleteTexture(t Texture) { func (c *Context) DeleteTexture(t Texture) {
gl := c.gl gl := c.gl
if !gl.IsTexture(t.Object) {
return
}
gl.DeleteTexture(t.Object) gl.DeleteTexture(t.Object)
} }
@ -236,6 +239,9 @@ func (c *Context) FillFramebuffer(r, g, b, a float64) error {
func (c *Context) DeleteFramebuffer(f Framebuffer) { func (c *Context) DeleteFramebuffer(f Framebuffer) {
gl := c.gl gl := c.gl
if !gl.IsFramebuffer(f.Object) {
return
}
// If a framebuffer to be delted is bound, a newly bound framebuffer // If a framebuffer to be delted is bound, a newly bound framebuffer
// will be a default framebuffer. // will be a default framebuffer.
// https://www.khronos.org/opengles/sdk/docs/man/xhtml/glDeleteFramebuffers.xml // https://www.khronos.org/opengles/sdk/docs/man/xhtml/glDeleteFramebuffers.xml

View File

@ -156,6 +156,9 @@ func (c *Context) BindTexture(t Texture) {
func (c *Context) DeleteTexture(t Texture) { func (c *Context) DeleteTexture(t Texture) {
gl := c.gl gl := c.gl
if !gl.IsTexture(mgl.Texture(t)) {
return
}
gl.DeleteTexture(mgl.Texture(t)) gl.DeleteTexture(mgl.Texture(t))
} }
@ -211,6 +214,9 @@ func (c *Context) FillFramebuffer(r, g, b, a float64) error {
func (c *Context) DeleteFramebuffer(f Framebuffer) { func (c *Context) DeleteFramebuffer(f Framebuffer) {
gl := c.gl gl := c.gl
if !gl.IsFramebuffer(mgl.Framebuffer(f)) {
return
}
// If a framebuffer to be delted is bound, a newly bound framebuffer // If a framebuffer to be delted is bound, a newly bound framebuffer
// will be a default framebuffer. // will be a default framebuffer.
// https://www.khronos.org/opengles/sdk/docs/man/xhtml/glDeleteFramebuffers.xml // https://www.khronos.org/opengles/sdk/docs/man/xhtml/glDeleteFramebuffers.xml