So I have a rendering engine, and I have a resource manager that adds classes that derive from type 'Resource'. It's a very flexible and generic resource manager, of which only one can exist (it is a static class). Thus, a class
Camera can easily be added like so:
rm::add("textShader", new ShaderProgram("assets/shaders/renderText.vert", "assets/shaders/renderText.frag", true, true)); rm::add("fpsCamera", new FPSCamera(glm::vec3(0.f, 0.f, 20.f), 45.f, 4.f / 3.f, 1.f, 1000.f));
Now, this may seem quite straightforward; but a theoretical question I ask myself is: when is a resource a resource? How does one differentiate between something that ought to be stored (e.g. a resource) vs. something that should not be stored (e.g. non-resource)?
For instance, I know that I will be using my
Camera as well as
Texture (all of type
Resource) a lot. In order for me to get the explicit type of a Resource, I do the following:
convert(Camera*, rm::get("fpsCamera"))->func(); // call Camera's func()
Thus, I know that it if I need to reuse something over and over again I would have to store it in the resource manager.
When it comes to another class, however, it gets a bit more complicated. I have two other classes:
Scene. The relationship between the two is very intimate insofar that a
Renderable is an abstract class for renderables such as
Model etc; and
Scene is simply a container of a number of
Renderables. Thus, in a graphics application it is likely that I will be loading scenes and unloading them to free up resources when required. But I am not sure whether Renderable should derive from type
Resource or whether
Scene should derive from type
Resource (thereby calling
Scene a resource) or whether both should simply be a Resource. If a
Renderable were a resource then that means it can be accessed by anyone as easy as:
Now before you yell at me about type-safety in the above function, I'd like to reassure everyone that the compiler checks against the type and sees if the called function is resolved. It's a
dynamic_cast after all.
Anyway, the dilemma thus continues and at first thought I can only assert that
Renderable could be a Resource only IF we want to reuse the renderables in question. Thus, if I were to add a
Model to the resource manager then that means it is available everywhere in the program. But, it can't be retrieved unless you know the ID of that Resource. Thus, it is entirely possible for me to reuse a
Model object to replace an existing Mesh inside it.
Without getting too technical, I again ask the simple question: When is a resource a resource, and where do we draw the line?