Added logic to allow switching the Qt GUI video driver while program is running with out needing a restart... although a restart is still probably the safest.

This commit is contained in:
mjbudd77 2021-03-25 20:20:01 -04:00
parent 4be5045fc7
commit 18c7c95ef3
6 changed files with 91 additions and 19 deletions

View File

@ -747,6 +747,11 @@ void ConsoleVideoConfDialog_t::driverChanged(int index)
g_config->save ();
printf("Note: A restart of the application is needed for video driver change to take effect...\n");
if ( consoleWindow )
{
consoleWindow->loadVideoDriver( driver );
}
}
//----------------------------------------------------
void ConsoleVideoConfDialog_t::scalerChanged(int index)

View File

@ -103,20 +103,6 @@ ConsoleViewGL_t::ConsoleViewGL_t(QWidget *parent)
ConsoleViewGL_t::~ConsoleViewGL_t(void)
{
// Make sure the context is current and then explicitly
// destroy all underlying OpenGL resources.
makeCurrent();
// Free GL texture
if (gltexture)
{
//printf("Destroying GL Texture\n");
glDeleteTextures(1, &gltexture);
gltexture=0;
}
doneCurrent();
if ( localBuf )
{
free( localBuf ); localBuf = NULL;
@ -160,15 +146,36 @@ void ConsoleViewGL_t::buildTextures(void)
void ConsoleViewGL_t::initializeGL(void)
{
//printf("initializeGL\n");
initializeOpenGLFunctions();
// Set up the rendering context, load shaders and other resources, etc.:
//QOpenGLFunctions *gl = QOpenGLContext::currentContext()->functions();
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
initializeOpenGLFunctions();
// Set up the rendering context, load shaders and other resources, etc.:
//QOpenGLFunctions *gl = QOpenGLContext::currentContext()->functions();
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
//printf("GL Init!\n");
buildTextures();
connect(context(), &QOpenGLContext::aboutToBeDestroyed, this, &ConsoleViewGL_t::cleanupGL);
}
void ConsoleViewGL_t::cleanupGL(void)
{
//printf("cleanupGL\n");
// Make sure the context is current and then explicitly
// destroy all underlying OpenGL resources.
makeCurrent();
// Free GL texture
if (gltexture)
{
//printf("Destroying GL Texture\n");
glDeleteTextures(1, &gltexture);
gltexture=0;
}
doneCurrent();
}
void ConsoleViewGL_t::resizeGL(int w, int h)

View File

@ -69,5 +69,6 @@ class ConsoleViewGL_t : public QOpenGLWidget, protected QOpenGLFunctions
uint32_t localBufSize;
private slots:
void cleanupGL(void);
};

View File

@ -44,6 +44,7 @@ ConsoleViewSDL_t::ConsoleViewSDL_t(QWidget *parent)
setMinimumWidth( 256 );
setMinimumHeight( 224 );
setFocusPolicy(Qt::StrongFocus);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
view_width = GL_NES_WIDTH;
view_height = GL_NES_HEIGHT;
@ -103,6 +104,7 @@ ConsoleViewSDL_t::~ConsoleViewSDL_t(void)
{
free( localBuf ); localBuf = NULL;
}
cleanup();
}
void ConsoleViewSDL_t::setLinearFilterEnable( bool ena )

View File

@ -38,6 +38,7 @@
#include <QDesktopServices>
#include <QStyleFactory>
#include <QApplication>
#include <QShortcut>
#include <QUrl>
#include "../../fceu.h"
@ -555,6 +556,7 @@ void consoleWin_t::createMainMenu(void)
QMenu *subMenu;
QActionGroup *group;
int useNativeMenuBar;
//QShortcut *shortcut;
QStyle *style;
style = this->style();
@ -572,13 +574,16 @@ void consoleWin_t::createMainMenu(void)
fileMenu = menubar->addMenu(tr("&File"));
// File -> Open ROM
openROM = new QAction(tr("&Open ROM"), this);
openROM = new QAction(tr("&Open ROM\tCtrl+O"), this);
openROM->setShortcuts(QKeySequence::Open);
openROM->setStatusTip(tr("Open ROM File"));
//openROM->setIcon( QIcon(":icons/rom.png") );
//openROM->setIcon( style->standardIcon( QStyle::SP_FileIcon ) );
openROM->setIcon( style->standardIcon( QStyle::SP_FileDialogStart ) );
connect(openROM, SIGNAL(triggered()), this, SLOT(openROMFile(void)) );
//shortcut = new QShortcut( QKeySequence::Open, this );
//connect(shortcut, SIGNAL(activated()), this, SLOT(openROMFile(void)) );
fileMenu->addAction(openROM);
@ -1282,6 +1287,56 @@ void consoleWin_t::createMainMenu(void)
helpMenu->addAction(act);
};
//---------------------------------------------------------------------------
int consoleWin_t::loadVideoDriver( int driverId )
{
if ( driverId )
{ // SDL Driver
if ( viewport_SDL != NULL )
{ // Already Loaded
return 0;
}
if ( viewport_GL != NULL )
{
if ( viewport_GL == centralWidget() )
{
takeCentralWidget();
}
delete viewport_GL;
viewport_GL = NULL;
}
viewport_SDL = new ConsoleViewSDL_t(this);
setCentralWidget(viewport_SDL);
viewport_SDL->init();
}
else
{ // OpenGL Driver
if ( viewport_GL != NULL )
{ // Already Loaded
return 0;
}
if ( viewport_SDL != NULL )
{
if ( viewport_SDL == centralWidget() )
{
takeCentralWidget();
}
delete viewport_SDL;
viewport_SDL = NULL;
}
viewport_GL = new ConsoleViewGL_t(this);
setCentralWidget(viewport_GL);
}
return 0;
}
//---------------------------------------------------------------------------
void consoleWin_t::clearRomList(void)
{
std::list <std::string*>::iterator it;

View File

@ -113,6 +113,8 @@ class consoleWin_t : public QMainWindow
int getMaxSchedPriority(void);
#endif
int loadVideoDriver( int driverId );
emulatorThread_t *emulatorThread;
void addRecentRom( const char *rom );