Hello, (new to openGL)
I’m finding glutSwapBuffers() function a bit slow in some circumstances. I would like to try with equivalent commands in plain GL but I could not find them.
Can someone give me some help/directions on that ?
(I’m using Ruby just in case language implementation became important).
swapping buffers is not slow, check doing a glFlush right before.
Well, glFlush() before glutSwapBuffers() did not improved.
Let me explain my scenario:
- The model is a simple 35500 vertex rendered as GL_POINTS.
- My machine needs 30 ms to render those points in a non-buffered view (GLUT_SINGLE) using just the CPU.
- Needs only 0.15 ms in a non-buffered view but now using the GPU (via glNewList(x, GL_COMPILE).
- 30 ms in a buffered view (GLUT_DOUBLE) with CPU.
- 17 ms buffered view with GPU.
- 17 ms to render nothing in a buffered view (just simple execution of the glutSwapBuffers).
And doing a glFlush right before does not change these numbers.
Am I missing something or doing something wrong ?
The actual cost of swapping buffers is negligible.
What you see is probably an effect of vsync. Before doing benchmarks, disable it, otherwise you only measure your display refresh rate.
ie : 1 s /60 Hz = 16.667 ms
Bingo! Thank you very much.
Turning off vsync resolved my “issue”.
“swapping buffers is not slow, check doing a glFlush right before”
Yeah, but doesn’t glutSwapBuffers() block until all previously sent data flows out of the rendering pipeline and into the frame buffer before swapping?
My mistake, I meant glFinish().
Normally swapbuffers implies glFlush(), not a glFinish(). Of course the implementation can do a glFinish() instead.
What happens is that the card can buffer a bunch of GL commands before blocking, so you can already have submitted multiple frames without blocking, and before they are actually drawn.