Merge pull request #404 from xsacha/master

Qt update
This commit is contained in:
B1ackDaemon 2014-07-08 20:18:44 +03:00
commit f232351720
6 changed files with 90 additions and 103 deletions

View file

@ -1,88 +1,56 @@
#include "glviewer.h" #include "glviewer.h"
#include <QQuickWindow> #include <QQuickWindow>
#include <QOpenGLContext> #include <QOpenGLContext>
#include <QSGSimpleTextureNode>
#include <QCoreApplication> #include <QCoreApplication>
GLViewer::GLViewer(QQuickItem* parent) // This class hooks beforeRendering and allows us to draw a scene and reset GL state.
: QQuickItem(parent), // In future, we will likely want to manually control the update rate.
m_timerID(0),
m_fbo(0)
{
this->setFlag(QQuickItem::ItemHasContents);
}
GLViewer::~GLViewer() void GLRenderer::paint() {
{ // Do GL here
this->cleanup(); glViewport(0, 0, m_viewportSize.width(), m_viewportSize.height());
}
void GLViewer::timerEvent(QTimerEvent* evt)
{
if (evt && evt->timerId() == m_timerID)
this->update();
}
QSGNode* GLViewer::updatePaintNode(QSGNode* node, UpdatePaintNodeData* data)
{
QSGSimpleTextureNode* textureNode = static_cast<QSGSimpleTextureNode*>(node);
if (!textureNode)
textureNode = new QSGSimpleTextureNode();
// Push Qt state.
glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);
glPushAttrib(GL_ALL_ATTRIB_BITS);
glMatrixMode(GL_TEXTURE);
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glShadeModel(GL_FLAT);
glDisable(GL_CULL_FACE);
glDisable(GL_LIGHTING);
glDisable(GL_STENCIL_TEST);
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
// Draw blue to the window to show that we work
glClearColor(0.2, 0, 0.8, 1);
glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE);
// Put the GL state back to how it was in case it makes SceneGraph angry
((QQuickWindow*)sender())->resetOpenGLState();
}
delete m_fbo; GLViewer::GLViewer()
m_fbo = 0; : m_renderer(0)
int width = this->width(); {
int height = this->height(); connect(this, SIGNAL(windowChanged(QQuickWindow*)), this, SLOT(handleWindowChanged(QQuickWindow*)));
if (width && height) { }
m_fbo = new QOpenGLFramebufferObject(width, height);
textureNode->setTexture(this->window()->createTextureFromId(m_fbo->texture(), m_fbo->size())); void GLViewer::handleWindowChanged(QQuickWindow *win)
{
if (win) {
connect(win, SIGNAL(beforeSynchronizing()), this, SLOT(sync()), Qt::DirectConnection);
connect(win, SIGNAL(sceneGraphInvalidated()), this, SLOT(cleanup()), Qt::DirectConnection);
// We will take over from here
win->setClearBeforeRendering(false);
} }
else }
{
textureNode->setTexture(this->window()->createTextureFromId(0, QSize(0,0))); void GLViewer::sync()
{
if (!m_renderer) {
m_renderer = new GLRenderer();
connect(window(), SIGNAL(beforeRendering()), m_renderer, SLOT(paint()), Qt::DirectConnection);
} }
textureNode->setRect(this->boundingRect()); m_renderer->setViewportSize(window()->size() * window()->devicePixelRatio());
if (m_fbo) {
m_fbo->bind();
}
// Restore (pop) Qt state.
glMatrixMode(GL_TEXTURE);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glPopAttrib();
glPopClientAttrib();
if (!m_timerID)
m_timerID = this->startTimer(16);
return textureNode;
} }
void GLViewer::cleanup() { void GLViewer::cleanup() {
this->killTimer(m_timerID); if (m_renderer) {
m_timerID = 0; delete m_renderer;
delete m_fbo; m_renderer = 0;
m_fbo = nullptr; }
} }

View file

@ -1,23 +1,35 @@
#pragma once #pragma once
#include <QQuickItem> #include <QQuickItem>
#include <QOpenGLFramebufferObject>
class GLRenderer : public QObject {
Q_OBJECT
public:
GLRenderer() { }
void setViewportSize(const QSize &size) { m_viewportSize = size; }
public slots:
void paint();
private:
QSize m_viewportSize;
};
class GLViewer : public QQuickItem class GLViewer : public QQuickItem
{ {
Q_OBJECT Q_OBJECT
public: public:
GLViewer(QQuickItem* parent = 0); GLViewer();
virtual ~GLViewer(); ~GLViewer() { cleanup(); }
protected: public slots:
QSGNode* updatePaintNode(QSGNode* old, UpdatePaintNodeData* data); void sync();
void timerEvent(QTimerEvent* evt);
private slots:
void cleanup(); void cleanup();
private slots:
void handleWindowChanged(QQuickWindow *win);
private: private:
int m_timerID; GLRenderer *m_renderer;
QOpenGLFramebufferObject* m_fbo;
}; };

