Ray-caster: only draw when the scene is changed
This is how I typically schedule draw calls in JavaScript applications. The baseline CPU activity for the display prototype is now in line with other pages (though perhaps a bit higher), and the profiler shows little time being spent in draw calls, even when I'm continually moving a slider. The interface feels pretty responsive overall, although the sliders seem to be lagging a bit.
This commit is contained in:
parent
f62f44b5a7
commit
a40a110788
@ -108,6 +108,21 @@ fn main() {
|
|||||||
// display
|
// display
|
||||||
let display = create_node_ref();
|
let display = create_node_ref();
|
||||||
|
|
||||||
|
// change listener
|
||||||
|
let scene_changed = create_signal(true);
|
||||||
|
create_effect(move || {
|
||||||
|
ctrl_x.track();
|
||||||
|
ctrl_y.track();
|
||||||
|
radius_x.track();
|
||||||
|
radius_y.track();
|
||||||
|
opacity.track();
|
||||||
|
highlight.track();
|
||||||
|
layer_threshold.track();
|
||||||
|
debug_mode.track();
|
||||||
|
|
||||||
|
scene_changed.set(true);
|
||||||
|
});
|
||||||
|
|
||||||
on_mount(move || {
|
on_mount(move || {
|
||||||
// list construction elements
|
// list construction elements
|
||||||
const SPHERE_MAX: usize = 12;
|
const SPHERE_MAX: usize = 12;
|
||||||
@ -216,7 +231,8 @@ fn main() {
|
|||||||
bind_vertex_attrib(&ctx, position_index, 3, &positions);
|
bind_vertex_attrib(&ctx, position_index, 3, &positions);
|
||||||
|
|
||||||
// set up a repainting routine
|
// set up a repainting routine
|
||||||
let (_, start_updating_display, _) = create_raf(move || {
|
let (_, start_animation_loop, _) = create_raf(move || {
|
||||||
|
if scene_changed.get() {
|
||||||
/* INSTRUMENTS */
|
/* INSTRUMENTS */
|
||||||
// measure frame time
|
// measure frame time
|
||||||
frames_since_last_sample += 1;
|
frames_since_last_sample += 1;
|
||||||
@ -267,15 +283,15 @@ fn main() {
|
|||||||
|
|
||||||
// draw the scene
|
// draw the scene
|
||||||
ctx.draw_arrays(WebGl2RenderingContext::TRIANGLES, 0, VERTEX_CNT as i32);
|
ctx.draw_arrays(WebGl2RenderingContext::TRIANGLES, 0, VERTEX_CNT as i32);
|
||||||
});
|
|
||||||
|
|
||||||
/*
|
// clear scene change flag
|
||||||
this wastes CPU time by running an animation loop, which updates the
|
scene_changed.set(false);
|
||||||
display even when nothing has changed. there should be a way to make
|
} else {
|
||||||
Sycamore do single-frame updates in response to changes, but i
|
frames_since_last_sample = 0;
|
||||||
haven't found it yet
|
frame_time.set(-1.0);
|
||||||
*/
|
}
|
||||||
start_updating_display();
|
});
|
||||||
|
start_animation_loop();
|
||||||
});
|
});
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
|
Loading…
Reference in New Issue
Block a user