// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com) // This file is part of the "Nazara Engine - Graphics module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once #ifndef NAZARA_GRAPHICS_UBERSHADER_HPP #define NAZARA_GRAPHICS_UBERSHADER_HPP #include #include #include #include #include #include #include #include namespace Nz { class ShaderModule; class NAZARA_GRAPHICS_API UberShader { public: struct Config; struct Option; using ConfigCallback = std::function& vertexBuffers)>; UberShader(nzsl::ShaderStageTypeFlags shaderStages, std::string moduleName); UberShader(nzsl::ShaderStageTypeFlags shaderStages, nzsl::ModuleResolver& moduleResolver, std::string moduleName); UberShader(nzsl::ShaderStageTypeFlags shaderStages, nzsl::Ast::ModulePtr shaderModule); ~UberShader() = default; inline nzsl::ShaderStageTypeFlags GetSupportedStages() const; const std::shared_ptr& Get(const Config& config); inline bool HasOption(const std::string& optionName, Pointer* option = nullptr) const; inline void UpdateConfig(Config& config, const std::vector& vertexBuffers); inline void UpdateConfigCallback(ConfigCallback callback); struct Config { std::unordered_map optionValues; }; struct ConfigEqual { inline bool operator()(const Config& lhs, const Config& rhs) const; }; struct ConfigHasher { inline std::size_t operator()(const Config& config) const; }; struct Option { UInt32 hash; }; NazaraSignal(OnShaderUpdated, UberShader* /*uberShader*/); private: nzsl::Ast::ModulePtr Validate(const nzsl::Ast::Module& module, std::unordered_map* options); NazaraSlot(nzsl::ModuleResolver, OnModuleUpdated, m_onShaderModuleUpdated); std::unordered_map, ConfigHasher, ConfigEqual> m_combinations; std::unordered_map m_optionIndexByName; nzsl::Ast::ModulePtr m_shaderModule; ConfigCallback m_configCallback; nzsl::ShaderStageTypeFlags m_shaderStages; }; } #include #endif // NAZARA_GRAPHICS_UBERSHADER_HPP