graphics: Add a func to delete programs and buffers

This commit is contained in:
Hajime Hoshi 2016-05-16 11:54:34 +09:00
parent ba6d10dec0
commit 46cbd0c4a0
3 changed files with 40 additions and 0 deletions

View File

@ -391,6 +391,13 @@ func (c *Context) DisableVertexAttribArray(p Program, location string) {
})
}
func (c *Context) DeleteProgram(p Program) {
c.RunOnContextThread(func() error {
gl.DeleteProgram(uint32(p))
return nil
})
}
func (c *Context) NewBuffer(bufferType BufferType, v interface{}, bufferUsage BufferUsage) Buffer {
var buffer Buffer
c.RunOnContextThread(func() error {
@ -425,6 +432,14 @@ func (c *Context) BufferSubData(bufferType BufferType, data []int16) {
})
}
func (c *Context) DeleteBuffer(b Buffer) {
c.RunOnContextThread(func() error {
bb := uint32(b)
gl.DeleteBuffers(1, &bb)
return nil
})
}
func (c *Context) DrawElements(mode Mode, len int) {
c.RunOnContextThread(func() error {
gl.DrawElements(uint32(mode), int32(len), gl.UNSIGNED_SHORT, gl.PtrOffset(0))

View File

@ -341,6 +341,11 @@ func (c *Context) DisableVertexAttribArray(p Program, location string) {
gl.DisableVertexAttribArray(int(l))
}
func (c *Context) DeleteProgram(p Program) {
gl := c.gl
gl.DeleteProgram(p.Object)
}
func (c *Context) NewBuffer(bufferType BufferType, v interface{}, bufferUsage BufferUsage) Buffer {
gl := c.gl
b := gl.CreateBuffer()
@ -359,6 +364,11 @@ func (c *Context) BufferSubData(bufferType BufferType, data []int16) {
gl.BufferSubData(int(bufferType), 0, data)
}
func (c *Context) DeleteBuffer(b Buffer) {
gl := c.gl
gl.DeleteBuffer(b.Object)
}
func (c *Context) DrawElements(mode Mode, len int) {
gl := c.gl
gl.DrawElements(int(mode), len, gl.UNSIGNED_SHORT, 0)

View File

@ -47,6 +47,10 @@ func Initialize(c *opengl.Context) error {
return theOpenGLState.initialize(c)
}
func Finalize(c *opengl.Context) error {
return theOpenGLState.finalize(c)
}
func (s *openGLState) initialize(c *opengl.Context) error {
var zeroProgram opengl.Program
s.lastProgram = zeroProgram
@ -92,6 +96,17 @@ func (s *openGLState) initialize(c *opengl.Context) error {
return nil
}
func (s *openGLState) finalize(c *opengl.Context) error {
var zeroProgram opengl.Program
s.lastProgram = zeroProgram
s.lastProjectionMatrix = nil
s.lastModelviewMatrix = nil
s.lastColorMatrix = nil
c.DeleteBuffer(s.indexBufferQuads)
c.DeleteProgram(s.programTexture)
return nil
}
func areSameFloat32Array(a, b []float32) bool {
if len(a) != len(b) {
return false