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 406

Summary: SDL_Flip doesn't wait vsync under X11
Product: SDL Reporter: Antony <al-lists>
Component: videoAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED WONTFIX QA Contact: Sam Lantinga <slouken>
Severity: major    
Priority: P2 CC: johan.walles, renesd
Version: 1.2.11Keywords: target-1.2.14
Hardware: x86   
OS: Linux   
Attachments: Test SDL_Flip() vsync, by filling black then white

Description Antony 2007-03-03 22:00:46 UTC
http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fFlip says

If your display mode is using the flags pygame.HWSURFACE and pygame.DOUBLEBUF, this will wait for a vertical retrace and swap the surfaces. If you are using a different type of display mode, it will simply update the entire contents of the surface.

It doesn't work with SDL under X11, wich mean that every SDL applications runs with tearing artefacts under X11. IMHO it is a critical bug. I know it's due to X11, but a solution must be found NOW ! It's amazing to imagine that simple graphical applications that could be done on a C64 cannot be done under Linux/X11 in 2007 :).



With pygame installed, you can easily test it (if you like to take risks) by typing on a terminal:

  python -c "`curl http://lesuisse.net/vsynctest.py `"

or run the following python code
-----------------------------------
#!/usr/bin/python
import math,sys,time,pygame
pygame.init()
screen = pygame.display.set_mode((640,480),pygame.FULLSCREEN|pygame.DOUBLEBUF|pygame.HWSURFACE)
c=0
while 1:
    c=((c+1)%2)*255
    for event in pygame.event.get():
        if event.type in [2,5,6,12]:
            sys.exit()
    screen.fill((c,c,c))
    pygame.display.flip()
------------------------------------
Comment 1 Antony 2007-03-03 22:02:23 UTC
Created attachment 196 [details]
Test SDL_Flip() vsync, by filling black then white
Comment 2 Ryan C. Gordon 2007-07-03 03:24:29 UTC
This can't be fixed at this time, as there's no way to sync to vblank in 2D X11 (OpenGL has a few methods, though, so SDL 1.3's OpenGL backend for 2D rendering should make this possible).

Using 2D rendering without OpenGL, we would need someone to develop an X11 extension.

--ryan.

Comment 3 Rene Dudfield 2009-05-29 20:37:08 UTC
Many other 2d programs work with vsync in a window on X11 without opengl.

So there must be some way to do it.

This is a very common bug report we get at pygame.

Reopening this bug so we can research a fix/workaround.
Comment 4 Rene Dudfield 2009-05-29 21:15:09 UTC
The XVideo extension appears to let you flip a buffer on vertical sync(vsync).

So perhaps the SDL overlay code can be used for this.  Since it already uses Xvideo.

The idea would be to create a buffer, and then feed the buffer to the overlay instead of flipping/updating.

Trying this out using pygame to test the performance.
Comment 5 Rene Dudfield 2009-05-30 00:44:05 UTC

Another option for python SDL users is to use the Lamina module which lets you draw using pygame in software, and then it updates opengl in the background.
However that's not all that fast for some types of games - but it will allow you to vsync - assuming your X11 supports opengl.

http://pypi.python.org/pypi/Lamina
Comment 6 Ryan C. Gordon 2009-09-13 16:33:31 UTC
Tagging this bug with "target-1.2.14" so we can try to resolve it for SDL 1.2.14.

Please note that we may choose to resolve it as WONTFIX. This tag is largely so we have a comprehensive wishlist of bugs to examine for 1.2.14 (and so we can close bugs that we'll never fix, rather than have them live forever in Bugzilla).

--ryan.
Comment 7 Patrice Mandin 2009-09-14 10:44:49 UTC
*** Bug 583 has been marked as a duplicate of this bug. ***
Comment 8 Sam Lantinga 2009-09-20 22:46:38 UTC
It's not likely that we'll do anything with this for SDL 1.2, but I've put it on the list for SDL 1.3 since it uses OpenGL when available.