diff --git a/src/drivers/Qt/ConsoleViewerGL.cpp b/src/drivers/Qt/ConsoleViewerGL.cpp index b62102727..3f2035195 100644 --- a/src/drivers/Qt/ConsoleViewerGL.cpp +++ b/src/drivers/Qt/ConsoleViewerGL.cpp @@ -86,6 +86,12 @@ ConsoleViewGL_t::ConsoleViewGL_t(QWidget *parent) setFocusPolicy(Qt::StrongFocus); //setAttribute(Qt::WA_OpaquePaintEvent); + drawTimer = new QTimer(this); + drawTimer->setInterval(14); + drawTimer->setSingleShot(true); + drawTimer->setTimerType(Qt::PreciseTimer); + connect(drawTimer, &QTimer::timeout, this, &ConsoleViewGL_t::onDrawSignal); + localBufSize = (4 * GL_NES_WIDTH) * (4 * GL_NES_HEIGHT) * sizeof(uint32_t); localBuf = (uint32_t*)malloc( localBufSize ); @@ -137,6 +143,8 @@ ConsoleViewGL_t::ConsoleViewGL_t(QWidget *parent) ConsoleViewGL_t::~ConsoleViewGL_t(void) { //printf("Destroying GL Viewport\n"); + drawTimer->stop(); + delete drawTimer; if ( localBuf ) { @@ -566,6 +574,22 @@ void ConsoleViewGL_t::getNormalizedCursorPos( double &x, double &y ) void ConsoleViewGL_t::renderFinished(void) { videoBufferSwapMark(); + + // Schedule draw timing inline with vsync + drawTimer->start(); +} + +void ConsoleViewGL_t::queueRedraw(void) +{ + if (!drawTimer->isActive()) + { + update(); + } +} + +void ConsoleViewGL_t::onDrawSignal(void) +{ + update(); } void ConsoleViewGL_t::paintGL(void) diff --git a/src/drivers/Qt/ConsoleViewerGL.h b/src/drivers/Qt/ConsoleViewerGL.h index 12768ff79..22d92ee9c 100644 --- a/src/drivers/Qt/ConsoleViewerGL.h +++ b/src/drivers/Qt/ConsoleViewerGL.h @@ -22,7 +22,7 @@ class ConsoleViewGL_t : public QOpenGLWidget, protected QOpenGLFunctions, public int init(void); void reset(void); - void queueRedraw(void){ update(); }; + void queueRedraw(void); int driver(void){ return VIDEO_DRIVER_OPENGL; }; void transfer2LocalBuffer(void); @@ -90,6 +90,7 @@ class ConsoleViewGL_t : public QOpenGLWidget, protected QOpenGLFunctions, public unsigned int textureType; unsigned int mouseButtonMask; QColor *bgColor; + QTimer *drawTimer; uint32_t *localBuf; uint32_t localBufSize; @@ -97,5 +98,6 @@ class ConsoleViewGL_t : public QOpenGLWidget, protected QOpenGLFunctions, public private slots: void cleanupGL(void); void renderFinished(void); + void onDrawSignal(); };