Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/configwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion include/scenerenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions src/configwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<VarTypes::VarBool>("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");
Expand Down
2 changes: 1 addition & 1 deletion src/glwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
30 changes: 28 additions & 2 deletions tests/rendering_regression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QElapsedTimer>
#include <QThread>
#include <QWindow>
#include <QMouseEvent>
#include <cstdio>
#include <cstdlib>
#include <set>
Expand Down Expand Up @@ -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);
};
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 18 additions & 0 deletions tests/settings_regression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,22 @@ 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();
passed = check(settings.DesiredFPS() == 7.0 && settings.DeltaTime() == 0.008,
"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;
Expand All @@ -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<VarList>("Physics");
auto renamedWorld = std::make_shared<VarList>("World");
Expand Down
Loading