I'm working on a framework that can be used to develop 3d applications in opengl (with the intention of updating to use vulkan in the future). The basic idea is that the user initializes the App in main(), adds an initial scene, then controls the flow of the application from the scenes they compose, abstracting away the logic required for the fixed timestep loop, model loading, gpu rendering, etc. A quick outline is as follows:
> App (singleton responsible for managing window, input, and kicking off the main loop)
> Scene (collection of stages)
> Stages
> Camera (base class for PerspectiveCamera and OrthographicCamera)
> Meshes (Stage owns unique instances of meshes and hands out pointers, ie 10 props could share the same mesh)
> Props (are transformable)
> Mesh (pointer to mesh managed by stage)
> Renderable (tracks gpu state and draws mesh) (optional as not required if headless)
> Actors (are transformable and animatable) (not currently implemented)
I have a working example of the basic features and wanted to get some feedback before I get too carried away. My main concerns are as follows:
1. My usage of a singleton pattern to express the App object. It made sense to me at the time to implement this using a singleton since there can only ever be one instance of the App, however from the research I have been doing many people say not to use singletons and that almost everywhere they are used, a better solution could be implemented. Does anyone know of a better way for me to handle my App object, or is my current usage of the singleton pattern acceptable in this scenario?
2. In an effort to NEVER use "new" (except in the above singleton) I create and move several `unique_ptr`s. I chose to use `unique_ptr`s vs `shared_ptr`s to express that the object which owns the pointer is responsible for it's lifetime. For example, my `Stage` object contains a `meshes` member which is a vector of `unique_ptr`s to `Mesh` instances. When instantiating a `Prop`, I obtain the raw pointer from one of these `unique_ptr`s as the and save it as a member of `Prop`. My reason for doing this as opposed to using a `shared_ptr` is that the lifetime of the `Mesh` is managed by `Stage` and a `Prop` will never outlive it's `Stage`. Am I correct to implement this in the way that I have, or should I be using `shared_ptr` instead?
Also curious to know if there is anything that sticks out to anyone that is horribly wrong or could be better implemented.
The project is live on github. You should be able to download and open in visual studio without any issue as I have included all required dependencies. Please let me know if you have any issues: https://github.com/useless3d/useless3d
The name is meant to be a joke, and will be changed in the future if this project actually becomes “Useful”