Skip to content

Commit f7a001c

Browse files
committedNov 12, 2023
Fixed bug where rendered/exported frame was not updated when visualization_modes changed
1 parent d585070 commit f7a001c

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed
 

‎src/lbm.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -462,10 +462,10 @@ bool LBM_Domain::Graphics::update_camera() {
462462
}
463463
return change; // return false if camera parameters remain unchanged
464464
}
465-
bool LBM_Domain::Graphics::enqueue_draw_frame(const int visualization_modes, const int slice_mode, const int slice_x, const int slice_y, const int slice_z) {
465+
bool LBM_Domain::Graphics::enqueue_draw_frame(const int visualization_modes, const int slice_mode, const int slice_x, const int slice_y, const int slice_z, const bool visualization_change) {
466466
const bool camera_update = update_camera();
467467
#if defined(INTERACTIVE_GRAPHICS)||defined(INTERACTIVE_GRAPHICS_ASCII)
468-
if(!camera_update&&!camera.key_update&&lbm->get_t()==t_last_rendered_frame) return false; // don't render a new frame if the scene hasn't changed since last frame
468+
if(!visualization_change&&!camera_update&&!camera.key_update&&lbm->get_t()==t_last_rendered_frame) return false; // don't render a new frame if the scene hasn't changed since last frame
469469
#endif // INTERACTIVE_GRAPHICS||INTERACTIVE_GRAPHICS_ASCII
470470
t_last_rendered_frame = lbm->get_t();
471471
camera.key_update = false;
@@ -1069,8 +1069,14 @@ int* LBM::Graphics::draw_frame() {
10691069
if(key_Q) { slice_z = clamp(slice_z-1, 0, (int)lbm->get_Nz()-1); key_Q = false; }
10701070
if(key_E) { slice_z = clamp(slice_z+1, 0, (int)lbm->get_Nz()-1); key_E = false; }
10711071
}
1072+
const bool visualization_change = last_visualization_modes!=visualization_modes||last_slice_mode!=slice_mode||last_slice_x!=slice_x||last_slice_y!=slice_y||last_slice_z!=slice_z;
1073+
last_visualization_modes = visualization_modes;
1074+
last_slice_mode = slice_mode;
1075+
last_slice_x = slice_x;
1076+
last_slice_y = slice_y;
1077+
last_slice_z = slice_z;
10721078
bool new_frame = true;
1073-
for(uint d=0u; d<lbm->get_D(); d++) new_frame = new_frame && lbm->lbm[d]->graphics.enqueue_draw_frame(visualization_modes, slice_mode, slice_x, slice_y, slice_z);
1079+
for(uint d=0u; d<lbm->get_D(); d++) new_frame = new_frame && lbm->lbm[d]->graphics.enqueue_draw_frame(visualization_modes, slice_mode, slice_x, slice_y, slice_z, visualization_change);
10741080
for(uint d=0u; d<lbm->get_D(); d++) lbm->lbm[d]->finish_queue();
10751081
int* bitmap = lbm->lbm[0]->graphics.get_bitmap();
10761082
int* zbuffer = lbm->lbm[0]->graphics.get_zbuffer();

‎src/lbm.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class LBM_Domain {
185185
return *this;
186186
}
187187
void allocate(Device& device); // allocate memory for bitmap and zbuffer
188-
bool enqueue_draw_frame(const int visualization_modes, const int slice_mode=0, const int slice_x=0, const int slice_y=0, const int slice_z=0); // main rendering function, calls rendering kernels, returns true if new frame is rendered, false if old frame is returned when camera has not moved
188+
bool enqueue_draw_frame(const int visualization_modes, const int slice_mode=0, const int slice_x=0, const int slice_y=0, const int slice_z=0, const bool visualization_change=true); // main rendering function, calls rendering kernels, returns true if new frame is rendered, false if old frame is returned when camera has not moved
189189
int* get_bitmap(); // returns pointer to bitmap
190190
int* get_zbuffer(); // returns pointer to zbuffer
191191
string device_defines() const; // returns preprocessor constants for embedding in OpenCL C code
@@ -495,6 +495,7 @@ class LBM {
495495
LBM* lbm = nullptr;
496496
std::atomic_int running_encoders = 0;
497497
uint last_exported_frame = 0u; // for next_frame(...) function
498+
int last_visualization_modes=0, last_slice_mode=0, last_slice_x=0, last_slice_y=0, last_slice_z=0; // don't render a new frame if the scene hasn't changed since last frame
498499
void default_settings() {
499500
visualization_modes |= VIS_FLAG_LATTICE;
500501
#ifdef PARTICLES

0 commit comments

Comments
 (0)
Please sign in to comment.