From c6c301c9f58698e7070b2e063123d9325d8d97b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Wed, 22 Jul 2020 14:47:57 +0200 Subject: [PATCH] ShaderNode: Fix BufferField remaining bugs --- src/ShaderNode/DataModels/BufferField.cpp | 35 +++++++++++++++++------ src/ShaderNode/DataModels/BufferField.hpp | 10 +++---- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/ShaderNode/DataModels/BufferField.cpp b/src/ShaderNode/DataModels/BufferField.cpp index 480d53c2c..844f56bd8 100644 --- a/src/ShaderNode/DataModels/BufferField.cpp +++ b/src/ShaderNode/DataModels/BufferField.cpp @@ -3,8 +3,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -12,6 +14,8 @@ BufferField::BufferField(ShaderGraph& graph) : ShaderNode(graph) { + UpdateFieldList(); + m_onBufferListUpdateSlot.Connect(GetGraph().OnBufferListUpdate, [&](ShaderGraph*) { UpdateBufferIndex(); }); m_onBufferUpdateSlot.Connect(GetGraph().OnBufferUpdate, [&](ShaderGraph*, std::size_t bufferIndex) { @@ -25,6 +29,7 @@ ShaderNode(graph) m_onStructListUpdateSlot.Connect(GetGraph().OnStructListUpdate, [&](ShaderGraph*) { + UpdateFieldList(); UpdateFieldIndex(); UpdatePreview(); @@ -33,6 +38,7 @@ ShaderNode(graph) m_onStructUpdateSlot.Connect(GetGraph().OnStructUpdate, [&](ShaderGraph*, std::size_t) { + UpdateFieldList(); UpdateFieldIndex(); UpdatePreview(); @@ -87,7 +93,7 @@ Nz::ShaderNodes::ExpressionPtr BufferField::GetExpression(Nz::ShaderNodes::Expre const auto& memberEntry = sourceStruct->members[currentField.finalFieldIndex]; assert(std::holds_alternative(memberEntry.type)); - return Nz::ShaderBuilder::AccessMember(std::move(sourceExpr), 0, graph.ToShaderExpressionType(std::get(memberEntry.type))); + return Nz::ShaderBuilder::AccessMember(std::move(sourceExpr), currentField.finalFieldIndex, graph.ToShaderExpressionType(std::get(memberEntry.type))); } unsigned int BufferField::nPorts(QtNodes::PortType portType) const @@ -109,7 +115,7 @@ void BufferField::BuildNodeEdition(QFormLayout* layout) connect(fieldSelection, qOverload(&QComboBox::currentIndexChanged), [=](int index) { if (index >= 0) - m_currentFieldText = fieldSelection->itemText(index).toStdString(); + m_currentFieldText = m_fieldList[index]; else m_currentFieldText.clear(); @@ -132,9 +138,9 @@ void BufferField::BuildNodeEdition(QFormLayout* layout) { m_currentBufferIndex = static_cast(index); - const ShaderGraph& graph = GetGraph(); - const auto& buffer = graph.GetBuffer(*m_currentBufferIndex); - PopulateField(fieldSelection, buffer.structIndex); + UpdateFieldList(); + for (const std::string& field : m_fieldList) + fieldSelection->addItem(QString::fromStdString(field)); } else m_currentBufferIndex.reset(); @@ -257,6 +263,7 @@ void BufferField::restore(const QJsonObject& data) m_currentBufferText = data["buffer"].toString().toStdString(); m_currentFieldText = data["field"].toString().toStdString(); UpdateBufferIndex(); + UpdateFieldIndex(); ShaderNode::restore(data); } @@ -307,7 +314,7 @@ bool BufferField::ComputePreview(QPixmap& pixmap) return true;*/ } -void BufferField::PopulateField(QComboBox* fieldList, std::size_t structIndex, const std::string& prefix) +void BufferField::PopulateFieldList(std::size_t structIndex, const std::string& prefix) { const auto& s = GetGraph().GetStruct(structIndex); for (const auto& member : s.members) @@ -316,9 +323,9 @@ void BufferField::PopulateField(QComboBox* fieldList, std::size_t structIndex, c { using T = std::decay_t; if constexpr (std::is_same_v) - fieldList->addItem(QString::fromStdString(prefix + member.name)); + m_fieldList.push_back(prefix + member.name); else if constexpr (std::is_same_v) - PopulateField(fieldList, arg, prefix + member.name + "."); + PopulateFieldList(arg, prefix + member.name + "."); else static_assert(AlwaysFalse::value, "non-exhaustive visitor"); }, @@ -454,3 +461,15 @@ void BufferField::UpdateFieldIndex() if (FetchField(buffer.structIndex, "")) resetIfNotFound.Reset(); } + +void BufferField::UpdateFieldList() +{ + m_fieldList.clear(); + if (!m_currentBufferIndex) + return; + + const ShaderGraph& graph = GetGraph(); + const auto& buffer = graph.GetBuffer(*m_currentBufferIndex); + + PopulateFieldList(buffer.structIndex); +} diff --git a/src/ShaderNode/DataModels/BufferField.hpp b/src/ShaderNode/DataModels/BufferField.hpp index 7d1295e99..8bd232a7a 100644 --- a/src/ShaderNode/DataModels/BufferField.hpp +++ b/src/ShaderNode/DataModels/BufferField.hpp @@ -3,13 +3,11 @@ #ifndef NAZARA_SHADERNODES_BUFFERFIELD_HPP #define NAZARA_SHADERNODES_BUFFERFIELD_HPP -#include -#include -#include #include #include -#include #include +#include +#include class BufferField : public ShaderNode { @@ -41,11 +39,12 @@ class BufferField : public ShaderNode private: bool ComputePreview(QPixmap& pixmap) override; - void PopulateField(QComboBox* fieldList, std::size_t structIndex, const std::string& prefix = ""); + void PopulateFieldList(std::size_t structIndex, const std::string& prefix = ""); const ShaderGraph::StructMemberEntry& RetrieveNestedMember() const; void UpdateBufferIndex(); void UpdateBufferText(); void UpdateFieldIndex(); + void UpdateFieldList(); NazaraSlot(ShaderGraph, OnBufferListUpdate, m_onBufferListUpdateSlot); NazaraSlot(ShaderGraph, OnBufferUpdate, m_onBufferUpdateSlot); @@ -63,6 +62,7 @@ class BufferField : public ShaderNode std::optional m_currentFieldIndex; std::string m_currentBufferText; std::string m_currentFieldText; + std::vector m_fieldList; }; #include