0

I'm programming a video software where I'm using Qt's QGLWidget to show the frames with the following 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?

genpfault
  • 51,148
  • 11
  • 85
  • 139
user2563661
  • 314
  • 1
  • 3
  • 13
  • Don't use the double-precision version of GL API calls. Granted immediate mode is not going to give you reasonable performance to begin with, but making the driver convert from double-precision to single-precision for no reason is equally bad form. GL creates the illusion that double-precision is supported throughout the pipeline by offering double-precision API functions, but on most hardware and GL implementations this could not be farther from the truth... use `glTexCoord2f` and `glVertex2f` instead. – Andon M. Coleman Nov 19 '13 at 22:58

1 Answers1

2

glTexImage2D is a very expensive call, as it reinitializes the whole texture object from scratch. For just updating video texture images use glTexSubImage2D which is much faster. You can combine it with a Pixel Buffer Object to allow OpenGL even more asynchronous operation.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • glTexSubImage2D also takes from 1ms to 16ms to execute as if waiting for VBLANK. I don't think the problem here is that glTexImage2D is an expensive call. It seems that glTexImage2D/glTexSubImage2D is vsynced although I only want to have updateGL vsynced. – user2563661 Nov 20 '13 at 09:55