1
0
mirror of https://github.com/libretro/RetroArch synced 2025-03-23 10:20:57 +00:00

Qt: show shader pass in parameters window, reload shader params when shader is reloaded

This commit is contained in:
Brad Parker 2018-08-14 21:38:52 -04:00
parent 553394c266
commit 341cf63399
9 changed files with 192 additions and 84 deletions

@ -2441,10 +2441,14 @@ TODO: Add a setting for these tweaks */
if (!command_event_save_core_config())
return false;
break;
case CMD_EVENT_SHADER_PRESET_LOADED:
ui_companion_event_command(cmd);
break;
case CMD_EVENT_SHADERS_APPLY_CHANGES:
#ifdef HAVE_MENU
menu_shader_manager_apply_changes();
#endif
ui_companion_event_command(cmd);
break;
case CMD_EVENT_PAUSE_CHECKS:
{

@ -158,6 +158,8 @@ enum event_command
CMD_EVENT_MENU_REFRESH,
/* Applies shader changes. */
CMD_EVENT_SHADERS_APPLY_CHANGES,
/* A new shader preset has been loaded */
CMD_EVENT_SHADER_PRESET_LOADED,
/* Initializes shader directory. */
CMD_EVENT_SHADER_DIR_INIT,
/* Deinitializes shader directory. */

@ -2632,8 +2632,8 @@ void video_driver_frame(const void *data, unsigned width,
if (video_info.fps_show)
runloop_msg_queue_push(video_info.fps_text, 2, 1, true);
/* trigger set resolution*/
if (video_info.crt_switch_resolution)
/* trigger set resolution*/
if (video_info.crt_switch_resolution)
{
video_driver_crt_switching_active = true;
@ -2646,9 +2646,9 @@ void video_driver_frame(const void *data, unsigned width,
crt_switch_res_core(width, height, video_driver_core_hz);
}
else if (!video_info.crt_switch_resolution)
video_driver_crt_switching_active = false;
video_driver_crt_switching_active = false;
/* trigger set resolution*/
/* trigger set resolution*/
}
void video_driver_display_type_set(enum rarch_display_type type)
@ -3518,6 +3518,9 @@ bool video_shader_driver_get_current_shader(video_shader_ctx_t *shader)
bool video_shader_driver_direct_get_current_shader(
video_shader_ctx_t *shader)
{
if (!current_shader)
return false;
shader->data = current_shader->get_current_shader(current_shader_data);
return true;

@ -35,6 +35,7 @@
#include "../verbosity.h"
#include "../configuration.h"
#include "../frontend/frontend_driver.h"
#include "../command.h"
#include "video_driver.h"
#include "video_shader_parse.h"
@ -785,6 +786,8 @@ bool video_shader_read_conf_cgp(config_file_t *conf,
string_list_free(file_list);
}
command_event(CMD_EVENT_SHADER_PRESET_LOADED, NULL);
if (!video_shader_parse_textures(conf, shader))
return false;

@ -41,6 +41,7 @@ UI
#include "../ui/drivers/qt/ui_qt_browser_window.cpp"
#include "../ui/drivers/qt/ui_qt_msg_window.cpp"
#include "../ui/drivers/qt/ui_qt_application.cpp"
#include "../ui/drivers/qt/flowlayout.cpp"
#endif
/*============================================================

@ -203,6 +203,22 @@ static void setElidedText(QLabel *label, QWidget *clipWidget, int padding, const
const QPixmap getInvader();
ShaderParamsDialog::ShaderParamsDialog(QWidget *parent) :
QDialog(parent)
{
}
ShaderParamsDialog::~ShaderParamsDialog()
{
}
void ShaderParamsDialog::closeEvent(QCloseEvent *event)
{
QDialog::closeEvent(event);
emit closed();
}
GridItem::GridItem() :
QObject()
,widget(NULL)
@ -928,7 +944,7 @@ MainWindow::MainWindow(QWidget *parent) :
,m_allPlaylistsGridMaxCount(0)
,m_playlistEntryDialog(NULL)
,m_statusMessageElapsedTimer()
,m_shaderParamsDialog(NULL)
,m_shaderParamsDialog()
,m_networkManager(new QNetworkAccessManager(this))
,m_updateProgressDialog(new QProgressDialog())
,m_updateFile()
@ -1152,7 +1168,10 @@ MainWindow::MainWindow(QWidget *parent) :
/* make sure these use an auto connection so it will be queued if called from a different thread (some facilities in RA log messages from other threads) */
connect(this, SIGNAL(gotLogMessage(const QString&)), this, SLOT(onGotLogMessage(const QString&)), Qt::AutoConnection);
connect(this, SIGNAL(gotStatusMessage(QString,unsigned,unsigned,bool)), this, SLOT(onGotStatusMessage(QString,unsigned,unsigned,bool)), Qt::AutoConnection);
connect(this, SIGNAL(gotReloadPlaylists()), this, SLOT(onGotReloadPlaylists()));
connect(this, SIGNAL(gotReloadPlaylists()), this, SLOT(onGotReloadPlaylists()), Qt::AutoConnection);
connect(this, SIGNAL(gotReloadShaderParams()), this, SLOT(onGotReloadShaderParams()), Qt::AutoConnection);
/* these are always queued */
connect(this, SIGNAL(showErrorMessageDeferred(QString)), this, SLOT(onShowErrorMessage(QString)), Qt::QueuedConnection);
connect(this, SIGNAL(extractArchiveDeferred(QString)), this, SLOT(onExtractArchive(QString)), Qt::QueuedConnection);
@ -1218,9 +1237,11 @@ void MainWindow::removeUpdateTempFiles()
void MainWindow::onShaderParamsClicked()
{
QFormLayout *form = new QFormLayout();
video_shader_ctx_t shader_info;
unsigned i;
int last_pass = -1;
QFormLayout *last_form = NULL;
QGroupBox *last_group = NULL;
video_shader_driver_get_current_shader(&shader_info);
@ -1231,77 +1252,109 @@ void MainWindow::onShaderParamsClicked()
if (m_shaderParamsDialog)
delete m_shaderParamsDialog;
m_shaderParamsDialog = new QDialog();
m_shaderParamsDialog->setLayout(form);
m_shaderParamsDialog = new ShaderParamsDialog();
m_shaderParamsDialog->setLayout(new QVBoxLayout());
m_shaderParamsDialog->setWindowTitle(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_VIDEO_SHADER_PARAMETERS));
for (i = 0; i < shader_info.data->num_parameters; i++)
connect(m_shaderParamsDialog, SIGNAL(closed()), m_shaderParamsDialog, SLOT(deleteLater()));
if (shader_info.data->num_parameters == 0)
{
struct video_shader_parameter *param = &shader_info.data->parameters[i];
QString desc = param->desc;
QLabel *label = new QLabel(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NO_SHADER_PARAMETERS), m_shaderParamsDialog);
label->setAlignment(Qt::AlignCenter);
if ((param->minimum == 0.0)
&& (param->maximum
== (param->minimum
+ param->step)))
m_shaderParamsDialog->layout()->addWidget(label);
}
else
{
/* NOTE: We assume that parameters are always grouped in order by the pass number, e.g., all parameters for pass 0 come first, then params for pass 1, etc. */
for (i = 0; i < shader_info.data->num_parameters; i++)
{
/* option is basically a bool, so use a checkbox */
QCheckBox *checkBox = new QCheckBox(m_shaderParamsDialog);
checkBox->setChecked(param->current == param->maximum ? true : false);
checkBox->setProperty("param", QVariant::fromValue(param));
struct video_shader_parameter *param = &shader_info.data->parameters[i];
QString desc = param->desc;
QFormLayout *form = last_form;
connect(checkBox, SIGNAL(clicked()), this, SLOT(onShaderParamCheckBoxClicked()));
form->addRow(desc, checkBox);
}
else
{
QDoubleSpinBox *doubleSpinBox = NULL;
QSpinBox *spinBox = NULL;
QHBoxLayout *box = new QHBoxLayout();
QSlider *slider = new QSlider(Qt::Horizontal, m_shaderParamsDialog);
double value = lerp(param->minimum, param->maximum, 0, 100, param->current);
double intpart = 0;
bool stepIsFractional = modf(param->step, &intpart);
slider->setRange(0, 100);
slider->setSingleStep(1);
slider->setValue(value);
slider->setProperty("param", QVariant::fromValue(param));
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(onShaderParamSliderValueChanged(int)));
box->addWidget(slider);
if (stepIsFractional)
if (param->pass > last_pass)
{
doubleSpinBox = new QDoubleSpinBox(m_shaderParamsDialog);
doubleSpinBox->setRange(param->minimum, param->maximum);
doubleSpinBox->setSingleStep(param->step);
doubleSpinBox->setValue(param->current);
doubleSpinBox->setProperty("slider", QVariant::fromValue(slider));
slider->setProperty("doubleSpinBox", QVariant::fromValue(doubleSpinBox));
QGroupBox *groupBox = NULL;
QFileInfo fileInfo(shader_info.data->pass[param->pass].source.path);
QString shaderBasename = fileInfo.completeBaseName();
connect(doubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(onShaderParamDoubleSpinBoxValueChanged(double)));
form = new QFormLayout();
groupBox = new QGroupBox(shaderBasename);
groupBox->setLayout(form);
box->addWidget(doubleSpinBox);
m_shaderParamsDialog->layout()->addWidget(groupBox);
last_form = form;
last_pass = param->pass;
}
if ((param->minimum == 0.0)
&& (param->maximum
== (param->minimum
+ param->step)))
{
/* option is basically a bool, so use a checkbox */
QCheckBox *checkBox = new QCheckBox(m_shaderParamsDialog);
checkBox->setChecked(param->current == param->maximum ? true : false);
checkBox->setProperty("param", QVariant::fromValue(param));
connect(checkBox, SIGNAL(clicked()), this, SLOT(onShaderParamCheckBoxClicked()));
form->addRow(desc, checkBox);
}
else
{
spinBox = new QSpinBox(m_shaderParamsDialog);
spinBox->setRange(param->minimum, param->maximum);
spinBox->setSingleStep(param->step);
spinBox->setValue(param->current);
spinBox->setProperty("slider", QVariant::fromValue(slider));
slider->setProperty("spinBox", QVariant::fromValue(spinBox));
QDoubleSpinBox *doubleSpinBox = NULL;
QSpinBox *spinBox = NULL;
QHBoxLayout *box = new QHBoxLayout();
QSlider *slider = new QSlider(Qt::Horizontal, m_shaderParamsDialog);
double value = lerp(param->minimum, param->maximum, 0, 100, param->current);
double intpart = 0;
bool stepIsFractional = modf(param->step, &intpart);
connect(spinBox, SIGNAL(valueChanged(int)), this, SLOT(onShaderParamSpinBoxValueChanged(int)));
slider->setRange(0, 100);
slider->setSingleStep(1);
slider->setValue(value);
slider->setProperty("param", QVariant::fromValue(param));
box->addWidget(spinBox);
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(onShaderParamSliderValueChanged(int)));
box->addWidget(slider);
if (stepIsFractional)
{
doubleSpinBox = new QDoubleSpinBox(m_shaderParamsDialog);
doubleSpinBox->setRange(param->minimum, param->maximum);
doubleSpinBox->setSingleStep(param->step);
doubleSpinBox->setValue(param->current);
doubleSpinBox->setProperty("slider", QVariant::fromValue(slider));
slider->setProperty("doubleSpinBox", QVariant::fromValue(doubleSpinBox));
connect(doubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(onShaderParamDoubleSpinBoxValueChanged(double)));
box->addWidget(doubleSpinBox);
}
else
{
spinBox = new QSpinBox(m_shaderParamsDialog);
spinBox->setRange(param->minimum, param->maximum);
spinBox->setSingleStep(param->step);
spinBox->setValue(param->current);
spinBox->setProperty("slider", QVariant::fromValue(slider));
slider->setProperty("spinBox", QVariant::fromValue(spinBox));
connect(spinBox, SIGNAL(valueChanged(int)), this, SLOT(onShaderParamSpinBoxValueChanged(int)));
box->addWidget(spinBox);
}
form->addRow(desc, box);
}
form->addRow(desc, box);
}
m_shaderParamsDialog->layout()->addItem(new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding));
}
m_shaderParamsDialog->resize(720, 480);
@ -2456,6 +2509,17 @@ void MainWindow::onGotStatusMessage(QString msg, unsigned priority, unsigned dur
}
}
void MainWindow::deferReloadShaderParams()
{
emit gotReloadShaderParams();
}
void MainWindow::onGotReloadShaderParams()
{
if (m_shaderParamsDialog && m_shaderParamsDialog->isVisible())
onShaderParamsClicked();
}
void MainWindow::deferReloadPlaylists()
{
emit gotReloadPlaylists();

@ -623,11 +623,23 @@ static void ui_companion_qt_toggle(void *data, bool force)
static void ui_companion_qt_event_command(void *data, enum event_command cmd)
{
ui_companion_qt_t *handle = (ui_companion_qt_t*)data;
(void)cmd;
ui_window_qt_t *win_handle = (ui_window_qt_t*)handle->window;
if (!handle)
return;
switch (cmd)
{
case CMD_EVENT_SHADERS_APPLY_CHANGES:
/* PRESET_LOADED already fires in more situations than APPLY_CHANGES, use that for reloading the params window */
break;
case CMD_EVENT_SHADER_PRESET_LOADED:
RARCH_LOG("[Qt]: Reloading shader parameters.\n");
win_handle->qtWindow->deferReloadShaderParams();
break;
default:
break;
}
}
static void ui_companion_qt_notify_list_pushed(void *data, file_list_t *list,

@ -250,6 +250,18 @@ private:
QSpinBox *m_allPlaylistsGridMaxCountSpinBox;
};
class ShaderParamsDialog : public QDialog
{
Q_OBJECT
public:
ShaderParamsDialog(QWidget *parent = 0);
~ShaderParamsDialog();
signals:
void closed();
protected:
void closeEvent(QCloseEvent *event);
};
class CoreInfoLabel : public QLabel
{
Q_OBJECT
@ -365,6 +377,7 @@ signals:
void gotLogMessage(const QString &msg);
void gotStatusMessage(QString msg, unsigned priority, unsigned duration, bool flush);
void gotReloadPlaylists();
void gotReloadShaderParams();
void showErrorMessageDeferred(QString msg);
void extractArchiveDeferred(QString path);
@ -393,6 +406,7 @@ public slots:
void reloadPlaylists();
void deferReloadPlaylists();
void onGotReloadPlaylists();
void onGotReloadShaderParams();
void showWelcomeScreen();
void onIconViewClicked();
void onListViewClicked();
@ -403,6 +417,7 @@ public slots:
void showDocs();
void updateRetroArchNightly();
void onUpdateRetroArchFinished(bool success);
void deferReloadShaderParams();
private slots:
void onLoadCoreClicked(const QStringList &extensionFilters = QStringList());
@ -520,7 +535,7 @@ private:
int m_allPlaylistsGridMaxCount;
PlaylistEntryDialog *m_playlistEntryDialog;
QElapsedTimer m_statusMessageElapsedTimer;
QDialog *m_shaderParamsDialog;
QPointer<ShaderParamsDialog> m_shaderParamsDialog;
QNetworkAccessManager *m_networkManager;
QProgressDialog *m_updateProgressDialog;
QFile m_updateFile;

@ -103,6 +103,10 @@ void ui_companion_event_command(enum event_command action)
if (ui && ui->event_command)
ui->event_command(ui_companion_data, action);
#ifdef HAVE_QT
if (ui_companion_qt.toggle && qt_is_inited)
ui_companion_qt.event_command(ui_companion_qt_data, action);
#endif
}
void ui_companion_driver_deinit(void)