I'm programming a video software where I'm using Qt's QGLWidget to show the frames with the following code:
Code :glTexImage2D(GL_TEXTURE_2D, 0, (color ? GL_RGB8 : GL_LUMINANCE8), VIDEO_WIDTH, VIDEO_HEIGHT, 0, (color ? GL_RGB : GL_LUMINANCE), GL_UNSIGNED_BYTE, (GLubyte*)imBuf); glBegin(GL_QUADS); glTexCoord2d(0.0,0.0); glVertex2d(-1.0,+1.0); glTexCoord2d(1.0,0.0); glVertex2d(+1.0,+1.0); glTexCoord2d(1.0,1.0); glVertex2d(+1.0,-1.0); glTexCoord2d(0.0,1.0); glVertex2d(-1.0,-1.0); glEnd(); updateGL();
I want to use vsync so I set a swapInterval of 1. I measured the time to execute the code above. As expected updateGL takes about 16ms to execute. What puzzles me is that glTexImage2D also takes 1..16ms time to execute as if it was waiting for VBLANK signal as well. When I turn vsync off with swapInterval of 0, glTexImage2D only takes about 1 ms to execute. Now, instead of the 16ms delay for the whole program vsync is supposed to give me, I get 32ms of delay at worst. I don't understand why updateGL and glTexImage2D both wait for VBLANK. I want to have as little delay as possible so could someone explain what is going on here?