remove OpenGL error reporting

This commit is contained in:
faiface 2016-12-06 16:05:08 +01:00
parent c8ee45dd4f
commit 4323e83d49
5 changed files with 8 additions and 117 deletions

View File

@ -1,2 +1,4 @@
// Package pixelgl provides higher-level abstractions around the basic OpenGL primitives and operations. // 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 package pixelgl

View File

@ -5,7 +5,6 @@ import (
"github.com/go-gl/gl/v3.3-core/gl" "github.com/go-gl/gl/v3.3-core/gl"
"github.com/go-gl/mathgl/mgl32" "github.com/go-gl/mathgl/mgl32"
"github.com/pkg/errors"
) )
// UniformFormat defines names, purposes and types of uniform variables inside a shader. // 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), uniforms: make(map[Attr]int32),
} }
var err, glerr error var err error
parent.Do(func(ctx Context) { parent.Do(func(ctx Context) {
err, glerr = DoErrGLErr(func() error { err = DoErr(func() error {
var vshader, fshader uint32 var vshader, fshader uint32
// vertex shader // vertex shader
@ -120,15 +119,9 @@ func NewShader(parent Doer, vertexFormat VertexFormat, uniformFormat UniformForm
return nil return nil
}) })
}) })
if err != nil && glerr != nil {
return nil, errors.Wrap(glerr, err.Error())
}
if err != nil { if err != nil {
return nil, err return nil, err
} }
if glerr != nil {
return nil, glerr
}
return shader, nil return shader, nil
} }

View File

@ -1,9 +1,6 @@
package pixelgl package pixelgl
import ( import "github.com/go-gl/gl/v3.3-core/gl"
"github.com/go-gl/gl/v3.3-core/gl"
"github.com/pkg/errors"
)
// Texture is an OpenGL texture. // Texture is an OpenGL texture.
type Texture struct { type Texture struct {
@ -17,9 +14,8 @@ type Texture struct {
func NewTexture(parent Doer, width, height int, pixels []uint8) (*Texture, error) { func NewTexture(parent Doer, width, height int, pixels []uint8) (*Texture, error) {
texture := &Texture{parent: parent} texture := &Texture{parent: parent}
var err error
parent.Do(func(ctx Context) { parent.Do(func(ctx Context) {
err = DoGLErr(func() { Do(func() {
gl.GenTextures(1, &texture.tex) gl.GenTextures(1, &texture.tex)
gl.BindTexture(gl.TEXTURE_2D, 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) gl.BindTexture(gl.TEXTURE_2D, 0)
}) })
}) })
if err != nil {
return nil, errors.Wrap(err, "failed to create a texture")
}
return texture, nil return texture, nil
} }

View File

@ -1,7 +1,6 @@
package pixelgl package pixelgl
import ( import (
"fmt"
"runtime" "runtime"
"github.com/go-gl/gl/v3.3-core/gl" "github.com/go-gl/gl/v3.3-core/gl"
@ -97,73 +96,3 @@ func DoVal(f func() interface{}) interface{} {
} }
return <-val 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
}

View File

@ -105,9 +105,9 @@ func NewVertexArray(parent Doer, format VertexFormat, mode VertexDrawMode, usage
offset += attr.Type.Size() offset += attr.Type.Size()
} }
var err, glerr error var err error
parent.Do(func(ctx Context) { parent.Do(func(ctx Context) {
err, glerr = DoErrGLErr(func() error { err = DoErr(func() error {
gl.GenVertexArrays(1, &va.vao) gl.GenVertexArrays(1, &va.vao)
gl.BindVertexArray(va.vao) gl.BindVertexArray(va.vao)
@ -149,15 +149,9 @@ func NewVertexArray(parent Doer, format VertexFormat, mode VertexDrawMode, usage
return nil return nil
}) })
}) })
if err != nil && glerr != nil {
return nil, errors.Wrap(errors.Wrap(glerr, err.Error()), "failed to create vertex array")
}
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to create vertex array") 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 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.BufferSubData(gl.ARRAY_BUFFER, offset, va.format.Size(), gl.Ptr(data))
gl.BindBuffer(gl.ARRAY_BUFFER, 0) 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.BufferSubData(gl.ARRAY_BUFFER, offset, attr.Type.Size(), unsafe.Pointer(&value))
gl.BindBuffer(gl.ARRAY_BUFFER, 0) gl.BindBuffer(gl.ARRAY_BUFFER, 0)
if err := getLastGLErr(); err != nil {
panic(errors.Wrap(err, "set attribute vertex"))
}
}) })
return true 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.BufferSubData(gl.ARRAY_BUFFER, offset, attr.Type.Size(), unsafe.Pointer(&value))
gl.BindBuffer(gl.ARRAY_BUFFER, 0) gl.BindBuffer(gl.ARRAY_BUFFER, 0)
if err := getLastGLErr(); err != nil {
panic(errors.Wrap(err, "set attribute vertex"))
}
}) })
return true 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.BufferSubData(gl.ARRAY_BUFFER, offset, attr.Type.Size(), unsafe.Pointer(&value))
gl.BindBuffer(gl.ARRAY_BUFFER, 0) gl.BindBuffer(gl.ARRAY_BUFFER, 0)
if err := getLastGLErr(); err != nil {
panic(errors.Wrap(err, "set attribute vertex"))
}
}) })
return true 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.BufferSubData(gl.ARRAY_BUFFER, offset, attr.Type.Size(), unsafe.Pointer(&value))
gl.BindBuffer(gl.ARRAY_BUFFER, 0) gl.BindBuffer(gl.ARRAY_BUFFER, 0)
if err := getLastGLErr(); err != nil {
panic(errors.Wrap(err, "set attribute vertex"))
}
}) })
return true return true
} }