I am trying to Implement resource manager for my hobby game engine. The problem I am trying to solve is that I want one centralized resource manager, which delegates resource loading to a bunch of "subsystems" which are each responsible for managing their own type of resource, like in the code below.
struct Resource {
std:: extensionType;
std::string path;
int refCount;
};
class ResourceLoader {
virtual ResourceType* loadResource(std::string) = 0;
virtual void unloadResource(ResourceType*) = 0;
};
class ResourceManager {
std::map<std::string, ResourceLoader*> _loaders;
void addResourceLoader(std::string extensionType, FileLoader* loader);
template<typename T>
T* loadResource(std::string filePath);
void reloadAll();
}
class TextureResource: public Resource {
TextureHandle* handle;
};
class TextureLoader: public ResourceLoader {
ResourceType* loadResource(std::string); //load + return a TextureResource
void unloadResource(ResourceType*); //unload texture
};
//Later on, to use:
int main(int argc, char* argv[]) {
ResourceManager resourceMgr;
TextureLoader textureLoader;
resourceMgr.addResourceLoader(textureLoader);
TextureResource* texture = resourceMgr.loadResource<TextureResource*>("SOMETEXTURE.PNG");
return 0;
}
This is just an example of my implementation. My problem shows up with more specific types of resources like Shaders. I want to store shaders as a ShaderSet or ShaderProgram ( in OpenGL every shader program has its own ID ), so when I am loading ShaderProgram, I need to specify at least vertex shader and fragment shader ( vertex filepath and fragment filepath ), but with my current logic I can't think of an elegant solution for this problem.
for example to have something like this:
T* loadResource(std::string vs_filePath, std::string fs_filepath);
I can't figure out how can I have ShaderProgram saved in the same resource manager class, any Ideas?