Created a local buffer for the openGL video image to better sync the image with the drawing frame in the gui thread.

This commit is contained in:
Matthew Budd 2020-07-05 21:40:19 -04:00
parent 4dca42bfca
commit f9b5796ef0
3 changed files with 31 additions and 3 deletions

View File

@ -30,6 +30,14 @@ ConsoleViewGL_t::ConsoleViewGL_t(QWidget *parent)
devPixRatio = screen->devicePixelRatio(); devPixRatio = screen->devicePixelRatio();
//printf("Ratio: %f \n", screen->devicePixelRatio() ); //printf("Ratio: %f \n", screen->devicePixelRatio() );
} }
localBufSize = GL_NES_WIDTH * GL_NES_HEIGHT * sizeof(uint32_t);
localBuf = (uint32_t*)malloc( localBufSize );
if ( localBuf )
{
memset( localBuf, 0, localBufSize );
}
} }
ConsoleViewGL_t::~ConsoleViewGL_t(void) ConsoleViewGL_t::~ConsoleViewGL_t(void)
@ -47,6 +55,11 @@ ConsoleViewGL_t::~ConsoleViewGL_t(void)
} }
doneCurrent(); doneCurrent();
if ( localBuf )
{
free( localBuf ); localBuf = NULL;
}
} }
int ConsoleViewGL_t::init( void ) int ConsoleViewGL_t::init( void )
@ -109,6 +122,11 @@ void ConsoleViewGL_t::resizeGL(int w, int h)
buildTextures(); buildTextures();
} }
void ConsoleViewGL_t::transfer2LocalBuffer(void)
{
memcpy( localBuf, nes_shm->pixbuf, localBufSize );
}
void ConsoleViewGL_t::paintGL(void) void ConsoleViewGL_t::paintGL(void)
{ {
int texture_width = nes_shm->ncol; int texture_width = nes_shm->ncol;
@ -149,7 +167,7 @@ void ConsoleViewGL_t::paintGL(void)
glTexSubImage2D(GL_TEXTURE_RECTANGLE, 0, glTexSubImage2D(GL_TEXTURE_RECTANGLE, 0,
0, 0, GL_NES_WIDTH, GL_NES_HEIGHT, 0, 0, GL_NES_WIDTH, GL_NES_HEIGHT,
GL_BGRA, GL_UNSIGNED_BYTE, nes_shm->pixbuf ); GL_BGRA, GL_UNSIGNED_BYTE, localBuf );
glBegin(GL_QUADS); glBegin(GL_QUADS);
glTexCoord2f( l, b); // Bottom left of picture. glTexCoord2f( l, b); // Bottom left of picture.

View File

@ -3,6 +3,8 @@
#pragma once #pragma once
#include <stdint.h>
#include <QOpenGLWidget> #include <QOpenGLWidget>
#include <QOpenGLFunctions> #include <QOpenGLFunctions>
@ -16,8 +18,10 @@ class ConsoleViewGL_t : public QOpenGLWidget, protected QOpenGLFunctions
int init( void ); int init( void );
void transfer2LocalBuffer(void);
protected: protected:
void initializeGL(void); void initializeGL(void);
void resizeGL(int w, int h); void resizeGL(int w, int h);
void paintGL(void); void paintGL(void);
@ -31,6 +35,9 @@ class ConsoleViewGL_t : public QOpenGLWidget, protected QOpenGLFunctions
GLuint gltexture; GLuint gltexture;
bool linearFilter; bool linearFilter;
uint32_t *localBuf;
uint32_t localBufSize;
private slots: private slots:
}; };

View File

@ -295,7 +295,10 @@ void consoleWin_t::update(void)
{ {
nes_shm->blitUpdated = 0; nes_shm->blitUpdated = 0;
viewport->repaint(); viewport->transfer2LocalBuffer();
//viewport->repaint();
viewport->update();
} }
return; return;