ACMX 2.139.0
Dual-Backend Real-Time GPU Video Synthesis
Loading...
Searching...
No Matches
shaderlibrary.cpp
Go to the documentation of this file.
1
2#include "shaderlibrary.hpp"
4#include "custom_style.hpp"
5#include "shader-manifest.hpp"
6#include <QDir>
7#include <QFile>
8#include <QSettings>
9#include <QTextStream>
10
11LibraryWindow::LibraryWindow(acmx2::Backend selectedBackend, QWidget *parent) : QDialog(parent), backend(selectedBackend) { init(); }
12
14 QVBoxLayout *layout = new QVBoxLayout(this);
15
16 QLabel *instructionLabel = new QLabel("Select a folder to create a shader index file:", this);
17 layout->addWidget(instructionLabel);
18
19 folderPathEdit = new QLineEdit(this);
20 folderPathEdit->setPlaceholderText("Folder path");
21 layout->addWidget(folderPathEdit);
22
23 browseButton = new QPushButton("Browse", this);
24 connect(browseButton, &QPushButton::clicked, this, &LibraryWindow::onBrowseButtonClicked);
25 layout->addWidget(browseButton);
26
27 createDefaultShaderCheckBox = new QCheckBox("Create default shader", this);
29 createDefaultShaderCheckBox->setText("Create default.frag passthrough shader");
30 createDefaultShaderCheckBox->setChecked(true);
31 createDefaultShaderCheckBox->setEnabled(false);
32 createDefaultShaderCheckBox->setToolTip("A new ACMXVK source library starts with a valid fragment shader.");
33 }
34 layout->addWidget(createDefaultShaderCheckBox);
35
36 createJsonManifestCheckBox = new QCheckBox("Use library.json manifest", this);
37 createJsonManifestCheckBox->setToolTip("Store the shader list as JSON. Existing libraries continue to support index.txt.");
38 layout->addWidget(createJsonManifestCheckBox);
40 createJsonManifestCheckBox->setChecked(true);
41 createJsonManifestCheckBox->setEnabled(false);
42 createJsonManifestCheckBox->setToolTip("ACMXVK source libraries always use library.json.");
43 }
44
45 QHBoxLayout *buttonLayout = new QHBoxLayout();
46 okButton = new QPushButton("OK", this);
47 connect(okButton, &QPushButton::clicked, this, &LibraryWindow::onOkButtonClicked);
48 buttonLayout->addWidget(okButton);
49
50 cancelButton = new QPushButton("Cancel", this);
51 connect(cancelButton, &QPushButton::clicked, this, &LibraryWindow::onCancelButtonClicked);
52 buttonLayout->addWidget(cancelButton);
53
54 layout->addLayout(buttonLayout);
55
56 setLayout(layout);
57 setWindowTitle("Shader Library Folder Selector");
58 resize(400, 200);
60}
61
63 QSettings appSettings("LostSideDead");
64 QString lastDir = appSettings.value("lastLibraryDir", "").toString();
65 QString folderPath = QFileDialog::getExistingDirectory(this, "Select Folder", lastDir);
66 if (!folderPath.isEmpty()) {
67 appSettings.setValue("lastLibraryDir", folderPath);
68 folderPathEdit->setText(folderPath + "/shaders");
69 }
70}
71
72const char *defaultFile = R"(#version 330 core
73in vec2 tc;
74out vec4 color;
75
76uniform sampler2D samp;
77
78void main() {
79 color = texture(samp, tc);
80}
81)";
82
83const char *defaultAcmxvkFile = R"(#version 450
84
85layout(location = 0) in vec2 tc;
86layout(location = 0) out vec4 color;
87layout(set = 0, binding = 0) uniform sampler2D samp;
88
89void main() {
90 color = texture(samp, tc);
91}
92)";
93
95 QString folderPath = folderPathEdit->text().trimmed();
96
97 if (folderPath.isEmpty()) {
98 QMessageBox::warning(this, "Warning", "Please select a folder.");
99 return;
100 }
101
102 QMessageBox::StandardButton reply = QMessageBox::question(this, "Confirm", QString("Do you want to create a shader library in the folder: %1?").arg(folderPath), QMessageBox::Yes | QMessageBox::No);
103
104 if (reply == QMessageBox::Yes) {
105 QDir dir;
106 if (!dir.mkpath(folderPath)) {
107 QMessageBox::critical(this, "Error", "Failed to create the shader library directory.");
108 return;
109 }
110 path = folderPath;
111
112 const QString defaultName = backend == acmx2::Backend::Acmxvk ? QStringLiteral("default.frag") : QStringLiteral("default.glsl");
113 QFile file(QDir(folderPath).filePath(defaultName));
114 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
115 QMessageBox::critical(this, "Error", QString("Failed to create %1: %2").arg(defaultName, file.errorString()));
116 return;
117 }
118 QTextStream out(&file);
119 if (createDefaultShaderCheckBox->isChecked())
121 out << "\n";
122 file.close();
123
124 if (!createShaderManifest(folderPath))
125 return;
126
127 QMessageBox::information(this, "Success", "Shader library created successfully.");
128 accept();
129 }
130}
131
133
135
136bool LibraryWindow::createShaderManifest(const QString &folderPath) {
137 QString error;
140 if (!acmx2::create_acmxvk_source_manifest(folderPath, QString(), result, error)) {
141 QMessageBox::critical(this, "Error", error);
142 return false;
143 }
144 return true;
145 }
147 if (!acmx2::create_shader_manifest(folderPath, format, {"default.glsl"}, error)) {
148 QMessageBox::critical(this, "Error", error);
149 return false;
150 }
151 return true;
152}
acmx2::Backend backend
void onBrowseButtonClicked()
void onOkButtonClicked()
QLineEdit * folderPathEdit
QCheckBox * createDefaultShaderCheckBox
void onCancelButtonClicked()
QCheckBox * createJsonManifestCheckBox
QPushButton * cancelButton
QString getShaderPath()
Return folder chosen for shader-library indexing.
bool createShaderManifest(const QString &folderPath)
QPushButton * okButton
LibraryWindow(acmx2::Backend backend, QWidget *parent=nullptr)
QPushButton * browseButton
bool create_acmxvk_source_manifest(const QString &rootDirectory, const QString &outputPath, AcmxvkSourceManifestResult &result, QString &error)
Scan an ACMXVK source tree and atomically generate its library.json.
Backend
Definition backend.hpp:8
void applyCustomStyleIfEnabled(QWidget *widget)
bool create_shader_manifest(const QString &directory, ShaderManifestFormat format, const QStringList &shaders, QString &error)
Create a new manifest in the requested format.
Optional JSON and legacy text shader-library manifests.
const char * defaultAcmxvkFile
const char * defaultFile
Dialog for generating a shader index from a selected folder.