Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to wait for VSYNC in Xlib app?

I am drawing something on screen using XWindow Drawable, Pixmap, and XRender. I can see that sometimes there is flicker. Is there a way to wait for VBLANK? I googled a lot already, feels like looking for a coin in a forest.

There is NO OpenGL involved. It is Linux (Ubuntu). I could use (nano)sleep(), but need to know when the time to draw has come some how.

like image 335
exebook Avatar asked May 16 '15 15:05

exebook


1 Answers

I find the by far most simple solution is using GLX because of its excellent high level interface towards synchronization and double buffering. Please note GLX is not OpenGL, it is an X extension. You need a dummy OpenGL context as SwapBuffers (for some odd reason) demands it but that´s about it.

If you want to do it without GLX for any reason, you can do it by creating double buffers through X Double Buffer Extension (DBE) and syncronize manually towards display using the X Syncronization Extension. I have not done so myself but you should be able to find something to your liking calling XSyncListSystemCounters (after proper initialization!):

XSyncListSystemCounters returns a pointer to an array of system counters supported by the display

Can´t find much more myself about the hard way though. Good Luck.

like image 83
Andreas Avatar answered Nov 05 '22 09:11

Andreas