matf-rg-engine 1.0.0
Base for project for the Computer Graphics course at Faculty of Mathematics, University of Belgrade
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
engine::resources::ResourcesController Class Referencefinal

Manages app resources: Model, Texture, Shader, and Skybox. More...

#include <ResourcesController.hpp>

Inheritance diagram for engine::resources::ResourcesController:
Inheritance graph
[legend]
Collaboration diagram for engine::resources::ResourcesController:
Collaboration graph
[legend]

Public Member Functions

std::string_view name () const override
 
Modelmodel (const std::string &name)
 Retrieves the model with a given name. You are not supposed to call delete on this pointer.
 
Texturetexture (const std::string &name, const std::filesystem::path &path="", TextureType texture_type=TextureType::Regular, bool flip_uvs=false)
 Retrieves the Texture with a given name. You are not supposed to call delete on this pointer.
 
Skyboxskybox (const std::string &name, const std::filesystem::path &path="", bool flip_uvs=false)
 Retrieves the Skybox with a given name. You are not supposed to call delete on this pointer.
 
Shadershader (const std::string &name, const std::filesystem::path &path="")
 Retrieves the Shader with a given name. You are not supposed to call delete on this pointer.
 
- Public Member Functions inherited from engine::core::Controller
virtual ~Controller ()=default
 
void before (Controller *next)
 
void after (Controller *prev)
 
const std::vector< Controller * > & next () const
 
bool is_enabled () const
 Controller will execute as long this function returns true.
 
void set_enable (bool value)
 Enables or disables the controller based on value. The ControllerManager executes only the enabled controllers, except for the Controller::poll_events function, that's executed always. By default, controllers are enabled when registered.
 

Private Member Functions

void initialize () override
 Loads all the resources from the "resources/" directory.
 
void load_models ()
 Loads all the models from the "resources/models" directory based on the provided configuration. Called during ResourcesController::initialize.
 
void load_textures ()
 Loads all the models from the "resources/textures" directory. Called during ResourcesController::initialize.
 
void load_skyboxes ()
 Loads all the skyboxes from the "resources/skyboxes" directory. Called during ResourcesController::initialize.
 
void load_shaders ()
 Loads and compile all the shaders from the "resources/shaders" directory. Called during ResourcesController::initialize.
 

Private Attributes

std::unordered_map< std::string, std::unique_ptr< Model > > m_models
 A hashmap of all the loaded Model.
 
std::unordered_map< std::string, std::unique_ptr< Texture > > m_textures
 A hashmap of all the loaded Texture.
 
std::unordered_map< std::string, std::unique_ptr< Skybox > > m_sky_boxes
 A hashmap of all the loaded Skybox.
 
std::unordered_map< std::string, std::unique_ptr< Shader > > m_shaders
 A hashmap of all the loaded Shader.
 
const std::filesystem::path m_models_path = "resources/models"
 
const std::filesystem::path m_textures_path = "resources/textures"
 
const std::filesystem::path m_shaders_path = "resources/shaders"
 
const std::filesystem::path m_skyboxes_path = "resources/skyboxes"
 

Additional Inherited Members

- Static Public Member Functions inherited from engine::core::Controller
template<typename TController >
static TControllerget (std::source_location location=std::source_location::current())
 Serves as a single access point for all the Controller types throughout the code base. Make sure to register the controller via App::register_controller before calling this function.
 

Detailed Description

Manages app resources: Model, Texture, Shader, and Skybox.

Member Function Documentation

◆ name()

std::string_view engine::resources::ResourcesController::name ( ) const
inlineoverridevirtual

Returns the controller class name; used for logging.

Returns
Controller name

Reimplemented from engine::core::Controller.

◆ model()

Model * engine::resources::ResourcesController::model ( const std::string &  name)

Retrieves the model with a given name. You are not supposed to call delete on this pointer.

Parameters
nameof the model in the configuration file.
Returns
The pointer to the Model associated with the name.

