Skip to content

Commit

Permalink
Added vsync timer logic to Qt OpenGL video driver.
Browse files Browse the repository at this point in the history
  • Loading branch information
thor2016 committed Jan 31, 2024
1 parent 0135840 commit 4fa0d06
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/drivers/Qt/ConsoleViewerGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/drivers/Qt/ConsoleViewerGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -90,12 +90,14 @@ class ConsoleViewGL_t : public QOpenGLWidget, protected QOpenGLFunctions, public
unsigned int textureType;
unsigned int mouseButtonMask;
QColor *bgColor;
QTimer *drawTimer;

uint32_t *localBuf;
uint32_t localBufSize;

private slots:
void cleanupGL(void);
void renderFinished(void);
void onDrawSignal();
};

0 comments on commit 4fa0d06

Please sign in to comment.