I've read everything I could find on these things, and I'm starting to implement this and questions are arising. Sometimes I find typing all this out helps get my head in order...A lot of this might be duplicates of prior threads asked in a different way and much of it will be just plain hypotheticals... Without further ado...
I am using SFML and want to sort by texture, and then by depth (really layer, since this is a 2d game).
So. I can store all the sf::Drawables in a vector (that gets filled by the scenegraph/culling/whatever system).
std::vector<sf::Drawable> allOpaqueDrawables; std::vector<sf::Drawable> allAlphaDrawables;
Should these be pointers to the drawable which is instead stored in the game objects themselves?
Should there be a master list of all drawables in the game that "owns" them, letting both the game object and these "sub-drawables-within-the-scene" use pointers to this master list?
Some other third option?
Now, I need to sort this. So I can make a render queue which is just indicies into the vector of all drawables.
I'm not positive how to implement this... a first try might be something like:
std::map<sortKey, int16_t> renderQOpaque; std::map<sortKey, int16_t> renderQAlpha; // with sortkey being a POD integer type built from the texureID and layer value of the drawable
I guess the idea is that the small int16 keys are the only thing that needs to be copied around to sort the map?
1) Is this a sane way of doing this part?
2) Is std::map a reasonable choice for the implementation?
Then the map can be iterated through taking the int16_t as indicies into the vector allDrawables to call draw() on each one.
A few problems:
1) Where to store and generate the sortKey, if it needs to be stored at all?
a) I need an integer representation of a texture.
b) (At least part of) the sortKey needs to be updated if the objects layer (depth) changes.
My texture storage assigns a unique integer ID number and prevents duplicates from loading. Does it make sense to actually store this value in the texture? Right now it is only kept in the texture storage (as a std::map<texID, sf::Texture>).
I could inheret from sf::Texture and create a version that contains the texID. Unnecessary?
SFML uses an sf::Drawable which contains the geometry to be drawn as well as the "rules" to draw it (actual draw() call).
It also uses an sf::RenderStates which holds...
2) *Shader (if used)
Since this RenderState holds damn near everything I need to generate the sortKey, it almost sounds reasonable to create my own RenderStates which derives from sf::RenderStates so that I can contain the sortKey in it and regenerate the sortKey anytime one of those three items are changed. Yea/Nay?
I realize most of this is just my thinking out-loud/rambling. Any feedback is appreciated.