Rendu
A lightweight rendering engine for experimentations
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
Resources Class Reference

The Resources manager is responsible for all resources loading and setup. More...

#include <ResourcesManager.hpp>

Classes

struct  FileInfos
 Properties of a resource file. More...
 
struct  ProgramInfos
 

Public Member Functions

void addResources (const std::string &path)
 
void reload ()
 
void clean ()
 
Resourcesoperator= (const Resources &)=delete
 
 Resources (const Resources &)=delete
 
Resourcesoperator= (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 MeshgetMesh (const std::string &name, Storage options)
 
const TexturegetTexture (const std::string &name, const Layout &format, Storage options, const std::string &refName="")
 
const TexturegetTexture (const std::string &name)
 
const TexturegetDefaultTexture (TextureShape shape)
 
ProgramgetProgram (const std::string &name, const std::string &vertexName="", const std::string &fragmentName="", const std::string &tessControlName="", const std::string &tessEvalName="")
 
ProgramgetProgram2D (const std::string &name)
 
ProgramgetProgramCompute (const std::string &name)
 
FontgetFont (const std::string &name)
 
const Data * getData (const std::string &filename)
 
void getFiles (const std::string &extension, std::vector< FileInfos > &files) const
 

Static Public Member Functions

static Resourcesmanager ()
 
static char * loadRawDataFromExternalFile (const std::string &path, size_t &size)
 
static std::string loadStringFromExternalFile (const std::string &path)
 
static void saveRawDataToExternalFile (const std::string &path, char *rawContent, size_t size)
 
static void saveStringToExternalFile (const std::string &path, const std::string &content)
 
static bool externalFileExists (const std::string &path)
 

Private Member Functions

 Resources ()=default
 
void parseArchive (const std::string &archivePath)
 
void parseDirectory (const std::string &directoryPath)
 
std::string getImagePath (const std::string &name)
 
std::vector< std::string > getCubemapPaths (const std::string &name)
 
std::vector< std::string > getLayeredPaths (const std::string &name, const std::string &suffix)
 
char * getRawData (const std::string &path, size_t &size)
 
 ~Resources ()=default
 

Private Attributes

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.
 

Friends

class Image
 Image class.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Resources() [1/3]

Resources::Resources ( const Resources )
delete

Copy constructor (disabled).

◆ Resources() [2/3]

Resources::Resources ( Resources &&  )
delete

Move constructor (disabled).

◆ Resources() [3/3]

Resources::Resources ( )
privatedefault

Constructor.

◆ ~Resources()

Resources::~Resources ( )
privatedefault

Destructor (disabled).

Member Function Documentation

◆ addResources()

void Resources::addResources ( const std::string &  path)

Add another resources directory/archive.

Parameters
paththe 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
paththe 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
namethe 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
filenamethe data file base name
Returns
the data (internally managed)

◆ getDefaultTexture()

const Texture * Resources::getDefaultTexture ( TextureShape  shape)

Get a default, empty texture of a given shape. This is useful for filling optional texture slots.

Parameters
shapethe texture shape
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
extensionthe extension of the files to list
fileswill 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
namethe font base name
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
namethe 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
namethe name of the layered image
suffixthe 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
namethe mesh file name
optionsdata 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
namethe name to represent the program
vertexNamethe name of the vertex shader
fragmentNamethe name of the fragment shader
tessControlNamethe name of the optional tessellation control shader
tessEvalNamethe 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
namethe 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
namethe 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
paththe path to the file
sizewill 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
filenamethe file name
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
filenamethe file name
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
filenamethe file name
nameswill 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
namethe 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
namethe texture base name
formatthe texture format to use
optionsdata loading and storage options
refNamethe 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
paththe path to the file on disk
sizewill 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
paththe path to the file on disk
Returns
the file string content
Note
Mainly used to load configuration or user selected files.

◆ manager()

Resources & Resources::manager ( )
static

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]

Resources & Resources::operator= ( const Resources )
delete

Copy assignment operator (disabled).

Returns
a reference to the object assigned to

◆ operator=() [2/2]

Resources & Resources::operator= ( Resources &&  )
delete

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
archivePaththe 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
directoryPaththe 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
paththe path to the file on disk
rawContenta pointer to the file binary data
sizewill 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
paththe path to the file on disk
contentthe string to save

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