Register renderables every frame?

Started by
14 comments, last by PAndersson 11 years, 9 months ago
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?
Advertisement

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.

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

You dont want to reupload/register data that doesnt change. Only update data that changes (like position).

o3o


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 :-)

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

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! :D
Reading, Reading, Reading... why do you read not more?
I have a blog: omercan1993.wordpress.com look there for more content
And I also do some art: omercan1993.deviantart.com
And whats about the Pear3DEngine? Never heard of it? Go and look!
Yeah, and currently I do this: SimuWorld

PS: Please look at this poll on my blog about scripting languages: A opinion poll about scripting language
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

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

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.
Don't thank me, thank the moon's gravitation pull! Post in My Journal and help me to not procrastinate!

This topic is closed to new replies.

Advertisement