mirror of
https://github.com/starr-dusT/yuzu-mainline
synced 2024-03-05 21:12:25 -08:00
Fix the threading for GL Context in Qt5.
Connect the emu_thread start/finish to a moveContext slot.
This commit is contained in:
parent
fab2f28ea5
commit
a3a70e56ac
@ -1,5 +1,6 @@
|
|||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
#include "common/common.h"
|
#include "common/common.h"
|
||||||
#include "bootmanager.hxx"
|
#include "bootmanager.hxx"
|
||||||
@ -79,15 +80,11 @@ class GGLWidgetInternal : public QGLWidget
|
|||||||
public:
|
public:
|
||||||
GGLWidgetInternal(QGLFormat fmt, GRenderWindow* parent) : QGLWidget(parent)
|
GGLWidgetInternal(QGLFormat fmt, GRenderWindow* parent) : QGLWidget(parent)
|
||||||
{
|
{
|
||||||
doneCurrent();
|
|
||||||
parent_ = parent;
|
parent_ = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
void paintEvent(QPaintEvent* ev)
|
void paintEvent(QPaintEvent* ev)
|
||||||
{
|
{
|
||||||
// Apparently, Windows doesn't display anything if we don't call this here.
|
|
||||||
// TODO: Breaks linux though because we aren't calling doneCurrent() ... -.-
|
|
||||||
// makeCurrent();
|
|
||||||
}
|
}
|
||||||
void resizeEvent(QResizeEvent* ev) {
|
void resizeEvent(QResizeEvent* ev) {
|
||||||
parent_->SetClientAreaWidth(size().width());
|
parent_->SetClientAreaWidth(size().width());
|
||||||
@ -118,10 +115,22 @@ GRenderWindow::GRenderWindow(QWidget* parent) : QWidget(parent), emu_thread(this
|
|||||||
layout->addWidget(child);
|
layout->addWidget(child);
|
||||||
layout->setMargin(0);
|
layout->setMargin(0);
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
QObject::connect(&emu_thread, SIGNAL(started()), this, SLOT(moveContext()));
|
||||||
|
QObject::connect(&emu_thread, SIGNAL(finished()), this, SLOT(moveContext()));
|
||||||
|
|
||||||
BackupGeometry();
|
BackupGeometry();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GRenderWindow::moveContext()
|
||||||
|
{
|
||||||
|
DoneCurrent();
|
||||||
|
// We need to move GL context to the swapping thread in Qt5
|
||||||
|
#if QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
|
||||||
|
// If the thread started running, move the GL Context to the new thread. Otherwise, move it back.
|
||||||
|
child->context()->moveToThread(emu_thread.isRunning() ? &emu_thread : qApp->thread());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
GRenderWindow::~GRenderWindow()
|
GRenderWindow::~GRenderWindow()
|
||||||
{
|
{
|
||||||
emu_thread.Stop();
|
emu_thread.Stop();
|
||||||
@ -129,7 +138,7 @@ GRenderWindow::~GRenderWindow()
|
|||||||
|
|
||||||
void GRenderWindow::SwapBuffers()
|
void GRenderWindow::SwapBuffers()
|
||||||
{
|
{
|
||||||
child->makeCurrent(); // TODO: Not necessary?
|
// MakeCurrent is already called in renderer_opengl
|
||||||
child->swapBuffers();
|
child->swapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,4 +221,5 @@ void GRenderWindow::keyReleaseEvent(QKeyEvent* event)
|
|||||||
if (!key_processed)
|
if (!key_processed)
|
||||||
QWidget::keyPressEvent(event);
|
QWidget::keyPressEvent(event);
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,6 +81,8 @@ signals:
|
|||||||
|
|
||||||
class GRenderWindow : public QWidget, public EmuWindow
|
class GRenderWindow : public QWidget, public EmuWindow
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GRenderWindow(QWidget* parent = NULL);
|
GRenderWindow(QWidget* parent = NULL);
|
||||||
~GRenderWindow();
|
~GRenderWindow();
|
||||||
@ -103,6 +105,9 @@ public:
|
|||||||
void keyPressEvent(QKeyEvent* event);
|
void keyPressEvent(QKeyEvent* event);
|
||||||
void keyReleaseEvent(QKeyEvent* event);
|
void keyReleaseEvent(QKeyEvent* event);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void moveContext();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QGLWidget* child;
|
QGLWidget* child;
|
||||||
|
|
||||||
|
@ -142,7 +142,6 @@ void GMainWindow::BootGame(std::string filename)
|
|||||||
registersWidget->OnCPUStepped();
|
registersWidget->OnCPUStepped();
|
||||||
callstackWidget->OnCPUStepped();
|
callstackWidget->OnCPUStepped();
|
||||||
|
|
||||||
render_window->DoneCurrent(); // make sure EmuThread can access GL context
|
|
||||||
render_window->GetEmuThread().SetFilename(filename);
|
render_window->GetEmuThread().SetFilename(filename);
|
||||||
render_window->GetEmuThread().start();
|
render_window->GetEmuThread().start();
|
||||||
|
|
||||||
@ -204,7 +203,6 @@ void GMainWindow::ToggleWindowMode()
|
|||||||
ui.horizontalLayout->removeWidget(render_window);
|
ui.horizontalLayout->removeWidget(render_window);
|
||||||
render_window->setParent(NULL);
|
render_window->setParent(NULL);
|
||||||
render_window->setVisible(true);
|
render_window->setVisible(true);
|
||||||
render_window->DoneCurrent();
|
|
||||||
render_window->RestoreGeometry();
|
render_window->RestoreGeometry();
|
||||||
}
|
}
|
||||||
else if (!enable && render_window->parent() == NULL)
|
else if (!enable && render_window->parent() == NULL)
|
||||||
@ -212,7 +210,6 @@ void GMainWindow::ToggleWindowMode()
|
|||||||
render_window->BackupGeometry();
|
render_window->BackupGeometry();
|
||||||
ui.horizontalLayout->addWidget(render_window);
|
ui.horizontalLayout->addWidget(render_window);
|
||||||
render_window->setVisible(true);
|
render_window->setVisible(true);
|
||||||
render_window->DoneCurrent();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,6 @@ void Init(EmuWindow* emu_window) {
|
|||||||
glewExperimental = GL_TRUE;
|
glewExperimental = GL_TRUE;
|
||||||
|
|
||||||
g_emu_window = emu_window;
|
g_emu_window = emu_window;
|
||||||
g_emu_window->MakeCurrent();
|
|
||||||
g_renderer = new RendererOpenGL();
|
g_renderer = new RendererOpenGL();
|
||||||
g_renderer->SetWindow(g_emu_window);
|
g_renderer->SetWindow(g_emu_window);
|
||||||
g_renderer->Init();
|
g_renderer->Init();
|
||||||
|
Loading…
Reference in New Issue
Block a user