Added logic to allow the use to optionally select either the Qt/OpenGL or SDL as the video driver.

This commit is contained in:
Matthew Budd 2020-07-20 22:45:33 -04:00
parent f59bf15d30
commit 3fc99f7d30
8 changed files with 122 additions and 29 deletions

View File

@ -26,7 +26,7 @@ ConsoleVideoConfDialog_t::ConsoleVideoConfDialog_t(QWidget *parent)
driverSelect = new QComboBox();
driverSelect->addItem( tr("OpenGL"), 0 );
//driverSelect->addItem( tr("SDL"), 1 );
driverSelect->addItem( tr("SDL"), 1 );
hbox1 = new QHBoxLayout();
@ -52,8 +52,10 @@ ConsoleVideoConfDialog_t::ConsoleVideoConfDialog_t(QWidget *parent)
regionSelect->addItem( tr("Dendy"), 2 );
setComboBoxFromProperty( regionSelect, "SDL.PAL");
setComboBoxFromProperty( driverSelect, "SDL.VideoDriver");
connect(regionSelect, SIGNAL(currentIndexChanged(int)), this, SLOT(regionChanged(int)) );
connect(driverSelect, SIGNAL(currentIndexChanged(int)), this, SLOT(driverChanged(int)) );
hbox1 = new QHBoxLayout();
@ -199,6 +201,20 @@ void ConsoleVideoConfDialog_t::showFPSChanged( int value )
fceuWrapperUnLock();
}
//----------------------------------------------------
void ConsoleVideoConfDialog_t::driverChanged(int index)
{
int driver;
//printf("Driver: %i : %i \n", index, driverSelect->itemData(index).toInt() );
driver = driverSelect->itemData(index).toInt();
g_config->setOption ("SDL.VideoDriver", driver);
g_config->save ();
printf("Note: A restart of the application is needed for video driver change to take effect...\n");
}
//----------------------------------------------------
void ConsoleVideoConfDialog_t::regionChanged(int index)
{
int region;

View File

@ -47,6 +47,7 @@ class ConsoleVideoConfDialog_t : public QDialog
void clipSidesChanged( int value );
void showFPSChanged( int value );
void regionChanged(int index);
void driverChanged(int index);
void applyChanges( void );
void closewindow( void );

View File

@ -15,6 +15,12 @@ extern unsigned int gui_draw_area_height;
ConsoleViewSDL_t::ConsoleViewSDL_t(QWidget *parent)
: QWidget( parent )
{
QPalette pal = palette();
pal.setColor(QPalette::Background, Qt::black);
setAutoFillBackground(true);
setPalette(pal);
view_width = GL_NES_WIDTH;
view_height = GL_NES_HEIGHT;
@ -30,11 +36,29 @@ ConsoleViewSDL_t::ConsoleViewSDL_t(QWidget *parent)
sdlTexture = NULL;
vsyncEnabled = false;
localBufSize = GL_NES_WIDTH * GL_NES_HEIGHT * sizeof(uint32_t);
localBuf = (uint32_t*)malloc( localBufSize );
if ( localBuf )
{
memset( localBuf, 0, localBufSize );
}
}
ConsoleViewSDL_t::~ConsoleViewSDL_t(void)
{
if ( localBuf )
{
free( localBuf ); localBuf = NULL;
}
}
void ConsoleViewSDL_t::transfer2LocalBuffer(void)
{
memcpy( localBuf, nes_shm->pixbuf, localBufSize );
}
int ConsoleViewSDL_t::init(void)
@ -46,10 +70,16 @@ int ConsoleViewSDL_t::init(void)
printf("[SDL] Failed to initialize video subsystem.\n");
return -1;
}
//else
//{
// printf("Initialized SDL Video Subsystem\n");
//}
else
{
printf("Initialized SDL Video Subsystem\n");
}
for (int i=0; i<SDL_GetNumVideoDrivers(); i++)
{
printf("SDL Video Driver %i: %s\n", i, SDL_GetVideoDriver(i) );
}
printf("Using Video Driver: %s \n", SDL_GetCurrentVideoDriver() );
windowHandle = this->winId();
@ -132,17 +162,18 @@ void ConsoleViewSDL_t::resizeEvent(QResizeEvent *event)
s = event->size();
view_width = s.width();
view_height = s.height();
//printf("SDL Resize: %i x %i \n", view_width, view_height);
printf("SDL Resize: %i x %i \n", view_width, view_height);
reset();
sdlViewport.x = sdlRendW - view_width;
sdlViewport.y = sdlRendH - view_height;
sdlViewport.w = view_width;
sdlViewport.h = view_height;
//sdlViewport.x = sdlRendW - view_width;
//sdlViewport.y = sdlRendH - view_height;
//sdlViewport.w = view_width;
//sdlViewport.h = view_height;
}
void ConsoleViewSDL_t::paintEvent( QPaintEvent *event )
//void ConsoleViewSDL_t::paintEvent( QPaintEvent *event )
void ConsoleViewSDL_t::render(void)
{
int nesWidth = GL_NES_WIDTH;
int nesHeight = GL_NES_HEIGHT;
@ -167,8 +198,10 @@ void ConsoleViewSDL_t::paintEvent( QPaintEvent *event )
rw=(int)(nesWidth*xscale);
rh=(int)(nesHeight*yscale);
sx=sdlViewport.x + (view_width-rw)/2;
sy=sdlViewport.y + (view_height-rh)/2;
//sx=sdlViewport.x + (view_width-rw)/2;
//sy=sdlViewport.y + (view_height-rh)/2;
sx=(view_width-rw)/2;
sy=(view_height-rh)/2;
if ( (sdlRenderer == NULL) || (sdlTexture == NULL) )
{
@ -183,13 +216,13 @@ void ConsoleViewSDL_t::paintEvent( QPaintEvent *event )
int rowPitch;
SDL_LockTexture( sdlTexture, nullptr, (void**)&textureBuffer, &rowPitch);
{
memcpy( textureBuffer, nes_shm->pixbuf, GL_NES_HEIGHT*GL_NES_WIDTH*sizeof(uint32_t) );
memcpy( textureBuffer, localBuf, GL_NES_HEIGHT*GL_NES_WIDTH*sizeof(uint32_t) );
}
SDL_UnlockTexture(sdlTexture);
SDL_RenderSetViewport( sdlRenderer, &sdlViewport );
//SDL_RenderSetViewport( sdlRenderer, &sdlViewport );
SDL_Rect source = {0, 0, GL_NES_WIDTH, GL_NES_HEIGHT };
SDL_Rect source = {0, 0, nesWidth, nesHeight };
SDL_Rect dest = { sx, sy, rw, rh };
SDL_RenderCopy(sdlRenderer, sdlTexture, &source, &dest);

View File

@ -19,10 +19,13 @@ class ConsoleViewSDL_t : public QWidget
int init(void);
void reset(void);
void cleanup(void);
void render(void);
void transfer2LocalBuffer(void);
protected:
void paintEvent(QPaintEvent *event);
//void paintEvent(QPaintEvent *event);
void resizeEvent(QResizeEvent *event);
int view_width;
int view_height;
@ -37,10 +40,13 @@ class ConsoleViewSDL_t : public QWidget
bool vsyncEnabled;
uint32_t *localBuf;
uint32_t localBufSize;
SDL_Window *sdlWindow;
SDL_Renderer *sdlRenderer;
SDL_Texture *sdlTexture;
SDL_Rect sdlViewport;
//SDL_Rect sdlViewport;
private slots:
};

View File

@ -33,13 +33,28 @@
consoleWin_t::consoleWin_t(QWidget *parent)
: QMainWindow( parent )
{
int use_SDL_video = false;
createMainMenu();
viewport = new ConsoleViewGL_t(this);
//viewport = new ConsoleViewSDL_t(this);
g_config->getOption( "SDL.VideoDriver", &use_SDL_video );
viewport_GL = NULL;
viewport_SDL = NULL;
if ( use_SDL_video )
{
viewport_SDL = new ConsoleViewSDL_t(this);
setCentralWidget(viewport_SDL);
}
else
{
viewport_GL = new ConsoleViewGL_t(this);
setCentralWidget(viewport_GL);
}
setCentralWidget(viewport);
setWindowIcon(QIcon(":fceux1.png"));
gameTimer = new QTimer( this );
@ -75,7 +90,14 @@ consoleWin_t::~consoleWin_t(void)
emulatorThread->quit();
emulatorThread->wait();
delete viewport;
if ( viewport_GL != NULL )
{
delete viewport_GL; viewport_GL = NULL;
}
if ( viewport_SDL != NULL )
{
delete viewport_SDL; viewport_SDL = NULL;
}
delete mutex;
// LoadGame() checks for an IP and if it finds one begins a network session
@ -1333,10 +1355,17 @@ void consoleWin_t::updatePeriodic(void)
{
nes_shm->blitUpdated = 0;
viewport->transfer2LocalBuffer();
//viewport->repaint();
viewport->update();
if ( viewport_SDL )
{
viewport_SDL->transfer2LocalBuffer();
viewport_SDL->render();
}
else
{
viewport_GL->transfer2LocalBuffer();
//viewport_GL->repaint();
viewport_GL->update();
}
}
return;

View File

@ -39,8 +39,8 @@ class consoleWin_t : public QMainWindow
consoleWin_t(QWidget *parent = 0);
~consoleWin_t(void);
ConsoleViewGL_t *viewport;
//ConsoleViewSDL_t *viewport;
ConsoleViewGL_t *viewport_GL;
ConsoleViewSDL_t *viewport_SDL;
void setCyclePeriodms( int ms );

View File

@ -199,6 +199,7 @@ InitConfig()
// video controls
config->addOption('f', "fullscreen", "SDL.Fullscreen", 0);
config->addOption("videoDriver", "SDL.VideoDriver", 0);
// set x/y res to 0 for automatic fullscreen resolution detection (no change)
config->addOption('x', "xres", "SDL.XResolution", 0);

View File

@ -17,7 +17,14 @@ int main( int argc, char *argv[] )
consoleWindow->resize( 512, 512 );
consoleWindow->show();
consoleWindow->viewport->init();
if ( consoleWindow->viewport_SDL )
{
consoleWindow->viewport_SDL->init();
}
else
{
consoleWindow->viewport_GL->init();
}
retval = app.exec();