#include #include template Mat4BinOp::Mat4BinOp(ShaderGraph& graph) : ShaderNode(graph) { UpdateOutput(); } template Nz::ShaderNodes::ExpressionPtr Mat4BinOp::GetExpression(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count) const { assert(count == 2); using BuilderType = typename Nz::ShaderBuilder::template BinOpBuilder; constexpr BuilderType builder; return builder(expressions[0], expressions[1]); } template QtNodes::NodeDataType Mat4BinOp::dataType(QtNodes::PortType /*portType*/, QtNodes::PortIndex portIndex) const { assert(portIndex == 0 || portIndex == 1); return Matrix4Data::Type(); } template unsigned int Mat4BinOp::nPorts(QtNodes::PortType portType) const { switch (portType) { case QtNodes::PortType::In: return 2; case QtNodes::PortType::Out: return 1; } return 0; } template std::shared_ptr Mat4BinOp::outData(QtNodes::PortIndex port) { assert(port == 0); return m_output; } template void Mat4BinOp::setInData(std::shared_ptr value, int index) { assert(index == 0 || index == 1); std::shared_ptr castedValue; if (value) { assert(dynamic_cast(value.get()) != nullptr); castedValue = std::static_pointer_cast(value); } if (index == 0) m_lhs = std::move(castedValue); else m_rhs = std::move(castedValue); UpdateOutput(); } template QtNodes::NodeValidationState Mat4BinOp::validationState() const { if (!m_lhs || !m_rhs) return QtNodes::NodeValidationState::Error; return QtNodes::NodeValidationState::Valid; } template QString Mat4BinOp::validationMessage() const { if (!m_lhs || !m_rhs) return "Missing operands"; return QString(); } template bool Mat4BinOp::ComputePreview(QPixmap& pixmap) { if (!m_lhs || !m_rhs) return false; return false; //pixmap = QPixmap::fromImage(m_output->preview.GenerateImage()); //return true; } template void Mat4BinOp::UpdateOutput() { if (validationState() != QtNodes::NodeValidationState::Valid) { m_output = std::make_shared(); return; } m_output = std::make_shared(); /*m_output = std::make_shared(m_lhs->componentCount); const PreviewValues& leftPreview = m_lhs->preview; const PreviewValues& rightPreview = m_rhs->preview; std::size_t maxWidth = std::max(leftPreview.GetWidth(), rightPreview.GetWidth()); std::size_t maxHeight = std::max(leftPreview.GetHeight(), rightPreview.GetHeight()); // FIXME: Prevent useless copy PreviewValues leftResized = leftPreview; if (leftResized.GetWidth() != maxWidth || leftResized.GetHeight() != maxHeight) leftResized = leftResized.Resized(maxWidth, maxHeight); PreviewValues rightResized = rightPreview; if (rightResized.GetWidth() != maxWidth || rightResized.GetHeight() != maxHeight) rightResized = rightResized.Resized(maxWidth, maxHeight); m_output->preview = PreviewValues(maxWidth, maxHeight); ApplyOp(leftResized.GetData(), rightResized.GetData(), m_output->preview.GetData(), maxWidth * maxHeight);*/ Q_EMIT dataUpdated(0); UpdatePreview(); }