FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
fge::shader::ShaderManager Class Reference

Manage shaders. More...

#include <shader_manager.hpp>

Inheritance diagram for fge::shader::ShaderManager:
fge::manager::BaseManager< vulkan::Shader, DataBlock >

Public Types

using DataType
 
using DataBlockType
 
using DataBlockPointer
 
using Map
 

Public Member Functions

bool initialize () override
 Initialize the shader manager.
 
bool isInitialized () override
 
void uninitialize () override
 
bool loadFromMemory (std::string_view name, void const *data, int size, fge::vulkan::Shader::Type type, ShaderInputTypes input, bool debugBuild=false)
 Load a shader from the memory.
 
bool loadFromFile (std::string_view name, std::filesystem::path path, fge::vulkan::Shader::Type type, ShaderInputTypes input, bool debugBuild=false)
 Load a shader from a file.
 
std::size_t size () const
 Get the number of elements in the manager.
 
AccessLock< std::mutex > acquireLock () const
 Acquire a AccessLock, with the manager mutex.
 
Map::const_iterator begin (AccessLock< std::mutex > const &lock) const
 Get the "begin" iterator of the manager.
 
Map::const_iterator end (AccessLock< std::mutex > const &lock) const
 Get the "end" iterator of the manager.
 
DataBlockPointer const & getBadElement () const
 Get the "bad" element.
 
DataBlockPointer getElement (std::string_view name) const
 Get the resource with the given name.
 
bool contains (std::string_view name) const
 
bool unload (std::string_view name)
 
void unloadAll ()
 
bool push (std::string_view name, DataBlockPointer block)
 Add a user handled resource.
 

Protected Attributes

DataBlockPointer _g_badElement
 

Detailed Description

Manage shaders.

See also
TextureManager

Member Function Documentation

◆ acquireLock()

AccessLock< std::mutex > fge::manager::BaseManager< vulkan::Shader, DataBlock >::acquireLock ( ) const
nodiscardinherited

Acquire a AccessLock, with the manager mutex.

In order to use iterators, you have to acquire a unique lock from this function. The lock is not differed and will lock the mutex.

Returns
A AccessLock bound to this mutex

◆ begin()

BaseManager< vulkan::Shader, DataBlock >::Map::const_iterator fge::manager::BaseManager< vulkan::Shader, DataBlock >::begin ( AccessLock< std::mutex > const & lock) const
nodiscardinherited

Get the "begin" iterator of the manager.

You have to provide a valid reference to a AccessLock acquired with the function AcquireLock(). This function will throw if one of this is not respected :

  • The mutex pointer of the lock does not correspond to this mutex.
Parameters
lockA AccessLock bound to this mutex
Returns
The "begin" iterator of the texture manager

◆ end()

BaseManager< vulkan::Shader, DataBlock >::Map::const_iterator fge::manager::BaseManager< vulkan::Shader, DataBlock >::end ( AccessLock< std::mutex > const & lock) const
nodiscardinherited

Get the "end" iterator of the manager.

See also
begin()
Parameters
lockA AccessLock bound to this mutex
Returns
The "end" iterator of the manager

◆ getBadElement()

BaseManager< vulkan::Shader, DataBlock >::DataBlockPointer const & fge::manager::BaseManager< vulkan::Shader, DataBlock >::getBadElement ( ) const
nodiscardinherited

Get the "bad" element.

A bad element is a "valid" default resource that is returned when the requested resource is not found. return The "bad" element

◆ getElement()

BaseManager< vulkan::Shader, DataBlock >::DataBlockPointer fge::manager::BaseManager< vulkan::Shader, DataBlock >::getElement ( std::string_view name) const
nodiscardinherited

Get the resource with the given name.

Parameters
nameThe name of the resource to get
Returns
The resource with the given name or the bad resource if not found

◆ initialize()

bool fge::shader::ShaderManager::initialize ( )
overridevirtual

Initialize the shader manager.

A bad shader is created with this function, it is used when a shader is not found. You also have to provide a default vertex and fragments shaders.

3 default shaders are created : FGE_SHADER_DEFAULT_VERTEX : The default vertex shader (in shaderResources.hpp gDefaultVertexShader) FGE_SHADER_DEFAULT_NOTEXTURE_FRAGMENT : The default fragment shader with no texture attached (in shaderResources.hpp gDefaultFragmentShader) FGE_SHADER_DEFAULT_FRAGMENT : The default fragment shader (in shaderResources.hpp gDefaultFragmentTextureShader)

Returns
true if the shader manager is correctly initialized, false otherwise

Implements fge::manager::BaseManager< vulkan::Shader, DataBlock >.

◆ isInitialized()

bool fge::shader::ShaderManager::isInitialized ( )
nodiscardoverridevirtual

◆ loadFromFile()

bool fge::shader::ShaderManager::loadFromFile ( std::string_view name,
std::filesystem::path path,
fge::vulkan::Shader::Type type,
ShaderInputTypes input,
bool debugBuild = false )

Load a shader from a file.

Parameters
nameThe name of the shader to load
pathThe path of the file to load
typeThe shader type
inputThe input file type
debugBuildIf the input must be compiled into SPIR-V, then it will be compiled with debug symbols
Returns
true if the shader was loaded, false otherwise

◆ loadFromMemory()

bool fge::shader::ShaderManager::loadFromMemory ( std::string_view name,
void const * data,
int size,
fge::vulkan::Shader::Type type,
ShaderInputTypes input,
bool debugBuild = false )

Load a shader from the memory.

Warning
if you pass a SPIR-V binary data, the size must be a multiple of 4.
Parameters
nameThe name of the shader to load
dataThe data address to load
sizeThe data size to load
typeThe shader type
inputThe input file type
debugBuildIf the input must be compiled into SPIR-V, then it will be compiled with debug symbols
Returns
true if the shader was loaded, false otherwise

◆ push()

bool fge::manager::BaseManager< vulkan::Shader, DataBlock >::push ( std::string_view name,
DataBlockPointer block )
inherited

Add a user handled resource.

Parameters
nameThe name of the texture to add
blockThe block data to add
Returns
true if the resource was added, false otherwise

◆ size()

std::size_t fge::manager::BaseManager< vulkan::Shader, DataBlock >::size ( ) const
nodiscardinherited

Get the number of elements in the manager.

return The number of elements in the manager without the "bad" element

◆ uninitialize()

void fge::shader::ShaderManager::uninitialize ( )
overridevirtual

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