I'm creating my own drawing library in C++ to provide shared rendering code for my projects.
Since the library is designed to be used as a component of other projects, the renderer's representation of 3D objects and scenes will be "attached" to whatever the program's native representation of an "object" or "scene" is. Then, the renderer will use this scene information to draw all the objects.
There are two approaches I could go with. The first approach would involve assigning each drawable object in my program (for this example, let's call our program's objects ProgramObject
) a Drawable
member from the drawing library. Then, whenever a ProgramObject
is created, it gets added to a list in an instance of the program's "scene" class (let's call this one ProgramScene
), which can then add the ProgramObject
's Drawable
member to it's DrawableScene
member. The ProgramScene
can register its DrawableScene
with the renderer for drawing. A Drawable
contains information such as mesh data, materials, etc. The renderer consumes Drawable
s from a DrawableScene
and uses them to construct a frame in OpenGL.
The second approach would be mostly the same, except instead of ProgramObject
and ProgramScene
having Drawable
and DrawableScene
members, ProgramObject
and ProgramScene
would inherit from Drawable
and DrawableScene
respectively.
Which approach would be better?