The classic standard answer for single-threaded games is to render first, then update game logic, and only then call your SwapBuffers
.
while (running) {
draw();
update_game_logic();
GL_SwapBuffers();
}
If you render first and then update game logic, the GPU can continue processing the submitted rendering commands while the game logic is updated on the CPU.
It's worth noting that really the important part there is to keep your draw
and SwapBuffers
calls far apart from each other. For example, if you really want/need to do your game logic in the beginning of the loop, you can actually SwapBuffers
before draw
(so you're syncing the previous frame before rendering the next frame).
while (running) {
update_game_logic();
GL_SwapBuffers();
draw();
}
control
function? Especially when you useOpenGL
, there are functions not meant for drawing (for example messing with matrices) that are being calculated on the GPU behind the scenes, at least when available. \$\endgroup\$