diff --git a/qrenderdoc/Windows/Dialogs/ProjectionGuessDialog.cpp b/qrenderdoc/Windows/Dialogs/ProjectionGuessDialog.cpp new file mode 100644 index 000000000..c1d3cd13c --- /dev/null +++ b/qrenderdoc/Windows/Dialogs/ProjectionGuessDialog.cpp @@ -0,0 +1,179 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2019-2025 Baldur Karlsson + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +#include "ProjectionGuessDialog.h" +#include +#include "Code/QRDUtils.h" +#include "ui_ProjectionGuessDialog.h" + +ProjectionGuessDialog::ProjectionGuessDialog(ICaptureContext &Ctx, + const ProjectionGuessParameters ¶ms, QWidget *parent) + : QDialog(parent), m_Ctx(Ctx), ui(new Ui::ProjectionGuessDialog) +{ + ui->setupUi(this); + setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); + + m_Params = params; + + if(m_Params.orthographic) + ui->matrixType->setCurrentIndex(1); + else + ui->matrixType->setCurrentIndex(0); + + ui->fov->setValue(m_Params.fov); + if(m_Params.aspect <= 0.0) + ui->aspectRatio->setText(QString()); + else + ui->aspectRatio->setText(QFormatStr("%1").arg(m_Params.aspect)); + + if(m_Params.nearPlane <= 0.0) + ui->nearPlane->setText(QString()); + else + ui->nearPlane->setText(QFormatStr("%1").arg(m_Params.nearPlane)); + + if(m_Params.farPlane == FLT_MAX) + ui->infiniteFar->setChecked(true); + else if(m_Params.farPlane <= 0.0) + ui->farPlane->setText(QString()); + else + ui->farPlane->setText(QFormatStr("%1").arg(m_Params.farPlane)); + + connect(ui->buttonBox, &QDialogButtonBox::accepted, this, + &ProjectionGuessDialog::validateParameters); + connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); +} + +void ProjectionGuessDialog::on_infiniteFar_toggled() +{ + if(ui->infiniteFar->isChecked()) + { + ui->farPlane->setEnabled(false); + ui->farPlane->setText(tr("Infinite - Reverse Z")); + } + else + { + ui->farPlane->setEnabled(true); + ui->farPlane->setText(QString()); + } +} + +void ProjectionGuessDialog::on_matrixType_currentIndexChanged(int idx) +{ + const bool ortho = (idx == 1); + + // not used for orthographic projection + ui->aspectRatio->setEnabled(!ortho); + ui->fov->setEnabled(!ortho); +} + +void ProjectionGuessDialog::validateParameters() +{ + QString str; + bool ok = false; + + m_Params.orthographic = (ui->matrixType->currentIndex() == 1); + + if(m_Params.orthographic) + { + m_Params.aspect = 0.0f; + m_Params.fov = 90.0f; + } + else + { + str = ui->aspectRatio->text(); + if(str.isEmpty()) + { + m_Params.aspect = 0.0f; + } + else + { + m_Params.aspect = str.toFloat(&ok); + if(!ok) + { + RDDialog::critical(this, tr("Aspect ratio error"), + tr("Unrecognised aspect ratio %1, expected decimal number.").arg(str)); + return; + } + } + + m_Params.fov = (float)ui->fov->value(); + } + + str = ui->nearPlane->text(); + if(str.isEmpty()) + { + m_Params.nearPlane = 0.0f; + } + else + { + m_Params.nearPlane = str.toFloat(&ok); + if(!ok) + { + RDDialog::critical( + this, tr("Near plane error"), + tr("Unrecognised near plane %1, expected decimal number if specified.").arg(str)); + return; + } + } + + if(ui->infiniteFar->isChecked()) + { + m_Params.farPlane = FLT_MAX; + } + else + { + str = ui->farPlane->text(); + if(str.isEmpty()) + { + m_Params.farPlane = 0.0f; + } + else + { + m_Params.farPlane = str.toFloat(&ok); + if(!ok) + { + RDDialog::critical( + this, tr("Far plane error"), + tr("Unrecognised far plane %1, expected decimal number if specified.").arg(str)); + return; + } + } + } + + if(m_Params.nearPlane > 0 && m_Params.farPlane > 0 && m_Params.nearPlane >= m_Params.farPlane) + { + RDDialog::critical(this, tr("Invalid near & far plane"), + tr("Near plane %1 must be less than far plane %2.") + .arg(m_Params.nearPlane) + .arg(m_Params.farPlane)); + return; + } + + accept(); +} + +ProjectionGuessDialog::~ProjectionGuessDialog() +{ + delete ui; +} diff --git a/qrenderdoc/Windows/Dialogs/ProjectionGuessDialog.h b/qrenderdoc/Windows/Dialogs/ProjectionGuessDialog.h new file mode 100644 index 000000000..f276f8ad2 --- /dev/null +++ b/qrenderdoc/Windows/Dialogs/ProjectionGuessDialog.h @@ -0,0 +1,66 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2019-2025 Baldur Karlsson + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +#pragma once + +#include +#include "Code/Interface/QRDInterface.h" + +struct ProjectionGuessParameters +{ + bool orthographic = false; + float fov = 90.0f; + float aspect = 0.0f; + float nearPlane = 0.0f; + float farPlane = 0.0f; +}; + +namespace Ui +{ +class ProjectionGuessDialog; +} + +struct ICaptureContext; + +class ProjectionGuessDialog : public QDialog +{ + Q_OBJECT +public: + explicit ProjectionGuessDialog(ICaptureContext &Ctx, const ProjectionGuessParameters ¶ms, + QWidget *parent = 0); + const ProjectionGuessParameters &getParameters() { return m_Params; } + ~ProjectionGuessDialog(); + +public slots: + void on_infiniteFar_toggled(); + void on_matrixType_currentIndexChanged(int idx); + +private slots: + void validateParameters(); + +private: + Ui::ProjectionGuessDialog *ui; + ICaptureContext &m_Ctx; + ProjectionGuessParameters m_Params; +}; diff --git a/qrenderdoc/Windows/Dialogs/ProjectionGuessDialog.ui b/qrenderdoc/Windows/Dialogs/ProjectionGuessDialog.ui new file mode 100644 index 000000000..ba1ea960c --- /dev/null +++ b/qrenderdoc/Windows/Dialogs/ProjectionGuessDialog.ui @@ -0,0 +1,180 @@ + + + ProjectionGuessDialog + + + + 0 + 0 + 296 + 356 + + + + Vertex Projection Configuration + + + + 10 + + + 10 + + + 10 + + + 10 + + + + + <html><head/><body><p>Configure your application's projection matrix used for final vertex transform, which will be used to unproject rasterized vertices into world space.</p><p>Some parameters can be empty, which will use an estimate/guess based on the current mesh data.</p><p>For reverse-Z you can enable an infinite far plane.</p></body></html> + + + true + + + + + + + Qt::Horizontal + + + + + + + 10 + + + + + Auto + + + true + + + + + + + Auto + + + true + + + + + + + 1 + + + 1.000000000000000 + + + 179.000000000000000 + + + 90.000000000000000 + + + + + + + Far Plane: + + + + + + + Aspect Ratio: + + + + + + + Auto + + + true + + + + + + + Matrix type + + + + + + + Near Plane: + + + + + + + FOV: + + + + + + + + Perspective + + + + + Orthographic + + + + + + + + Infinite + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + true + + + + + + + matrixType + fov + aspectRatio + nearPlane + farPlane + infiniteFar + + + +