Core::ResourceManager
Resource manager for loading resources from the filesystem. More...
#include "Core/Resources/ResourceManager.h"
Inherits from Module, IStateful
Public Classes
| Name | |
|---|---|
| struct | ModelSaveEntry |
Public Functions
| Name | |
|---|---|
| ~ResourceManager()<br>If true loaded models will be normalized. | |
| bool | cleanUpModelFiles(State::Scene * scene)<br>Ensure there are no unused model files in the scene_data directory of the passed scene. |
| virtual void | clearGlobal() override<br>Set the global state to some default empty state. |
| virtual void | clearScene() override<br>Set the scene state to some default empty state. |
| std::vector< ModelSaveEntry > | deserializeModels(const rapidjson::Value & modelsEntry) |
| std::vector< Resource > | getDefaultResources(ResourceType type)<br>Returns default resources of type. |
| std::vector< std::string > | getImportedResourceAliases() |
| bool | importModel(const fs::path & path, bool normalize) |
| void | loadDefaultResources(rapidjson::Document & doc)<br>Loads resources from the a json document and marks them as default. |
| virtual void | loadGlobal(const Memento & memento) override<br>Load global state from a memento. |
| virtual void | loadScene(const Memento & memento, State::Scene * scene) override<br>Called on scene load, undo and redo. |
| Mesh * | mesh(const std::string & alias, const std::string & path)<br>Get or create model by alias or file. |
| Mesh * | mesh(const std::string & alias, Mesh::PrimitiveType primitiveType, const float * verts, const unsigned int nVertices, const float * colors, const unsigned int nColors)<br>Get model by alias or create it using provided vertex data. |
| Mesh * | mesh(const std::string & alias, Mesh::PrimitiveType primitiveType, const float * verts, const unsigned int nVertices, const unsigned int * indices, const unsigned int nIndices, const float * colors, const unsigned int nColors)<br>Get model by alias or create it using provided indexed vertex data. |
| Mesh * | mesh(const std::string & path)<br>Get or create model from file. |
| Mesh * | meshByAlias(const std::string & alias)<br>Get existing model using an alias. |
| void | registerDefault(const std::string & alias)<br>Register an alias as a "default" resource. |
| bool | removeImportedModel(const std::string & alias) |
| bool | removeResource(ManagedResource * managedResource, bool force =false)<br>Dispose the specified resource and remove it from the manager. |
| bool | resourceExists(size_t id) |
| bool | resourceExists(std::string & alias) |
| virtual Memento | saveGlobal() override<br>Save shared global state. |
| virtual Memento | saveScene(State::Scene * scene) override<br>Save state for the current scene. |
| void | serializeModels(std::vector< std::string > modelAliases, Scene * scene, rapidjson::Value & targetArr, rapidjson::Document::AllocatorType & a) |
| GLuint | shader(const std::string & alias, const std::string & vertShader, const std::string & fragShader)<br>Get or create shader by alias or files. |
| GLuint | shader(const std::string & vertShader, const std::string & fragShader)<br>Get or create shader from files. |
| GLuint | shaderByAlias(const std::string & alias)<br>Get existing shader using an alias. |
| GLuint | shaderG(const std::string & alias, const std::string & vertShader, const std::string & fragShader, const std::string & geoShader)<br>Get or create shader by alias or files. |
| GLuint | shaderG(const std::string & vertShader, const std::string & fragShader, const std::string & geoShader)<br>Get or create shader from files. |
| GLuint | texture(const std::string & alias, const std::string & path)<br>Get or create texture by alias or path. |
| GLuint | texture(const std::string & path)<br>Get or create texture for file path. |
| GLuint | textureByAlias(const std::string & alias)<br>Get existing texture using an alias. |
| void | updateModelFiles(State::Scene * scene)<br>Ensure that model files required by the scene are in the right place. |
| ResourceManager & | instance() |
Public Attributes
| Name | |
|---|---|
| bool | m_forceMinimumLoad <br>If true any resource fetches will not be cached. |
| bool | m_forceModelNormalize <br>If true just the bare minimum of resources is loaded. |
| bool | m_forceReload |
Additional inherited members
Public Functions inherited from Module
| Name | |
|---|---|
| Module() =default | |
| virtual | ~Module() =default |
| virtual void | onBeginFrame() |
| virtual void | onClose() |
| virtual void | onEndFrame() |
| virtual void | onInit() |
| virtual void | onUpdate(double deltaSeconds) |
Friends inherited from Module
| Name | |
|---|---|
| class | Application |
Public Functions inherited from IStateful
| Name | |
|---|---|
| virtual | ~IStateful() |
| Memento | emptyMemento()<br>Create an empty memento (rapidjson::Document) |
Detailed Description
class Core::ResourceManager;class Core::ResourceManager;Resource manager for loading resources from the filesystem.
Can be accessed from a singleton ResourceManager::instance()
Currently loads and manages models, shaders and textures.
Models are loaded using assimp or created directly from vertex arrays.
Resources are uniquely identified using a hash. Usually a hash of their file path string. Each resource can have an alias. A single string using which it can be retrieved. Aliases cannot be reassigned and point to a single resource type.
Finally a resource can be marked as default and returned using getDefaultResources().
An RM define is provided to shorten "Core::ResourceManager" An RMI define shortens "Core::ResourceManager::instance()"
Public Functions Documentation
function ~ResourceManager
~ResourceManager()~ResourceManager()If true loaded models will be normalized.
function cleanUpModelFiles
bool cleanUpModelFiles(
State::Scene * scene
)bool cleanUpModelFiles(
State::Scene * scene
)Ensure there are no unused model files in the scene_data directory of the passed scene.
function clearGlobal
virtual void clearGlobal() overridevirtual void clearGlobal() overrideSet the global state to some default empty state.
Reimplements: IStateful::clearGlobal
function clearScene
virtual void clearScene() overridevirtual void clearScene() overrideSet the scene state to some default empty state.
Reimplements: IStateful::clearScene
function deserializeModels
std::vector< ModelSaveEntry > deserializeModels(
const rapidjson::Value & modelsEntry
)std::vector< ModelSaveEntry > deserializeModels(
const rapidjson::Value & modelsEntry
)function getDefaultResources
std::vector< Resource > getDefaultResources(
ResourceType type
)std::vector< Resource > getDefaultResources(
ResourceType type
)Returns default resources of type.
function getImportedResourceAliases
std::vector< std::string > getImportedResourceAliases()std::vector< std::string > getImportedResourceAliases()function importModel
bool importModel(
const fs::path & path,
bool normalize
)bool importModel(
const fs::path & path,
bool normalize
)function loadDefaultResources
void loadDefaultResources(
rapidjson::Document & doc
)void loadDefaultResources(
rapidjson::Document & doc
)Loads resources from the a json document and marks them as default.
The json document must contain an "defaultResources" entry.
function loadGlobal
virtual void loadGlobal(
const Memento & memento
) overridevirtual void loadGlobal(
const Memento & memento
) overrideLoad global state from a memento.
Parameters:
- memento New global state
Reimplements: IStateful::loadGlobal
function loadScene
virtual void loadScene(
const Memento & memento,
State::Scene * scene
) overridevirtual void loadScene(
const Memento & memento,
State::Scene * scene
) overrideCalled on scene load, undo and redo.
Parameters:
- scene The current scene or nullptr (in case of undo/redo)
- memento New scene state
Reimplements: IStateful::loadScene
function mesh
Mesh * mesh(
const std::string & alias,
const std::string & path
)Mesh * mesh(
const std::string & alias,
const std::string & path
)Get or create model by alias or file.
Return: Pointer to the Mesh object.
Necessary textures might be loaded as well. Alias is assigned if it doesn't exist.
function mesh
Mesh * mesh(
const std::string & alias,
Mesh::PrimitiveType primitiveType,
const float * verts,
const unsigned int nVertices,
const float * colors,
const unsigned int nColors
)Mesh * mesh(
const std::string & alias,
Mesh::PrimitiveType primitiveType,
const float * verts,
const unsigned int nVertices,
const float * colors,
const unsigned int nColors
)Get model by alias or create it using provided vertex data.
Parameters:
- alias Resource alias
- primitiveType Mesh primitive type
- verts Pointer to vertex position array
- nVertices Vertex position array size
- colors Pointer to color array
- nColors Color array size
Return: Pointer to the Mesh object.
Alias is assigned if it doesn't exist.
function mesh
Mesh * mesh(
const std::string & alias,
Mesh::PrimitiveType primitiveType,
const float * verts,
const unsigned int nVertices,
const unsigned int * indices,
const unsigned int nIndices,
const float * colors,
const unsigned int nColors
)Mesh * mesh(
const std::string & alias,
Mesh::PrimitiveType primitiveType,
const float * verts,
const unsigned int nVertices,
const unsigned int * indices,
const unsigned int nIndices,
const float * colors,
const unsigned int nColors
)Get model by alias or create it using provided indexed vertex data.
Parameters:
- alias Resource alias
- primitiveType Mesh primitive type
- verts Pointer to vertex position array
- nVertices Vertex position array size
- indices Pointer to indices array
- nIndices Indices array size
- colors Pointer to color array
- nColors Color array size
Return: Pointer to the Mesh object.
Alias is assigned if it doesn't exist.
function mesh
Mesh * mesh(
const std::string & path
)Mesh * mesh(
const std::string & path
)Get or create model from file.
Return: Pointer to the Mesh object.
Necessary textures might be loaded as well.
function meshByAlias
Mesh * meshByAlias(
const std::string & alias
)Mesh * meshByAlias(
const std::string & alias
)Get existing model using an alias.
Return: Pointer to the Mesh object.
function registerDefault
void registerDefault(
const std::string & alias
)void registerDefault(
const std::string & alias
)Register an alias as a "default" resource.
The aliased resource must exist.
function removeImportedModel
bool removeImportedModel(
const std::string & alias
)bool removeImportedModel(
const std::string & alias
)function removeResource
bool removeResource(
ManagedResource * managedResource,
bool force =false
)bool removeResource(
ManagedResource * managedResource,
bool force =false
)Dispose the specified resource and remove it from the manager.
Parameters:
- managedResource The actual resource returned by fetch methods.
Return: false on failure
function resourceExists
bool resourceExists(
size_t id
)bool resourceExists(
size_t id
)function resourceExists
bool resourceExists(
std::string & alias
)bool resourceExists(
std::string & alias
)function saveGlobal
virtual Memento saveGlobal() overridevirtual Memento saveGlobal() overrideSave shared global state.
Reimplements: IStateful::saveGlobal
function saveScene
virtual Memento saveScene(
State::Scene * scene
) overridevirtual Memento saveScene(
State::Scene * scene
) overrideSave state for the current scene.
Parameters:
- scene The current scene or nullptr (in case of undo/redo)
Reimplements: IStateful::saveScene
The scene parameter should contain a scene object for full filesystem saves and nullptr for quick undo/redo operations.
function serializeModels
void serializeModels(
std::vector< std::string > modelAliases,
Scene * scene,
rapidjson::Value & targetArr,
rapidjson::Document::AllocatorType & a
)void serializeModels(
std::vector< std::string > modelAliases,
Scene * scene,
rapidjson::Value & targetArr,
rapidjson::Document::AllocatorType & a
)function shader
GLuint shader(
const std::string & alias,
const std::string & vertShader,
const std::string & fragShader
)GLuint shader(
const std::string & alias,
const std::string & vertShader,
const std::string & fragShader
)Get or create shader by alias or files.
Return: OpenGL id of the shader object
Alias is assigned if it doesn't exist.
function shader
GLuint shader(
const std::string & vertShader,
const std::string & fragShader
)GLuint shader(
const std::string & vertShader,
const std::string & fragShader
)Get or create shader from files.
Return: OpenGL id of the shader object
function shaderByAlias
GLuint shaderByAlias(
const std::string & alias
)GLuint shaderByAlias(
const std::string & alias
)Get existing shader using an alias.
Return: OpenGL id of the shader object
function shaderG
GLuint shaderG(
const std::string & alias,
const std::string & vertShader,
const std::string & fragShader,
const std::string & geoShader
)GLuint shaderG(
const std::string & alias,
const std::string & vertShader,
const std::string & fragShader,
const std::string & geoShader
)Get or create shader by alias or files.
Return: OpenGL id of the shader object
Alias is assigned if it doesn't exist.
function shaderG
GLuint shaderG(
const std::string & vertShader,
const std::string & fragShader,
const std::string & geoShader
)GLuint shaderG(
const std::string & vertShader,
const std::string & fragShader,
const std::string & geoShader
)Get or create shader from files.
Return: OpenGL id of the shader object
function texture
GLuint texture(
const std::string & alias,
const std::string & path
)GLuint texture(
const std::string & alias,
const std::string & path
)Get or create texture by alias or path.
Return: OpenGL id of the texture object
Alias is assigned if it doesn't exist.
function texture
GLuint texture(
const std::string & path
)GLuint texture(
const std::string & path
)Get or create texture for file path.
Return: OpenGL id of the texture object
function textureByAlias
GLuint textureByAlias(
const std::string & alias
)GLuint textureByAlias(
const std::string & alias
)Get existing texture using an alias.
Return: OpenGL id of the texture object
function updateModelFiles
void updateModelFiles(
State::Scene * scene
)void updateModelFiles(
State::Scene * scene
)Ensure that model files required by the scene are in the right place.
function instance
static ResourceManager & instance()static ResourceManager & instance()Public Attributes Documentation
variable m_forceMinimumLoad
bool m_forceMinimumLoad {false};bool m_forceMinimumLoad {false};If true any resource fetches will not be cached.
variable m_forceModelNormalize
bool m_forceModelNormalize {false};bool m_forceModelNormalize {false};If true just the bare minimum of resources is loaded.
variable m_forceReload
bool m_forceReload {false};bool m_forceReload {false};Updated on 2025-09-07 at 16:13:51 +0000