I've seen this mentioned a lot in the past (and again more recently by L. Spiro in this thread) where you take advantage of temporal coherence between frames so that you don't have to perform a full re-sort (I'm not sure what the best terminology for this is) on the queue. The idea being that between frames, objects will be more or less in the same order as such a small time has passed.
But how is this achieved? If you use your already sorted list, how do you know which (renderable) objects in the list should be removed (e.g. because they were culled)?
My first idea would be something like this:
- Iterate through sorted list, check if culled. If not, keep it. If it is, remove it.
- Traverse through spatial tree (or however your scene is partitioned) and add objects which need rendering - have to check list for duplicates though!
- Then we can sort the queue.
But step 2 doesn't seem very efficient if you have to iterate the list a load of times to check if the object already exists.
As I write this, I realise you could add two extra fields to each of the objects to say in which frame it was last rendered, and when in which frame it was last removed. Then checking for existence in the list can be a simple lastRenderedFrame == currentFrame - 1 && lastRemovedFrame < currentFrame. You'd also need to update the lastRenderFrame field when you add it to the queue (step 2), and update the lastRemovedFrame when you removed from the queue (step 1).
Am I on the right sort of lines?