We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 117

Summary: [Patch] Vertical retrace sync for OpenGL on Mac OS X (Quartz)
Product: SDL Reporter: Christian Walther <cwalther>
Component: videoAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: enhancement    
Priority: P2    
Version: HG 1.2   
Hardware: PowerPC   
OS: Mac OS X (All)   
Bug Depends on: 2    
Bug Blocks:    
Attachments: Quartz GL vsync patch

Description Christian Walther 2006-01-30 13:48:46 UTC
On Mac OS X (Quartz), (double-buffered) OpenGL rendering is currently not synchronized to vertical retrace - SDL_GL_SwapBuffers() swaps and returns immediately. The attached patch changes this (see http://lists.apple.com/archives/mac-opengl/2006/Jan/msg00080.html for what it does exactly).

I actually wondered whether there might be a reason this has been unimplemented for so long. I'm not sure what SDL's general policy on vertical retrace syncing for OpenGL is (the SDL_GL_SwapBuffers() documentation doesn't mention it) and I didn't check what other backends do about it, but since for non-OpenGL the policy seems to be "do it if possible" (see the SDL_Flip() documentation), I figured it might not be a bad thing to add. Does everybody agree with that, or might there be an application that depends on the previous behavior? For my own application, the effect is very beneficial - no more tearing, less fan noise, and longer battery life.

The patch has been tested on Mac OS X 10.2.8, 10.3.9, and 10.4.3, and it works both in fullscreen and in windowed mode (on 10.4 even when the window is partially obscured).
Comment 1 Christian Walther 2006-01-30 13:49:54 UTC
Created attachment 55 [details]
Quartz GL vsync patch
Comment 2 Ryan C. Gordon 2006-01-30 13:58:28 UTC
There is a parameter for SDL_GL_SetAttribute() to enable this (but the attribute itself may be sitting in another bugzilla entry...). We shouldn't enable it by default, because it hurts framerate, which can be a real problem in some situations.

--ryan.

Comment 3 Christian Walther 2006-01-30 14:40:59 UTC
Ah, you mean https://bugzilla.libsdl.org/show_bug.cgi?id=2 . I saw it before I submitted this bug, but only glanced over it since it seemed to refer to OpenGL extensions (which is not true, it refers to the GLX and WGL equivalents of what I'm doing here). I now examined that patch in more detail and came to the conclusion that it would be trivial to adapt my patch to be the Quartz implementation of the other one. So that's probably the way to go, even if it means waiting for 1.3. It's certainly the cleaner way of making it optional than conditionalizing it on an environment variable, which was my first idea.
Comment 4 Ryan C. Gordon 2006-01-30 14:48:19 UTC
While Bug #2 is an API change, it doesn't require us to break binary compatibility, so it could be added to 1.2.10...we did this with several other API additions, not the least of which being multisampling support in SDL_GL_SetAttribute() for 1.2.9.

I'm flagging this bug as depending on Bug #2, since that seems to be the way forward, in any case.

--ryan.

Comment 5 Sam Lantinga 2006-04-27 03:59:17 UTC
This is in SVN, thanks!