How to wait for VSYNC in Xlib app?
Asked Answered
C

1

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.

Capful answered 16/5, 2015 at 15:46 Comment(0)
C
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.

Coerce answered 27/7, 2016 at 12:46 Comment(3)
So I was able to find some docs for XSyncListSystemCounters here. From that I was able to hack together a test program 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. :( YMMVFulminate
XSync seems to be a general purpose syncing solution. I can not see how this can be used to wait for the graphics hardware.Yuyuan
@Yuyuan Edited to lower expectations. Being many years older and wiser maybe I should give this investigation another go.Coerce

© 2022 - 2024 — McMap. All rights reserved.