Render list + render thread

Started by
2 comments, last by dubplatecode 12 years, 12 months ago
I'm finding little information on organising render data and wondering what others do for this situation:

My game has a seperate render thread which renders a prepared visible list of world entities, each list item contains transformation & animation info for the entity.

It crashes when the game thread updates the object render list as the render thread is trying to use it.

To solve this I'm thinking of having two lists where one list is drawn while the other is updated on the other thread. Then flip and repeat.

Is this generally how others have solved this problem? Thanks
Advertisement
You could do it with two nice and easy, but that'll probably take up more memory etc. You could make the render call wait until the render queue is ready to be rendered and then fill up the render queue a frame before it gets used? So just after you've finished copying your queue to the graphics memory, you can set a flag to say that it is ready to be rendered and also set another to say that you can start filling up the queue again.

To solve this I'm thinking of having two lists where one list is drawn while the other is updated on the other thread. Then flip and repeat. Is this generally how others have solved this problem?
Yes this is one common solution - known as double-buffered data.
When you perform the flip, you need to ensure that the update thread has finished writing to it's buffer, and that the render thread has finished reading from it's buffer. You'll likely use one critical section for each buffer, so that each thread can lock one of them at a time. In order to perform the flip, one thread will have to lock both of them.

[color="#1C2837"]Check out Multicore Programming Two Years Later for some examples of double-buffered data, and other solutions.
Thanks Hodgman just what I needed! I like the idea of maintaining a smaller mirrored data set for the render thread ( just updating changes instead of preparing a whole list )

Good to confirm I'm on the right track.


This topic is closed to new replies.

Advertisement