From 97f4ef2763596993bcb8a6b84150c9ec906dde08 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 21 Jan 2014 18:56:32 +0100 Subject: Better shared GLAutoDrawable synchronization: Block slave instances to also block until all master's GLEventListener.init(..) methods have been called Better shared GLAutoDrawable synchronization. Block slave instances to also block until all master's GLEventListener.init(..) methods have been called - GLSharedContextSetter: Add areAllGLEventListenerInitialized() - GLCanvas (SWT, AWT) - GLJPanel - GLAutoDrawableBase (GLWindow, ..) - GLDrawableHelper's isSharedGLContextPending(..) takes 'areAllGLEventListenerInitialized()' into consideration allowing to block the slave creation until master is completed. This solves teh use case, where the master creates resources in it's GLEventListener initialization (buffers), which are shared with it's slaves. --- src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java | 5 +++++ .../classes/javax/media/opengl/GLSharedContextSetter.java | 14 ++++++++++++-- src/jogl/classes/javax/media/opengl/awt/GLCanvas.java | 5 +++++ src/jogl/classes/javax/media/opengl/awt/GLJPanel.java | 5 +++++ src/jogl/classes/jogamp/opengl/GLAutoDrawableBase.java | 5 +++++ src/jogl/classes/jogamp/opengl/GLDrawableHelper.java | 15 ++++++++++++++- 6 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java b/src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java index cad780a89..cd5aa338d 100644 --- a/src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java +++ b/src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java @@ -724,6 +724,11 @@ public class GLCanvas extends Canvas implements GLAutoDrawable, GLSharedContextS return helper.getGLEventListener(index); } + @Override + public boolean areAllGLEventListenerInitialized() { + return helper.areAllGLEventListenerInitialized(); + } + @Override public boolean getGLEventListenerInitState(GLEventListener listener) { return helper.getGLEventListenerInitState(listener); diff --git a/src/jogl/classes/javax/media/opengl/GLSharedContextSetter.java b/src/jogl/classes/javax/media/opengl/GLSharedContextSetter.java index 69ee03546..2ea4e4cd6 100644 --- a/src/jogl/classes/javax/media/opengl/GLSharedContextSetter.java +++ b/src/jogl/classes/javax/media/opengl/GLSharedContextSetter.java @@ -98,6 +98,12 @@ package javax.media.opengl; *

*/ public interface GLSharedContextSetter extends GLAutoDrawable { + /** + * Returns true if all {@link GLEventListener} are initialized, otherwise false. + * @deprecated Promote method to {@link GLAutoDrawable} + */ + boolean areAllGLEventListenerInitialized(); + /** * Specifies an {@link GLContext OpenGL context}, which shall be shared by this {@link GLAutoDrawable}'s {@link GLContext}. *

@@ -130,8 +136,12 @@ public interface GLSharedContextSetter extends GLAutoDrawable { *

*

* A set sharedAutoDrawable will block context creation, i.e. {@link GLAutoDrawable#initialization GLAutoDrawable initialization}, - * as long it's {@link GLContext} is null - * or has not been {@link GLContext#isCreated() created natively}. + * as long it's + *

*

*

* See Lifecycle Considerations. diff --git a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java index 7ea216dd9..abf670c95 100644 --- a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java +++ b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java @@ -969,6 +969,11 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing return helper.getGLEventListener(index); } + @Override + public boolean areAllGLEventListenerInitialized() { + return helper.areAllGLEventListenerInitialized(); + } + @Override public boolean getGLEventListenerInitState(GLEventListener listener) { return helper.getGLEventListenerInitState(listener); diff --git a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java index f7200186b..522585f16 100644 --- a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java +++ b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java @@ -804,6 +804,11 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing return helper.getGLEventListener(index); } + @Override + public boolean areAllGLEventListenerInitialized() { + return helper.areAllGLEventListenerInitialized(); + } + @Override public boolean getGLEventListenerInitState(GLEventListener listener) { return helper.getGLEventListenerInitState(listener); diff --git a/src/jogl/classes/jogamp/opengl/GLAutoDrawableBase.java b/src/jogl/classes/jogamp/opengl/GLAutoDrawableBase.java index 42d0a2ec4..7cd685d5a 100644 --- a/src/jogl/classes/jogamp/opengl/GLAutoDrawableBase.java +++ b/src/jogl/classes/jogamp/opengl/GLAutoDrawableBase.java @@ -509,6 +509,11 @@ public abstract class GLAutoDrawableBase implements GLAutoDrawable, GLStateKeepe return helper.getGLEventListener(index); } + @Override + public boolean areAllGLEventListenerInitialized() { + return helper.areAllGLEventListenerInitialized(); + } + @Override public boolean getGLEventListenerInitState(GLEventListener listener) { return helper.getGLEventListenerInitState(listener); diff --git a/src/jogl/classes/jogamp/opengl/GLDrawableHelper.java b/src/jogl/classes/jogamp/opengl/GLDrawableHelper.java index b498748fd..0e135d5e0 100644 --- a/src/jogl/classes/jogamp/opengl/GLDrawableHelper.java +++ b/src/jogl/classes/jogamp/opengl/GLDrawableHelper.java @@ -58,6 +58,7 @@ import javax.media.opengl.GLEventListener; import javax.media.opengl.GLException; import javax.media.opengl.GLFBODrawable; import javax.media.opengl.GLRunnable; +import javax.media.opengl.GLSharedContextSetter; /** Encapsulates the implementation of most of the GLAutoDrawable's methods to be able to share it between GLAutoDrawable implementations like GLAutoDrawableBase, GLCanvas and GLJPanel. */ @@ -149,8 +150,14 @@ public class GLDrawableHelper { final GLContext shareWith; final boolean pending; if ( null != sharedAutoDrawable ) { + final boolean allGLELInitialized; + if( sharedAutoDrawable instanceof GLSharedContextSetter ) { + allGLELInitialized = ((GLSharedContextSetter)sharedAutoDrawable).areAllGLEventListenerInitialized(); + } else { + allGLELInitialized = true; // we have to assume 'yes' + } shareWith = sharedAutoDrawable.getContext(); - pending = null == shareWith || !shareWith.isCreated(); + pending = null == shareWith || !shareWith.isCreated() || !allGLELInitialized; } else { shareWith = sharedContext; pending = null != shareWith && !shareWith.isCreated(); @@ -434,6 +441,12 @@ public class GLDrawableHelper { } } + public final boolean areAllGLEventListenerInitialized() { + synchronized(listenersLock) { + return 0 == listenersToBeInit.size(); + } + } + public final boolean getGLEventListenerInitState(GLEventListener listener) { synchronized(listenersLock) { return !listenersToBeInit.contains(listener); -- cgit v1.2.3