aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/net/java/games/jogl/GLCanvas.java8
-rw-r--r--src/net/java/games/jogl/GLJPanel.java51
2 files changed, 57 insertions, 2 deletions
diff --git a/src/net/java/games/jogl/GLCanvas.java b/src/net/java/games/jogl/GLCanvas.java
index 17aed5bea..e0065153f 100644
--- a/src/net/java/games/jogl/GLCanvas.java
+++ b/src/net/java/games/jogl/GLCanvas.java
@@ -59,6 +59,8 @@ import net.java.games.jogl.impl.*;
public final class GLCanvas extends Canvas implements GLDrawable {
+ protected static final boolean DEBUG = Debug.debug("GLCanvas");
+
private GLDrawableHelper drawableHelper = new GLDrawableHelper();
private GLContext context;
@@ -90,6 +92,9 @@ public final class GLCanvas extends Canvas implements GLDrawable {
public void addNotify() {
super.addNotify();
context.setRealized();
+ if (DEBUG) {
+ System.err.println("GLCanvas.addNotify()");
+ }
}
/** Overridden from Canvas; used to indicate that it's no longer
@@ -97,6 +102,9 @@ public final class GLCanvas extends Canvas implements GLDrawable {
public void removeNotify() {
context.destroy();
super.removeNotify();
+ if (DEBUG) {
+ System.err.println("GLCanvas.removeNotify()");
+ }
}
/** Overridden from Canvas; causes {@link GLDrawableHelper#reshape}
diff --git a/src/net/java/games/jogl/GLJPanel.java b/src/net/java/games/jogl/GLJPanel.java
index 229cc3446..d21081dfe 100644
--- a/src/net/java/games/jogl/GLJPanel.java
+++ b/src/net/java/games/jogl/GLJPanel.java
@@ -67,7 +67,10 @@ import net.java.games.jogl.impl.*;
them. */
public final class GLJPanel extends JPanel implements GLDrawable {
+ protected static final boolean DEBUG = Debug.debug("GLJPanel");
+
private GLDrawableHelper drawableHelper = new GLDrawableHelper();
+ private volatile boolean isInitialized;
// Data used for either pbuffers or pixmap-based offscreen surfaces
private GLCapabilities offscreenCaps;
@@ -114,11 +117,13 @@ public final class GLJPanel extends JPanel implements GLDrawable {
offscreenCaps.setDoubleBuffered(false);
this.chooser = chooser;
this.shareWith = shareWith;
-
- initialize();
}
public void display() {
+ if (!isInitialized) {
+ return;
+ }
+
if (EventQueue.isDispatchThread()) {
// Want display() to be synchronous, so call paintImmediately()
paintImmediately(0, 0, getWidth(), getHeight());
@@ -137,6 +142,10 @@ public final class GLJPanel extends JPanel implements GLDrawable {
GLEventListener#display}. Should not be invoked by applications
directly. */
public void paintComponent(Graphics g) {
+ if (!isInitialized) {
+ return;
+ }
+
updater.setGraphics(g);
if (!hardwareAccelerationDisabled) {
if (!pbufferInitializationCompleted) {
@@ -161,6 +170,37 @@ public final class GLJPanel extends JPanel implements GLDrawable {
}
}
+ public void addNotify() {
+ super.addNotify();
+ initialize();
+ if (DEBUG) {
+ System.err.println("GLJPanel.addNotify()");
+ }
+ }
+
+ /** Overridden from JPanel; used to indicate that it's no longer
+ safe to have an OpenGL context for the component. */
+ public void removeNotify() {
+ if (DEBUG) {
+ System.err.println("GLJPanel.removeNotify()");
+ }
+ if (!hardwareAccelerationDisabled) {
+ if (pbuffer != null) {
+ pbuffer.destroy();
+ }
+ if (toplevel != null) {
+ toplevel.dispose();
+ }
+ pbuffer = null;
+ heavyweight = null;
+ toplevel = null;
+ } else {
+ offscreenContext.destroy();
+ }
+ isInitialized = false;
+ super.removeNotify();
+ }
+
/** Overridden from Canvas; causes {@link GLDrawableHelper#reshape}
to be called on all registered {@link GLEventListener}s. Called
automatically by the AWT; should not be invoked by applications
@@ -168,6 +208,10 @@ public final class GLJPanel extends JPanel implements GLDrawable {
public void reshape(int x, int y, int width, int height) {
super.reshape(x, y, width, height);
+ if (!isInitialized) {
+ return;
+ }
+
// Move all reshape requests onto AWT EventQueue thread
final int fx = x;
final int fy = y;
@@ -393,6 +437,7 @@ public final class GLJPanel extends JPanel implements GLDrawable {
}
}
});
+ isInitialized = true;
return;
} else {
// If the heavyweight reports that it can't create an
@@ -415,6 +460,8 @@ public final class GLJPanel extends JPanel implements GLDrawable {
}
}, true, initAction);
}
+
+ isInitialized = true;
}
class Updater implements GLEventListener {