0
$\begingroup$

I am updating my scene graph in response to user input and the network. What is the best way to do this? The updating threads are separate. Some approaches I am thinking about:

  • double buffer. There are 2 copies of the scene graph, one is used for rendering and the other for updates. The rendering graph is updated at the end of the render loop. This update can be expensive for a large graph,

  • synchronization objects, like mutices, probably unsuitable,

  • dumping updating functors into a FIFO queue while rendering, then executing the functors at the end of the rendering loop. Updating the queue may block.

Is there something better and which approach is best?

$\endgroup$
  • $\begingroup$ You should probably implement a push pull graph if you are cpu bound $\endgroup$ – joojaa Jun 11 at 21:24
  • $\begingroup$ Never heard of it. Are there examples or articles? $\endgroup$ – user1095108 Jun 12 at 4:25
  • $\begingroup$ A push pull graph does not actually update on changes. It pushes a flag that marks the graph element as needing to update (maya for example calls this flag a dirty bit, since the node attribute is dirty and needs washing). Instead the actual computation is pulled from the final nodes if needed. Causing the nodes to compute only when the downstream thing is needed. Thisway the graph self optimizes since it does not evaluate stuff that does not need to be updated. $\endgroup$ – joojaa Jun 12 at 5:16
2
$\begingroup$

A few more options:

  1. don't use a scenegraph. They don't map well to the data a gpu needs for rendering. A flat array of object tends to work much better for the cache as well

  2. separate the scenegraph into render-related data and non-render-related data. Then only double buffer the render-related data.

    The render related data would end up in a flat array containing per rendered object: reference to the mesh, the final model matrix, a reference to the texture

Flat arrays are much easier to double buffer than node-based data structures.

$\endgroup$
  • $\begingroup$ Is batching outdated? It uses a queue after all. I was thinking about abusing the batching queue for state updates? $\endgroup$ – user1095108 Jun 12 at 4:24
  • $\begingroup$ Batching is still recommended, however a scenegraph hinders efficient batching more than it helps. With a flat array of objects you can sort it so similar render commands end up next to each other. $\endgroup$ – ratchet freak Jun 12 at 9:54

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.