Monday, November 7, 2016

rendering - does order of updates and renders matter?



I know in a game loop there needs to be an order like physics should update before rendering. So, I have created two separate functions: update and render and the game loops like below:


while(running) {
clock.reset();
for(auto system : systems) {
system->checkForInput();
system->update(clock.getElapsedTime());
}

for(auto system : systems)
system->render();

}

Some systems have empty render function or empty update functions.


My question is, does the order of updates or renders matter? would it matter if gui is rendered before graphics, or input is updated after physics?



Answer



It's easiest to think of your order in a single frame, think of it as a series of dependencies.



  • User input depends on nothing, so it goes first.

  • Objects being updated depend on the user input, so they go second.

  • Physics depend on the new updated objects, so it goes third.


  • Rendering depends on the latest physics state and object updates, so it goes fourth.

  • UI depends on the scene to already be rendered, so it goes fifth.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...