diff options
author | rtk0c <[email protected]> | 2024-04-27 10:06:05 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2025-08-16 11:34:45 -0700 |
commit | c1b01f66de039a34914387abe21ac52e7e00347a (patch) | |
tree | ef5d9d370a5c1956a27f5da06b839133913169e9 /src/brussel.engine/Material.cpp | |
parent | 9b2387dfe702bbadbdfde03fad8ba20daec127f8 (diff) |
Commit misc work from a while ago
Diffstat (limited to 'src/brussel.engine/Material.cpp')
-rw-r--r-- | src/brussel.engine/Material.cpp | 37 |
1 files changed, 19 insertions, 18 deletions
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<ShaderMathVariable&>(*decl); + switch (decl.index()) { + case ShaderInfo::kKindMath: { + auto& mathDecl = std::get<ShaderMathVariable>(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<ShaderSamplerVariable>(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<ShaderMathVariable&>(*shaderInfo.uniforms[field.infoUniformIndex]); + auto& decl = std::get<ShaderMathVariable>(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<ShaderMathVariable&>(*shaderInfo.uniforms[field.infoUniformIndex]); + auto& decl = std::get<ShaderMathVariable>(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<ShaderMathVariable&>(*shaderInfo.uniforms[field.infoUniformIndex]); + auto& decl = std::get<ShaderMathVariable>(shaderInfo.uniforms[field.infoUniformIndex]); decl.ShowInfo(); // TODO } for (auto& field : mInstance->mBoundTextures) { - auto& decl = static_cast<ShaderSamplerVariable&>(*shaderInfo.uniforms[field.infoUniformIndex]); + auto& decl = std::get<ShaderSamplerVariable>(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) { |