PDA

View Full Version : Code Organization



Ruggero Visitnin
09-11-2014, 01:05 PM
hi all,
i know that is not an Opengl related answer but i want to organize my resources like shaders, meshes, textures, materials... and so on, how can i organize a class in cpp in order to make order in my code and start doing things seriously?
i thought to something like:


ResourceManager
-Mesh
-Material
-Texture

-Shader

-Camera

-Light

how can i obtain a well ordered code (it is not bad for now but i want to do things well)?

Godlike
09-11-2014, 03:31 PM
I organize my resources like this:


Mesh (VBOs)
Shader
Texture
Material

N * Texture
N * Shader


Model

Mesh
Material




In the above scheme some resources "own" other type of resources.

The cameras and lights are part of another hierarchy, the scene graph.

Ruggero Visitnin
09-11-2014, 04:57 PM
thanks, i think code organization is very important to build good applications.
i was watching your engine, good job, how much time did you spend on this?

EDIT:
ok now that i have a clean ResourceManager header so what about the Scene Graph? what is the hierarchy?
thanks advance.

Godlike
09-12-2014, 06:58 AM
thanks, i think code organization is very important to build good applications.
i was watching your engine, good job, how much time did you spend on this?

EDIT:
ok now that i have a clean ResourceManager header so what about the Scene Graph? what is the hierarchy?
thanks advance.

Thanks. I am working on it whenever I have free time for the last ~7 years.

About the scene graph. Scene graph is one of the most weird things to get right. After re-writing it a found a design that I am mostly happy with. That design is "component based" and the bases of this design are the "scene nodes" and the "components".

The scene node, roughly, is an object hierarchy that connects it with other nodes. It also contains a list of components.

The components define the properties of the scene node. Example components are the MoveComponent, FrustumComponent (essentially defines an object that has a frustum), RenderComponent and others. For example, a movable model is a scene node with MoveComponent and RenderComponent. A static model is a scene node with a RenderComponent. A camera is a node with FrustumComponent and MoveComponent. A light with shadow is a node with FrustumComponent, LightComponent and MoveComponent.

Every component has a specific job in the pipeline. For example, on visibility tests I iterate the scene nodes that have a RenderableComponent or a LightComponent and I determine the visible ones. The list of visibles will be used by the renderer later on.

Hope that helps

Ruggero Visitnin
09-12-2014, 07:29 AM
thanks you are helping me a lot, i got the point but i did not implemented this elements in my engine yet, for now i will keep my Scene Graph as it is: basic light and camera components.

last thing i swear (i don't wont to waste your time)
if in my engine i have classes like PickManager or ObjParser and so on, to what kind of hierarchy they belong?

Godlike
09-12-2014, 08:47 AM
It's OK.

Maybe PickManager is a helper of the SceneGraph since it interacts with it closely.

The ObjParser is a helper class used by the Mesh. In my case that job is done by the MeshLoader.

Ruggero Visitnin
09-12-2014, 12:47 PM
ok thanks a lot i have a lot of work to do