diff options
Diffstat (limited to 'src/brussel.engine')
-rw-r--r-- | src/brussel.engine/Shader.cpp | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/src/brussel.engine/Shader.cpp b/src/brussel.engine/Shader.cpp index d795188..0b830c9 100644 --- a/src/brussel.engine/Shader.cpp +++ b/src/brussel.engine/Shader.cpp @@ -584,6 +584,20 @@ void IresShader::Write(IresWritingContext& ctx, rapidjson::Value& value, rapidjs out << mInstance->mInfo; } +static void ReadShaderMathVariable(const rapidjson::Value& rv, ShaderMathVariable& var) { + // TODO +} + +static void ReadShaderSamplerVariable(const rapidjson::Value& rv, ShaderSamplerVariable& var) { + // TODO +} + +template <typename T> +static void AddUniform(ShaderInfo& si, T uniform) { + si.things.try_emplace(uniform.name, ShaderThingId{ ShaderThingId::KD_Uniform, (int)si.uniforms.size() }); + si.uniforms.emplace_back(std::move(uniform)); +} + void IresShader::Read(IresLoadingContext& ctx, const rapidjson::Value& value) { using namespace ProjectBrussel_UNITY_ID; @@ -654,28 +668,22 @@ void IresShader::Read(IresLoadingContext& ctx, const rapidjson::Value& value) { BRUSSEL_JSON_GET_DEFAULT(rvUniform, "AutoFill", bool, autoFill, false); if (autoFill) continue; - auto uniform = [&]() -> std::unique_ptr<ShaderVariable> { - if (type == "Math"sv) { - auto uniform = std::make_unique<ShaderMathVariable>(); - ReadShaderMathVariable(*rvValue, *uniform); - - return uniform; - } else if (type == "Sampler"sv) { - auto uniform = std::make_unique<ShaderSamplerVariable>(); - ReadShaderSamplerVariable(*rvValue, *uniform); - - return uniform; - } - - return nullptr; - }(); - if (uniform) { - shaderInfo.things.try_emplace(uniform->name, ShaderThingId{ ShaderThingId::KD_Uniform, (int)shaderInfo.uniforms.size() }); - shaderInfo.uniforms.emplace_back(std::move(uniform)); + if (type == "Math"sv) { + ShaderMathVariable uniform; + ReadShaderMathVariable(*rvValue, uniform); + AddUniform(shaderInfo, uniform); + } else if (type == "Sampler"sv) { + ShaderSamplerVariable uniform; + ReadShaderSamplerVariable(*rvValue, uniform); + AddUniform(shaderInfo, uniform); } } for (auto& uniform : shaderInfo.uniforms) { - uniform->location = glGetUniformLocation(shaderProgram, uniform->name.c_str()); + std::visit( + [&](auto&& uniform) { + uniform.location = glGetUniformLocation(shaderProgram, uniform.name.c_str()); + }, + uniform); } } |