From 7151b0e5bcabb0216e79e742ae13c4f429ec2011 Mon Sep 17 00:00:00 2001 From: rtk0c Date: Sat, 27 Apr 2024 10:06:05 -0700 Subject: Commit misc work from a while ago --- src/brussel.engine/Material.cpp | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'src/brussel.engine/Material.cpp') diff --git a/src/brussel.engine/Material.cpp b/src/brussel.engine/Material.cpp index 4443ae5..21edd4d 100644 --- a/src/brussel.engine/Material.cpp +++ b/src/brussel.engine/Material.cpp @@ -230,35 +230,36 @@ void Material::SetShader(Shader* shader) { mBoundTextures.clear(); for (int i = 0; i < info.uniforms.size(); ++i) { auto& decl = info.uniforms[i]; - switch (decl->kind) { - case ShaderVariable::KD_Math: { - auto& mathDecl = static_cast(*decl); + switch (decl.index()) { + case ShaderInfo::kKindMath: { + auto& mathDecl = std::get(decl); if (mathDecl.width == 1) { if (mathDecl.height == 1) { // Scalar auto& scalar = mBoundScalars.emplace_back(); - scalar.location = decl->location; + scalar.location = mathDecl.location; scalar.infoUniformIndex = i; } else { // Vector auto& vec = mBoundVectors.emplace_back(); - vec.location = decl->location; + vec.location = mathDecl.location; vec.infoUniformIndex = i; vec.actualLength = mathDecl.height; } } else { // Matrix auto& mat = mBoundMatrices.emplace_back(); - mat.location = decl->location; + mat.location = mathDecl.location; mat.infoUniformIndex = i; mat.actualWidth = mathDecl.width; mat.actualHeight = mathDecl.height; } } break; - case ShaderVariable::KD_Sampler: { + case ShaderInfo::kKindSampler: { + auto& samplerDecl = std::get(decl); auto& uniform = mBoundTextures.emplace_back(); - uniform.location = decl->location; + uniform.location = samplerDecl.location; uniform.infoUniformIndex = i; } break; } @@ -363,7 +364,7 @@ void IresMaterial::ShowEditor(IEditor& editor) { auto shaderIres = shader->GetIres(); for (auto& field : mInstance->mBoundScalars) { - auto& decl = static_cast(*shaderInfo.uniforms[field.infoUniformIndex]); + auto& decl = std::get(shaderInfo.uniforms[field.infoUniformIndex]); decl.ShowInfo(); ImGui::Indent(); @@ -377,7 +378,7 @@ void IresMaterial::ShowEditor(IEditor& editor) { ImGui::Unindent(); } for (auto& field : mInstance->mBoundVectors) { - auto& decl = static_cast(*shaderInfo.uniforms[field.infoUniformIndex]); + auto& decl = std::get(shaderInfo.uniforms[field.infoUniformIndex]); decl.ShowInfo(); ImGui::Indent(); @@ -394,13 +395,13 @@ void IresMaterial::ShowEditor(IEditor& editor) { ImGui::Unindent(); } for (auto& field : mInstance->mBoundMatrices) { - auto& decl = static_cast(*shaderInfo.uniforms[field.infoUniformIndex]); + auto& decl = std::get(shaderInfo.uniforms[field.infoUniformIndex]); decl.ShowInfo(); // TODO } for (auto& field : mInstance->mBoundTextures) { - auto& decl = static_cast(*shaderInfo.uniforms[field.infoUniformIndex]); + auto& decl = std::get(shaderInfo.uniforms[field.infoUniformIndex]); decl.ShowInfo(); // TODO @@ -423,7 +424,7 @@ void IresMaterial::Write(IresWritingContext& ctx, rapidjson::Value& value, rapid rapidjson::Value fields(rapidjson::kArrayType); for (auto& scalar : mInstance->mBoundScalars) { rapidjson::Value rvField(rapidjson::kObjectType); - rvField.AddMember("Name", shaderInfo.uniforms[scalar.infoUniformIndex]->name, root.GetAllocator()); + rvField.AddMember("Name", std::visit([](auto&& v) { return v.name; }, shaderInfo.uniforms[scalar.infoUniformIndex]), root.GetAllocator()); rvField.AddMember("Type", "Scalar", root.GetAllocator()); switch (scalar.actualType) { case GL_FLOAT: rvField.AddMember("Value", scalar.floatValue, root.GetAllocator()); break; @@ -434,14 +435,14 @@ void IresMaterial::Write(IresWritingContext& ctx, rapidjson::Value& value, rapid } for (auto& vector : mInstance->mBoundVectors) { rapidjson::Value rvField(rapidjson::kObjectType); - rvField.AddMember("Name", shaderInfo.uniforms[vector.infoUniformIndex]->name, root.GetAllocator()); + rvField.AddMember("Name", std::visit([](auto&& v) { return v.name; }, shaderInfo.uniforms[vector.infoUniformIndex]), root.GetAllocator()); rvField.AddMember("Type", "Vector", root.GetAllocator()); rvField.AddMember("Value", MakeVectorJson(vector, root).Move(), root.GetAllocator()); fields.PushBack(rvField, root.GetAllocator()); } for (auto& matrix : mInstance->mBoundMatrices) { rapidjson::Value rvField(rapidjson::kObjectType); - rvField.AddMember("Name", shaderInfo.uniforms[matrix.infoUniformIndex]->name, root.GetAllocator()); + rvField.AddMember("Name", std::visit([](auto&& v) { return v.name; }, shaderInfo.uniforms[matrix.infoUniformIndex]), root.GetAllocator()); rvField.AddMember("Type", "Matrix", root.GetAllocator()); rvField.AddMember("Value", MakeMatrixJson(matrix, root).Move(), root.GetAllocator()); fields.PushBack(rvField, root.GetAllocator()); @@ -492,7 +493,7 @@ void IresMaterial::Read(IresLoadingContext& ctx, const rapidjson::Value& value) Material::ScalarUniform uniform; if (rvName) { TryFindShaderId(shader, rapidjson::AsStringView(*rvName), uniform.infoUniformIndex); - uniform.location = shaderInfo.uniforms[uniform.infoUniformIndex]->location; + uniform.location = std::visit([](auto&& v) { return v.location; }, shaderInfo.uniforms[uniform.infoUniformIndex]); } if (rvValue->IsFloat()) { uniform.actualType = GL_FLOAT; @@ -509,14 +510,14 @@ void IresMaterial::Read(IresLoadingContext& ctx, const rapidjson::Value& value) auto uniform = ReadVectorFromJson(*rvValue); if (rvName) { TryFindShaderId(shader, rapidjson::AsStringView(*rvName), uniform.infoUniformIndex); - uniform.location = shaderInfo.uniforms[uniform.infoUniformIndex]->location; + uniform.location = std::visit([](auto&& v) { return v.location; }, shaderInfo.uniforms[uniform.infoUniformIndex]); } mInstance->mBoundVectors.push_back(std::move(uniform)); } else if (type == "Matrix"sv) { auto uniform = ReadMatrixFromjson(*rvValue); if (rvName) { TryFindShaderId(shader, rapidjson::AsStringView(*rvName), uniform.infoUniformIndex); - uniform.location = shaderInfo.uniforms[uniform.infoUniformIndex]->location; + uniform.location = std::visit([](auto&& v) { return v.location; }, shaderInfo.uniforms[uniform.infoUniformIndex]); } mInstance->mBoundMatrices.push_back(uniform); } else if (type == "Texture"sv) { -- cgit v1.2.3-70-g09d2