In the past, I've used std::multimap to sort things by their material, where materials consist of a pair of shaders, and a list of textures.
For a small game, the multimap solution (with a predicate based on the shader ID and then the texture ID's ) is plenty fast.
There's no longstanding registration/link between renderable objects and the renderer.
There is a better way this can be done which takes advantage of temporal coherence.
In my system, objects register just the information needed for sorting to a render queue (this part is standard in every rendering system). The objects will often register this data in the same order every frame since I am walking the octree (etc.) the same way every time.
This data is not sorted directly.
The render queue class responsible for sorting this data instead sorts indices into this data.
This improves sort bandwidth since I am only copying 32-bit values instead of structures, but it also allows temporal coherence.
The indices are not cleared every frame. If more objects appear, the indices for those objects are added to the end of the otherwise sorted indices.
If there are fewer objects, the indices are reset back to 0 1 2 3, etc.
And if the number of objects is the same the indices are left as-is.
Then an insertion sort is done over the indices.
In most cases the indices will already be in sorted order or at least very close, so this system outperforms quick sort and merge sort in virtually all situations.
This basically provides a way to submit objects to the render queue in any order, and as long as that order is mostly consistent then you can take advantage of temporal coherence.
I also keep multiple render queues. One for each shadow-casting light (shadow maps), one for opaque objects in the main render, one for alpha objects in the main render, etc.
Just because spatial partitioning schemes can be used to accelerate rendering does not mean that is all they can do.There is no physics API able to return a list of visible items? O_O
In fact the actual system is completely unrelated and disconnected to/from rendering. When you “query” an octree for a list of objects within some kind of bounding area, the octree has no idea why you are asking for that list or what you intend to do with it. If you intend to use it as “a list of things in view” then fine. If you intend to use it as “a list of things that could potentially be in contact with a given object” then fine.
L. Spiro