From 694a7b04e42cf9c91c82527d70431752a061169a Mon Sep 17 00:00:00 2001 From: Fred Huang Date: Wed, 4 Nov 2026 17:34:47 +0000 Subject: [PATCH] Make the skybox an independent display setting Default the optional skybox to off and persist its value independently of Low Spec Mode. Exercise the setting in the existing rendering and settings regressions. --- include/configwidget.h | 1 + include/scenerenderer.h | 4 +++- src/configwidget.cpp | 3 +++ src/glwidget.cpp | 2 +- tests/rendering_regression.cpp | 30 ++++++++++++++++++++++++++++-- tests/settings_regression.cpp | 18 ++++++++++++++++++ 6 files changed, 54 insertions(+), 4 deletions(-) diff --git a/include/configwidget.h b/include/configwidget.h index 58905fa9..d33ef1fb 100644 --- a/include/configwidget.h +++ b/include/configwidget.h @@ -160,6 +160,7 @@ class ConfigWidget : public VarTreeView DEF_VALUE(double,Double,DesiredFPS) DEF_VALUE(double,Double,DeltaTime) DEF_VALUE(bool,Bool,LowSpecMode) + DEF_VALUE(bool,Bool,ShowSkybox) DEF_VALUE(int,Int,sendGeometryEvery) DEF_VALUE(double,Double,Gravity) DEF_VALUE(bool,Bool,ResetTurnOver) diff --git a/include/scenerenderer.h b/include/scenerenderer.h index 290476c2..3b1ea082 100644 --- a/include/scenerenderer.h +++ b/include/scenerenderer.h @@ -9,7 +9,9 @@ struct RenderQuality { bool lowSpec; bool showSkybox; bool showRobotLabels; - static RenderQuality forLowSpec(bool enabled) { return {enabled, !enabled, !enabled}; } + static RenderQuality forLowSpec(bool enabled, bool showSkybox) { + return {enabled, showSkybox, !enabled}; + } }; class SceneRenderer { diff --git a/src/configwidget.cpp b/src/configwidget.cpp index ea48b697..69883e7e 100644 --- a/src/configwidget.cpp +++ b/src/configwidget.cpp @@ -157,6 +157,9 @@ ConfigWidget::ConfigWidget(bool persist, const QString& settingsPath) ADD_VALUE(worldp_vars,Double,Gravity,9.81,"Gravity") ADD_VALUE(worldp_vars,Bool,ResetTurnOver,true,"Auto reset turn-over") ADD_VALUE(worldp_vars,Bool,LowSpecMode,false,"Low Spec Mode") + // The renderer reads this option directly on each frame. + v_ShowSkybox = std::make_shared("Show Skybox", false); + worldp_vars->addChild(v_ShowSkybox); VarListPtr ballp_vars(new VarList("Ball")); phys_vars->addChild(ballp_vars); ADD_VALUE(ballp_vars,Double,BallMass,0.043,"Ball mass"); diff --git a/src/glwidget.cpp b/src/glwidget.cpp index 77dcf63c..66c5367c 100644 --- a/src/glwidget.cpp +++ b/src/glwidget.cpp @@ -524,7 +524,7 @@ void GLWidget::paintGL() const auto& ball = snapshot->ballPosition; graphics.lookAt(ball[0], ball[1], ball[2]); } - const auto quality = RenderQuality::forLowSpec(cfg->LowSpecMode()); + const auto quality = RenderQuality::forLowSpec(cfg->LowSpecMode(), cfg->ShowSkybox()); GLint viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); const int fullW = qMax(1, viewport[2]), fullH = qMax(1, viewport[3]); diff --git a/tests/rendering_regression.cpp b/tests/rendering_regression.cpp index 9a58fdbb..571100a2 100644 --- a/tests/rendering_regression.cpp +++ b/tests/rendering_regression.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -95,8 +96,7 @@ static bool checkTexturedCylinderDetail(GLWidget& view) GLfloat feedback[16384]; glFeedbackBuffer(16384, GL_3D, feedback); glRenderMode(GL_FEEDBACK); - auto quality = RenderQuality::forLowSpec(low); - quality.showSkybox = false; + const auto quality = RenderQuality::forLowSpec(low, false); renderer.draw(fixture, 512, 512, quality, -1, false, {{0, 0, 0}}, 0); return glRenderMode(GL_RENDER); }; @@ -110,6 +110,31 @@ static bool checkTexturedCylinderDetail(GLWidget& view) return passed; } +static bool checkSkyboxToggle(ConfigWidget* config, SimulationController* simulation) +{ + TestView view(config, simulation); + view.resize(320, 240); + // Look above the horizon so the sky cannot be hidden behind the ground. + QMouseEvent lookUp(QEvent::MouseMove, QPointF(0, -240), Qt::NoButton, + Qt::LeftButton, Qt::NoModifier); + QCoreApplication::sendEvent(&view, &lookUp); + bool passed = true; + for (bool low : {false, true}) { + config->v_LowSpecMode->setBool(low); + auto capture = [&](bool skybox) { + config->v_ShowSkybox->setBool(skybox); + return view.renderPixmap(320, 240, false).toImage().convertToFormat(QImage::Format_RGB32); + }; + const QImage off = capture(false), on = capture(true), offAgain = capture(false); + const bool toggles = !off.isNull() && !on.isNull() && off != on && off == offAgain; + std::printf("%s skybox switches off/on/off while rendering low=%d\n", + toggles ? "PASS" : "FAIL", low); + passed = toggles && passed; + } + config->v_LowSpecMode->setBool(false); + return passed; +} + static bool checkPicking(TestView& view) { view.updateGL(); @@ -272,6 +297,7 @@ int main(int argc, char** argv) return passed ? 0 : 1; } bool passed = true; + passed = checkSkyboxToggle(config, view->simulation) && passed; passed = checkTexturedCylinderDetail(*view) && passed; for (const QSize size : {QSize(512, 512), QSize(320, 240)}) { passed = checkCapture(*view, false, size) && passed; diff --git a/tests/settings_regression.cpp b/tests/settings_regression.cpp index 4ea20ffb..b11503ae 100644 --- a/tests/settings_regression.cpp +++ b/tests/settings_regression.cpp @@ -42,7 +42,10 @@ int main(int argc, char** argv) VarXML::write(physics, path.toStdString()); bool passed = true; { + int simulationEdits = 0; ConfigWidget config(true, path); + passed = check(!config.ShowSkybox(), + "skybox defaults off when older settings omit the option") && passed; passed = check(config.DesiredFPS() == 7.0 && config.DeltaTime() == 0.008, "legacy timing values load into the active controls") && passed; const auto settings = config.simulationSettings(); @@ -50,6 +53,11 @@ int main(int argc, char** argv) "saved timestep reaches copied simulation settings") && passed; config.v_DesiredFPS->setDouble(13); config.v_DeltaTime->setDouble(0.01); + QObject::connect(&config, &ConfigWidget::settingsEdited, &config, [&]() { ++simulationEdits; }); + config.v_ShowSkybox->setBool(true); + emit config.v_ShowSkybox->wasEdited(config.v_ShowSkybox); + QCoreApplication::processEvents(); + passed = check(simulationEdits == 0, "editing the skybox leaves the simulation configuration alone") && passed; } QFile saved(path); if (!saved.open(QIODevice::ReadOnly)) return 2; @@ -61,10 +69,20 @@ int main(int argc, char** argv) "timing edits update the original keys without inactive duplicates") && passed; passed = check(!xml.contains("Synchronize ODE with OpenGL"), "obsolete synchronization control is removed from saved settings") && passed; + passed = check(xml.count("name=\"Show Skybox\"") == 1, + "skybox has one persistent settings entry") && passed; { ConfigWidget config(true, path); passed = check(config.DesiredFPS() == 13 && config.DeltaTime() == 0.01, "edited timing values survive a settings round trip") && passed; + passed = check(config.ShowSkybox(), + "enabled skybox survives a settings round trip") && passed; + config.v_ShowSkybox->setBool(false); + } + { + ConfigWidget config(false, path); + passed = check(!config.ShowSkybox(), + "disabled skybox survives a settings round trip") && passed; } auto renamedPhysics = std::make_shared("Physics"); auto renamedWorld = std::make_shared("World");