Added vsync timer logic to Qt OpenGL video driver.

This commit is contained in:
harry 2024-01-31 07:08:08 -05:00
parent 01358407fd
commit 4fa0d0651a
2 changed files with 27 additions and 1 deletions

View File

@ -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)

View File

@ -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();
};