Significantly improve renderer performance

This commit is contained in:
Cacodemon345
2021-12-02 00:47:02 +06:00
parent 88452f7957
commit 23dbb85fa8
4 changed files with 26 additions and 10 deletions

View File

@@ -1,4 +1,5 @@
#include <QApplication>
#include <QImage>
#include "qt_gleswidget.hpp"
#ifdef __APPLE__
#include <CoreGraphics/CoreGraphics.h>
@@ -53,13 +54,20 @@ void GLESWidget::resizeGL(int w, int h)
void GLESWidget::initializeGL()
{
initializeOpenGLFunctions();
connect(this, &GLESWidget::reqUpdate, this, &GLESWidget::reqUpdate_);
}
void GLESWidget::paintGL()
{
QPainter painter(this);
//painter.fillRect(rect, QColor(0, 0, 0));
painter.drawImage(QRect(0, 0, width(), height()), m_image.convertToFormat(QImage::Format_RGBA8888), QRect(sx, sy, sw, sh));
painter.drawImage(QRect(0, 0, width(), height()), m_image.convertToFormat(QImage::Format_RGBX8888), QRect(sx, sy, sw, sh));
painter.end();
firstupdate = true;
}
void GLESWidget::reqUpdate_()
{
update();
}
void GLESWidget::mouseReleaseEvent(QMouseEvent *event)
@@ -114,8 +122,7 @@ void GLESWidget::mouseMoveEvent(QMouseEvent *event)
void GLESWidget::qt_real_blit(int x, int y, int w, int h)
{
// printf("Offpainter thread ID: %X\n", SDL_ThreadID());
if ((w <= 0) || (h <= 0) || (w > 2048) || (h > 2048) || (buffer32 == NULL))
if ((w <= 0) || (h <= 0) || (w > 2048) || (h > 2048) || (buffer32 == NULL) || !firstupdate)
{
video_blit_complete();
return;
@@ -124,7 +131,7 @@ void GLESWidget::qt_real_blit(int x, int y, int w, int h)
sy = y;
sw = this->w = w;
sh = this->h = h;
auto imagebits = m_image.bits();
static auto imagebits = m_image.bits();
for (int y1 = y; y1 < (y + h - 1); y1++)
{
auto scanline = imagebits + (y1 * (2048 + 64) * 4);
@@ -135,5 +142,5 @@ void GLESWidget::qt_real_blit(int x, int y, int w, int h)
video_screenshot((uint32_t *)imagebits, 0, 0, 2048 + 64);
}
video_blit_complete();
update();
this->reqUpdate();
}

View File

@@ -6,6 +6,8 @@
#include <QEvent>
#include <QKeyEvent>
#include <atomic>
class GLESWidget : public QOpenGLWidget, protected QOpenGLFunctions
{
Q_OBJECT
@@ -38,9 +40,13 @@ public:
{
event->ignore();
}
signals:
void reqUpdate();
public slots:
void qt_real_blit(int x, int y, int w, int h);
void qt_mouse_poll();
void reqUpdate_();
private:
struct mouseinputdata {
@@ -48,5 +54,5 @@ private:
int mousebuttons;
};
mouseinputdata mousedata;
std::atomic<bool> firstupdate{false};
};

View File

@@ -44,8 +44,6 @@ MainWindow::MainWindow(QWidget *parent) :
video_setblit(qt_blit);
ui->glesWidget->setMouseTracking(true);
connect(this, &MainWindow::blitToWidget, ui->glesWidget, &GLESWidget::qt_real_blit);
connect(this, &MainWindow::showMessageForNonQtThread, this, &MainWindow::showMessage_, Qt::BlockingQueuedConnection);
connect(this, &MainWindow::setTitleForNonQtThread, this, &MainWindow::setTitle_, Qt::BlockingQueuedConnection);
@@ -702,6 +700,11 @@ void MainWindow::keyPressEvent(QKeyEvent* event)
}
}
void MainWindow::blitToWidget(int x, int y, int w, int h)
{
ui->glesWidget->qt_real_blit(x, y, w, h);
}
void MainWindow::keyReleaseEvent(QKeyEvent* event)
{
#ifdef __APPLE__

View File

@@ -22,9 +22,9 @@ public:
void showMessage(const QString& header, const QString& message);
void setTitle(const wchar_t* title);
void getTitle(wchar_t* title);
void blitToWidget(int x, int y, int w, int h);
signals:
void paint(const QImage& image);
void blitToWidget(int x, int y, int w, int h);
void resizeContents(int w, int h);
void pollMouse();
void updateStatusBarPanes();