go-opengl-pixel/pixelgl/error.go

42 lines
1.2 KiB
Go

package pixelgl
import (
"github.com/go-gl/gl/v3.3-core/gl"
"github.com/pkg/errors"
)
// getLastError returns (and consumes) the last error generated by OpenGL inside the current Do, DoErr or DoVal.
// If no error has been generated, this function returns nil.
//
// Call this function only inside the OpenGL thread (Do, DoErr or DoVal function). It's not guaranteed
// to work correctly outside of it, because the thread swallows extra unchecked errors.
func getLastError() 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 nil
}
switch err {
case gl.INVALID_ENUM:
return errors.New("invalid enum")
case gl.INVALID_VALUE:
return errors.New("invalid value")
case gl.INVALID_OPERATION:
return errors.New("invalid operation")
case gl.STACK_OVERFLOW:
return errors.New("stack overflow")
case gl.STACK_UNDERFLOW:
return errors.New("stack underflow")
case gl.OUT_OF_MEMORY:
return errors.New("out of memory")
case gl.INVALID_FRAMEBUFFER_OPERATION:
return errors.New("invalid framebuffer operation")
case gl.CONTEXT_LOST:
return errors.New("context lost")
default:
return errors.New("unknown error")
}
}