From 1bbbd26563c1fa50f5f74831d89473bf5d7dda24 Mon Sep 17 00:00:00 2001
From: bunnei <bunneidev@gmail.com>
Date: Tue, 26 Jun 2018 14:36:26 -0400
Subject: [PATCH] settings: Add a configuration for use_accurate_framebuffers.

---
 src/core/settings.h                           | 1 +
 src/core/telemetry_session.cpp                | 2 ++
 src/yuzu/configuration/config.cpp             | 3 +++
 src/yuzu/configuration/configure_graphics.cpp | 2 ++
 src/yuzu/configuration/configure_graphics.ui  | 7 +++++++
 src/yuzu_cmd/config.cpp                       | 2 ++
 src/yuzu_cmd/default_ini.h                    | 4 ++++
 7 files changed, 21 insertions(+)

diff --git a/src/core/settings.h b/src/core/settings.h
index a7f1e5fa0d..7150d97555 100644
--- a/src/core/settings.h
+++ b/src/core/settings.h
@@ -129,6 +129,7 @@ struct Values {
     // Renderer
     float resolution_factor;
     bool toggle_framelimit;
+    bool use_accurate_framebuffers;
 
     float bg_red;
     float bg_green;
diff --git a/src/core/telemetry_session.cpp b/src/core/telemetry_session.cpp
index a60aa1143b..270d682222 100644
--- a/src/core/telemetry_session.cpp
+++ b/src/core/telemetry_session.cpp
@@ -161,6 +161,8 @@ TelemetrySession::TelemetrySession() {
              Settings::values.resolution_factor);
     AddField(Telemetry::FieldType::UserConfig, "Renderer_ToggleFramelimit",
              Settings::values.toggle_framelimit);
+    AddField(Telemetry::FieldType::UserConfig, "Renderer_UseAccurateFramebuffers",
+             Settings::values.use_accurate_framebuffers);
     AddField(Telemetry::FieldType::UserConfig, "System_UseDockedMode",
              Settings::values.use_docked_mode);
 }
diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp
index 8316db7082..cd7986efa8 100644
--- a/src/yuzu/configuration/config.cpp
+++ b/src/yuzu/configuration/config.cpp
@@ -84,6 +84,8 @@ void Config::ReadValues() {
     qt_config->beginGroup("Renderer");
     Settings::values.resolution_factor = qt_config->value("resolution_factor", 1.0).toFloat();
     Settings::values.toggle_framelimit = qt_config->value("toggle_framelimit", true).toBool();
+    Settings::values.use_accurate_framebuffers =
+        qt_config->value("use_accurate_framebuffers", false).toBool();
 
     Settings::values.bg_red = qt_config->value("bg_red", 0.0).toFloat();
     Settings::values.bg_green = qt_config->value("bg_green", 0.0).toFloat();
@@ -184,6 +186,7 @@ void Config::SaveValues() {
     qt_config->beginGroup("Renderer");
     qt_config->setValue("resolution_factor", (double)Settings::values.resolution_factor);
     qt_config->setValue("toggle_framelimit", Settings::values.toggle_framelimit);
+    qt_config->setValue("use_accurate_framebuffers", Settings::values.use_accurate_framebuffers);
 
     // Cast to double because Qt's written float values are not human-readable
     qt_config->setValue("bg_red", (double)Settings::values.bg_red);
diff --git a/src/yuzu/configuration/configure_graphics.cpp b/src/yuzu/configuration/configure_graphics.cpp
index 47b9b6e952..7664880d53 100644
--- a/src/yuzu/configuration/configure_graphics.cpp
+++ b/src/yuzu/configuration/configure_graphics.cpp
@@ -59,11 +59,13 @@ void ConfigureGraphics::setConfiguration() {
     ui->resolution_factor_combobox->setCurrentIndex(
         static_cast<int>(FromResolutionFactor(Settings::values.resolution_factor)));
     ui->toggle_framelimit->setChecked(Settings::values.toggle_framelimit);
+    ui->use_accurate_framebuffers->setChecked(Settings::values.use_accurate_framebuffers);
 }
 
 void ConfigureGraphics::applyConfiguration() {
     Settings::values.resolution_factor =
         ToResolutionFactor(static_cast<Resolution>(ui->resolution_factor_combobox->currentIndex()));
     Settings::values.toggle_framelimit = ui->toggle_framelimit->isChecked();
+    Settings::values.use_accurate_framebuffers = ui->use_accurate_framebuffers->isChecked();
     Settings::Apply();
 }
diff --git a/src/yuzu/configuration/configure_graphics.ui b/src/yuzu/configuration/configure_graphics.ui
index 366931a9ac..7d092df035 100644
--- a/src/yuzu/configuration/configure_graphics.ui
+++ b/src/yuzu/configuration/configure_graphics.ui
@@ -29,6 +29,13 @@
           </property>
          </widget>
         </item>
+        <item>
+         <widget class="QCheckBox" name="use_accurate_framebuffers">
+          <property name="text">
+           <string>Use accurate framebuffers (slow)</string>
+          </property>
+         </widget>
+        </item>
         <item>
          <layout class="QHBoxLayout" name="horizontalLayout">
           <item>
diff --git a/src/yuzu_cmd/config.cpp b/src/yuzu_cmd/config.cpp
index ee6e4d658f..150915c176 100644
--- a/src/yuzu_cmd/config.cpp
+++ b/src/yuzu_cmd/config.cpp
@@ -98,6 +98,8 @@ void Config::ReadValues() {
         (float)sdl2_config->GetReal("Renderer", "resolution_factor", 1.0);
     Settings::values.toggle_framelimit =
         sdl2_config->GetBoolean("Renderer", "toggle_framelimit", true);
+    Settings::values.use_accurate_framebuffers =
+        sdl2_config->GetBoolean("Renderer", "use_accurate_framebuffers", false);
 
     Settings::values.bg_red = (float)sdl2_config->GetReal("Renderer", "bg_red", 0.0);
     Settings::values.bg_green = (float)sdl2_config->GetReal("Renderer", "bg_green", 0.0);
diff --git a/src/yuzu_cmd/default_ini.h b/src/yuzu_cmd/default_ini.h
index 1c438c3f5b..5896971d4b 100644
--- a/src/yuzu_cmd/default_ini.h
+++ b/src/yuzu_cmd/default_ini.h
@@ -102,6 +102,10 @@ resolution_factor =
 # 0 (default): Off, 1: On
 use_vsync =
 
+# Whether to use accurate framebuffers
+# 0 (default): Off (fast), 1 : On (slow)
+use_accurate_framebuffers =
+
 # The clear color for the renderer. What shows up on the sides of the bottom screen.
 # Must be in range of 0.0-1.0. Defaults to 1.0 for all.
 bg_red =