◆ texture()

Texture * engine::resources::ResourcesController::texture ( const std::string &  name,
const std::filesystem::path &  path = "",
TextureType  texture_type = TextureType::Regular,
bool  flip_uvs = false 
)

Retrieves the Texture with a given name. You are not supposed to call delete on this pointer.

Other params, except name, are optional. If not provided the function will search for a texture in the: "resources/textures".

Parameters
nameof the texture without the extension.
pathform which to load the texture.
texture_type
flip_uvsflip the uvs on load if set to true
Returns
The pointer to the Texture associated with the name.

◆ skybox()

Skybox * engine::resources::ResourcesController::skybox ( const std::string &  name,
const std::filesystem::path &  path = "",
bool  flip_uvs = false 
)

Retrieves the Skybox with a given name. You are not supposed to call delete on this pointer.

Other params, except name, are optional. If not provided the function will search for a skybox in the: "resources/skyboxes". Images for the sides of the skybox cube should be named: left.jpg, right.jpg, top.jpg, bottom.jpg, front.jpg, back.jpg (any supported image extension).

Parameters
nameof the skybox directory that contains 6 images for each side of the cube.
pathform which to load the texture.
flip_uvsflip the uvs on load if set to true
Returns
The pointer to the Skybox associated with the name.

◆ shader()

Shader * engine::resources::ResourcesController::shader ( const std::string &  name,
const std::filesystem::path &  path = "" 
)

Retrieves the Shader with a given name. You are not supposed to call delete on this pointer.

Parameters
pathto the shader.glsl file that contains shader source code.
Returns
The pointer to the Shader associated with the name.

◆ initialize()

void engine::resources::ResourcesController::initialize ( )
overrideprivatevirtual

Loads all the resources from the "resources/" directory.

Reimplemented from engine::core::Controller.

◆ load_models()

void engine::resources::ResourcesController::load_models ( )
private

Loads all the models from the "resources/models" directory based on the provided configuration. Called during ResourcesController::initialize.

◆ load_textures()

void engine::resources::ResourcesController::load_textures ( )
private

Loads all the models from the "resources/textures" directory. Called during ResourcesController::initialize.

◆ load_skyboxes()

void engine::resources::ResourcesController::load_skyboxes ( )
private

Loads all the skyboxes from the "resources/skyboxes" directory. Called during ResourcesController::initialize.

◆ load_shaders()

void engine::resources::ResourcesController::load_shaders ( )
private

Loads and compile all the shaders from the "resources/shaders" directory. Called during ResourcesController::initialize.

Member Data Documentation

◆ m_models

std::unordered_map<std::string, std::unique_ptr<Model> > engine::resources::ResourcesController::m_models
private

A hashmap of all the loaded Model.

◆ m_textures

std::unordered_map<std::string, std::unique_ptr<Texture> > engine::resources::ResourcesController::m_textures
private

A hashmap of all the loaded Texture.

◆ m_sky_boxes

std::unordered_map<std::string, std::unique_ptr<Skybox> > engine::resources::ResourcesController::m_sky_boxes
private

A hashmap of all the loaded Skybox.

◆ m_shaders

std::unordered_map<std::string, std::unique_ptr<Shader> > engine::resources::ResourcesController::m_shaders
private

A hashmap of all the loaded Shader.

◆ m_models_path

const std::filesystem::path engine::resources::ResourcesController::m_models_path = "resources/models"
private

◆ m_textures_path

const std::filesystem::path engine::resources::ResourcesController::m_textures_path = "resources/textures"
private

◆ m_shaders_path

const std::filesystem::path engine::resources::ResourcesController::m_shaders_path = "resources/shaders"
private

◆ m_skyboxes_path

const std::filesystem::path engine::resources::ResourcesController::m_skyboxes_path = "resources/skyboxes"
private

The documentation for this class was generated from the following files: