Class Shader#

Nested Relationships#

Nested Types#

Inheritance Relationships#

Derived Type#

Class Documentation#

class Shader#

Subclassed by TRAP::Graphics::API::VulkanShader

Public Functions

consteval Shader(const Shader&) = delete#

Copy constructor.

consteval Shader &operator=(const Shader&) = delete#

Copy assignment operator.

Shader(Shader&&) noexcept = default#

Move constructor.

Shader &operator=(Shader&&) noexcept = default#

Move assignment operator.

virtual ~Shader() = default#

Destructor.

bool Reload()#

Reload shader.

Returns:

True on successful reload (valid shader), else (invalid shader) otherwise.

virtual constexpr usize GetID() const noexcept = 0#

Retrieve the unique identifier of the shader.

Note

The ID of the shader changes when reloaded.

constexpr std::string GetName() const noexcept#

Retrieve the name of the shader.

Returns:

Name of the shader.

std::filesystem::path GetFilePath() const noexcept#

Retrieve the file path of the shader.

Returns:

File path of the shader.

constexpr RendererAPI::ShaderStage GetShaderStages() const noexcept#

Retrieve the shader stages of the shader.

Returns:

Shader stages of the shader.

constexpr const std::vector<Macro> &GetMacros() const noexcept#

Retrieve the used macros of the shader.

Returns:

Used macros.

TRAP::Ref<RootSignature> GetRootSignature() const noexcept#

Retrieve the root signature of the shader.

Returns:

Root signature of the shader.

constexpr const std::array<TRAP::Scope<DescriptorSet>, RendererAPI::MaxDescriptorSets> &GetDescriptorSets() const noexcept#

Retrieve the descriptor sets of the shader.

Returns:

Descriptor sets of the shader.

constexpr bool IsShaderValid() const noexcept#

Retrieve whether the shader is valid (i.e. loaded and compiled) or not.

Returns:

True if shader is valid, false otherwise.

constexpr RendererAPI::ShaderType GetShaderType() const noexcept#

Retrieve the type of the shader.

Returns:

ShaderType.

virtual void Use(const Window &window = *TRAP::Application::GetWindow()) = 0#

Use shader for rendering on the given window.

Remark

Headless mode: This function is not available in headless mode.

Parameters:

windowWindow to use the shader for. Default: Main Window.

virtual void UseTexture(u32 set, u32 binding, const TRAP::Graphics::Texture &texture, const Window &window = *TRAP::Application::GetWindow()) const = 0#

Use texture with this shader on the given window.

Remark

Headless mode: This function is not available in headless mode.

Parameters:
  • set – Descriptor set to use the texture with.

  • binding – Binding point of the texture.

  • textureTexture to use.

  • windowWindow to use the shader for. Default: Main Window.

virtual void UseTextures(u32 set, u32 binding, const std::vector<const TRAP::Graphics::Texture*> &textures, const Window &window = *TRAP::Application::GetWindow()) const = 0#

Use multiple textures with this shader on the given window.

Remark

Headless mode: This function is not available in headless mode.

Parameters:
  • set – Descriptor set to use the textures with.

  • binding – Binding point of the textures.

  • textures – Textures to use.

  • windowWindow to use the shader for. Default: Main Window.

virtual void UseSampler(u32 set, u32 binding, const TRAP::Graphics::Sampler &sampler, const Window &window = *TRAP::Application::GetWindow()) const = 0#

Use sampler with this shader on the given window.

Remark

Headless mode: This function is not available in headless mode.

Parameters:
  • set – Descriptor set to use the sampler with.

  • binding – Binding point of the sampler.

  • samplerSampler to use.

  • windowWindow to use the shader for. Default: Main Window.

virtual void UseSamplers(u32 set, u32 binding, const std::vector<const TRAP::Graphics::Sampler*> &samplers, const Window &window = *TRAP::Application::GetWindow()) const = 0#

Use multiple samplers with this shader on the given window.

Remark

Headless mode: This function is not available in headless mode.

Parameters:
  • set – Descriptor set to use the samplers with.

  • binding – Binding point of the samplers.

  • samplers – Samplers to use.

  • windowWindow to use the shader for. Default: Main Window.

virtual void UseUBO(u32 set, u32 binding, const TRAP::Graphics::UniformBuffer &uniformBuffer, u64 size = 0, u64 offset = 0, const Window &window = *TRAP::Application::GetWindow()) const = 0#

Use uniform buffer object with this shader on the given window.

Remark

Headless mode: This function is not available in headless mode.

Parameters:
  • set – Descriptor set to use the UBO with.

  • binding – Binding point of the UBO.

  • uniformBuffer – Uniform buffer to use.

  • size – Size of the UBO.

  • offset – Offset of the UBO.

  • windowWindow to use the shader for. Default: Main Window.

virtual void UseSSBO(u32 set, u32 binding, const TRAP::Graphics::StorageBuffer &storageBuffer, u64 size = 0, const Window &window = *TRAP::Application::GetWindow()) const = 0#

Use shader storage buffer object with this shader on the given window.

Remark

Headless mode: This function is not available in headless mode.

Parameters:
  • set – Descriptor set to use the SSBO with.

  • binding – Binding point of the SSBO.

  • storageBuffer – Storage buffer to use.

  • size – Size of the SSBO.

  • windowWindow to use the shader for. Default: Main Window.

virtual constexpr std::array<u32, 3> GetNumThreadsPerGroup() const noexcept = 0#

Retrieve the shaders thread count per work group.

Returns:

Shaders thread count per work group.

Public Static Functions

static Ref<Shader> CreateFromFile(RendererAPI::ShaderType shaderType, const std::string &name, const std::filesystem::path &filePath, const std::vector<Macro> &userMacros = {})#

Create a shader from file.

Parameters:
  • shaderType – Type of the shader.

  • name – Name for the shader.

  • filePath – File path of the shader.

  • userMacrosOptional user defined macros. Default: nullptr.

Returns:

Loaded Shader on success, Fallback Shader otherwise.

static Ref<Shader> CreateFromFile(RendererAPI::ShaderType shaderType, const std::filesystem::path &filePath, const std::vector<Macro> &userMacros = {})#

Create a shader from file. File name will be used as the shader name.

Parameters:
  • shaderType – Type of the shader.

  • filePath – File path of the shader.

  • userMacrosOptional user defined macros. Default: nullptr.

Returns:

Loaded Shader on success, Fallback Shader otherwise.

static Ref<Shader> CreateFromSource(RendererAPI::ShaderType shaderType, const std::string &name, const std::string &glslSource, const std::vector<Macro> &userMacros = {})#

Create a shader from GLSL source.

Parameters:
  • shaderType – Type of the shader.

  • name – Name for the shader.

  • glslSource – GLSL Source code.

  • userMacrosOptional user defined macros. Default: nullptr.

Returns:

Loaded Shader on success, Fallback Shader otherwise.

Public Static Attributes

static constexpr std::array<std::string_view, 3> SupportedShaderFormatSuffixes = {".shader", ".glsl", ".tp-spv"}#

Protected Functions

Shader(RendererAPI::ShaderType shaderType, std::string name, bool valid, RendererAPI::ShaderStage stages, const std::vector<Macro> &userMacros = {}, std::filesystem::path filepath = "")#

Constructor.

virtual void Init(const RendererAPI::BinaryShaderDesc &desc) = 0#

Initialize API dependent shader.

Parameters:

desc – Binary shader description.

virtual void Shutdown() = 0#

Shutdown API dependent shader.

Protected Attributes

std::string m_name#
std::filesystem::path m_filepath#
RendererAPI::ShaderStage m_shaderStages = {}#
TRAP::Ref<RootSignature> m_rootSignature#
std::array<TRAP::Scope<DescriptorSet>, RendererAPI::MaxDescriptorSets> m_descriptorSets = {}#
std::vector<Macro> m_macros#
bool m_valid = {}#
RendererAPI::ShaderType m_shaderType#
struct Macro#

Struct defining a shader macro.

Public Members

std::string Definition = {}#
std::string Value = {}#