epezent / implot

Immediate Mode Plotting
MIT License
4.64k stars 516 forks source link

reusing rendered data #422

Closed hinxx closed 1 year ago

hinxx commented 1 year ago

I'm trying to plot several (i.e. up to 10) digitized signals of the real world data that can be quite big (+10000 points). My input data rate is about 15 times a second. If I just use the vsync and nominal 60 FPS the rendering of same plot data happens 4 times when it could be happening just once it I was able to "save" the rendered plot line result from the first time. I wonder if it would be possible to keep the rendered line data while regenerating the rest of the plot widget (frame, axes, legend, ..).

My current idea is to look at the ImDrawList that is being built in the call to PlotLineEx and stove away the relevant indexes/vertices and in the next call plug them in somehow. Maybe this could work as long as the plot widget is in the same place et.al. but might be to cumbersome to manage when supporting the expected plot behavior / interaction as we know it today. Thoughts?

Is this something that would be possible, and if yes, which part of the code should I look into?

phkehl commented 1 year ago

Not sure if this is an option for you, but what I do is lowering the FPS dynamically. The main loop runs at a minimal FPS (e.g., 15) and only temporarily boosts that to a max FPS when there is user activity (mouse, keyboard). This saves quite a bit of CPU for my use case.

See https://github.com/phkehl/ubloxcfg/blob/master/cfggui/cfggui.cpp lines 61-106, 268-272 and line 384 in the main loop.

hinxx commented 1 year ago

@phkehl , that seems to work quite well for me. Thanks for sharing the idea / code!