mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-04-20 11:36:13 +00:00
Qt: Update to Qt 5.2 code base. Makes the code much simpler!
This commit is contained in:
parent
3c7d48933f
commit
ba3838f54c
4 changed files with 77 additions and 98 deletions
|
@ -1,88 +1,56 @@
|
|||
#include "glviewer.h"
|
||||
#include <QQuickWindow>
|
||||
#include <QOpenGLContext>
|
||||
#include <QSGSimpleTextureNode>
|
||||
#include <QCoreApplication>
|
||||
|
||||
GLViewer::GLViewer(QQuickItem* parent)
|
||||
: QQuickItem(parent),
|
||||
m_timerID(0),
|
||||
m_fbo(0)
|
||||
{
|
||||
this->setFlag(QQuickItem::ItemHasContents);
|
||||
}
|
||||
// This class hooks beforeRendering and allows us to draw a scene and reset GL state.
|
||||
// In future, we will likely want to manually control the update rate.
|
||||
|
||||
GLViewer::~GLViewer()
|
||||
{
|
||||
this->cleanup();
|
||||
}
|
||||
void GLRenderer::paint() {
|
||||
// Do GL here
|
||||
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);
|
||||
|
||||
// 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);
|
||||
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;
|
||||
m_fbo = 0;
|
||||
int width = this->width();
|
||||
int height = this->height();
|
||||
if (width && height) {
|
||||
m_fbo = new QOpenGLFramebufferObject(width, height);
|
||||
textureNode->setTexture(this->window()->createTextureFromId(m_fbo->texture(), m_fbo->size()));
|
||||
GLViewer::GLViewer()
|
||||
: m_renderer(0)
|
||||
{
|
||||
connect(this, SIGNAL(windowChanged(QQuickWindow*)), this, SLOT(handleWindowChanged(QQuickWindow*)));
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
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;
|
||||
m_renderer->setViewportSize(window()->size() * window()->devicePixelRatio());
|
||||
}
|
||||
|
||||
void GLViewer::cleanup() {
|
||||
this->killTimer(m_timerID);
|
||||
m_timerID = 0;
|
||||
delete m_fbo;
|
||||
m_fbo = nullptr;
|
||||
if (m_renderer) {
|
||||
delete m_renderer;
|
||||
m_renderer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,23 +1,35 @@
|
|||
#pragma once
|
||||
|
||||
#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
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
GLViewer(QQuickItem* parent = 0);
|
||||
virtual ~GLViewer();
|
||||
GLViewer();
|
||||
~GLViewer() { cleanup(); }
|
||||
|
||||
protected:
|
||||
QSGNode* updatePaintNode(QSGNode* old, UpdatePaintNodeData* data);
|
||||
void timerEvent(QTimerEvent* evt);
|
||||
public slots:
|
||||
void sync();
|
||||
void cleanup();
|
||||
|
||||
private slots:
|
||||
void cleanup();
|
||||
void handleWindowChanged(QQuickWindow *win);
|
||||
|
||||
private:
|
||||
int m_timerID;
|
||||
QOpenGLFramebufferObject* m_fbo;
|
||||
GLRenderer *m_renderer;
|
||||
};
|
||||
|
|
|
@ -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
|
||||
#include <QGuiApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import QtQuick 2.1
|
||||
import QtQuick.Controls 1.0
|
||||
import QtQuick.Window 2.0
|
||||
import QtQuick 2.2
|
||||
import QtQuick.Controls 1.1
|
||||
import QtQuick.Window 2.1
|
||||
import GLViewer 1.0
|
||||
|
||||
ApplicationWindow {
|
||||
|
@ -44,19 +44,18 @@ ApplicationWindow {
|
|||
MenuItem { text: qsTr("&About...") }
|
||||
}
|
||||
}
|
||||
GLViewer {
|
||||
anchors.fill: parent
|
||||
Rectangle {
|
||||
color: Qt.rgba(0, 0.5, 0.35);
|
||||
height: Math.round(parent.height / 2)
|
||||
width: height
|
||||
radius: width
|
||||
GLViewer {}
|
||||
Rectangle {
|
||||
color: Qt.rgba(0, 0.5, 0.35);
|
||||
height: Math.round(parent.height / 2)
|
||||
width: height
|
||||
radius: width
|
||||
anchors.centerIn: parent
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
font.pixelSize: parent.height / 2
|
||||
text: "Qt"
|
||||
}
|
||||
font.pixelSize: parent.height / 2
|
||||
text: "Qt"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue