Jump to content
  • Advertisement
Sign in to follow this  

Scene graph rendering

This topic is 799 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts



I'm writing a game (and its corresponding engine) at the moment where every game object is represented in a scene graph. At the top there's the root node, which may have an infinite number of child nodes (each having recursively infinute number of child nodes). As of now, the camera (represented by a view and projection matrix) is owned by the scene manager, and is passed down on to the components (rootNode->childNodes->entities->components->update(), causing the information to be sent not only to the relevant components) using their respective update methods. I would however want to represent the camera as a regular entity.

The whole thing is (obviously) designed using ECS, where each entity has a set of components. I can update everything just fine, but the tricky part is the rendering. Should each renderable entity have its own rendering component responsible for calling the core rendering system (pretty much an OpenGL abstraction layer) or should a separate system iterate the scene graph and sort the entities by type (i.e. cameras, static meshes, animated meshes, lights, etc) and then be responsible for passing the data to the core rendering system?

I'm sketching on a solution which looks like this:

  • The main loop is responsible for updating each and every entity (and its components) recursively. This update include (amongst other) updating position, recalculating model matrices and whatnot. This is already implemented and working fine.
  • Then (if the main loop thinks there's enough time) it calls the draw method in the rendering system. The draw method sorts everything as described above, and sends the proper data to the OpenGL wrapper.

This solution works fine in my head, despite slipping away from the ECS pattern (if I've understood it correctly).


You see, the problems I'm having with ECS is that I'm not sure how a component of an entity is supposed to keep track of the necessary view and projection matrices that are needed for rendering. I also can't grasp how to decouple updating (i.e. movement, collisions, etc) from drawing if they're part of the same entity.


What do you guys think? Should I go on implementing my solution, or should I try to stick with as pure ECS as possible (and if so: how?)? What's the pros and cons of these two designs?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!