implement non-blocking call queue calls
This commit is contained in:
parent
d4e242a59b
commit
c6c3e020a4
|
@ -103,7 +103,7 @@ func NewShader(parent BeginEnder, vertexShader, fragmentShader string) (*Shader,
|
|||
|
||||
// Delete deletes a shader program. Don't use a shader after deletion.
|
||||
func (s *Shader) Delete() {
|
||||
Do(func() {
|
||||
DoNoBlock(func() {
|
||||
gl.DeleteProgram(s.program)
|
||||
})
|
||||
}
|
||||
|
@ -111,14 +111,14 @@ func (s *Shader) Delete() {
|
|||
// Begin starts using a shader program.
|
||||
func (s *Shader) Begin() {
|
||||
s.parent.Begin()
|
||||
Do(func() {
|
||||
DoNoBlock(func() {
|
||||
gl.UseProgram(s.program)
|
||||
})
|
||||
}
|
||||
|
||||
// End stops using a shader program.
|
||||
func (s *Shader) End() {
|
||||
Do(func() {
|
||||
DoNoBlock(func() {
|
||||
gl.UseProgram(0)
|
||||
})
|
||||
s.parent.End()
|
||||
|
|
|
@ -45,7 +45,7 @@ func NewTexture(parent BeginEnder, width, height int, pixels []uint8) (*Texture,
|
|||
|
||||
// Delete deletes a texture. Don't use a texture after deletion.
|
||||
func (t *Texture) Delete() {
|
||||
Do(func() {
|
||||
DoNoBlock(func() {
|
||||
gl.DeleteTextures(1, &t.tex)
|
||||
})
|
||||
}
|
||||
|
@ -53,14 +53,14 @@ func (t *Texture) Delete() {
|
|||
// Begin binds a texture.
|
||||
func (t *Texture) Begin() {
|
||||
t.parent.Begin()
|
||||
Do(func() {
|
||||
DoNoBlock(func() {
|
||||
gl.BindTexture(gl.TEXTURE_2D, t.tex)
|
||||
})
|
||||
}
|
||||
|
||||
// End unbinds a texture.
|
||||
func (t *Texture) End() {
|
||||
Do(func() {
|
||||
DoNoBlock(func() {
|
||||
gl.BindTexture(gl.TEXTURE_2D, 0)
|
||||
})
|
||||
t.parent.End()
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
// execute all OpenGL calls from a single dedicated thread. This file defines functions to make
|
||||
// it possible.
|
||||
|
||||
var callQueue = make(chan func())
|
||||
var callQueue = make(chan func(), 32)
|
||||
|
||||
func init() {
|
||||
go func() {
|
||||
|
@ -34,6 +34,12 @@ func Init() {
|
|||
}
|
||||
}
|
||||
|
||||
// DoNoBlock executes a function inside a dedicated OpenGL thread.
|
||||
// DoNoBlock does not wait until the function finishes.
|
||||
func DoNoBlock(f func()) {
|
||||
callQueue <- f
|
||||
}
|
||||
|
||||
// Do executes a function inside a dedicated OpenGL thread.
|
||||
// Do blocks until the function finishes.
|
||||
//
|
||||
|
|
|
@ -144,7 +144,7 @@ func NewVertexArray(parent BeginEnder, format VertexFormat, mode VertexDrawMode,
|
|||
|
||||
// Delete deletes a vertex array and it's associated vertex buffer. Don't use a vertex array after deletion.
|
||||
func (va *VertexArray) Delete() {
|
||||
Do(func() {
|
||||
DoNoBlock(func() {
|
||||
gl.DeleteVertexArrays(1, &va.vao)
|
||||
gl.DeleteBuffers(1, &va.vbo)
|
||||
})
|
||||
|
@ -159,7 +159,7 @@ func (va *VertexArray) VertexFormat() VertexFormat {
|
|||
|
||||
// SetDrawMode sets the draw mode of a vertex array. Subsequent calls to Draw will use this draw mode.
|
||||
func (va *VertexArray) SetDrawMode(mode VertexDrawMode) {
|
||||
Do(func() {
|
||||
DoNoBlock(func() {
|
||||
va.mode = mode
|
||||
})
|
||||
}
|
||||
|
@ -181,22 +181,21 @@ func (va *VertexArray) Draw() {
|
|||
// UpdateData overwrites the current vertex array data starting at the index offset.
|
||||
//
|
||||
// Offset is not a number of bytes, instead, it's an index in the array.
|
||||
func (va *VertexArray) UpdateData(offset int, data []float64) error {
|
||||
err := DoGLErr(func() {
|
||||
func (va *VertexArray) UpdateData(offset int, data []float64) {
|
||||
DoNoBlock(func() {
|
||||
gl.BindBuffer(gl.ARRAY_BUFFER, va.vbo)
|
||||
gl.BufferSubData(gl.ARRAY_BUFFER, 8*offset, 8*len(data), gl.Ptr(data))
|
||||
gl.BindBuffer(gl.ARRAY_BUFFER, 0)
|
||||
if err := getLastGLErr(); err != nil {
|
||||
panic(errors.Wrap(err, "failed to update vertex array"))
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to update vertex array")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Begin binds a vertex array and it's associated vertex buffer.
|
||||
func (va *VertexArray) Begin() {
|
||||
va.parent.Begin()
|
||||
Do(func() {
|
||||
DoNoBlock(func() {
|
||||
gl.BindVertexArray(va.vao)
|
||||
gl.BindBuffer(gl.ARRAY_BUFFER, va.vbo)
|
||||
})
|
||||
|
@ -204,7 +203,7 @@ func (va *VertexArray) Begin() {
|
|||
|
||||
// End draws a vertex array and unbinds it alongside with it's associated vertex buffer.
|
||||
func (va *VertexArray) End() {
|
||||
Do(func() {
|
||||
DoNoBlock(func() {
|
||||
gl.DrawArrays(uint32(va.mode), 0, int32(va.count))
|
||||
gl.BindBuffer(gl.ARRAY_BUFFER, 0)
|
||||
gl.BindVertexArray(0)
|
||||
|
|
Loading…
Reference in New Issue