timing when vertical sync is ON

I am running the application with GL_SYNC_TO_VBLANK=1 ( Vertical sync is ON), thus framerate is 60
Hz (given video rate of 60 Hz). What I need to do is to determine the
“actual” rendering time which is needed to render the image including FSAA.
i.e. the time from the first openGL call until the image is completely drawn in
the backbuffer including AA (Anti-Aliasing).

How do I get this time. Just measuring time between my first and my last
openGL call seems to deliver time without AA.

any suggestions?

Start your timing before any rendering, and at the end, call glFinish() and then end your timing after that returns.

On NVIDIA hardware, if you do a timing after glFinish, you will not get the actual rendering time but a multiple of the video frequency (assuming vsynch is on).
So for instance, if you do:

start = getClock();
glClear();
wglSwapBuffers();
glFinish();
frame_duration = getClock() - start;

you will get 16.66 ms (if your frequency is set to 60Hz)

what you should do is :

start = getClock();
glClear();
glReadPixels(1 pixel);
frame_duration = getClock() - start;
wglSwapBuffers();
glFinish();

you issue a blocking glReadPixels to force the GPU to rasterize all pending polygons. You do a timing right after that but before glFinish

i just realized the following will also work :

start = getClock();
glClear();
glFinish();
frame_duration = getClock() - start;
wglSwapBuffers();
glFinish();

I don’t understand why the second call to glFinish waits for the next vertical retrace and the first call does not.

Any ideas ?

Not the glFinish waits for vertical retrace, the wglSwapBuffers does.

i think you are wrong
i have tried :

start = getClock();
glClear();
wglSwapBuffers();
frame_duration = getClock() - start;
glFinish();

and i don’t get 60Hz but a much higher value.
this proves wglSwapBuffers is not blocking

>>I don’t understand why the second call to glFinish waits for the next vertical retrace and the first call does not.<<

I meant glFinish has nothing to do with vertical retrace. It just waits until OpenGL has finished rasterization.
Your measurements show that the wglSwapBuffers call doesn’t block by itself but will not happen until the next vertical retrace because the glFinish didn’t return until that swap “rasterization” had finished.

i think you are right !!

now i understand
thanks