diff --git a/src/drivers/Qt/ConsoleVideoConf.cpp b/src/drivers/Qt/ConsoleVideoConf.cpp index 88793071..76bce9ca 100644 --- a/src/drivers/Qt/ConsoleVideoConf.cpp +++ b/src/drivers/Qt/ConsoleVideoConf.cpp @@ -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) diff --git a/src/drivers/Qt/ConsoleViewerGL.cpp b/src/drivers/Qt/ConsoleViewerGL.cpp index 79801980..db7dc9ff 100644 --- a/src/drivers/Qt/ConsoleViewerGL.cpp +++ b/src/drivers/Qt/ConsoleViewerGL.cpp @@ -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) diff --git a/src/drivers/Qt/ConsoleViewerGL.h b/src/drivers/Qt/ConsoleViewerGL.h index f8f68163..dfdff004 100644 --- a/src/drivers/Qt/ConsoleViewerGL.h +++ b/src/drivers/Qt/ConsoleViewerGL.h @@ -69,5 +69,6 @@ class ConsoleViewGL_t : public QOpenGLWidget, protected QOpenGLFunctions uint32_t localBufSize; private slots: + void cleanupGL(void); }; diff --git a/src/drivers/Qt/ConsoleViewerSDL.cpp b/src/drivers/Qt/ConsoleViewerSDL.cpp index 5d0d9997..e00a36f8 100644 --- a/src/drivers/Qt/ConsoleViewerSDL.cpp +++ b/src/drivers/Qt/ConsoleViewerSDL.cpp @@ -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 ) diff --git a/src/drivers/Qt/ConsoleWindow.cpp b/src/drivers/Qt/ConsoleWindow.cpp index 2f69a286..b5fdf795 100644 --- a/src/drivers/Qt/ConsoleWindow.cpp +++ b/src/drivers/Qt/ConsoleWindow.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #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 ::iterator it; diff --git a/src/drivers/Qt/ConsoleWindow.h b/src/drivers/Qt/ConsoleWindow.h index 1ea3599c..2b7e44a4 100644 --- a/src/drivers/Qt/ConsoleWindow.h +++ b/src/drivers/Qt/ConsoleWindow.h @@ -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 );