View file

@ -1,4 +1,4 @@
// Qt5.1+ frontend implementation for rpcs3. Known to work on Windows, Linux, Mac // Qt5.2+ frontend implementation for rpcs3. Known to work on Windows, Linux, Mac
// by Sacha Refshauge // by Sacha Refshauge
#include <QGuiApplication> #include <QGuiApplication>
#include <QQmlApplicationEngine> #include <QQmlApplicationEngine>

View file

@ -1,21 +1,21 @@
import QtQuick 2.1 import QtQuick 2.2
import QtQuick.Controls 1.0 import QtQuick.Controls 1.1
import QtQuick.Window 2.0 import QtQuick.Window 2.1
import GLViewer 1.0 import GLViewer 1.0
ApplicationWindow { ApplicationWindow {
visible: true visible: true
title: qsTr("RPCS3 Qt") title: qsTr("RPCS3 Qt")
width: 500 width: Screen.desktopAvailableWidth / 2
height: 500 height: Screen.desktopAvailableHeight / 2
menuBar: MenuBar { menuBar: MenuBar {
Menu { Menu {
title: qsTr("&Boot") title: qsTr("&Boot")
MenuItem { text: qsTr("&Boot Game...") } MenuItem { text: qsTr("&Boot Game...") }
MenuItem { text: qsTr("&Boot Game and Start...") }
MenuItem { text: qsTr("&Install PKG") } MenuItem { text: qsTr("&Install PKG") }
MenuSeparator {} MenuSeparator {}
MenuItem { text: qsTr("Boot &ELF") } MenuItem { text: qsTr("Boot &(S)ELF") }
MenuItem { text: qsTr("Boot &SELF") }
MenuSeparator {} MenuSeparator {}
MenuItem { text: qsTr("E\&xit"); onTriggered: Qt.quit() } MenuItem { text: qsTr("E\&xit"); onTriggered: Qt.quit() }
} }
@ -30,6 +30,7 @@ ApplicationWindow {
Menu { Menu {
title: qsTr("&Config") title: qsTr("&Config")
MenuItem { text: qsTr("&Settings") } MenuItem { text: qsTr("&Settings") }
MenuItem { text: qsTr("&PAD Settings") }
MenuSeparator {} MenuSeparator {}
MenuItem { text: qsTr("Virtual &File System Manager") } MenuItem { text: qsTr("Virtual &File System Manager") }
MenuItem { text: qsTr("Virtual &HDD Manager") } MenuItem { text: qsTr("Virtual &HDD Manager") }
@ -38,14 +39,14 @@ ApplicationWindow {
title: qsTr("&Tools") title: qsTr("&Tools")
MenuItem { text: qsTr("&ELF Compiler") } MenuItem { text: qsTr("&ELF Compiler") }
MenuItem { text: qsTr("&Memory Viewer") } MenuItem { text: qsTr("&Memory Viewer") }
MenuItem { text: qsTr("&RSX Debugger") }
} }
Menu { Menu {
title: qsTr("&Help") title: qsTr("&Help")
MenuItem { text: qsTr("&About...") } MenuItem { text: qsTr("&About...") }
} }
} }
GLViewer { GLViewer {}
anchors.fill: parent
Rectangle { Rectangle {
color: Qt.rgba(0, 0.5, 0.35); color: Qt.rgba(0, 0.5, 0.35);
height: Math.round(parent.height / 2) height: Math.round(parent.height / 2)
@ -58,5 +59,5 @@ ApplicationWindow {
text: "Qt" text: "Qt"
} }
} }
}
} }

View file

@ -1,4 +1,4 @@
# Qt5.1+ project for rpcs3. Works on Windows, Linux and Mac OSX # Qt5.2+ project for rpcs3. Works on Windows, Linux and Mac OSX
QT += gui opengl quick QT += gui opengl quick
CONFIG += c++11 CONFIG += c++11

View file

@ -50,6 +50,10 @@
#endif // _DEBUG #endif // _DEBUG
#endif // MSVC_CRT_MEMLEAK_DETECTION #endif // MSVC_CRT_MEMLEAK_DETECTION
// This header should be frontend-agnostic, so don't assume wx includes everything
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cstdint> #include <cstdint>
typedef unsigned int uint; typedef unsigned int uint;
@ -302,7 +306,9 @@ enum Status
#include "Emu/FS/vfsStreamMemory.h" #include "Emu/FS/vfsStreamMemory.h"
#include "Emu/FS/vfsFile.h" #include "Emu/FS/vfsFile.h"
#include "Emu/FS/vfsDir.h" #include "Emu/FS/vfsDir.h"
#ifndef QT_UI
#include "rpcs3.h" #include "rpcs3.h"
#endif
#define _PRGNAME_ "RPCS3" #define _PRGNAME_ "RPCS3"
#define _PRGVER_ "0.0.0.4" #define _PRGVER_ "0.0.0.4"