Skip to content

Commit

Permalink
tidy up on shutdown to allow multiple init/shutdown cycles per pr…
Browse files Browse the repository at this point in the history
…ocess

- Hide window.
- Clear `contextStack`.
- Reset cached `lazy` properties. Had to convert from namespace to struct to allow default initialisation reset.
- Set `state::initialized = false`.
  • Loading branch information
gkoulin authored and giorgek-rfpro committed Oct 1, 2024
1 parent 0615cd7 commit eae79f6
Showing 1 changed file with 31 additions and 19 deletions.
50 changes: 31 additions & 19 deletions src/polyscope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -934,14 +934,20 @@ bool windowRequestsClose() {
return false;
}

void resetLazy();

void shutdown() {

// TODO should we make an effort to destruct everything here?
if (options::usePrefsFile) {
writePrefsFile();
}

render::engine->hideWindow();
render::engine->shutdownImGui();
contextStack.clear();
resetLazy();
state::initialized = false;
}

bool registerStructure(Structure* s, bool replaceIfPresent) {
Expand Down Expand Up @@ -1179,16 +1185,18 @@ void refresh() {
}

// Cached versions of lazy properties used for updates
namespace lazy {
struct Lazy {
TransparencyMode transparencyMode = TransparencyMode::None;
int transparencyRenderPasses = 8;
int ssaaFactor = 1;
bool groundPlaneEnabled = true;
GroundPlaneMode groundPlaneMode = GroundPlaneMode::TileReflection;
ScaledValue<float> groundPlaneHeightFactor = 0;
int shadowBlurIters = 2;
float shadowDarkness = .4;
} // namespace lazy
float shadowDarkness = .4f;
};
static Lazy lazy{};


void processLazyProperties() {

Expand All @@ -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) {
Expand Down

0 comments on commit eae79f6

Please sign in to comment.