nicer code
This commit is contained in:
parent
52a3a96d20
commit
c8dba6aaf1
|
@ -21,9 +21,9 @@ func NewShader(parent Doer, vertexShader, fragmentShader string) (*Shader, error
|
|||
parent: parent,
|
||||
}
|
||||
|
||||
errChan := make(chan error, 1)
|
||||
var err, glerr error
|
||||
parent.Do(func() {
|
||||
err, glerr := DoErrGLErr(func() error {
|
||||
err, glerr = DoErrGLErr(func() error {
|
||||
var vshader, fshader uint32
|
||||
|
||||
// vertex shader
|
||||
|
@ -89,31 +89,26 @@ func NewShader(parent Doer, vertexShader, fragmentShader string) (*Shader, error
|
|||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
if glerr != nil {
|
||||
err = errors.Wrap(glerr, err.Error())
|
||||
}
|
||||
errChan <- err
|
||||
return
|
||||
}
|
||||
if glerr != nil {
|
||||
errChan <- err
|
||||
return
|
||||
}
|
||||
errChan <- nil
|
||||
})
|
||||
err := <-errChan
|
||||
if err != nil && glerr != nil {
|
||||
return nil, errors.Wrap(glerr, err.Error())
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if glerr != nil {
|
||||
return nil, glerr
|
||||
}
|
||||
|
||||
return shader, nil
|
||||
}
|
||||
|
||||
// Delete deletes a shader program. Don't use a shader after deletion.
|
||||
func (s *Shader) Delete() {
|
||||
DoNoBlock(func() {
|
||||
gl.DeleteProgram(s.program)
|
||||
s.parent.Do(func() {
|
||||
DoNoBlock(func() {
|
||||
gl.DeleteProgram(s.program)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -16,9 +16,9 @@ type Texture struct {
|
|||
func NewTexture(parent Doer, width, height int, pixels []uint8) (*Texture, error) {
|
||||
texture := &Texture{parent: parent}
|
||||
|
||||
errChan := make(chan error, 1)
|
||||
var err error
|
||||
parent.Do(func() {
|
||||
errChan <- DoGLErr(func() {
|
||||
err = DoGLErr(func() {
|
||||
gl.GenTextures(1, &texture.tex)
|
||||
gl.BindTexture(gl.TEXTURE_2D, texture.tex)
|
||||
|
||||
|
@ -39,7 +39,6 @@ func NewTexture(parent Doer, width, height int, pixels []uint8) (*Texture, error
|
|||
gl.BindTexture(gl.TEXTURE_2D, 0)
|
||||
})
|
||||
})
|
||||
err := <-errChan
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to create a texture")
|
||||
}
|
||||
|
@ -49,8 +48,10 @@ func NewTexture(parent Doer, width, height int, pixels []uint8) (*Texture, error
|
|||
|
||||
// Delete deletes a texture. Don't use a texture after deletion.
|
||||
func (t *Texture) Delete() {
|
||||
DoNoBlock(func() {
|
||||
gl.DeleteTextures(1, &t.tex)
|
||||
t.parent.Do(func() {
|
||||
DoNoBlock(func() {
|
||||
gl.DeleteTextures(1, &t.tex)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -106,9 +106,9 @@ func NewVertexArray(parent Doer, format VertexFormat, mode VertexDrawMode, usage
|
|||
mode: mode,
|
||||
}
|
||||
|
||||
errChan := make(chan error, 1)
|
||||
var err error
|
||||
parent.Do(func() {
|
||||
err := DoGLErr(func() {
|
||||
err = DoGLErr(func() {
|
||||
gl.GenVertexArrays(1, &va.vao)
|
||||
gl.BindVertexArray(va.vao)
|
||||
|
||||
|
@ -136,13 +136,7 @@ func NewVertexArray(parent Doer, format VertexFormat, mode VertexDrawMode, usage
|
|||
gl.BindBuffer(gl.ARRAY_BUFFER, 0)
|
||||
gl.BindVertexArray(0)
|
||||
})
|
||||
if err != nil {
|
||||
errChan <- err
|
||||
return
|
||||
}
|
||||
errChan <- nil
|
||||
})
|
||||
err := <-errChan
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to create a vertex array")
|
||||
}
|
||||
|
@ -152,9 +146,11 @@ func NewVertexArray(parent Doer, format VertexFormat, mode VertexDrawMode, usage
|
|||
|
||||
// Delete deletes a vertex array and it's associated vertex buffer. Don't use a vertex array after deletion.
|
||||
func (va *VertexArray) Delete() {
|
||||
DoNoBlock(func() {
|
||||
gl.DeleteVertexArrays(1, &va.vao)
|
||||
gl.DeleteBuffers(1, &va.vbo)
|
||||
va.parent.Do(func() {
|
||||
DoNoBlock(func() {
|
||||
gl.DeleteVertexArrays(1, &va.vao)
|
||||
gl.DeleteBuffers(1, &va.vbo)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue