From 6a62e3077b97ed7c20f5d53303f0950c714da3e8 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Tue, 13 Nov 2012 12:10:13 +0000 Subject: [PATCH] sdl: Don't set SDL_GL_DOUBLEBUFFER when the swap chain has no pref MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ‘length’ for the swap chain is initially -1 which is supposed to mean ‘no preference’. However, both of the SDL winsys's were explicitly setting the SDL_GL_DOUBLEBUFFER attribute to zero in that case which would try to disable double buffering. On OS X, the equivalent to eglSwapBuffers (ie, [NSOpenGLContext flushBuffer]) does nothing for a single buffer context. The cogl-sdl-hello example does not specify the swap chain length so presumably it would end up with a single buffer config. When cogl_onscreen_swap_buffers is called it therefore does nothing and nothing is painted. I guess to make single-buffered contexts actually useful we should expose some public equivalent to glFlush so that you can ensure the rendering commands will actually hit the buffer. Alternatively we could document that cogl_onscreen_swap_buffers performs this task on single-buffered configs and then we could make the SDL winsys explicitly call glFlush in that case. Reviewed-by: Robert Bragg (cherry picked from commit 71e57f99002d5dee79bbd44b3bc57712b99acb55) --- cogl/winsys/cogl-winsys-sdl.c | 5 +++-- cogl/winsys/cogl-winsys-sdl2.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cogl/winsys/cogl-winsys-sdl.c b/cogl/winsys/cogl-winsys-sdl.c index 9d279840f..95d5ab909 100644 --- a/cogl/winsys/cogl-winsys-sdl.c +++ b/cogl/winsys/cogl-winsys-sdl.c @@ -134,8 +134,9 @@ set_gl_attribs_from_framebuffer_config (CoglFramebufferConfig *config) SDL_GL_SetAttribute (SDL_GL_STENCIL_SIZE, config->need_stencil ? 1 : 0); - SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, - config->swap_chain->length > 1 ? 1 : 0); + if (config->swap_chain->length >= 0) + SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, + config->swap_chain->length > 1 ? 1 : 0); SDL_GL_SetAttribute (SDL_GL_ALPHA_SIZE, config->swap_chain->has_alpha ? 1 : 0); diff --git a/cogl/winsys/cogl-winsys-sdl2.c b/cogl/winsys/cogl-winsys-sdl2.c index f9b94e97e..8ea5919b1 100644 --- a/cogl/winsys/cogl-winsys-sdl2.c +++ b/cogl/winsys/cogl-winsys-sdl2.c @@ -130,8 +130,9 @@ set_gl_attribs_from_framebuffer_config (CoglFramebufferConfig *config) SDL_GL_SetAttribute (SDL_GL_STENCIL_SIZE, config->need_stencil ? 1 : 0); - SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, - config->swap_chain->length > 1 ? 1 : 0); + if (config->swap_chain->length >= 0) + SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, + config->swap_chain->length > 1 ? 1 : 0); SDL_GL_SetAttribute (SDL_GL_ALPHA_SIZE, config->swap_chain->has_alpha ? 1 : 0);