From 5016c98739f000c0a515d3972f22cff4d2fe60f9 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Thu, 28 Nov 2019 14:41:49 +0100 Subject: [PATCH] app/internal/egl: split surface creation from making context current Signed-off-by: Elias Naur --- app/internal/egl/egl.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/internal/egl/egl.go b/app/internal/egl/egl.go index d3214b79..968dbb10 100644 --- a/app/internal/egl/egl.go +++ b/app/internal/egl/egl.go @@ -151,12 +151,15 @@ func (c *Context) MakeCurrent() error { if c.eglWin == nilEGLNativeWindowType { return nil } - eglSurf, err := createSurfaceAndMakeCurrent(c.eglCtx, win) + eglSurf, err := createSurface(c.eglCtx, win) c.eglSurf = eglSurf if err != nil { c.eglWin = nilEGLNativeWindowType return err } + if !eglMakeCurrent(c.eglCtx.disp, eglSurf, eglSurf, c.eglCtx.ctx) { + return fmt.Errorf("eglMakeCurrent error 0x%x", eglGetError()) + } // eglSwapInterval 1 leads to erratic frame rates and unnecessary blocking. // We rely on platform specific frame rate limiting instead, except on Windows // and X11 where eglSwapInterval is all there is. @@ -258,7 +261,7 @@ func createContext(disp NativeDisplayType) (*eglContext, error) { }, nil } -func createSurfaceAndMakeCurrent(eglCtx *eglContext, win NativeWindowType) (_EGLSurface, error) { +func createSurface(eglCtx *eglContext, win NativeWindowType) (_EGLSurface, error) { var surfAttribs []_EGLint if eglCtx.srgb { surfAttribs = append(surfAttribs, _EGL_GL_COLORSPACE_KHR, _EGL_GL_COLORSPACE_SRGB_KHR) @@ -274,9 +277,5 @@ func createSurfaceAndMakeCurrent(eglCtx *eglContext, win NativeWindowType) (_EGL if eglSurf == nilEGLSurface { return nilEGLSurface, fmt.Errorf("newContext: eglCreateWindowSurface failed 0x%x (sRGB=%v)", eglGetError(), eglCtx.srgb) } - if !eglMakeCurrent(eglCtx.disp, eglSurf, eglSurf, eglCtx.ctx) { - eglDestroySurface(eglCtx.disp, eglSurf) - return nilEGLSurface, fmt.Errorf("eglMakeCurrent error 0x%x", eglGetError()) - } return eglSurf, nil }