MapLibre Native Core
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mbgl::gfx::ShaderRegistry Class Reference

A ShaderRegistry contains a collection of gfx::Shader instances. Using the registry, shaders may be dynamically registered or replaced at runtime. More...

#include <shader_registry.hpp>

Public Member Functions

 ShaderRegistry ()
 
 ShaderRegistry (const ShaderRegistry &)=delete
 
 ShaderRegistry (ShaderRegistry &&) noexcept=delete
 
ShaderRegistryoperator= (const ShaderRegistry &)=delete
 
ShaderRegistryoperator= (ShaderRegistry &&) noexcept=delete
 
virtual ~ShaderRegistry ()=default
 
virtual bool isShader (const std::string &shaderName) const noexcept
 Checks if a shader exists in the registry for the given name. More...
 
virtual const std::shared_ptr< gfx::ShadergetShader (const std::string &shaderName) const noexcept
 Get a shader from the registry by name. More...
 
virtual bool replaceShader (std::shared_ptr< Shader > &&shader) noexcept
 Replace a matching shader in the registry with the provided instance. Shader type-names must match. More...
 
virtual bool replaceShader (std::shared_ptr< Shader > &&shader, const std::string &shaderName) noexcept
 Replace a matching shader in the registry with the provided instance. Shader type-names must match. This variant replaces by explicit name. More...
 
virtual bool registerShader (std::shared_ptr< Shader > &&shader) noexcept
 Register a new shader with the registry. If a shader is present in the registry with a conflicting name, registration will fail. More...
 
virtual bool registerShader (std::shared_ptr< Shader > &&shader, const std::string &shaderName) noexcept
 Register a new shader with the registry. If a shader is present in the registry with a conflicting name, registration will fail. This variant registers using an explicit name. More...
 
template<typename T , typename std::enable_if_t< is_shader_v< T >, bool > * = nullptr>
std::shared_ptr< T > get (const std::string &shaderName) noexcept
 Shorthand helper to quickly get a derived type from the registry. More...
 
template<typename T , typename std::enable_if_t< is_shader_v< T >, bool > * = nullptr>
std::shared_ptr< T > get () noexcept
 Shorthand helper to quickly get a derived type from the registry. This variant looks up shaders only by type name. More...
 
template<typename T , typename std::enable_if_t< is_shader_v< T >, bool > * = nullptr>
bool populate (std::shared_ptr< T > &to, const std::string &shaderName) noexcept
 Ensure the destination 'to' is populated with the requested shader. If already non-null, does nothing. More...
 
template<typename T , typename std::enable_if_t< is_shader_v< T >, bool > * = nullptr>
bool populate (std::shared_ptr< T > &to) noexcept
 Ensure the destination 'to' is populated with the requested shader. If already non-null, does nothing. This variant looks up shaders only by type name. More...
 

Detailed Description

A ShaderRegistry contains a collection of gfx::Shader instances. Using the registry, shaders may be dynamically registered or replaced at runtime.

Definition at line 16 of file shader_registry.hpp.

Constructor & Destructor Documentation

◆ ShaderRegistry() [1/3]

mbgl::gfx::ShaderRegistry::ShaderRegistry ( )
explicit

◆ ShaderRegistry() [2/3]

mbgl::gfx::ShaderRegistry::ShaderRegistry ( const ShaderRegistry )
delete

◆ ShaderRegistry() [3/3]

mbgl::gfx::ShaderRegistry::ShaderRegistry ( ShaderRegistry &&  )
deletenoexcept

◆ ~ShaderRegistry()

virtual mbgl::gfx::ShaderRegistry::~ShaderRegistry ( )
virtualdefault

Member Function Documentation

◆ get() [1/2]

template<typename T , typename std::enable_if_t< is_shader_v< T >, bool > * = nullptr>
std::shared_ptr<T> mbgl::gfx::ShaderRegistry::get ( )
inlinenoexcept

Shorthand helper to quickly get a derived type from the registry. This variant looks up shaders only by type name.

Template Parameters
TDerived type, inheriting gfx::Shader
Returns
T or nullptr if not found in the registry

Definition at line 96 of file shader_registry.hpp.

◆ get() [2/2]

template<typename T , typename std::enable_if_t< is_shader_v< T >, bool > * = nullptr>
std::shared_ptr<T> mbgl::gfx::ShaderRegistry::get ( const std::string &  shaderName)
inlinenoexcept

