# Input before or after update/draw?

This is how I understood the game loop, and I wanted to know if I'm correct or not:

1) Draw/render -> input
CPU    |    GPU
------------------
Update |
Draw   |
Input  | Rendering

2) Input -> Draw/render
CPU        |    GPU
------------------
Input      |
Update     |
Draw       |
(nothing?) | Rendering


By rendering I mean updating the actual frame. What happens in the second case? Is the CPU doing nothing or is it checking input for the next frame already? Are there any differences from checking input before or after the update/draw part?

Whether you input, update, render or render, input, update is irrelevant. The loop will restart, so there is no difference. Same with whether you input, update, draw or update, draw, input(which becomes input, update, draw under the same logic). Now, if your blocking at the end for a swap or frame-sync, then you may have input lag to rendering if you receive input before the waiting.

Hence, I always input, update, and then render.

• Well, that was my point, at the end there is a swap (see GPU rendering part), so based on this I was wondering if there were any differences... – Xriuk May 17 '16 at 15:48
• @Xriuk Yes, you could end up with input lag, if you receive input only before waiting. – JavaProphet May 17 '16 at 16:24
• Does the swap wait until GPU has finished? – Xriuk May 18 '16 at 12:34
• @Xriuk SwapBuffers literally swaps the buffers. The GPU has been rendering asynchronously, into a non-visible buffer(assuming your using double-buffers), which will be swapped to the screen. Since the GPU is rendering asynchronously, if it's not complete, SwapBuffers will wait for the GPU. – JavaProphet May 18 '16 at 13:55

If i was you, i should multithread the whole thing, having a renderthreat and a enginethreat or whatever you want to call it

• In my opinion that would be useless. Since every step is directly linked to the following. – Xriuk May 25 '16 at 16:42
• If you want to have a high framerate, i shouldn't include the input in a frame – Maxim DC May 25 '16 at 19:38
• I have input in my engine being part of everything and sequentially blocking, and I still reach 4000+ fps with many triangles on the screen. You will not notice the input at all unless you're doing something very wrong. – Water Mar 15 '19 at 20:57