glcanon: rewrite the G-code preview on OpenGL 3.3 core - #4293
Conversation
Replaces the fixed-function preview shared by AXIS, the GTK screens and QtVCP with a shader/VBO renderer: a baked trajectory buffer, an offscreen ID-buffer pass for picking, and a glyph atlas for overlay text. The GL matrix stack, display lists, immediate mode and GL_SELECT are gone.
Why rewrite?
Performance
Code RefactoringCode is also reviewed and refactored for eaiser maintenance .
Hardware supportThis rewrite targets the OpenGL 3.3 standard, released in 2010 and widely supported. In case of hardware problems, or if drivers don't support the necessary features, the env var Verification
Known Problems
Performance testing resultsBenchmarked against stock master on AXIS end-to-end (4 reps, real GUI,
|
| master | rewrite | ||
|---|---|---|---|
| peak RSS | 1674 MB | 748 MB | 2.24× lower |
| ⤷ minus idle baseline (194 MB both) | 1480 MB | 554 MB | 2.67× lower |
| steady redraw frame | 0.32 s | 0.12 s | 2.7× faster |
open_file_guts (open→drawn) |
7.6 s (6.8–8.5) | 7.1 s (7.1–7.4) | a wash |
⤷ load_preview alone |
3.00 s | 2.96 s | a wash |
Both screenshots confirm the file actually drew — this isn't one branch skipping work.
Phase harness (3 reps, EGL, isolates parse / extents / GPU build)
| phase | master | rewrite |
|---|---|---|
gcode.parse |
1.66 s, +575 MB | 2.76 s, +28 MB |
calc_extents |
0.86 s, +432 MB | 0.00002 s, +0 |
| GPU build | 0.28 s (glNewList), +31 MB |
bake 0.027 s + upload 0.002 s |
| GL payload | not queryable | 24,003,600 B VBO (counted at glBufferData) |
| load total | 2.82 s | 2.80 s |
| peak RSS | 1122 MB | 276 MB |
| first click in preview | +0.75 s, +276 MB (selection lists) | none |
What the numbers say
- Memory is the headline. 2.2× lower peak in the real GUI, and the gap widens on first click: master compiles a second, per-line-named copy of the program into selection display lists (+276 MB); the rewrite's picker reads the buffers already uploaded.
- Load time is unchanged, but for a non-obvious reason. The rewrite's raw parse is ~1.1 s slower — it transforms and fills arrays on the move path. That's fully paid back by
calc_extents/unrotate_previewdropping from 0.86 s to zero, since the rewrite accumulates extents during the fill. If you want load time to actually drop, the parse hot path is where the remaining 1.1 s lives. - Frame time is 2.7× better and the GPU build is 10× cheaper (0.03 s vs 0.28 s).
Two caveats worth stating: llvmpipe puts display lists and VBOs in process RSS, so the RSS deltas are the only cross-branch-comparable "GPU memory" figure — a display list has no queryable size, so master gets no exact byte count. And I noticed that at the same view master's preview saturates to white where the rewrite renders mid-grey; that's a blend difference on densely overlapping geometry which I did not investigate.
|
Good work. Functional touch screen support is rather important to keep working. Breaking a touch interface would probably make quite a few users pulling hairs and may even require baldness treatments when it persists. Some cases that should function: running on RPi4, Rpi5 and running with remote X (also ssh tunneled)? |
Replaces the fixed-function preview shared by AXIS, the GTK screens and QtVCP with a shader/VBO renderer: a baked trajectory buffer, an offscreen ID-buffer pass for picking, and a glyph atlas for overlay text. The GL matrix stack, display lists, immediate mode and GL_SELECT are gone.