Revert "app/internal/egl: accept zero EGLDisplay values as valid"

This reverts commit 66138e7890.

Reason: According to #77, it didn't work and the proposed fix
(retry when EGL_NO_DISPLAY is returned) is correct.
This commit is contained in:
Elias Naur
2020-01-11 23:15:23 +01:00
parent 2e66c90aee
commit bc30683588
+13 -18
View File
@@ -33,6 +33,7 @@ type eglContext struct {
} }
var ( var (
nilEGLDisplay _EGLDisplay
nilEGLSurface _EGLSurface nilEGLSurface _EGLSurface
nilEGLContext _EGLContext nilEGLContext _EGLContext
nilEGLConfig _EGLConfig nilEGLConfig _EGLConfig
@@ -55,7 +56,6 @@ const (
_EGL_OPENGL_ES2_BIT = 0x4 _EGL_OPENGL_ES2_BIT = 0x4
_EGL_RED_SIZE = 0x3024 _EGL_RED_SIZE = 0x3024
_EGL_RENDERABLE_TYPE = 0x3040 _EGL_RENDERABLE_TYPE = 0x3040
_EGL_SUCCESS = 0x3000
_EGL_SURFACE_TYPE = 0x3033 _EGL_SURFACE_TYPE = 0x3033
_EGL_WINDOW_BIT = 0x4 _EGL_WINDOW_BIT = 0x4
) )
@@ -72,6 +72,7 @@ func (c *Context) Release() {
eglReleaseThread() eglReleaseThread()
c.eglCtx = nil c.eglCtx = nil
} }
c.disp = nilEGLDisplay
} }
func (c *Context) Present() error { func (c *Context) Present() error {
@@ -79,7 +80,7 @@ func (c *Context) Present() error {
c.srgbFBO.Blit() c.srgbFBO.Blit()
} }
if !eglSwapBuffers(c.disp, c.eglSurf) { if !eglSwapBuffers(c.disp, c.eglSurf) {
return fmt.Errorf("eglSwapBuffers: %v", eglErr()) return fmt.Errorf("eglSwapBuffers failed (%x)", eglGetError())
} }
if c.srgbFBO != nil { if c.srgbFBO != nil {
c.srgbFBO.AfterPresent() c.srgbFBO.AfterPresent()
@@ -92,8 +93,8 @@ func NewContext(disp NativeDisplayType) (*Context, error) {
return nil, err return nil, err
} }
eglDisp := eglGetDisplay(disp) eglDisp := eglGetDisplay(disp)
if err := eglErr(); err != nil { if eglDisp == nilEGLDisplay {
return nil, fmt.Errorf("eglGetDisplay: %v", err) return nil, fmt.Errorf("eglGetDisplay failed: 0x%x", eglGetError())
} }
eglCtx, err := createContext(eglDisp) eglCtx, err := createContext(eglDisp)
if err != nil { if err != nil {
@@ -107,14 +108,6 @@ func NewContext(disp NativeDisplayType) (*Context, error) {
return c, nil return c, nil
} }
func eglErr() error {
errCode := eglGetError()
if errCode == _EGL_SUCCESS {
return nil
}
return fmt.Errorf("EGL error 0x%x", errCode)
}
func (c *Context) Functions() *gl.Functions { func (c *Context) Functions() *gl.Functions {
return c.c return c.c
} }
@@ -144,7 +137,9 @@ func (c *Context) CreateSurface(win NativeWindowType, width, height int) error {
} }
func (c *Context) ReleaseCurrent() { func (c *Context) ReleaseCurrent() {
eglMakeCurrent(c.disp, nilEGLSurface, nilEGLSurface, nilEGLContext) if c.disp != nilEGLDisplay {
eglMakeCurrent(c.disp, nilEGLSurface, nilEGLSurface, nilEGLContext)
}
} }
func (c *Context) MakeCurrent() error { func (c *Context) MakeCurrent() error {
@@ -152,7 +147,7 @@ func (c *Context) MakeCurrent() error {
return errors.New("no surface created yet EGL_KHR_surfaceless_context is not supported") return errors.New("no surface created yet EGL_KHR_surfaceless_context is not supported")
} }
if !eglMakeCurrent(c.disp, c.eglSurf, c.eglSurf, c.eglCtx.ctx) { if !eglMakeCurrent(c.disp, c.eglSurf, c.eglSurf, c.eglCtx.ctx) {
return fmt.Errorf("eglMakeCurrent: %v", eglErr()) return fmt.Errorf("eglMakeCurrent error 0x%x", eglGetError())
} }
if c.eglCtx.srgb || c.eglSurf == nilEGLSurface { if c.eglCtx.srgb || c.eglSurf == nilEGLSurface {
return nil return nil
@@ -191,7 +186,7 @@ func hasExtension(exts []string, ext string) bool {
func createContext(disp _EGLDisplay) (*eglContext, error) { func createContext(disp _EGLDisplay) (*eglContext, error) {
major, minor, ret := eglInitialize(disp) major, minor, ret := eglInitialize(disp)
if !ret { if !ret {
return nil, fmt.Errorf("eglInitialize: %v", eglErr()) return nil, fmt.Errorf("eglInitialize failed: 0x%x", eglGetError())
} }
// sRGB framebuffer support on EGL 1.5 or if EGL_KHR_gl_colorspace is supported. // sRGB framebuffer support on EGL 1.5 or if EGL_KHR_gl_colorspace is supported.
exts := strings.Split(eglQueryString(disp, _EGL_EXTENSIONS), " ") exts := strings.Split(eglQueryString(disp, _EGL_EXTENSIONS), " ")
@@ -216,7 +211,7 @@ func createContext(disp _EGLDisplay) (*eglContext, error) {
attribs = append(attribs, _EGL_NONE) attribs = append(attribs, _EGL_NONE)
eglCfg, ret := eglChooseConfig(disp, attribs) eglCfg, ret := eglChooseConfig(disp, attribs)
if !ret { if !ret {
return nil, fmt.Errorf("eglChooseConfig: %v", eglErr()) return nil, fmt.Errorf("eglChooseConfig failed: 0x%x", eglGetError())
} }
if eglCfg == nilEGLConfig { if eglCfg == nilEGLConfig {
return nil, errors.New("eglChooseConfig returned 0 configs") return nil, errors.New("eglChooseConfig returned 0 configs")
@@ -238,7 +233,7 @@ func createContext(disp _EGLDisplay) (*eglContext, error) {
} }
eglCtx = eglCreateContext(disp, eglCfg, nilEGLContext, ctxAttribs) eglCtx = eglCreateContext(disp, eglCfg, nilEGLContext, ctxAttribs)
if eglCtx == nilEGLContext { if eglCtx == nilEGLContext {
return nil, fmt.Errorf("eglCreateContext: %v", eglErr()) return nil, fmt.Errorf("eglCreateContext failed: 0x%x", eglGetError())
} }
} }
return &eglContext{ return &eglContext{
@@ -264,7 +259,7 @@ func createSurface(disp _EGLDisplay, eglCtx *eglContext, win NativeWindowType) (
eglSurf = eglCreateWindowSurface(disp, eglCtx.config, win, surfAttribs) eglSurf = eglCreateWindowSurface(disp, eglCtx.config, win, surfAttribs)
} }
if eglSurf == nilEGLSurface { if eglSurf == nilEGLSurface {
return nilEGLSurface, fmt.Errorf("newContext: eglCreateWindowSurface (sRGB=%v): %v", eglCtx.srgb, eglErr()) return nilEGLSurface, fmt.Errorf("newContext: eglCreateWindowSurface failed 0x%x (sRGB=%v)", eglGetError(), eglCtx.srgb)
} }
return eglSurf, nil return eglSurf, nil
} }