Shorthand helper to quickly get a derived type from the registry.

Template Parameters
TDerived type, inheriting gfx::Shader
Parameters
shaderNameThe registry name to look up
Returns
T or nullptr if not found in the registry

Definition at line 82 of file shader_registry.hpp.

◆ getShader()

virtual const std::shared_ptr<gfx::Shader> mbgl::gfx::ShaderRegistry::getShader ( const std::string &  shaderName) const
virtualnoexcept

Get a shader from the registry by name.

Parameters
shaderNameName of shader
Returns
A gfx::Shader or nullptr if no shader is found with the given name

◆ isShader()

virtual bool mbgl::gfx::ShaderRegistry::isShader ( const std::string &  shaderName) const
virtualnoexcept

Checks if a shader exists in the registry for the given name.

Parameters
shaderNameName of shader
Returns
If a shader is found, true

◆ operator=() [1/2]

ShaderRegistry& mbgl::gfx::ShaderRegistry::operator= ( const ShaderRegistry )
delete

◆ operator=() [2/2]

ShaderRegistry& mbgl::gfx::ShaderRegistry::operator= ( ShaderRegistry &&  )
deletenoexcept

◆ populate() [1/2]

template<typename T , typename std::enable_if_t< is_shader_v< T >, bool > * = nullptr>
bool mbgl::gfx::ShaderRegistry::populate ( std::shared_ptr< T > &  to)
inlinenoexcept

Ensure the destination 'to' is populated with the requested shader. If already non-null, does nothing. This variant looks up shaders only by type name.

Template Parameters
TDerived type, inheriting gfx::Shader
Parameters
toLocation to store the shader
Returns
True if 'to' has a valid program object, false otherwise.

Definition at line 133 of file shader_registry.hpp.

◆ populate() [2/2]

template<typename T , typename std::enable_if_t< is_shader_v< T >, bool > * = nullptr>
bool mbgl::gfx::ShaderRegistry::populate ( std::shared_ptr< T > &  to,
const std::string &  shaderName 
)
inlinenoexcept

Ensure the destination 'to' is populated with the requested shader. If already non-null, does nothing.

Template Parameters
TDerived type, inheriting gfx::Shader
Parameters
toLocation to store the shader
shaderNameThe registry name to look up
Returns
True if 'to' has a valid program object, false otherwise.

Definition at line 112 of file shader_registry.hpp.

◆ registerShader() [1/2]

virtual bool mbgl::gfx::ShaderRegistry::registerShader ( std::shared_ptr< Shader > &&  shader)
virtualnoexcept

Register a new shader with the registry. If a shader is present in the registry with a conflicting name, registration will fail.

Parameters
shaderA gfx::Shader to register. The ShaderRegistry will take ownership.
Returns
True if the shader was registered, false if another shader is already present with a conflicting name.

◆ registerShader() [2/2]

virtual bool mbgl::gfx::ShaderRegistry::registerShader ( std::shared_ptr< Shader > &&  shader,
const std::string &  shaderName 
)
virtualnoexcept

Register a new shader with the registry. If a shader is present in the registry with a conflicting name, registration will fail. This variant registers using an explicit name.

Parameters
shaderA gfx::Shader to register. The ShaderRegistry will take ownership.
shaderNameUnique name to register the shader under.
Returns
True if the shader was registered, false if another shader is already present with a conflicting name.

◆ replaceShader() [1/2]

virtual bool mbgl::gfx::ShaderRegistry::replaceShader ( std::shared_ptr< Shader > &&  shader)
virtualnoexcept

Replace a matching shader in the registry with the provided instance. Shader type-names must match.

Parameters
shaderA gfx::Shader. The ShaderRegistry will take ownership.
Returns
True if a match was found and the shader was replaced, false otherwise.

◆ replaceShader() [2/2]

virtual bool mbgl::gfx::ShaderRegistry::replaceShader ( std::shared_ptr< Shader > &&  shader,
const std::string &  shaderName 
)
virtualnoexcept

Replace a matching shader in the registry with the provided instance. Shader type-names must match. This variant replaces by explicit name.

Parameters
shaderA gfx::Shader. The ShaderRegistry will take ownership.
shaderNameUnique name to register the shader under.
Returns
True if a match was found and the shader was replaced, false otherwise.

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