20

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.

Jason C
  • 38,729
  • 14
  • 126
  • 182
exebook
  • 32,014
  • 33
  • 141
  • 226

1 Answers1

7

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 may be able to do it by creating double buffers through X Double Buffer Extension (DBE) and syncronize manually towards display using the X Syncronization Extension. You may be able to find something useful calling XSyncListSystemCounters, though it has yet to be confirmed by test:

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

Andreas
  • 5,086
  • 3
  • 16
  • 36
  • 3
    So I was able to find some docs for XSyncListSystemCounters [here](https://www.x.org/releases/X11R7.7/doc/libXext/synclib.txt). From that I was able to hack together a [test program](https://gist.github.com/JC3/fe3780cdfe609009e43ca14192a277eb) that lists the system counters and shows their frequency. Unfortunately, at least on my system, there was no vsync counter. Just a bunch of millisecond timers. :( YMMV – Jason C Nov 03 '19 at 22:54
  • `XSync` seems to be a general purpose syncing solution. I can not see how this can be used to wait for the graphics hardware. – ceving Mar 21 '23 at 10:52
  • @ceving Edited to lower expectations. Being many years older and wiser maybe I should give this investigation another go. – Andreas Mar 21 '23 at 12:12