From 1926b81fb05378240dc5a9b6be3a5520bd7b8d90 Mon Sep 17 00:00:00 2001 From: Kenneth Russel Date: Sun, 11 Nov 2001 01:28:34 +0000 Subject: Added automatic disabling of rendering from AWT thread for GLAnimCanvases when useRepaint is false for better stability with NVidia drivers --- gl4java/awt/GLAnimCanvas.java | 1 + gl4java/awt/GLCanvas.java | 58 +++++++++++++++++++++++++++++++++++++++---- 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/gl4java/awt/GLAnimCanvas.java b/gl4java/awt/GLAnimCanvas.java index b35f765..8cd973c 100644 --- a/gl4java/awt/GLAnimCanvas.java +++ b/gl4java/awt/GLAnimCanvas.java @@ -311,6 +311,7 @@ public class GLAnimCanvas extends GLCanvas public synchronized void setUseRepaint(boolean b) { useRepaint = b; + recomputeAWTThreadRendering(); } /** diff --git a/gl4java/awt/GLCanvas.java b/gl4java/awt/GLCanvas.java index e54505f..2ca77e7 100644 --- a/gl4java/awt/GLCanvas.java +++ b/gl4java/awt/GLCanvas.java @@ -174,6 +174,22 @@ public class GLCanvas extends Canvas // The list of GLEventListeners private GLEventListenerList listeners = new GLEventListenerList(); + // Indicates whether init() has been called yet. + private volatile boolean initCalled = false; + + // Indicates whether the canvas will permit any calls to init() or + // display() from within the paint() method. + private boolean enableAWTThreadRendering; + + void recomputeAWTThreadRendering() { + // Switches to false under the following circumstances: + // - this is (precisely a) GLAnimCanvas; subclassing may change + // the code flow significantly enough that this optimization + // breaks + // - useRepaint is false + enableAWTThreadRendering = !((getClass() == GLAnimCanvas.class) && !getUseRepaint()); + } + static { if(GLContext.doLoadNativeLibraries(null, null, null)==false) System.out.println("GLCanvas could not load def. native libs."); @@ -216,6 +232,7 @@ public class GLCanvas extends Canvas setSize(size); + recomputeAWTThreadRendering(); } /** @@ -316,6 +333,7 @@ public class GLCanvas extends Canvas setSize(size); + recomputeAWTThreadRendering(); } /** @@ -448,7 +466,10 @@ public class GLCanvas extends Canvas (float)col.getGreen()/255.0f, (float)col.getBlue()/255.0f, 0.0f); - init(); + if (enableAWTThreadRendering) { + init(); + initCalled = true; + } // fetch the top-level window , // to add us as the windowListener @@ -485,11 +506,29 @@ public class GLCanvas extends Canvas /* force a reshape, to be sure .. */ mustResize = true; isInit = true; + + /* if we are not allowed to render from the AWT + thread, release the OpenGL context for the + animation thread to use */ + if (!enableAWTThreadRendering) { + // makeCurrent() necessary to make GLContext + // realize that JAWT lock has to be released... + glj.gljMakeCurrent(); + glj.gljFree(); + } } - sDisplay(); + if (enableAWTThreadRendering) { + sDisplay(); + } } + // Package-private hack to make this work similarly to old + // releases. This avoids ever calling sDisplay() from the AWT + // thread if the component is a GLAnimCanvas and if + // setUseRepaint(false) has been called. + boolean getUseRepaint() { return true; } + /** * * This is your pre-init method. @@ -653,7 +692,7 @@ public class GLCanvas extends Canvas if(!cvsIsInit()) return; - if( mustResize ) + if( mustResize && initCalled ) { if( glj.gljMakeCurrent() == true ) { @@ -661,8 +700,10 @@ public class GLCanvas extends Canvas glj.gljResize( size.width, size.height ) ; reshape(size.width, size.height); mustResize = false; - invalidate(); - repaint(100); + if (enableAWTThreadRendering) { + invalidate(); + repaint(100); + } glj.gljFree(true); /* force freeing the context here .. */ } } @@ -742,6 +783,13 @@ public class GLCanvas extends Canvas listeners.sendPreDisplayEvent(this); if (glj.gljMakeCurrent()) { + if (!enableAWTThreadRendering) { + if (!initCalled) { + init(); + initCalled = true; + } + } + listeners.sendDisplayEvent(this); glj.gljSwap(); -- cgit v1.2.3