From f010e78e55d33cdcbf6560d15cbd49911d30c5e8 Mon Sep 17 00:00:00 2001
From: James Turner <zakalawe@mac.com>
Date: Thu, 14 May 2020 10:57:16 +0100
Subject: [PATCH] Launcher: basic Compositor support

---
 src/GUI/LauncherMainWindow.cxx |  6 ++++
 src/GUI/qml/Settings.qml       | 59 ++++++++++++++++++++++------------
 2 files changed, 44 insertions(+), 21 deletions(-)

diff --git a/src/GUI/LauncherMainWindow.cxx b/src/GUI/LauncherMainWindow.cxx
index 23acdbe66..c911ff16f 100644
--- a/src/GUI/LauncherMainWindow.cxx
+++ b/src/GUI/LauncherMainWindow.cxx
@@ -97,6 +97,12 @@ LauncherMainWindow::LauncherMainWindow() :
     ctx->setContextProperty("_location", m_controller->location());
     ctx->setContextProperty("_osName", osName);
 
+#if defined(ENABLE_COMPOSITOR)
+    ctx->setContextProperty("_haveCompositor", true);
+#else
+    ctx->setContextProperty("_haveCompositor", false);
+#endif
+
     auto weatherScenariosModel = new flightgear::WeatherScenariosModel(this);
     ctx->setContextProperty("_weatherScenarios", weatherScenariosModel);
 
diff --git a/src/GUI/qml/Settings.qml b/src/GUI/qml/Settings.qml
index 9013f9e4c..7dc83390d 100644
--- a/src/GUI/qml/Settings.qml
+++ b/src/GUI/qml/Settings.qml
@@ -412,7 +412,7 @@ Item {
                 width: parent.width
                 settingGroup: "render"
 
-                readonly property bool rembrandt: (renderer.selectedIndex == 2)
+                readonly property bool rembrandt: !_haveCompositor && (renderer.selectedIndex == 2)
                 readonly property bool alsEnabled: (renderer.selectedIndex == 1)
                 readonly property bool msaaEnabled: !rembrandt && (msaa.selectedIndex > 0)
 
@@ -425,27 +425,37 @@ Item {
                     return result;
                 }
 
+                readonly property var __traditionalRendererChoices: [qsTr("Default"),
+                    qsTr("Atmospheric Light Scattering"),
+                    qsTr("Rembrandt")]
+
+                readonly property var __compositorRendererChoices: [qsTr("Default"),
+                    qsTr("Atmospheric Light Scattering"),
+                    qsTr("Low-spec")]
+
+                readonly property string __defaultRenderDesc: qsTr("The default renderer provides standard visuals with maximum compatibility.")
+                readonly property string __alsRenderDesc: qsTr("The ALS renderer uses a sophisticated physical atmospheric model and several " +
+                                                               "other effects to give realistic rendering of large distances.")
+                readonly property string __rembrandtDesc: qsTr("Rembrandt is a configurable multi-pass renderer which supports shadow-maps, cinematic " +
+                                                               "effects and more. However, not all aircraft appear correctly and performance will " +
+                                                               "depend greatly on your system hardware.")
+                readonly property string __lowSpecDesc: qsTr("The low-spec renderer ensures maximum performance on older computers.")
+
+                readonly property var descriptions: _haveCompositor
+                                                    ? [__defaultRenderDesc, __alsRenderDesc, __lowSpecDesc]
+                                                    : [__defaultRenderDesc, __alsRenderDesc, __rembrandtDesc]
+
                 contents: [
                     SettingsComboBox {
                         id: renderer
                         label: qsTr("Renderer")
-                        choices: [qsTr("Default"),
-                            qsTr("Atmospheric Light Scattering"),
-                            qsTr("Rembrandt")]
-                        description: descriptions[selectedIndex]
-                        defaultIndex: 0
+                        choices: _haveCompositor
+                                 ? renderSection.__compositorRendererChoices
+                                 : renderSection.__traditionalRendererChoices
+                        description: renderSection.descriptions[selectedIndex]
+                        defaultIndex: 1
                         setting: "renderer"
-
-                        readonly property var descriptions: [
-                            qsTr("The default renderer provides standard visuals with maximum compatibility."),
-                            qsTr("The ALS renderer uses a sophisticated physical atmospheric model and several " +
-                            "other effects to give realistic rendering of large distances."),
-                            qsTr("Rembrandt is a configurable multi-pass renderer which supports shadow-maps, cinematic " +
-                            "effects and more. However, not all aircraft appear correctly and performance will " +
-                            "depend greatly on your system hardware.")
-                        ]
-
-                        keywords: ["als", "rembrandt", "render", "shadow"]
+                        keywords: ["als", "rembrandt", "render", "shadow", "low-spec", "graphics", "performance"]
                     },
 
                     SettingsComboBox {
@@ -485,10 +495,17 @@ Item {
                         _config.setProperty("/sim/rendering/multi-samples", msaa.data[msaa.selectedIndex])
                     }
 
-                    _config.setEnableDisableOption("rembrandt",  rembrandt);
-
-                    if (alsEnabled) {
-                        _config.setProperty("/sim/rendering/shaders/skydome", true);
+                    if (_haveCompositor) {
+                        if (alsEnabled) {
+                            _config.setArg("compositor", "Compositor/ALS");
+                        } else if (renderer.selectedIndex == 2) {
+                            _config.setArg("compositor", "Compositor/low-spec")
+                        }
+                    } else {
+                        _config.setEnableDisableOption("rembrandt",  rembrandt);
+                        if (alsEnabled) {
+                            _config.setProperty("/sim/rendering/shaders/skydome", true);
+                        }
                     }
 
                     _config.setProperty("/sim/rendering/texture-cache/cache-enabled", compressTextures.value);