Bläddra i källkod

qt: Recreate GL context on startup to support changing V-Sync.

bunnei 10 år sedan
förälder
incheckning
02702c6605
3 ändrade filer med 39 tillägg och 25 borttagningar
  1. 35 25
      src/citra_qt/bootmanager.cpp
  2. 2 0
      src/citra_qt/bootmanager.h
  3. 2 0
      src/citra_qt/main.cpp

+ 35 - 25
src/citra_qt/bootmanager.cpp

@@ -107,37 +107,13 @@ private:
 };
 };
 
 
 GRenderWindow::GRenderWindow(QWidget* parent, EmuThread* emu_thread) :
 GRenderWindow::GRenderWindow(QWidget* parent, EmuThread* emu_thread) :
-    QWidget(parent), keyboard_id(0), emu_thread(emu_thread) {
+    QWidget(parent), keyboard_id(0), emu_thread(emu_thread), child(nullptr) {
 
 
     std::string window_title = Common::StringFromFormat("Citra | %s-%s", Common::g_scm_branch, Common::g_scm_desc);
     std::string window_title = Common::StringFromFormat("Citra | %s-%s", Common::g_scm_branch, Common::g_scm_desc);
     setWindowTitle(QString::fromStdString(window_title));
     setWindowTitle(QString::fromStdString(window_title));
 
 
     keyboard_id = KeyMap::NewDeviceId();
     keyboard_id = KeyMap::NewDeviceId();
     ReloadSetKeymaps();
     ReloadSetKeymaps();
-
-    // TODO: One of these flags might be interesting: WA_OpaquePaintEvent, WA_NoBackground, WA_DontShowOnScreen, WA_DeleteOnClose
-    QGLFormat fmt;
-    fmt.setVersion(3,3);
-    fmt.setProfile(QGLFormat::CoreProfile);
-    fmt.setSwapInterval(VideoCore::g_vsync_enabled);
-    // Requests a forward-compatible context, which is required to get a 3.2+ context on OS X
-    fmt.setOption(QGL::NoDeprecatedFunctions);
-
-    child = new GGLWidgetInternal(fmt, this);
-    QBoxLayout* layout = new QHBoxLayout(this);
-
-    resize(VideoCore::kScreenTopWidth, VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight);
-    layout->addWidget(child);
-    layout->setMargin(0);
-    setLayout(layout);
-
-    OnMinimalClientAreaChangeRequest(GetActiveConfig().min_client_area_size);
-
-    OnFramebufferSizeChanged();
-    NotifyClientAreaSizeChanged(std::pair<unsigned,unsigned>(child->width(), child->height()));
-
-    BackupGeometry();
-
 }
 }
 
 
 void GRenderWindow::moveContext()
 void GRenderWindow::moveContext()
@@ -282,6 +258,40 @@ void GRenderWindow::OnClientAreaResized(unsigned width, unsigned height)
     NotifyClientAreaSizeChanged(std::make_pair(width, height));
     NotifyClientAreaSizeChanged(std::make_pair(width, height));
 }
 }
 
 
+void GRenderWindow::InitRenderTarget() {
+    if (child) {
+        delete child;
+    }
+
+    if (layout()) {
+        delete layout();
+    }
+
+    // TODO: One of these flags might be interesting: WA_OpaquePaintEvent, WA_NoBackground, WA_DontShowOnScreen, WA_DeleteOnClose
+    QGLFormat fmt;
+    fmt.setVersion(3, 3);
+    fmt.setProfile(QGLFormat::CoreProfile);
+    fmt.setSwapInterval(Settings::values.use_vsync);
+
+    // Requests a forward-compatible context, which is required to get a 3.2+ context on OS X
+    fmt.setOption(QGL::NoDeprecatedFunctions);
+
+    child = new GGLWidgetInternal(fmt, this);
+    QBoxLayout* layout = new QHBoxLayout(this);
+
+    resize(VideoCore::kScreenTopWidth, VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight);
+    layout->addWidget(child);
+    layout->setMargin(0);
+    setLayout(layout);
+
+    OnMinimalClientAreaChangeRequest(GetActiveConfig().min_client_area_size);
+
+    OnFramebufferSizeChanged();
+    NotifyClientAreaSizeChanged(std::pair<unsigned, unsigned>(child->width(), child->height()));
+
+    BackupGeometry();
+}
+
 void GRenderWindow::OnMinimalClientAreaChangeRequest(const std::pair<unsigned,unsigned>& minimal_size) {
 void GRenderWindow::OnMinimalClientAreaChangeRequest(const std::pair<unsigned,unsigned>& minimal_size) {
     setMinimumSize(minimal_size.first, minimal_size.second);
     setMinimumSize(minimal_size.first, minimal_size.second);
 }
 }

+ 2 - 0
src/citra_qt/bootmanager.h

@@ -126,6 +126,8 @@ public:
 
 
     void OnClientAreaResized(unsigned width, unsigned height);
     void OnClientAreaResized(unsigned width, unsigned height);
 
 
+    void InitRenderTarget();
+
 public slots:
 public slots:
     void moveContext();  // overridden
     void moveContext();  // overridden
 
 

+ 2 - 0
src/citra_qt/main.cpp

@@ -243,7 +243,9 @@ bool GMainWindow::InitializeSystem() {
     if (emu_thread != nullptr)
     if (emu_thread != nullptr)
         ShutdownGame();
         ShutdownGame();
 
 
+    render_window->InitRenderTarget();
     render_window->MakeCurrent();
     render_window->MakeCurrent();
+
     if (!gladLoadGL()) {
     if (!gladLoadGL()) {
         QMessageBox::critical(this, tr("Error while starting Citra!"),
         QMessageBox::critical(this, tr("Error while starting Citra!"),
                               tr("Failed to initialize the video core!\n\n"
                               tr("Failed to initialize the video core!\n\n"