Register renderables every frame?
I was wondering if it is a good idea to design the rendering system so that each game entity and interface element that should be rendered registers its visual representation every frame, or should they register and unregister as appropriate? Give that the objects typically change a lot, as their positions move and the like, I'd imagine that first option would result in simpler logic and better performance. Or am I completely wrong with how rendering systems usually are designed here?
I was wondering if it is a good idea to design the rendering system so that each game entity and interface element that should be rendered registers its visual representation every frame, or should they register and unregister as appropriate? Give that the objects typically change a lot, as their positions move and the like, I'd imagine that first option would result in simpler logic and better performance. Or am I completely wrong with how rendering systems usually are designed here?
Do you mean, for example, when an entity goes off the screen, it un-registers with the rendering system, and when it comes back on screen, it re-registers? It probably depends on how many renderable entities you have. If you have thousands, then you would probably save some cycles by not loping through every entity in the rendering system.
Otherwise, I think it might be worse to unregister and re-register considering you would have to check if the object is on-screen every loop anyway, you' just adding more steps to the process.
You dont want to reupload/register data that doesnt change. Only update data that changes (like position).
You dont want to reupload/register data that doesnt change. Only update data that changes (like position).
I'm not talking about reuploading entire meshes/textures, but perhaps re registering references to them.
The principle holds, though: if the object isn't actually definitely going away (or appearing), don't bother with changing its registration status. Do as little work as possible :-)
I suggest to register your meshes once and to unregister them when it is really necessary (i.e. mesh is destructed). Split your game entity into several parts. It doesn't needs to be one class and also allows multiple and shared meshes on one entity.
Register many things as possible and use dynamic allocation as less as possible. I think you don't want to have a memory bottleneck because you add or remove something from a list (when you use one) EVERY FRAME!
But use a unregistered scheme for something little or something who appears and disappears very fast like a debug system.
I use this approach and liked it. Try it!
Register many things as possible and use dynamic allocation as less as possible. I think you don't want to have a memory bottleneck because you add or remove something from a list (when you use one) EVERY FRAME!
But use a unregistered scheme for something little or something who appears and disappears very fast like a debug system.
I use this approach and liked it. Try it!
Normally "renderable" are registered when they come into existance and then each frame are visiblity tested to see if they should be submitted for rendering or not.
Objects should not be registered and unregistered.
Firstly, how often would you do this registration?
If not often enough, objects will be drawn even though they have drifted off the screen, and other objects have drifted onto the screen will not be drawn for a while and then suddenly appear on-screen.
If you register and unregister as often as is truly necessary then you have not saved any time.
Instead, use a spatial partitioning scheme such as an octree for 3D and quadtree for 2D (these can be exceptionally fast if done properly—instant insertion time, no node searching, no cache misses, no recursion) and process it every frame.
Only moving objects will register and unregister with the quad- or oc- tree, and this is done every frame, but insertion should be instantaneous, and the same quad- or oc- tree can be used for multiple subsystems, from graphics to collision detection.
L. Spiro
Firstly, how often would you do this registration?
If not often enough, objects will be drawn even though they have drifted off the screen, and other objects have drifted onto the screen will not be drawn for a while and then suddenly appear on-screen.
If you register and unregister as often as is truly necessary then you have not saved any time.
Instead, use a spatial partitioning scheme such as an octree for 3D and quadtree for 2D (these can be exceptionally fast if done properly—instant insertion time, no node searching, no cache misses, no recursion) and process it every frame.
Only moving objects will register and unregister with the quad- or oc- tree, and this is done every frame, but insertion should be instantaneous, and the same quad- or oc- tree can be used for multiple subsystems, from graphics to collision detection.
L. Spiro
Is adding a bunch of objects to a list every frame really going to cause performance issues? You don't need to allocate space for the array every frame, you could have an array that grows (like a variant of std::vector, or just use that). Besides, you could have one renderable for a set of instanced meshes if you're going to have tons of similar objects onscreen.
Is adding a bunch of objects to a list every frame really going to cause performance issues? You don't need to allocate space for the array every frame, you could have an array that grows (like a variant of std::vector, or just use that). Besides, you could have one renderable for a set of instanced meshes if you're going to have tons of similar objects onscreen.
In a word, no. Filling a preallocated list is incredibly cheap on modern hardware. It's an O(n) operation but you can cut down on that N by using some culling in the scene. What might be more of a concern is the order that things are added, because you might want to batch things up according to their material, or their mesh, etc. 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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement