Commit 8111efcf authored by Matthias Betz's avatar Matthias Betz
Browse files

Render GL viewport on demand instead of every frame



openglfx with fps=-1.0 repaints every JavaFX pulse (~60fps), allocating and
rendering continuously even when idle. Set fps=0.0 so a frame is drawn only
when repaint() is called (every state change and input already does), and add
canvas resize listeners to repaint on size changes. Idle now allocates nothing.

Co-Authored-By: default avatarClaude Opus 4.8 <noreply@anthropic.com>
parent 4bf0ac99
......@@ -36,7 +36,7 @@ public class GLViewport {
private volatile int[] lastIndices;
private volatile boolean wireframe = false;
private volatile boolean cull = false;
private volatile float pointScale = 14f;
private volatile float pointScale = 20f;
private volatile float lineScale = 4f;
// highlight marker data, uploaded on the GL thread when dirty
......@@ -56,8 +56,10 @@ public class GLViewport {
private double lastY;
public GLViewport() {
// args: executor, profile, flipY=false, msaa=4 -> request a 4x multisampled framebuffer for AA
canvas = new GLCanvas(new JOGLExecutor(), GLProfile.CORE, false, 4);
// args: executor, profile, flipY=false, msaa=4, fps=0.0
// fps=0 -> on-demand rendering: a frame is drawn only when repaint() is called (every state
// change / input does so), so an idle viewport allocates and renders nothing.
canvas = new GLCanvas(new JOGLExecutor(), GLProfile.CORE, false, 4, 0.0);
canvas.addOnInitEvent(ev -> {
// GL context (re)created: shaders/buffers from any previous context are gone. Drop our
// handles and re-queue the current scene so it is re-uploaded into the new context.
......@@ -69,6 +71,9 @@ public class GLViewport {
});
canvas.addOnRenderEvent(ev -> render((JOGLRenderEvent) ev));
canvas.addOnReshapeEvent(ev -> { /* aspect handled per-frame from width/height */ });
// on-demand mode: repaint when the canvas is resized so the framebuffer tracks the new size
canvas.widthProperty().addListener((obs, ov, nv) -> canvas.repaint());
canvas.heightProperty().addListener((obs, ov, nv) -> canvas.repaint());
installInputHandlers();
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment