How vsync work ? how is it possible to not wait a multiple of 16.6 ms between each eglSwapBuffers?

  

I do not understand, I took the source code of delphi to see how it is performed with OpenGL (under android). so on every paint delphi do :

eglSwapBuffers(TCustomAndroidContext.SharedDisplay, TCustomAndroidContext.SharedSurface)

so this make OpenGL swapping the back buffer with the display buffer, waiting for the vsync signal first. So as the vsync signal is fired every 16.6 ms I must have between every eglSwapBuffers a multiple of 16.6 (ex 16.6 or 33.2 or 49.8, etc).

To measure it I do like this :

I replace

procedure ContextFlip;
begin
if eglSwapBuffers(TCustomAndroidContext.SharedDisplay, TCustomAndroidContext.SharedSurface) = 0 then
glGetError;
end;

with

var vSyncStopWatch: TstopWatch;

procedure ContextFlip;
begin
if eglSwapBuffers(TCustomAndroidContext.SharedDisplay, TCustomAndroidContext.SharedSurface) = 0 then
glGetError;

vSyncStopWatch.Stop;
if vSyncStopWatch.Elapsed.TotalMilliseconds > 16.6 then allog(‘VSYNC deadline missed’, floattostr(vSyncStopWatch.Elapsed.TotalMilliseconds), tallogType.WARN);
vSyncStopWatch := TstopWatch.StartNew;

end;

but what I don’t understand, is why I have value like 18ms, 22ms, 24ms, 28ms, 27ms, etc.. instead of only 16.6 or 33.2 or 49.8, etc i even see value like 7ms between eglSwapBuffers. how is it possible ? does eglSwapBuffers really wait for the vsync signal to return ?

Comments are closed.