Skip to content

Core::ResourceManager

Resource manager for loading resources from the filesystem. More...

#include "Core/Resources/ResourceManager.h"

Inherits from Module, IStateful

Public Functions

Name
~ResourceManager()<br>If true loaded models will be normalized.
boolcleanUpModelFiles(State::Scene * scene)
virtual voidclearGlobal() override<br>Set the global state to some default empty state.
virtual voidclearScene() override<br>Set the scene state to some default empty state.
voidcreateDefaultResources(const std::vector< Resource > & defaultResources)<br>Loads provided resources and marks them as default.
std::vector< Resource >getDefaultResources(ResourceType type)<br>Returns default resources of type.
std::vector< std::string >getImportedResourceAliases()
boolimportModel(const fs::path & path, bool normalize)
virtual voidloadGlobal(const Memento & memento) override<br>Load global state from a memento.
virtual voidloadScene(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.
voidregisterDefault(const std::string & alias)<br>Register an alias as a "default" resource.
boolremoveImportedModel(const std::string & alias)
boolremoveResource(ManagedResource * managedResource, bool force =false)<br>Dispose the specified resource and remove it from the manager.
boolresourceExists(size_t id)
boolresourceExists(std::string & alias)
virtual MementosaveGlobal() override<br>Save shared global state.
virtual MementosaveScene(State::Scene * scene) override<br>Save state for the current scene.
GLuintshader(const std::string & alias, const std::string & vertShader, const std::string & fragShader)<br>Get or create shader by alias or files.
GLuintshader(const std::string & vertShader, const std::string & fragShader)<br>Get or create shader from files.
GLuintshaderByAlias(const std::string & alias)<br>Get existing shader using an alias.
GLuintshaderG(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.
GLuintshaderG(const std::string & vertShader, const std::string & fragShader, const std::string & geoShader)<br>Get or create shader from files.
GLuinttexture(const std::string & alias, const std::string & path)<br>Get or create texture by alias or path.
GLuinttexture(const std::string & path)<br>Get or create texture for file path.
GLuinttextureByAlias(const std::string & alias)<br>Get existing texture using an alias.
ResourceManager &instance()
std::optional< std::vector< Resource > >readResources(const rapidjson::Value & resources)

Public Attributes

Name
boolm_forceMinimumLoad <br>If true any resource fetches will not be cached.
boolm_forceModelNormalize <br>If true just the bare minimum of resources is loaded.
boolm_forceReload

Additional inherited members

Public Functions inherited from Module

Name
Module() =default
virtual~Module() =default
virtual voidonBeginFrame()
virtual voidonClose()
virtual voidonEndFrame()
virtual voidonInit()
virtual voidonUpdate(double delta)

Friends inherited from Module

Name
classApplication

Public Functions inherited from IStateful

Name
virtual~IStateful()
MementoemptyMemento()<br>Create an empty memento (rapidjson::Document)

Detailed Description

cpp
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

cpp
~ResourceManager()
~ResourceManager()

If true loaded models will be normalized.

function cleanUpModelFiles

cpp
bool cleanUpModelFiles(
    State::Scene * scene
)
bool cleanUpModelFiles(
    State::Scene * scene
)

function clearGlobal

cpp
virtual void clearGlobal() override
virtual void clearGlobal() override

Set the global state to some default empty state.

Reimplements: IStateful::clearGlobal

function clearScene

cpp
virtual void clearScene() override
virtual void clearScene() override

Set the scene state to some default empty state.

Reimplements: IStateful::clearScene

function createDefaultResources

cpp
void createDefaultResources(
    const std::vector< Resource > & defaultResources
)
void createDefaultResources(
    const std::vector< Resource > & defaultResources
)

Loads provided resources and marks them as default.

function getDefaultResources

cpp
std::vector< Resource > getDefaultResources(
    ResourceType type
)
std::vector< Resource > getDefaultResources(
    ResourceType type
)

Returns default resources of type.

function getImportedResourceAliases

cpp
std::vector< std::string > getImportedResourceAliases()
std::vector< std::string > getImportedResourceAliases()

function importModel

cpp
bool importModel(
    const fs::path & path,
    bool normalize
)
bool importModel(
    const fs::path & path,
    bool normalize
)

function loadGlobal

cpp
virtual void loadGlobal(
    const Memento & memento
) override
virtual void loadGlobal(
    const Memento & memento
) override

Load global state from a memento.

Parameters:

  • memento New global state

Reimplements: IStateful::loadGlobal

function loadScene

cpp
virtual void loadScene(
    const Memento & memento,
    State::Scene * scene
) override
virtual void loadScene(
    const Memento & memento,
    State::Scene * scene
) override

Called 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

cpp
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

cpp
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

cpp
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

cpp
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

cpp
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

cpp
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

cpp
bool removeImportedModel(
    const std::string & alias
)
bool removeImportedModel(
    const std::string & alias
)

function removeResource

cpp
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

cpp
bool resourceExists(
    size_t id
)
bool resourceExists(
    size_t id
)

function resourceExists

cpp
bool resourceExists(
    std::string & alias
)
bool resourceExists(
    std::string & alias
)

function saveGlobal

cpp
virtual Memento saveGlobal() override
virtual Memento saveGlobal() override

Save shared global state.

Reimplements: IStateful::saveGlobal

function saveScene

cpp
virtual Memento saveScene(
    State::Scene * scene
) override
virtual Memento saveScene(
    State::Scene * scene
) override

Save 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 shader

cpp
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

cpp
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

cpp
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

cpp
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

cpp
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

cpp
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

cpp
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

cpp
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 instance

cpp
static ResourceManager & instance()
static ResourceManager & instance()

function readResources

cpp
static std::optional< std::vector< Resource > > readResources(
    const rapidjson::Value & resources
)
static std::optional< std::vector< Resource > > readResources(
    const rapidjson::Value & resources
)

Public Attributes Documentation

variable m_forceMinimumLoad

cpp
bool m_forceMinimumLoad {false};
bool m_forceMinimumLoad {false};

If true any resource fetches will not be cached.

variable m_forceModelNormalize

cpp
bool m_forceModelNormalize {false};
bool m_forceModelNormalize {false};

If true just the bare minimum of resources is loaded.

variable m_forceReload

cpp
bool m_forceReload {false};
bool m_forceReload {false};

Updated on 2024-03-16 at 19:15:01 +0000