I am having some difficulty understanding the Panda3D main loop and task manager.
I have a shader attached to an object that takes an input through the setShaderInput command. I want to be able to alter the argument to setShaderInput each frame and have the result displayed the next frame.
Therefore I want the following sequence:
Task runs - updates shader input to 0
Shader(0) displays
Task runs - updates shader input to 1
Shader(1) displays
However I am currently experiencing a delay between when I set the argument to the shader with setShaderInput and when the frame is rendered.
I am used to programming with a display and update loop where it is well known when swapBuffers is called and I am quite confused about the order of these operations in Panda.
If I create a task in Panda will it run exactly once every frame, before the current frame is drawn?
If I change a value on setShaderInput will this affect the shader in the next frame?
When debugging through panda code, if I set a breakpoint is the current frame being rendered the frame that is visible?
The simple answer is that Panda does all of its rendering during the “igloop” task, which is given a sort value of 50 so it occurs at the end of the frame (you can view all the tasks in order by printing taskMgr). Thus, it is true that any values you set in your tasks will be immediately rendered by Panda before the next iteration of the task is executed.
However, the thing that may be tricking you here is the flip. This is the moment when Panda swaps the front buffer for the back buffer, making the results of the previous frame’s draw operation visible. By default, Panda does not perform the flip until the beginning of its igloop task, which means that each frame, you are viewing the results of the previous frame. This is actually a very important optimization–it means that all of your tasks can be executing in parallel with your graphics card, to potentially achieve a higher frame rate, depending on several properties.
But, you can turn off this behavior and ask Panda to perform the flip at the end of the igloop task, which means that the results of the drawing are made visible immediately. To do this, add the following to your Config.prc file: