Merge pull request #6410 from vitor-k/qt-vsync

citra_qt: fix vsync issues
This commit is contained in:
SachinVin 2023-04-08 16:51:29 +05:30 committed by GitHub
commit 6a0baef239
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 12 deletions

View file

@ -5,12 +5,11 @@
#include <glad/glad.h> #include <glad/glad.h>
#include <QApplication> #include <QApplication>
#include <QDragEnterEvent>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QKeyEvent> #include <QKeyEvent>
#include <QMessageBox> #include <QMessageBox>
#include <QPainter> #include <QPainter>
#include <fmt/format.h> #include <QWindow>
#include "citra_qt/bootmanager.h" #include "citra_qt/bootmanager.h"
#include "citra_qt/main.h" #include "citra_qt/main.h"
#include "common/color.h" #include "common/color.h"
@ -163,7 +162,7 @@ public:
// disable vsync for any shared contexts // disable vsync for any shared contexts
auto format = share_context->format(); auto format = share_context->format();
format.setSwapInterval(main_surface ? Settings::values.use_vsync_new.GetValue() : 0); format.setSwapInterval(0);
context = std::make_unique<QOpenGLContext>(); context = std::make_unique<QOpenGLContext>();
context->setShareContext(share_context); context->setShareContext(share_context);
@ -387,7 +386,7 @@ static Frontend::EmuWindow::WindowSystemInfo GetWindowSystemInfo(QWindow* window
return wsi; return wsi;
} }
std::shared_ptr<Frontend::GraphicsContext> GRenderWindow::main_context; std::unique_ptr<Frontend::GraphicsContext> GRenderWindow::main_context;
GRenderWindow::GRenderWindow(QWidget* parent_, EmuThread* emu_thread, bool is_secondary_) GRenderWindow::GRenderWindow(QWidget* parent_, EmuThread* emu_thread, bool is_secondary_)
: QWidget(parent_), EmuWindow(is_secondary_), emu_thread(emu_thread) { : QWidget(parent_), EmuWindow(is_secondary_), emu_thread(emu_thread) {
@ -668,12 +667,16 @@ bool GRenderWindow::InitializeOpenGL() {
child_widget->windowHandle()->create(); child_widget->windowHandle()->create();
if (!main_context) { if (!main_context) {
main_context = std::make_shared<OpenGLSharedContext>(); main_context = std::make_unique<OpenGLSharedContext>();
} }
auto child_context = CreateSharedContext(); auto child_context = CreateSharedContext();
child->SetContext(std::move(child_context)); child->SetContext(std::move(child_context));
auto format = child_widget->windowHandle()->format();
format.setSwapInterval(Settings::values.use_vsync_new.GetValue());
child_widget->windowHandle()->setFormat(format);
return true; return true;
#else #else
QMessageBox::warning(this, tr("OpenGL not available!"), QMessageBox::warning(this, tr("OpenGL not available!"),

View file

@ -10,17 +10,12 @@
#include <mutex> #include <mutex>
#include <QThread> #include <QThread>
#include <QWidget> #include <QWidget>
#include <QWindow>
#include "common/thread.h"
#include "core/core.h" #include "core/core.h"
#include "core/frontend/emu_window.h" #include "core/frontend/emu_window.h"
class QKeyEvent; class QKeyEvent;
class QTouchEvent; class QTouchEvent;
class QOffscreenSurface;
class QOpenGLContext;
class GMainWindow;
class GRenderWindow; class GRenderWindow;
namespace VideoCore { namespace VideoCore {
@ -197,7 +192,7 @@ private:
/// Main context that will be shared with all other contexts that are requested. /// Main context that will be shared with all other contexts that are requested.
/// If this is used in a shared context setting, then this should not be used directly, but /// If this is used in a shared context setting, then this should not be used directly, but
/// should instead be shared from /// should instead be shared from
static std::shared_ptr<Frontend::GraphicsContext> main_context; static std::unique_ptr<Frontend::GraphicsContext> main_context;
/// Temporary storage of the screenshot taken /// Temporary storage of the screenshot taken
QImage screenshot_image; QImage screenshot_image;

View file

@ -119,7 +119,8 @@ void ConfigureGraphics::SetupPerGameUI() {
ui->toggle_accurate_mul->setEnabled(Settings::values.shaders_accurate_mul.UsingGlobal()); ui->toggle_accurate_mul->setEnabled(Settings::values.shaders_accurate_mul.UsingGlobal());
ui->toggle_disk_shader_cache->setEnabled( ui->toggle_disk_shader_cache->setEnabled(
Settings::values.use_disk_shader_cache.UsingGlobal()); Settings::values.use_disk_shader_cache.UsingGlobal());
ui->toggle_vsync_new->setEnabled(Settings::values.use_vsync_new.UsingGlobal()); ui->toggle_vsync_new->setEnabled(ui->toggle_vsync_new->isEnabled() &&
Settings::values.use_vsync_new.UsingGlobal());
return; return;
} }