remove OpenGL error reporting
This commit is contained in:
parent
c8ee45dd4f
commit
4323e83d49
|
@ -1,2 +1,4 @@
|
|||
// Package pixelgl provides higher-level abstractions around the basic OpenGL primitives and operations.
|
||||
//
|
||||
// This package deliberately does not handle nor report OpenGL errors, it's up to you to cause none.
|
||||
package pixelgl
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
|
||||
"github.com/go-gl/gl/v3.3-core/gl"
|
||||
"github.com/go-gl/mathgl/mgl32"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// UniformFormat defines names, purposes and types of uniform variables inside a shader.
|
||||
|
@ -36,9 +35,9 @@ func NewShader(parent Doer, vertexFormat VertexFormat, uniformFormat UniformForm
|
|||
uniforms: make(map[Attr]int32),
|
||||
}
|
||||
|
||||
var err, glerr error
|
||||
var err error
|
||||
parent.Do(func(ctx Context) {
|
||||
err, glerr = DoErrGLErr(func() error {
|
||||
err = DoErr(func() error {
|
||||
var vshader, fshader uint32
|
||||
|
||||
// vertex shader
|
||||
|
@ -120,15 +119,9 @@ func NewShader(parent Doer, vertexFormat VertexFormat, uniformFormat UniformForm
|
|||
return nil
|
||||
})
|
||||
})
|
||||
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
|
||||
}
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
package pixelgl
|
||||
|
||||
import (
|
||||
"github.com/go-gl/gl/v3.3-core/gl"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
import "github.com/go-gl/gl/v3.3-core/gl"
|
||||
|
||||
// Texture is an OpenGL texture.
|
||||
type Texture struct {
|
||||
|
@ -17,9 +14,8 @@ type Texture struct {
|
|||
func NewTexture(parent Doer, width, height int, pixels []uint8) (*Texture, error) {
|
||||
texture := &Texture{parent: parent}
|
||||
|
||||
var err error
|
||||
parent.Do(func(ctx Context) {
|
||||
err = DoGLErr(func() {
|
||||
Do(func() {
|
||||
gl.GenTextures(1, &texture.tex)
|
||||
gl.BindTexture(gl.TEXTURE_2D, texture.tex)
|
||||
|
||||
|
@ -40,9 +36,6 @@ func NewTexture(parent Doer, width, height int, pixels []uint8) (*Texture, error
|
|||
gl.BindTexture(gl.TEXTURE_2D, 0)
|
||||
})
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to create a texture")
|
||||
}
|
||||
|
||||
return texture, nil
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package pixelgl
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
|
||||
"github.com/go-gl/gl/v3.3-core/gl"
|
||||
|
@ -97,73 +96,3 @@ func DoVal(f func() interface{}) interface{} {
|
|||
}
|
||||
return <-val
|
||||
}
|
||||
|
||||
// DoGLErr is same as Do, but also return an error generated by OpenGL.
|
||||
func DoGLErr(f func()) (gl error) {
|
||||
glerr := make(chan error)
|
||||
callQueue <- func() {
|
||||
getLastGLErr() // swallow
|
||||
f()
|
||||
glerr <- getLastGLErr()
|
||||
}
|
||||
return <-glerr
|
||||
}
|
||||
|
||||
// DoErrGLErr is same as DoErr, but also returns an error generated by OpenGL.
|
||||
func DoErrGLErr(f func() error) (_, gl error) {
|
||||
err := make(chan error)
|
||||
glerr := make(chan error)
|
||||
callQueue <- func() {
|
||||
getLastGLErr() // swallow
|
||||
err <- f()
|
||||
glerr <- getLastGLErr()
|
||||
}
|
||||
return <-err, <-glerr
|
||||
}
|
||||
|
||||
// DoValGLErr is same as DoVal, but also returns an error generated by OpenGL.
|
||||
func DoValGLErr(f func() interface{}) (_ interface{}, gl error) {
|
||||
val := make(chan interface{})
|
||||
glerr := make(chan error)
|
||||
callQueue <- func() {
|
||||
getLastGLErr() // swallow
|
||||
val <- f()
|
||||
glerr <- getLastGLErr()
|
||||
}
|
||||
return <-val, <-glerr
|
||||
}
|
||||
|
||||
// GLError represents an error code generated by OpenGL.
|
||||
type GLError uint32
|
||||
|
||||
// Error returns a human-readable textual representation of an OpenGL error.
|
||||
func (err GLError) Error() string {
|
||||
if desc, ok := glErrors[uint32(err)]; ok {
|
||||
return fmt.Sprintf("OpenGL error: %s", desc)
|
||||
}
|
||||
return fmt.Sprintf("OpenGL error: unknown error")
|
||||
}
|
||||
|
||||
var glErrors = map[uint32]string{
|
||||
gl.INVALID_ENUM: "invalid enum",
|
||||
gl.INVALID_VALUE: "invalid value",
|
||||
gl.INVALID_OPERATION: "invalid operation",
|
||||
gl.STACK_OVERFLOW: "stack overflow",
|
||||
gl.STACK_UNDERFLOW: "stack underflow",
|
||||
gl.OUT_OF_MEMORY: "out of memory",
|
||||
gl.INVALID_FRAMEBUFFER_OPERATION: "invalid framebuffer operation",
|
||||
gl.CONTEXT_LOST: "context lost",
|
||||
}
|
||||
|
||||
// getLastGLErr returns (and consumes) the last error generated by OpenGL.
|
||||
// Don't use outside DoGLErr, DoErrGLErr and DoValGLErr.
|
||||
func getLastGLErr() error {
|
||||
err := uint32(gl.NO_ERROR)
|
||||
for e := gl.GetError(); e != gl.NO_ERROR; e = gl.GetError() {
|
||||
err = e
|
||||
}
|
||||
if err != gl.NO_ERROR {
|
||||
return GLError(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -105,9 +105,9 @@ func NewVertexArray(parent Doer, format VertexFormat, mode VertexDrawMode, usage
|
|||
offset += attr.Type.Size()
|
||||
}
|
||||
|
||||
var err, glerr error
|
||||
var err error
|
||||
parent.Do(func(ctx Context) {
|
||||
err, glerr = DoErrGLErr(func() error {
|
||||
err = DoErr(func() error {
|
||||
gl.GenVertexArrays(1, &va.vao)
|
||||
gl.BindVertexArray(va.vao)
|
||||
|
||||
|
@ -149,15 +149,9 @@ func NewVertexArray(parent Doer, format VertexFormat, mode VertexDrawMode, usage
|
|||
return nil
|
||||
})
|
||||
})
|
||||
if err != nil && glerr != nil {
|
||||
return nil, errors.Wrap(errors.Wrap(glerr, err.Error()), "failed to create vertex array")
|
||||
}
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to create vertex array")
|
||||
}
|
||||
if glerr != nil {
|
||||
return nil, errors.Wrap(glerr, "failed to create vertex array")
|
||||
}
|
||||
|
||||
return va, nil
|
||||
}
|
||||
|
@ -222,10 +216,6 @@ func (va *VertexArray) SetVertex(vertex int, data interface{}) {
|
|||
gl.BufferSubData(gl.ARRAY_BUFFER, offset, va.format.Size(), gl.Ptr(data))
|
||||
|
||||
gl.BindBuffer(gl.ARRAY_BUFFER, 0)
|
||||
|
||||
if err := getLastGLErr(); err != nil {
|
||||
panic(errors.Wrap(err, "set vertex error"))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -253,10 +243,6 @@ func (va *VertexArray) SetVertexAttributeFloat(vertex int, purpose AttrPurpose,
|
|||
gl.BufferSubData(gl.ARRAY_BUFFER, offset, attr.Type.Size(), unsafe.Pointer(&value))
|
||||
|
||||
gl.BindBuffer(gl.ARRAY_BUFFER, 0)
|
||||
|
||||
if err := getLastGLErr(); err != nil {
|
||||
panic(errors.Wrap(err, "set attribute vertex"))
|
||||
}
|
||||
})
|
||||
return true
|
||||
}
|
||||
|
@ -279,10 +265,6 @@ func (va *VertexArray) SetVertexAttributeVec2(vertex int, purpose AttrPurpose, v
|
|||
gl.BufferSubData(gl.ARRAY_BUFFER, offset, attr.Type.Size(), unsafe.Pointer(&value))
|
||||
|
||||
gl.BindBuffer(gl.ARRAY_BUFFER, 0)
|
||||
|
||||
if err := getLastGLErr(); err != nil {
|
||||
panic(errors.Wrap(err, "set attribute vertex"))
|
||||
}
|
||||
})
|
||||
return true
|
||||
}
|
||||
|
@ -305,10 +287,6 @@ func (va *VertexArray) SetVertexAttributeVec3(vertex int, purpose AttrPurpose, v
|
|||
gl.BufferSubData(gl.ARRAY_BUFFER, offset, attr.Type.Size(), unsafe.Pointer(&value))
|
||||
|
||||
gl.BindBuffer(gl.ARRAY_BUFFER, 0)
|
||||
|
||||
if err := getLastGLErr(); err != nil {
|
||||
panic(errors.Wrap(err, "set attribute vertex"))
|
||||
}
|
||||
})
|
||||
return true
|
||||
}
|
||||
|
@ -331,10 +309,6 @@ func (va *VertexArray) SetVertexAttributeVec4(vertex int, purpose AttrPurpose, v
|
|||
gl.BufferSubData(gl.ARRAY_BUFFER, offset, attr.Type.Size(), unsafe.Pointer(&value))
|
||||
|
||||
gl.BindBuffer(gl.ARRAY_BUFFER, 0)
|
||||
|
||||
if err := getLastGLErr(); err != nil {
|
||||
panic(errors.Wrap(err, "set attribute vertex"))
|
||||
}
|
||||
})
|
||||
return true
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue