// Copyright (C) 2021 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 namespace Nz { class ShaderModule; class NAZARA_GRAPHICS_API UberShader { public: struct Config; struct Option; using ConfigCallback = std::function& vertexBuffers)>; UberShader(ShaderStageTypeFlags shaderStages, const ShaderAst::StatementPtr& shaderAst); ~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); static constexpr std::size_t MaximumOptionValue = 32; struct Config { std::array 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 { std::size_t index; ShaderAst::ExpressionType type; }; private: std::unordered_map, ConfigHasher, ConfigEqual> m_combinations; std::unordered_map m_optionIndexByName; ShaderAst::StatementPtr m_shaderAst; ConfigCallback m_configCallback; ShaderStageTypeFlags m_shaderStages; }; } #include #endif // NAZARA_GRAPHICS_UBERSHADER_HPP