diff --git a/src/polyscope.cpp b/src/polyscope.cpp index b26dec14..30f2e83e 100644 --- a/src/polyscope.cpp +++ b/src/polyscope.cpp @@ -934,6 +934,8 @@ bool windowRequestsClose() { return false; } +void resetLazy(); + void shutdown() { // TODO should we make an effort to destruct everything here? @@ -941,7 +943,11 @@ void shutdown() { writePrefsFile(); } + render::engine->hideWindow(); render::engine->shutdownImGui(); + contextStack.clear(); + resetLazy(); + state::initialized = false; } bool registerStructure(Structure* s, bool replaceIfPresent) { @@ -1179,7 +1185,7 @@ void refresh() { } // Cached versions of lazy properties used for updates -namespace lazy { +struct Lazy { TransparencyMode transparencyMode = TransparencyMode::None; int transparencyRenderPasses = 8; int ssaaFactor = 1; @@ -1187,8 +1193,10 @@ bool groundPlaneEnabled = true; GroundPlaneMode groundPlaneMode = GroundPlaneMode::TileReflection; ScaledValue groundPlaneHeightFactor = 0; int shadowBlurIters = 2; -float shadowDarkness = .4; -} // namespace lazy +float shadowDarkness = .4f; +}; +static Lazy lazy{}; + void processLazyProperties() { @@ -1203,49 +1211,53 @@ void processLazyProperties() { // transparency mode - if (lazy::transparencyMode != options::transparencyMode) { - lazy::transparencyMode = options::transparencyMode; + if (lazy.transparencyMode != options::transparencyMode) { + lazy.transparencyMode = options::transparencyMode; render::engine->setTransparencyMode(options::transparencyMode); } // transparency render passes - if (lazy::transparencyRenderPasses != options::transparencyRenderPasses) { - lazy::transparencyRenderPasses = options::transparencyRenderPasses; + if (lazy.transparencyRenderPasses != options::transparencyRenderPasses) { + lazy.transparencyRenderPasses = options::transparencyRenderPasses; requestRedraw(); } // ssaa - if (lazy::ssaaFactor != options::ssaaFactor) { - lazy::ssaaFactor = options::ssaaFactor; + if (lazy.ssaaFactor != options::ssaaFactor) { + lazy.ssaaFactor = options::ssaaFactor; render::engine->setSSAAFactor(options::ssaaFactor); } // ground plane - if (lazy::groundPlaneEnabled != options::groundPlaneEnabled || lazy::groundPlaneMode != options::groundPlaneMode) { - lazy::groundPlaneEnabled = options::groundPlaneEnabled; + if (lazy.groundPlaneEnabled != options::groundPlaneEnabled || lazy.groundPlaneMode != options::groundPlaneMode) { + lazy.groundPlaneEnabled = options::groundPlaneEnabled; if (!options::groundPlaneEnabled) { // if the (depecated) groundPlaneEnabled = false, set mode to None, so we only have one variable to check options::groundPlaneMode = GroundPlaneMode::None; } - lazy::groundPlaneMode = options::groundPlaneMode; + lazy.groundPlaneMode = options::groundPlaneMode; render::engine->groundPlane.prepare(); requestRedraw(); } - if (lazy::groundPlaneHeightFactor.asAbsolute() != options::groundPlaneHeightFactor.asAbsolute() || - lazy::groundPlaneHeightFactor.isRelative() != options::groundPlaneHeightFactor.isRelative()) { - lazy::groundPlaneHeightFactor = options::groundPlaneHeightFactor; + if (lazy.groundPlaneHeightFactor.asAbsolute() != options::groundPlaneHeightFactor.asAbsolute() || + lazy.groundPlaneHeightFactor.isRelative() != options::groundPlaneHeightFactor.isRelative()) { + lazy.groundPlaneHeightFactor = options::groundPlaneHeightFactor; requestRedraw(); } - if (lazy::shadowBlurIters != options::shadowBlurIters) { - lazy::shadowBlurIters = options::shadowBlurIters; + if (lazy.shadowBlurIters != options::shadowBlurIters) { + lazy.shadowBlurIters = options::shadowBlurIters; requestRedraw(); } - if (lazy::shadowDarkness != options::shadowDarkness) { - lazy::shadowDarkness = options::shadowDarkness; + if (lazy.shadowDarkness != options::shadowDarkness) { + lazy.shadowDarkness = options::shadowDarkness; requestRedraw(); } }; +void resetLazy() { + lazy = {}; +} + void updateStructureExtents() { if (!options::automaticallyComputeSceneExtents) {