opengl: glFlush() vs. glFinish()

前端 未结 8 1325
感情败类
感情败类 2020-12-02 06:40

I\'m having trouble distinguishing the practical difference between calling glFlush() and glFinish().

The docs say that glFlush()

8条回答
  •  一个人的身影
    2020-12-02 06:58

    I was always confused about those two commands too, but this image made it all clear to me: Apparently some GPU drivers don't send the issued commands to the hardware unless a certain number of commands has been accumulated. In this example that number is 5.
    The image shows various OpenGL commands (A, B, C, D, E...) that have been issued. As we can see at the top, the commands don't get issued yet, because the queue isn't full yet.

    In the middle we see how glFlush() affects the queued up commands. It tells the driver to send all queued up commands to the hardware (even if the queue isn't full yet). This doesn't block the calling thread. It merely signals the driver that we might not be sending any additional commands. Therefore waiting for the queue to fill up would be a waste of time.

    At the bottom we see an example using glFinish(). It almost does the same thing as glFlush(), except that it makes the calling thread wait till all commands have been processed by the hardware.

    Image taken from the book "Advanced Graphics Programming Using OpenGL".

提交回复
热议问题