Graphics/UberShader: Add config callback

This commit is contained in:
Jérôme Leclercq
2021-09-05 15:46:59 +02:00
parent b6c3988bbe
commit 732bb89a86
6 changed files with 100 additions and 5 deletions

View File

@@ -24,6 +24,8 @@ namespace Nz
public:
struct Config;
struct Option;
using ConfigCallback = std::function<void(Config& config, const std::vector<RenderPipelineInfo::VertexBufferData>& vertexBuffers)>;
UberShader(ShaderStageTypeFlags shaderStages, const ShaderAst::StatementPtr& shaderAst);
~UberShader() = default;
@@ -33,6 +35,9 @@ namespace Nz
inline bool HasOption(const std::string& optionName, Pointer<const Option>* option = nullptr) const;
inline void UpdateConfig(Config& config, const std::vector<RenderPipelineInfo::VertexBufferData>& vertexBuffers);
inline void UpdateConfigCallback(ConfigCallback callback);
static constexpr std::size_t MaximumOptionValue = 32;
struct Config
@@ -60,6 +65,7 @@ namespace Nz
std::unordered_map<Config, std::shared_ptr<ShaderModule>, ConfigHasher, ConfigEqual> m_combinations;
std::unordered_map<std::string, Option> m_optionIndexByName;
ShaderAst::StatementPtr m_shaderAst;
ConfigCallback m_configCallback;
ShaderStageTypeFlags m_shaderStages;
};
}

View File

@@ -24,6 +24,17 @@ namespace Nz
return true;
}
inline void UberShader::UpdateConfig(Config& config, const std::vector<RenderPipelineInfo::VertexBufferData>& vertexBuffers)
{
if (m_configCallback)
m_configCallback(config, vertexBuffers);
}
inline void UberShader::UpdateConfigCallback(ConfigCallback callback)
{
m_configCallback = std::move(callback);
}
inline bool UberShader::ConfigEqual::operator()(const Config& lhs, const Config& rhs) const
{
for (std::size_t i = 0; i < lhs.optionValues.size(); ++i)