From 9414beaed2af3736206fd33be3b10b9d7dbef105 Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 14 Jun 2020 14:05:20 +0200 Subject: [PATCH] Support multiple custom shaders directories for Texture Viewer --- qrenderdoc/Code/Interface/PersistantConfig.h | 9 +- qrenderdoc/Windows/Dialogs/SettingsDialog.cpp | 49 ++++-- qrenderdoc/Windows/Dialogs/SettingsDialog.h | 3 +- qrenderdoc/Windows/Dialogs/SettingsDialog.ui | 156 +++++++++--------- qrenderdoc/Windows/TextureViewer.cpp | 61 +++++-- qrenderdoc/Windows/TextureViewer.h | 4 +- 6 files changed, 163 insertions(+), 119 deletions(-) diff --git a/qrenderdoc/Code/Interface/PersistantConfig.h b/qrenderdoc/Code/Interface/PersistantConfig.h index 7b4e1447b..8ea22678a 100644 --- a/qrenderdoc/Code/Interface/PersistantConfig.h +++ b/qrenderdoc/Code/Interface/PersistantConfig.h @@ -302,7 +302,7 @@ DECLARE_REFLECTION_STRUCT(BugReport); \ CONFIG_SETTING_VAL(public, bool, bool, TextureViewer_PerTexYFlip, false) \ \ - CONFIG_SETTING_VAL(public, QString, rdcstr, TextureViewer_CustomShadersDirectory, "") \ + CONFIG_SETTING(public, QVariantList, rdcarray, TextureViewer_ShaderDirs) \ \ CONFIG_SETTING_VAL(public, bool, bool, AlwaysReplayLocally, false) \ \ @@ -525,12 +525,9 @@ For more information about some of these settings that are user-facing see Defaults to ``False``. -.. data:: TextureViewer_CustomShadersDirectory +.. data:: TextureViewer_ShadersDirs - Path to the directory containing custom shader files for Texture Viewer. If left empty, config - directory is used. - - Defaults to ``""`` + List of the directories containing custom shader files for the Texture Viewer. .. data:: AlwaysReplayLocally diff --git a/qrenderdoc/Windows/Dialogs/SettingsDialog.cpp b/qrenderdoc/Windows/Dialogs/SettingsDialog.cpp index e7c09a0a3..51da926da 100644 --- a/qrenderdoc/Windows/Dialogs/SettingsDialog.cpp +++ b/qrenderdoc/Windows/Dialogs/SettingsDialog.cpp @@ -127,7 +127,6 @@ SettingsDialog::SettingsDialog(ICaptureContext &ctx, QWidget *parent) ui->TextureViewer_ResetRange->setChecked(m_Ctx.Config().TextureViewer_ResetRange); ui->TextureViewer_PerTexSettings->setChecked(m_Ctx.Config().TextureViewer_PerTexSettings); ui->TextureViewer_PerTexYFlip->setChecked(m_Ctx.Config().TextureViewer_PerTexYFlip); - ui->TextureViewer_CustomShadersPath->setText(m_Ctx.Config().TextureViewer_CustomShadersDirectory); ui->CheckUpdate_AllowChecks->setChecked(m_Ctx.Config().CheckUpdate_AllowChecks); ui->Font_PreferMonospaced->setChecked(m_Ctx.Config().Font_PreferMonospaced); @@ -565,26 +564,48 @@ void SettingsDialog::on_TextureViewer_PerTexYFlip_toggled(bool checked) m_Ctx.Config().Save(); } -void SettingsDialog::on_browseCustomShadersPath_clicked() +void SettingsDialog::on_TextureViewer_ChooseShaderDirectories_clicked() { - QString dir = RDDialog::getExistingDirectory(this, tr("Choose directory for custom shaders"), - m_Ctx.Config().TextureViewer_CustomShadersDirectory); + QDialog listEditor; - if(!dir.isEmpty()) + listEditor.setWindowTitle(tr("Custom shaders search directories")); + listEditor.setWindowFlags(listEditor.windowFlags() & ~Qt::WindowContextHelpButtonHint); + + OrderedListEditor list(tr("Shaders Directory"), BrowseMode::Folder); + + QVBoxLayout layout; + QDialogButtonBox okCancel; + okCancel.setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok); + layout.addWidget(&list); + layout.addWidget(&okCancel); + + QObject::connect(&okCancel, &QDialogButtonBox::accepted, &listEditor, &QDialog::accept); + QObject::connect(&okCancel, &QDialogButtonBox::rejected, &listEditor, &QDialog::reject); + + listEditor.setLayout(&layout); + + QStringList items; + for(const rdcstr &dir : m_Ctx.Config().TextureViewer_ShaderDirs) { - m_Ctx.Config().TextureViewer_CustomShadersDirectory = dir; - ui->TextureViewer_CustomShadersPath->setText(dir); + items.append(dir); } - m_Ctx.Config().Save(); -} + list.setItems(items); -void SettingsDialog::on_resetCustomShadersPath_clicked() -{ - m_Ctx.Config().TextureViewer_CustomShadersDirectory = ""; - ui->TextureViewer_CustomShadersPath->setText(QString()); + int res = RDDialog::show(&listEditor); - m_Ctx.Config().Save(); + if(res) + { + items = list.getItems(); + + rdcarray newDirs(items.size()); + for(int i = 0; i < items.size(); i++) + { + newDirs[i] = items[i]; + } + + m_Ctx.Config().TextureViewer_ShaderDirs = newDirs; + } } void SettingsDialog::on_TextureViewer_ResetRange_toggled(bool checked) diff --git a/qrenderdoc/Windows/Dialogs/SettingsDialog.h b/qrenderdoc/Windows/Dialogs/SettingsDialog.h index b1573ab08..689da6a5c 100644 --- a/qrenderdoc/Windows/Dialogs/SettingsDialog.h +++ b/qrenderdoc/Windows/Dialogs/SettingsDialog.h @@ -81,8 +81,7 @@ private slots: void on_TextureViewer_PerTexSettings_toggled(bool checked); void on_TextureViewer_ResetRange_toggled(bool checked); void on_TextureViewer_PerTexYFlip_toggled(bool checked); - void on_browseCustomShadersPath_clicked(); - void on_resetCustomShadersPath_clicked(); + void on_TextureViewer_ChooseShaderDirectories_clicked(); // shader viewer void on_ShaderViewer_FriendlyNaming_toggled(bool checked); diff --git a/qrenderdoc/Windows/Dialogs/SettingsDialog.ui b/qrenderdoc/Windows/Dialogs/SettingsDialog.ui index a4fef3bd2..e18acf313 100644 --- a/qrenderdoc/Windows/Dialogs/SettingsDialog.ui +++ b/qrenderdoc/Windows/Dialogs/SettingsDialog.ui @@ -649,29 +649,61 @@ After interop is enabled you will need to reload any capture. Texture Viewer - - + + - Browse for the directory with custom shaders for Texture Viewer + List of the directories with custom shaders - Browse + Custom shader directories - - - - - 0 - 0 - + + + + + 50 + 0 + Reset visible range when changing event or texture + + Qt::RightToLeft + - Reset Range on changing selection + + + + + + + + + 50 + 0 + + + + Settings such as visible channels (RGBA) and selected mip/slice are remembered and restored per-texture. + + + Qt::RightToLeft + + + + + + + + + + Choose custom shader search directories. + + + Choose directories @@ -691,17 +723,42 @@ After interop is enabled you will need to reload any capture. - - + + + + + 50 + 0 + + - Path to the directory with custom shaders for Texture Viewer + Y-flipping state is remembered and restored per-texture, rather than treated as a global toggle. + + + Qt::RightToLeft - Custom shaders directory + - + + + + + 0 + 0 + + + + Reset visible range when changing event or texture + + + Reset Range on changing selection + + + + Qt::Vertical @@ -714,38 +771,6 @@ After interop is enabled you will need to reload any capture. - - - - - 50 - 0 - - - - Settings such as visible channels (RGBA) and selected mip/slice are remembered and restored per-texture. - - - - - - - - - - - 50 - 0 - - - - Reset visible range when changing event or texture - - - - - - @@ -762,39 +787,6 @@ After interop is enabled you will need to reload any capture. - - - - - 50 - 0 - - - - Y-flipping state is remembered and restored per-texture, rather than treated as a global toggle. - - - - - - - - - - Path to the directory with custom shaders for Texture Viewer - - - - - - - Reset custom shaders directory to default config path - - - Reset - - - diff --git a/qrenderdoc/Windows/TextureViewer.cpp b/qrenderdoc/Windows/TextureViewer.cpp index 80656ab98..db27e2633 100644 --- a/qrenderdoc/Windows/TextureViewer.cpp +++ b/qrenderdoc/Windows/TextureViewer.cpp @@ -4020,8 +4020,17 @@ void TextureViewer::reloadCustomShaders(const QString &filter) filters.push_back(lit("*.") + it.key()); } - QStringList files = getCustomShadersDir() - .entryList(filters, QDir::Files | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase); + QStringList files; + QList shaderDirectories = getShaderDirectories(); + for(const QDir &dir : shaderDirectories) + { + QStringList currentDirFiles = + dir.entryList(filters, QDir::Files | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase); + for(const QString &f : currentDirFiles) + { + files.append(QDir::cleanPath(dir.absoluteFilePath(f))); + } + } QStringList watchedFiles = m_Watcher->files(); if(!watchedFiles.isEmpty()) @@ -4037,12 +4046,11 @@ void TextureViewer::reloadCustomShaders(const QString &filter) if(!filter.isEmpty() && filter.toUpper() != key) continue; - QString filePath = QDir::cleanPath(getCustomShadersDir().absoluteFilePath(f)); - m_Watcher->addPath(filePath); + m_Watcher->addPath(f); if(!m_CustomShaders.contains(key) && !m_CustomShadersBusy.contains(key)) { - QFile fileHandle(filePath); + QFile fileHandle(f); if(fileHandle.open(QFile::ReadOnly | QFile::Text)) { QTextStream stream(&fileHandle); @@ -4134,11 +4142,36 @@ void TextureViewer::reloadCustomShaders(const QString &filter) } } -QDir TextureViewer::getCustomShadersDir() const +QList TextureViewer::getShaderDirectories() const { - return m_Ctx.Config().TextureViewer_CustomShadersDirectory.empty() - ? QDir(configFilePath(QString())) - : QDir(m_Ctx.Config().TextureViewer_CustomShadersDirectory); + QList dirs; + dirs.reserve(int(m_Ctx.Config().TextureViewer_ShaderDirs.size() + 1u)); + dirs.append(QDir(configFilePath(QString()))); + for(const rdcstr &dir : m_Ctx.Config().TextureViewer_ShaderDirs) + { + dirs.append(QDir(dir)); + } + + return dirs; +} + +QString TextureViewer::getShaderPath(const QString &filename) const +{ + QString path; + QList directories = getShaderDirectories(); + for(const QDir &dir : directories) + { + QStringList currentDirFiles = + dir.entryList(QDir::Files | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase); + + if(currentDirFiles.contains(filename, Qt::CaseInsensitive)) + { + path = QDir::cleanPath(dir.absoluteFilePath(filename)); + break; + } + } + + return path; } void TextureViewer::on_customCreate_clicked() @@ -4184,8 +4217,6 @@ void TextureViewer::on_customCreate_clicked() return; } - QString path = QDir::cleanPath(getCustomShadersDir().absoluteFilePath(filename)); - QString src; if(enc == ShaderEncoding::HLSL) @@ -4216,6 +4247,7 @@ void TextureViewer::on_customCreate_clicked() src = tr("Unknown format - no template available"); } + QString path = QDir::cleanPath(QDir(configFilePath(QString())).absoluteFilePath(filename)); QFile fileHandle(path); if(fileHandle.open(QFile::WriteOnly | QIODevice::Truncate | QIODevice::Text)) { @@ -4247,8 +4279,7 @@ void TextureViewer::on_customEdit_clicked() return; } - QString path = QDir::cleanPath(getCustomShadersDir().absoluteFilePath(filename)); - + QString path = getShaderPath(filename); QString src; QFile fileHandle(path); @@ -4339,7 +4370,8 @@ void TextureViewer::on_customDelete_clicked() if(res == QMessageBox::Yes) { - QString path = QDir::cleanPath(getCustomShadersDir().absoluteFilePath(shaderName)); + QString path = getShaderPath(shaderName); + if(!QFileInfo::exists(path)) { RDDialog::critical( @@ -4358,6 +4390,7 @@ void TextureViewer::on_customDelete_clicked() ui->customShader->setCurrentText(QString()); UI_UpdateChannels(); + reloadCustomShaders(QString()); } } diff --git a/qrenderdoc/Windows/TextureViewer.h b/qrenderdoc/Windows/TextureViewer.h index e28fc153f..293efebc9 100644 --- a/qrenderdoc/Windows/TextureViewer.h +++ b/qrenderdoc/Windows/TextureViewer.h @@ -24,6 +24,7 @@ #pragma once +#include #include #include #include @@ -350,7 +351,8 @@ private: bool canCompileCustomShader(ShaderEncoding encoding); void reloadCustomShaders(const QString &filter); - QDir getCustomShadersDir() const; + QList getShaderDirectories() const; + QString getShaderPath(const QString &filename) const; TextureDisplay m_TexDisplay; };