// 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 #include namespace Nz { class ShaderModule; class NAZARA_GRAPHICS_API UberShader { public: struct Config; struct Option; using ConfigCallback = std::function& vertexBuffers)>; UberShader(ShaderStageTypeFlags shaderStages, std::string moduleName); UberShader(ShaderStageTypeFlags shaderStages, ShaderModuleResolver& moduleResolver, std::string moduleName); UberShader(ShaderStageTypeFlags shaderStages, ShaderAst::ModulePtr shaderModule); ~UberShader() = default; inline 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: ShaderAst::ModulePtr Validate(const ShaderAst::Module& module, std::unordered_map* options); NazaraSlot(ShaderModuleResolver, OnModuleUpdated, m_onShaderModuleUpdated); std::unordered_map, ConfigHasher, ConfigEqual> m_combinations; std::unordered_map m_optionIndexByName; ShaderAst::ModulePtr m_shaderModule; ConfigCallback m_configCallback; ShaderStageTypeFlags m_shaderStages; }; } #include #endif // NAZARA_GRAPHICS_UBERSHADER_HPP