The Resources manager is responsible for all resources loading and setup.
More...
#include <ResourcesManager.hpp>
|
void | addResources (const std::string &path) |
|
void | reload () |
|
void | clean () |
|
Resources & | operator= (const Resources &)=delete |
|
| Resources (const Resources &)=delete |
|
Resources & | operator= (Resources &&)=delete |
|
| Resources (Resources &&)=delete |
|
std::string | getString (const std::string &filename) |
|
std::string | getStringWithIncludes (const std::string &filename, std::vector< std::string > &names) |
|
std::string | getStringWithIncludes (const std::string &filename) |
|
const Mesh * | getMesh (const std::string &name, Storage options) |
|
const Texture * | getTexture (const std::string &name, const Layout &format, Storage options, const std::string &refName="") |
|
const Texture * | getTexture (const std::string &name) |
|
const Texture * | getDefaultTexture (TextureShape shape) |
|
Program * | getProgram (const std::string &name, const std::string &vertexName="", const std::string &fragmentName="", const std::string &tessControlName="", const std::string &tessEvalName="") |
|
Program * | getProgram2D (const std::string &name) |
|
Program * | getProgramCompute (const std::string &name) |
|
Font * | getFont (const std::string &name) |
|
const Data * | getData (const std::string &filename) |
|
void | getFiles (const std::string &extension, std::vector< FileInfos > &files) const |
|
|
std::unordered_map< std::string, std::string > | _files |
| Listing of available files and their paths.
|
|
std::unordered_map< std::string, Texture > | _textures |
| Loaded textures, identified by name.
|
|
std::unordered_map< std::string, Mesh > | _meshes |
| Loaded meshes, identified by name.
|
|
std::unordered_map< std::string, Font > | _fonts |
| Loaded font infos, identified by name.
|
|
std::unordered_map< std::string, Data > | _blobs |
| Loaded binary blobs, identified by name.
|
|
std::unordered_map< std::string, Program > | _programs |
| Loaded shader programs, identified by name.
|
|
std::unordered_map< std::string, ProgramInfos > | _progInfos |
| Additional info to support shader reloading.
|
|
The Resources manager is responsible for all resources loading and setup.
It provides an abstraction over the file system: resources can be loaded directly from files on disk, or from a zip archive.
◆ Resources() [1/3]
Copy constructor (disabled).
◆ Resources() [2/3]
Move constructor (disabled).
◆ Resources() [3/3]
◆ ~Resources()
Resources::~Resources |
( |
| ) |
|
|
privatedefault |
◆ addResources()
void Resources::addResources |
( |
const std::string & |
path | ) |
|
Add another resources directory/archive.
- Parameters
-
path | the path to the additional directory/archive to parse |
◆ clean()
void Resources::clean |
( |
| ) |
|
Clean all loaded resources, both CPU and GPU side.
◆ externalFileExists()
bool Resources::externalFileExists |
( |
const std::string & |
path | ) |
|
|
static |
Check if a file exists on disk.
- Parameters
-
path | the path to the file on disk |
- Returns
- true if the file exists.
◆ getCubemapPaths()
std::vector< std::string > Resources::getCubemapPaths |
( |
const std::string & |
name | ) |
|
|
private |
Expand a cubemap base name in its faces paths, testing all possibles extensions.
- Parameters
-
name | the base name of the cubemap |
- Returns
- a list of each face path
◆ getData()
const Data * Resources::getData |
( |
const std::string & |
filename | ) |
|
Load arbitrary data from the resources.
- Parameters
-
filename | the data file base name |
- Returns
- the data (internally managed)
◆ getDefaultTexture()
Get a default, empty texture of a given shape. This is useful for filling optional texture slots.
- Parameters
-
- Returns
- the texture information
◆ getFiles()
void Resources::getFiles |
( |
const std::string & |
extension, |
|
|
std::vector< FileInfos > & |
files |
|
) |
| const |
Query all resource files with a given extension.
- Parameters
-
extension | the extension of the files to list |
files | will contain the file names and their paths |
◆ getFont()
Font * Resources::getFont |
( |
const std::string & |
name | ) |
|
Load a font metadata and texture atlas from the resources.
- Parameters
-
- Returns
- the font data
◆ getImagePath()
std::string Resources::getImagePath |
( |
const std::string & |
name | ) |
|
|
private |
Expand an image name in its path, testing all possibles extensions.
- Parameters
-
name | the name of the image |
- Returns
- the image path
◆ getLayeredPaths()
std::vector< std::string > Resources::getLayeredPaths |
( |
const std::string & |
name, |
|
|
const std::string & |
suffix |
|
) |
| |
|
private |
Expand a multi-layer image (array or 3D depending on the suffix) name in its slices path, testing all possibles extensions.
- Parameters
-
name | the name of the layered image |
suffix | the suffix to append before the layer number |
- Returns
- a list of the image paths
◆ getMesh()
const Mesh * Resources::getMesh |
( |
const std::string & |
name, |
|
|
Storage |
options |
|
) |
| |
Get a geometric mesh resource.
- Parameters
-
name | the mesh file name |
options | data loading and storage options |
- Returns
- the mesh informations
◆ getProgram()
Program * Resources::getProgram |
( |
const std::string & |
name, |
|
|
const std::string & |
vertexName = "" , |
|
|
const std::string & |
fragmentName = "" , |
|
|
const std::string & |
tessControlName = "" , |
|
|
const std::string & |
tessEvalName = "" |
|
) |
| |
Get a GPU program resource.
- Parameters
-
name | the name to represent the program |
vertexName | the name of the vertex shader |
fragmentName | the name of the fragment shader |
tessControlName | the name of the optional tessellation control shader |
tessEvalName | the name of the optional tessellation evaluation shader |
- Returns
- the program informations
◆ getProgram2D()
Program * Resources::getProgram2D |
( |
const std::string & |
name | ) |
|
Get a GPU program resource for 2D screen processing. It will use GPU::Vert::Passthrough as a vertex shader.
- Parameters
-
name | the name of the fragment shader |
- Returns
- the program informations
- See also
- GPU::Vert::Passthrough
◆ getProgramCompute()
Program * Resources::getProgramCompute |
( |
const std::string & |
name | ) |
|
Get a GPU program resource for compute.
- Parameters
-
name | the name of the compute shader |
- Returns
- the program informations
- See also
- GPU::Vert::Passthrough
◆ getRawData()
char * Resources::getRawData |
( |
const std::string & |
path, |
|
|
size_t & |
size |
|
) |
| |
|
private |
Load raw binary data from a resource file
- Parameters
-
path | the path to the file |
size | will contain the number of bytes loaded from the file |
- Returns
- a pointer to the file binary data
◆ getString()
std::string Resources::getString |
( |
const std::string & |
filename | ) |
|
Get a text file resource.
- Parameters
-
- Returns
- the string content of the file
◆ getStringWithIncludes() [1/2]
std::string Resources::getStringWithIncludes |
( |
const std::string & |
filename | ) |
|
Get a text file resource, following include directives.
- Parameters
-
- Returns
- the string content of the file
◆ getStringWithIncludes() [2/2]
std::string Resources::getStringWithIncludes |
( |
const std::string & |
filename, |
|
|
std::vector< std::string > & |
names |
|
) |
| |
Get a text file resource, following include directives.
- Parameters
-
filename | the file name |
names | will contain the included file names |
- Returns
- the string content of the file
◆ getTexture() [1/2]
const Texture * Resources::getTexture |
( |
const std::string & |
name | ) |
|
Get an existing texture resource.
- Parameters
-
name | the texture base name |
- Returns
- the texture informations
◆ getTexture() [2/2]
const Texture * Resources::getTexture |
( |
const std::string & |
name, |
|
|
const Layout & |
format, |
|
|
Storage |
options, |
|
|
const std::string & |
refName = "" |
|
) |
| |
Get a texture resource. Automatically handle custom mipmaps if present.
- Parameters
-
name | the texture base name |
format | the texture format to use |
options | data loading and storage options |
refName | the name to use for the texture in future calls |
- Returns
- the texture informations
- Note
- If the name is the string representation of an RGB(A) color ("1.0,0.0,1.0" for instance), a constant color 2D texture will be allocated using the passed descriptor.
-
Cubemaps will be automatically detected using suffixes _nx, _ny, _nz, _px, _py, _pz.
-
2D arrays will be automatically detected using suffix _sX where X=0,1..., 3D textures using suffix _zX where X=0,1...
◆ loadRawDataFromExternalFile()
char * Resources::loadRawDataFromExternalFile |
( |
const std::string & |
path, |
|
|
size_t & |
size |
|
) |
| |
|
static |
Load raw binary data from an external file
- Parameters
-
path | the path to the file on disk |
size | will contain the number of bytes loaded from the file |
- Returns
- a pointer to the file binary data
◆ loadStringFromExternalFile()
std::string Resources::loadStringFromExternalFile |
( |
const std::string & |
path | ) |
|
|
static |
Load text data from an external file
- Parameters
-
path | the path to the file on disk |
- Returns
- the file string content
- Note
- Mainly used to load configuration or user selected files.
◆ manager()
Singleton accessor.
- Returns
- the resources manager singleton
By enabling RESOURCES_PACKAGED, the resources will be loaded from a zip archive instead of the resources directory. Basic text files can still be read from disk (for configuration, settings,...) by using Resources::loadStringFromExternalFile.
◆ operator=() [1/2]
Copy assignment operator (disabled).
- Returns
- a reference to the object assigned to
◆ operator=() [2/2]
Move assignment operator (disabled).
- Returns
- a reference to the object assigned to
◆ parseArchive()
void Resources::parseArchive |
( |
const std::string & |
archivePath | ) |
|
|
private |
Parse the archive at the given path (using miniz), listing all files it contains.
- Parameters
-
archivePath | the path to the archive |
◆ parseDirectory()
void Resources::parseDirectory |
( |
const std::string & |
directoryPath | ) |
|
|
private |
Parse the directory at the given path (using tinydir), listing all files it contains.
- Parameters
-
directoryPath | the path to the directory |
◆ reload()
void Resources::reload |
( |
| ) |
|
Reload all shader programs.
◆ saveRawDataToExternalFile()
void Resources::saveRawDataToExternalFile |
( |
const std::string & |
path, |
|
|
char * |
rawContent, |
|
|
size_t |
size |
|
) |
| |
|
static |
Write raw binary data to an external file
- Parameters
-
path | the path to the file on disk |
rawContent | a pointer to the file binary data |
size | will contain the number of bytes loaded from the file |
◆ saveStringToExternalFile()
void Resources::saveStringToExternalFile |
( |
const std::string & |
path, |
|
|
const std::string & |
content |
|
) |
| |
|
static |
Write text data to an external file
- Parameters
-
path | the path to the file on disk |
content | the string to save |
The documentation for this class was generated from the following files: