Login  Register

Possible to know if glCanvas display() was called by Animator or because a redraw is required?

Posted by farrellf on Jan 14, 2022; 10:12pm
URL: https://forum.jogamp.org/Possible-to-know-if-glCanvas-display-was-called-by-Animator-or-because-a-redraw-is-required-tp4041585.html

I'm using a GLCanvas and an Animator to draw inside a JPanel. Therefore the display() callback is executed at 60Hz (or whatever vsync happens to be.)

To reduce GPU load, I'd like to do some checks at the beginning of display() to decide if I have to redraw or if I can return early and leave the existing image on screen. Obviously there may be times where I have to redraw because the OS has invalided the buffer. Is there any way for me to know this?

In case this isn't clear, here's some pseudocode explaining what I'd like to do:

display() {

    GL3 gl = ...;

    boolean wantToRedraw = queryMyCode();
    boolean haveToRedraw = queryOpenGL();

    if(!wantToRedraw && !haveToRedraw)
        return;
    else
        draw();

}


This way I don't waste GPU resources to redraw a static screen unless I am forced to redraw the static screen. I know I could pause the animator when my code doesn't need to redraw, but it would be cleaner if I could just decide that when display() is called.

-Farrell