From dba42715d40ed32596f176a194051c6d78a4c1c0 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Mon, 5 Dec 2011 15:55:12 +0000 Subject: [PATCH] egl-winsys: Bind the framebuffer before swapping For some reason the EGL spec says that the surface passed to eglSwapBuffers must be bound as the current surface for the swap to work. Mesa validates that this is the case and returns an error from the swap buffers call if not. https://bugzilla.gnome.org/show_bug.cgi?id=665604 Reviewed-by: Robert Bragg --- cogl/winsys/cogl-winsys-egl.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cogl/winsys/cogl-winsys-egl.c b/cogl/winsys/cogl-winsys-egl.c index 15d0d7af1..c0d7ab9b5 100644 --- a/cogl/winsys/cogl-winsys-egl.c +++ b/cogl/winsys/cogl-winsys-egl.c @@ -1538,6 +1538,14 @@ _cogl_winsys_onscreen_swap_region (CoglOnscreen *onscreen, rect[1] = framebuffer_height - rect[1] - rect[3]; } + /* At least for eglSwapBuffers the EGL spec says that the surface to + swap must be bound to the current context. It looks like Mesa + also validates that this is the case for eglSwapBuffersRegion so + we must bind here too */ + _cogl_framebuffer_flush_state (COGL_FRAMEBUFFER (onscreen), + COGL_FRAMEBUFFER (onscreen), + COGL_FRAMEBUFFER_STATE_BIND); + if (egl_renderer->pf_eglSwapBuffersRegion (egl_renderer->edpy, egl_onscreen->egl_surface, n_rectangles, @@ -1578,6 +1586,15 @@ _cogl_winsys_onscreen_swap_buffers (CoglOnscreen *onscreen) &egl_onscreen->kms_onscreen); return; #else + /* The specification for EGL (at least in 1.4) says that the surface + needs to be bound to the current context for the swap to work + although it may change in future. Mesa explicitly checks for this + and just returns an error if this is not the case so we can't + just pretend this isn't in the spec. */ + _cogl_framebuffer_flush_state (COGL_FRAMEBUFFER (onscreen), + COGL_FRAMEBUFFER (onscreen), + COGL_FRAMEBUFFER_STATE_BIND); + eglSwapBuffers (egl_renderer->edpy, egl_onscreen->egl_surface); #endif