2
\$\begingroup\$

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?

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ 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... \$\endgroup\$ – Xriuk May 17 '16 at 15:48
  • \$\begingroup\$ @Xriuk Yes, you could end up with input lag, if you receive input only before waiting. \$\endgroup\$ – JavaProphet May 17 '16 at 16:24
  • \$\begingroup\$ Does the swap wait until GPU has finished? \$\endgroup\$ – Xriuk May 18 '16 at 12:34
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ – JavaProphet May 18 '16 at 13:55
-1
\$\begingroup\$

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

\$\endgroup\$
  • \$\begingroup\$ In my opinion that would be useless. Since every step is directly linked to the following. \$\endgroup\$ – Xriuk May 25 '16 at 16:42
  • \$\begingroup\$ If you want to have a high framerate, i shouldn't include the input in a frame \$\endgroup\$ – Maxim DC May 25 '16 at 19:38
  • \$\begingroup\$ 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. \$\endgroup\$ – Water Mar 15 at 20:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.