Search in sources :

Example 1 with GLAnimatorControl

use of com.jogamp.opengl.GLAnimatorControl in project processing by processing.

the class PSurfaceJOGL method initAnimator.

protected void initAnimator() {
    if (PApplet.platform == PConstants.WINDOWS) {
        // Force Windows to keep timer resolution high by
        // sleeping for time which is not a multiple of 10 ms.
        // See section "Clocks and Timers on Windows":
        //   https://blogs.oracle.com/dholmes/entry/inside_the_hotspot_vm_clocks
        Thread highResTimerThread = new Thread(() -> {
            try {
                Thread.sleep(Long.MAX_VALUE);
            } catch (InterruptedException ignore) {
            }
        }, "HighResTimerThread");
        highResTimerThread.setDaemon(true);
        highResTimerThread.start();
    }
    animator = new FPSAnimator(window, 60);
    drawException = null;
    animator.setUncaughtExceptionHandler(new GLAnimatorControl.UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(final GLAnimatorControl animator, final GLAutoDrawable drawable, final Throwable cause) {
            synchronized (drawExceptionMutex) {
                drawException = cause;
                drawExceptionMutex.notify();
            }
        }
    });
    drawExceptionHandler = new Thread(new Runnable() {

        public void run() {
            synchronized (drawExceptionMutex) {
                try {
                    while (drawException == null) {
                        drawExceptionMutex.wait();
                    }
                    // System.err.println("Caught exception: " + drawException.getMessage());
                    if (drawException != null) {
                        Throwable cause = drawException.getCause();
                        if (cause instanceof ThreadDeath) {
                        // System.out.println("caught ThreadDeath");
                        // throw (ThreadDeath)cause;
                        } else if (cause instanceof RuntimeException) {
                            throw (RuntimeException) cause;
                        } else if (cause instanceof UnsatisfiedLinkError) {
                            throw new UnsatisfiedLinkError(cause.getMessage());
                        } else if (cause == null) {
                            throw new RuntimeException(drawException.getMessage());
                        } else {
                            throw new RuntimeException(cause);
                        }
                    }
                } catch (InterruptedException e) {
                    return;
                }
            }
        }
    });
    drawExceptionHandler.start();
}
Also used : FPSAnimator(com.jogamp.opengl.util.FPSAnimator) GLAutoDrawable(com.jogamp.opengl.GLAutoDrawable) GLAnimatorControl(com.jogamp.opengl.GLAnimatorControl)

Aggregations

GLAnimatorControl (com.jogamp.opengl.GLAnimatorControl)1 GLAutoDrawable (com.jogamp.opengl.GLAutoDrawable)1 FPSAnimator (com.jogamp.opengl.util.FPSAnimator)1