diff options
author | Sven Gothel <[email protected]> | 2012-06-28 18:37:55 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-06-28 18:37:55 +0200 |
commit | bd92af2b6b0ae2d1b1f22c64dcb0ffd0e94fae84 (patch) | |
tree | af392e26356f160e0a5d8237d6358e40892969dc /src/jogl/classes/javax | |
parent | 914b522af26b6d779dc931bf4303be3c7e898eff (diff) |
GLDrawable* cleanup: Add @Override, remove trailing whitespace, ..
Diffstat (limited to 'src/jogl/classes/javax')
6 files changed, 315 insertions, 177 deletions
diff --git a/src/jogl/classes/javax/media/opengl/GLAutoDrawable.java b/src/jogl/classes/javax/media/opengl/GLAutoDrawable.java index c676535c8..94e4bad66 100644 --- a/src/jogl/classes/javax/media/opengl/GLAutoDrawable.java +++ b/src/jogl/classes/javax/media/opengl/GLAutoDrawable.java @@ -1,22 +1,22 @@ /* * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Copyright (c) 2010 JogAmp Community. All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: - * + * * - Redistribution of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. - * + * * - Redistribution in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * + * * Neither the name of Sun Microsystems, Inc. or the names of * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. - * + * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A @@ -29,11 +29,11 @@ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * + * * You acknowledge that this software is not designed or intended for use * in the design, construction, operation or maintenance of any nuclear * facility. - * + * * Sun gratefully acknowledges that this software was originally authored * and developed by Kenneth Bradley Russell and Christopher John Kline. */ @@ -54,7 +54,7 @@ import jogamp.opengl.Debug; based rendering mechanism as well by end users directly.<P> The implementation shall initialize itself as soon as possible, - ie if the attached {@link javax.media.nativewindow.NativeSurface NativeSurface} becomes visible/realized. + ie if the attached {@link javax.media.nativewindow.NativeSurface NativeSurface} becomes visible/realized. The following protocol shall be satisfied: <ul> <li> Create the {@link GLDrawable} with the requested {@link GLCapabilities}</li> @@ -66,15 +66,15 @@ import jogamp.opengl.Debug; registered {@link GLEventListener}s. This shall be done after the {@link GLEventListener#init init(..)} calls.</li> </ul><P> - Another implementation detail is the drawable reconfiguration. One use case is where a window is being - dragged to another screen with a different pixel configuration, ie {@link GLCapabilities}. The implementation + Another implementation detail is the drawable reconfiguration. One use case is where a window is being + dragged to another screen with a different pixel configuration, ie {@link GLCapabilities}. The implementation shall be able to detect such cases in conjunction with the associated {@link javax.media.nativewindow.NativeSurface NativeSurface}.<br> For example, AWT's {@link java.awt.Canvas} 's {@link java.awt.Canvas#getGraphicsConfiguration getGraphicsConfiguration()} - is capable to determine a display device change. This is demonstrated within {@link javax.media.opengl.awt.GLCanvas}'s - and NEWT's <code>AWTCanvas</code> {@link javax.media.opengl.awt.GLCanvas#getGraphicsConfiguration getGraphicsConfiguration()} - specialization. Another demonstration is NEWT's {@link javax.media.nativewindow.NativeWindow NativeWindow} + is capable to determine a display device change. This is demonstrated within {@link javax.media.opengl.awt.GLCanvas}'s + and NEWT's <code>AWTCanvas</code> {@link javax.media.opengl.awt.GLCanvas#getGraphicsConfiguration getGraphicsConfiguration()} + specialization. Another demonstration is NEWT's {@link javax.media.nativewindow.NativeWindow NativeWindow} implementation on the Windows platform, which utilizes the native platform's <i>MonitorFromWindow(HWND)</i> function.<br> - All OpenGL resources shall be regenerated, while the drawable's {@link GLCapabilities} has + All OpenGL resources shall be regenerated, while the drawable's {@link GLCapabilities} has to be choosen again. The following protocol shall be satisfied. <ul> <li> Controlled disposal:</li> @@ -95,21 +95,21 @@ import jogamp.opengl.Debug; registered {@link GLEventListener}s. This shall be done after the {@link GLEventListener#init init(..)} calls.</li> </ul> </ul> - Note: Current graphics driver keep the surface configuration for a given window, even if the window is moved to + Note: Current graphics driver keep the surface configuration for a given window, even if the window is moved to a monitor with a different pixel configuration, ie 32bpp to 16bpp. However, it is best to not assume such behavior and make your application comply with the above protocol.<P> - However, to not introduce to much breakage with older applications and because of the situation - mentioned above, the <code>boolean</code> system property <code>jogl.screenchange.action</code> will control the + However, to not introduce to much breakage with older applications and because of the situation + mentioned above, the <code>boolean</code> system property <code>jogl.screenchange.action</code> will control the screen change action as follows:<br> <PRE> -Djogl.screenchange.action=false Disable the drawable reconfiguration (the default) -Djogl.screenchange.action=true Enable the drawable reconfiguration - </PRE> + </PRE> */ public interface GLAutoDrawable extends GLDrawable { - /** Flag reflecting wheather the drawable reconfiguration will be issued in + /** Flag reflecting wheather the drawable reconfiguration will be issued in * case a screen device change occured, e.g. in a multihead environment, * where you drag the window to another monitor. */ public static final boolean SCREEN_CHANGE_ACTION_ENABLED = Debug.getBooleanProperty("jogl.screenchange.action", true); @@ -130,10 +130,10 @@ public interface GLAutoDrawable extends GLDrawable { The listeners are notified of events in the order of the queue. */ public void addGLEventListener(GLEventListener listener); - /** + /** * Adds a {@link GLEventListener} at the given index of this drawable queue. * The listeners are notified of events in the order of the queue. - * @param index Position where the listener will be inserted. + * @param index Position where the listener will be inserted. * Should be within (0 <= index && index <= size()). * An index value of -1 is interpreted as the end of the list, size(). * @param listener The GLEventListener object to be inserted @@ -168,7 +168,7 @@ public interface GLAutoDrawable extends GLDrawable { * @see #display() * @see #invoke(boolean, GLRunnable) * @see javax.media.opengl.GLAnimatorControl - */ + */ public abstract void setAnimator(GLAnimatorControl animatorControl) throws GLException; /** @@ -179,12 +179,12 @@ public interface GLAutoDrawable extends GLDrawable { */ public GLAnimatorControl getAnimator(); - /** + /** * <p> * Enqueues a one-shot {@link GLRunnable}, * which will be executed within the next {@link #display()} call - * after all registered {@link GLEventListener}s - * {@link GLEventListener#display(GLAutoDrawable) display(GLAutoDrawable)} + * after all registered {@link GLEventListener}s + * {@link GLEventListener#display(GLAutoDrawable) display(GLAutoDrawable)} * methods has been called. * </p> * <p> @@ -201,7 +201,7 @@ public interface GLAutoDrawable extends GLDrawable { * @see #setAnimator(GLAnimatorControl) * @see #display() * @see GLRunnable - */ + */ public void invoke(boolean wait, GLRunnable glRunnable); /** Destroys all resources associated with this GLAutoDrawable, @@ -214,7 +214,7 @@ public interface GLAutoDrawable extends GLDrawable { routine may be called manually. */ public void destroy(); - /** + /** * <p> * Causes OpenGL rendering to be performed for this GLAutoDrawable * in the following order: @@ -224,21 +224,21 @@ public interface GLAutoDrawable extends GLDrawable { * <li> Executes all one-shot {@link javax.media.opengl.GLRunnable GLRunnable}, * enqueued via {@link #invoke(boolean, GLRunnable)}.</li> * </ul></p> - * <p> + * <p> * May be called periodically by a running {@link javax.media.opengl.GLAnimatorControl} implementation,<br> * which must register itself with {@link #setAnimator(javax.media.opengl.GLAnimatorControl)}.</p> * <p> * Called automatically by the window system toolkit upon receiving a repaint() request, <br> * except an {@link javax.media.opengl.GLAnimatorControl} implementation {@link javax.media.opengl.GLAnimatorControl#isAnimating()}.</p> - * <p> + * <p> * This routine may also be called manually for better control over the * rendering process. It is legal to call another GLAutoDrawable's * display method from within the {@link GLEventListener#display * display(..)} callback.</p> * <p> - * In case of a new generated OpenGL context, + * In case of a new generated OpenGL context, * the implementation shall call {@link GLEventListener#init init(..)} for all - * registered {@link GLEventListener}s <i>before</i> making the + * registered {@link GLEventListener}s <i>before</i> making the * actual {@link GLEventListener#display display(..)} calls, * in case this has not been done yet.</p> * @@ -260,12 +260,12 @@ public interface GLAutoDrawable extends GLDrawable { /** * @param flags Additional context creation flags. - * + * * @see GLContext#setContextCreationFlags(int) * @see GLContext#enableGLDebugMessage(boolean) */ public void setContextCreationFlags(int flags); - + /** * @return Additional context creation flags */ diff --git a/src/jogl/classes/javax/media/opengl/GLDrawable.java b/src/jogl/classes/javax/media/opengl/GLDrawable.java index 2b86a04ba..10eea2efc 100644 --- a/src/jogl/classes/javax/media/opengl/GLDrawable.java +++ b/src/jogl/classes/javax/media/opengl/GLDrawable.java @@ -1,22 +1,22 @@ /* * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Copyright (c) 2010 JogAmp Community. All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: - * + * * - Redistribution of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. - * + * * - Redistribution in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * + * * Neither the name of Sun Microsystems, Inc. or the names of * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. - * + * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A @@ -29,11 +29,11 @@ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * + * * You acknowledge that this software is not designed or intended for use * in the design, construction, operation or maintenance of any nuclear * facility. - * + * * Sun gratefully acknowledges that this software was originally authored * and developed by Kenneth Bradley Russell and Christopher John Kline. */ @@ -104,11 +104,11 @@ public interface GLDrawable { * * <P> * - * With an argument of <code>true</code>, - * the minimum implementation shall call + * With an argument of <code>true</code>, + * the minimum implementation shall call * {@link NativeSurface#lockSurface() NativeSurface's lockSurface()} and if successfull: * <ul> - * <li> Update the {@link GLCapabilities}, which are associated with + * <li> Update the {@link GLCapabilities}, which are associated with * the attached {@link NativeSurface}'s {@link AbstractGraphicsConfiguration}.</li> * <li> Release the lock with {@link NativeSurface#unlockSurface() NativeSurface's unlockSurface()}.</li> * </ul><br> @@ -146,7 +146,7 @@ public interface GLDrawable { On some platforms, the pixel format is not directly associated with the drawable; a best attempt is made to return a reasonable value in this case. <br> - This object shall be directly associated to the attached {@link NativeSurface}'s + This object shall be directly associated to the attached {@link NativeSurface}'s {@link AbstractGraphicsConfiguration}, and if changes are necessary, they should reflect those as well. @return A copy of the queried object. @@ -159,14 +159,14 @@ public interface GLDrawable { public GLProfile getGLProfile(); /** - * Returns the underlying native surface which surface handle + * Returns the underlying native surface which surface handle * represents this OpenGL drawable's native resource. - * + * * @see #getHandle() */ public NativeSurface getNativeSurface(); - /** + /** * This is the GL/Windowing drawable handle.<br> * It is usually the {@link javax.media.nativewindow.NativeSurface#getSurfaceHandle()}, * ie the native surface handle of the underlying windowing toolkit.<br> @@ -175,7 +175,9 @@ public interface GLDrawable { */ public long getHandle(); + /** Return the {@link GLDrawableFactory} being used to create this instance. */ public GLDrawableFactory getFactory(); + @Override public String toString(); } diff --git a/src/jogl/classes/javax/media/opengl/GLPbuffer.java b/src/jogl/classes/javax/media/opengl/GLPbuffer.java index 0250365b0..273a992cf 100644 --- a/src/jogl/classes/javax/media/opengl/GLPbuffer.java +++ b/src/jogl/classes/javax/media/opengl/GLPbuffer.java @@ -1,21 +1,21 @@ /* * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: - * + * * - Redistribution of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. - * + * * - Redistribution in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * + * * Neither the name of Sun Microsystems, Inc. or the names of * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. - * + * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A @@ -28,11 +28,11 @@ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * + * * You acknowledge that this software is not designed or intended for use * in the design, construction, operation or maintenance of any nuclear * facility. - * + * * Sun gratefully acknowledges that this software was originally authored * and developed by Kenneth Bradley Russell and Christopher John Kline. */ @@ -78,6 +78,7 @@ public interface GLPbuffer extends GLAutoDrawable { pbuffer, the application must destroy any additional OpenGL contexts which have been created for the pbuffer via {@link #createContext}. */ + @Override public void destroy(); /** Indicates which vendor's extension is being used to support diff --git a/src/jogl/classes/javax/media/opengl/awt/AWTGLAutoDrawable.java b/src/jogl/classes/javax/media/opengl/awt/AWTGLAutoDrawable.java index d1e725b00..2698678af 100644 --- a/src/jogl/classes/javax/media/opengl/awt/AWTGLAutoDrawable.java +++ b/src/jogl/classes/javax/media/opengl/awt/AWTGLAutoDrawable.java @@ -1,21 +1,21 @@ /* * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: - * + * * - Redistribution of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. - * + * * - Redistribution in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * + * * Neither the name of Sun Microsystems, Inc. or the names of * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. - * + * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A @@ -28,18 +28,18 @@ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * + * * You acknowledge that this software is not designed or intended for use * in the design, construction, operation or maintenance of any nuclear * facility. - * + * * Sun gratefully acknowledges that this software was originally authored * and developed by Kenneth Bradley Russell and Christopher John Kline. */ package javax.media.opengl.awt; -import javax.media.opengl.*; +import javax.media.opengl.GLAutoDrawable; public interface AWTGLAutoDrawable extends GLAutoDrawable, ComponentEvents { /** Requests a new width and height for this AWTGLAutoDrawable. */ diff --git a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java index 0a75865e2..604dea057 100644 --- a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java +++ b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java @@ -1,22 +1,22 @@ /* * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Copyright (c) 2010 JogAmp Community. All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: - * + * * - Redistribution of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. - * + * * - Redistribution in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * + * * Neither the name of Sun Microsystems, Inc. or the names of * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. - * + * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A @@ -29,11 +29,11 @@ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * + * * You acknowledge that this software is not designed or intended for use * in the design, construction, operation or maintenance of any nuclear * facility. - * + * * Sun gratefully acknowledges that this software was originally authored * and developed by Kenneth Bradley Russell and Christopher John Kline. */ @@ -139,22 +139,23 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing private static final boolean DEBUG = Debug.debug("GLCanvas"); - private GLDrawableHelper drawableHelper = new GLDrawableHelper(); + private final GLDrawableHelper drawableHelper = new GLDrawableHelper(); private AWTGraphicsConfiguration awtConfig; private volatile GLDrawable drawable; private GLContextImpl context; private boolean sendReshape = false; - + // copy of the cstr args, mainly for recreation private GLCapabilitiesImmutable capsReqUser; private GLCapabilitiesChooser chooser; private GLContext shareWith; - private int additionalCtxCreationFlags = 0; + private int additionalCtxCreationFlags = 0; private GraphicsDevice device; private boolean shallUseOffscreenLayer = false; private AWTWindowClosingProtocol awtWindowClosingProtocol = new AWTWindowClosingProtocol(this, new Runnable() { + @Override public void run() { GLCanvas.this.destroy(); } @@ -162,7 +163,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing /** Creates a new GLCanvas component with a default set of OpenGL capabilities, using the default OpenGL capabilities selection - mechanism, on the default screen device. + mechanism, on the default screen device. * @throws GLException if no default profile is available for the default desktop device. */ public GLCanvas() throws GLException { @@ -171,7 +172,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing /** Creates a new GLCanvas component with the requested set of OpenGL capabilities, using the default OpenGL capabilities - selection mechanism, on the default screen device. + selection mechanism, on the default screen device. * @throws GLException if no GLCapabilities are given and no default profile is available for the default desktop device. * @see GLCanvas#GLCanvas(javax.media.opengl.GLCapabilitiesImmutable, javax.media.opengl.GLCapabilitiesChooser, javax.media.opengl.GLContext, java.awt.GraphicsDevice) */ @@ -187,8 +188,8 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing * @throws GLException if no GLCapabilities are given and no default profile is available for the default desktop device. * @see GLCanvas#GLCanvas(javax.media.opengl.GLCapabilitiesImmutable, javax.media.opengl.GLCapabilitiesChooser, javax.media.opengl.GLContext, java.awt.GraphicsDevice) */ - public GLCanvas(GLCapabilitiesImmutable capsReqUser, GLContext shareWith) - throws GLException + public GLCanvas(GLCapabilitiesImmutable capsReqUser, GLContext shareWith) + throws GLException { this(capsReqUser, null, shareWith, null); } @@ -207,14 +208,14 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing sharing</a>. The passed GraphicsDevice indicates the screen on which to create the GLCanvas; the GLDrawableFactory uses the default screen device of the local GraphicsEnvironment if null - is passed for this argument. + is passed for this argument. * @throws GLException if no GLCapabilities are given and no default profile is available for the default desktop device. */ public GLCanvas(GLCapabilitiesImmutable capsReqUser, GLCapabilitiesChooser chooser, GLContext shareWith, - GraphicsDevice device) - throws GLException + GraphicsDevice device) + throws GLException { /* * Determination of the native window is made in 'super.addNotify()', @@ -246,14 +247,17 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing this.device = device; } + @Override public void setShallUseOffscreenLayer(boolean v) { shallUseOffscreenLayer = v; } + @Override public final boolean getShallUseOffscreenLayer() { - return shallUseOffscreenLayer; + return shallUseOffscreenLayer; } + @Override public final boolean isOffscreenLayerSurfaceEnabled() { if(null != drawable) { return ((JAWTWindow)drawable.getNativeSurface()).isOffscreenLayerSurfaceEnabled(); @@ -261,18 +265,18 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing return false; } - + /** * Overridden to choose a GraphicsConfiguration on a parent container's * GraphicsDevice because both devices */ - @Override + @Override public GraphicsConfiguration getGraphicsConfiguration() { /* * Workaround for problems with Xinerama and java.awt.Component.checkGD * when adding to a container on a different graphics device than the * one that this Canvas is associated with. - * + * * GC will be null unless: * - A native peer has assigned it. This means we have a native * peer, and are already comitted to a graphics configuration. @@ -286,7 +290,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing * chosen is only non-null on platforms where the GLDrawableFactory * returns a non-null GraphicsConfiguration (in the GLCanvas * constructor). - * + * * if gc is from this Canvas' native peer then it should equal chosen, * otherwise it is from an ancestor component that this Canvas is being * added to, and we go into this block. @@ -298,21 +302,21 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing * Check for compatibility with gc. If they differ by only the * device then return a new GCconfig with the super-class' GDevice * (and presumably the same visual ID in Xinerama). - * + * */ if (!chosen.getDevice().getIDstring().equals(gc.getDevice().getIDstring())) { /* * Here we select a GraphicsConfiguration on the alternate * device that is presumably identical to the chosen * configuration, but on the other device. - * + * * Should really check to ensure that we select a configuration * with the same X visual ID for Xinerama screens, otherwise the * GLDrawable may have the wrong visual ID (I don't think this * ever gets updated). May need to add a method to * X11GLDrawableFactory to do this in a platform specific * manner. - * + * * However, on platforms where we can actually get into this * block, both devices should have the same visual list, and the * same configuration should be selected here. @@ -353,7 +357,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing * return the GC that was selected in the constructor (and might * cause an exception in Component.checkGD when adding to a * container, but in this case that would be the desired behavior). - * + * */ return chosen; } else if (gc == null) { @@ -372,14 +376,17 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing */ return gc; } - + + @Override public GLContext createContext(GLContext shareWith) { return (null != drawable) ? drawable.createContext(shareWith) : null; } + @Override public void setRealized(boolean realized) { } + @Override public boolean isRealized() { return ( null != drawable ) ? drawable.isRealized() : false; } @@ -387,14 +394,17 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing return ( null != drawable ) ? drawable.isRealized() : false; } + @Override public WindowClosingMode getDefaultCloseOperation() { return awtWindowClosingProtocol.getDefaultCloseOperation(); } + @Override public WindowClosingMode setDefaultCloseOperation(WindowClosingMode op) { return awtWindowClosingProtocol.setDefaultCloseOperation(op); } + @Override public void display() { if( !validateGLDrawable() ) { if(DEBUG) { @@ -402,7 +412,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing } return; // not yet available .. } - Threading.invoke(true, displayOnEventDispatchThreadAction, getTreeLock()); + Threading.invoke(true, displayOnEDTAction, getTreeLock()); awtWindowClosingProtocol.addClosingListenerOneShot(); } @@ -425,14 +435,14 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing disposeRegenerate=regenerate; if(context.isCreated()) { - Threading.invoke(true, disposeOnEventDispatchThreadAction, getTreeLock()); + Threading.invoke(true, disposeOnEDTAction, getTreeLock()); } if(animatorPaused) { animator.resume(); } } - + if(!regenerate) { disposeAbstractGraphicsDevice(); } @@ -443,8 +453,14 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing } /** - * Just an alias for removeNotify + * {@inheritDoc} + * + * <p> + * This impl. calls this class's {@link #removeNotify()} AWT override, + * where the actual implementation resides. + * </p> */ + @Override public void destroy() { removeNotify(); } @@ -546,7 +562,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing jawtWindow.unlockSurface(); } } - + private boolean validateGLDrawable() { boolean realized = false; if (!Beans.isDesignTime()) { @@ -554,7 +570,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing realized = drawable.isRealized(); if ( !realized && 0 < drawable.getWidth() * drawable.getHeight() ) { // make sure drawable realization happens on AWT EDT, due to AWTTree lock - AWTEDTExecutor.singleton.invoke(true, setRealizedOnEventDispatchThreadAction); + AWTEDTExecutor.singleton.invoke(true, setRealizedOnEDTAction); realized = true; sendReshape=true; // ensure a reshape is being send .. if(DEBUG) { @@ -566,8 +582,9 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing } return realized; } - private Runnable setRealizedOnEventDispatchThreadAction = new Runnable() { - public void run() { + private Runnable setRealizedOnEDTAction = new Runnable() { + @Override + public void run() { drawable.setRealized(true); } }; @@ -626,7 +643,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing /** <B>Overrides:</B> <DL><DD><CODE>update</CODE> in class <CODE>java.awt.Component</CODE></DD></DL> */ - /** + /** * Overridden from Canvas to prevent the AWT's clearing of the * canvas from interfering with the OpenGL rendering. */ @@ -634,31 +651,38 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing public void update(Graphics g) { paint(g); } - + + @Override public void addGLEventListener(GLEventListener listener) { drawableHelper.addGLEventListener(listener); } + @Override public void addGLEventListener(int index, GLEventListener listener) { drawableHelper.addGLEventListener(index, listener); } + @Override public void removeGLEventListener(GLEventListener listener) { drawableHelper.removeGLEventListener(listener); } + @Override public void setAnimator(GLAnimatorControl animatorControl) { drawableHelper.setAnimator(animatorControl); } + @Override public GLAnimatorControl getAnimator() { return drawableHelper.getAnimator(); } + @Override public void invoke(boolean wait, GLRunnable glRunnable) { drawableHelper.invoke(this, wait, glRunnable); } + @Override public void setContext(GLContext ctx) { context=(GLContextImpl)ctx; if(null != context) { @@ -666,10 +690,12 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing } } + @Override public GLContext getContext() { return context; } + @Override public GL getGL() { if (Beans.isDesignTime()) { return null; @@ -678,6 +704,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing return (ctx == null) ? null : ctx.getGL(); } + @Override public GL setGL(GL gl) { GLContext ctx = getContext(); if (ctx != null) { @@ -688,30 +715,37 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing } + @Override public void setAutoSwapBufferMode(boolean onOrOff) { drawableHelper.setAutoSwapBufferMode(onOrOff); } + @Override public boolean getAutoSwapBufferMode() { return drawableHelper.getAutoSwapBufferMode(); } + @Override public void swapBuffers() { - Threading.invoke(true, swapBuffersOnEventDispatchThreadAction, getTreeLock()); + Threading.invoke(true, swapBuffersOnEDTAction, getTreeLock()); } + @Override public void setContextCreationFlags(int flags) { additionalCtxCreationFlags = flags; } - + + @Override public int getContextCreationFlags() { - return additionalCtxCreationFlags; + return additionalCtxCreationFlags; } - + + @Override public GLProfile getGLProfile() { return capsReqUser.getGLProfile(); } + @Override public GLCapabilitiesImmutable getChosenGLCapabilities() { if (awtConfig == null) { throw new GLException("No AWTGraphicsConfiguration: "+this); @@ -728,14 +762,17 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing return (GLCapabilitiesImmutable)awtConfig.getRequestedCapabilities(); } + @Override public NativeSurface getNativeSurface() { return (null != drawable) ? drawable.getNativeSurface() : null; } + @Override public long getHandle() { return (null != drawable) ? drawable.getHandle() : 0; } + @Override public GLDrawableFactory getFactory() { return (null != drawable) ? drawable.getFactory() : null; } @@ -744,9 +781,9 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing public String toString() { final int dw = (null!=drawable) ? drawable.getWidth() : -1; final int dh = (null!=drawable) ? drawable.getHeight() : -1; - + return "AWT-GLCanvas[Realized "+isRealized()+ - ",\n\t"+((null!=drawable)?drawable.getClass().getName():"null-drawable")+ + ",\n\t"+((null!=drawable)?drawable.getClass().getName():"null-drawable")+ ",\n\tFactory "+getFactory()+ ",\n\thandle 0x"+Long.toHexString(getHandle())+ ",\n\tDrawable size "+dw+"x"+dh+ @@ -754,13 +791,14 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing ",\n\tvisible "+isVisible()+ ",\n\t"+awtConfig+"]"; } - + //---------------------------------------------------------------------- // Internals only below this point // private boolean disposeRegenerate; private final Runnable postDisposeAction = new Runnable() { + @Override public void run() { context=null; if(null!=drawable) { @@ -769,39 +807,41 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing drawable=null; if(null!=jawtWindow) { jawtWindow.destroy(); - } + } } - + if(disposeRegenerate) { // Similar process as in addNotify()! - + // Recreate GLDrawable/GLContext to reflect it's new graphics configuration createDrawableAndContext(); - + if(DEBUG) { System.err.println(getThreadName()+": GLCanvas.dispose(true): new drawable: "+drawable); } validateGLDrawable(); // immediate attempt to recreate the drawable } } - }; + }; - private final Runnable disposeOnEventDispatchThreadAction = new Runnable() { + private final Runnable disposeOnEDTAction = new Runnable() { + @Override public void run() { - drawableHelper.disposeGL(GLCanvas.this, drawable, context, postDisposeAction); + drawableHelper.disposeGL(GLCanvas.this, drawable, context, postDisposeAction); } }; private final Runnable disposeAbstractGraphicsDeviceAction = new Runnable() { + @Override public void run() { if(null != awtConfig) { - final AbstractGraphicsConfiguration aconfig = awtConfig.getNativeGraphicsConfiguration(); + final AbstractGraphicsConfiguration aconfig = awtConfig.getNativeGraphicsConfiguration(); final AbstractGraphicsDevice adevice = aconfig.getScreen().getDevice(); final String adeviceMsg; if(DEBUG) { adeviceMsg = adevice.toString(); } else { - adeviceMsg = null; + adeviceMsg = null; } boolean closed = adevice.close(); if(DEBUG) { @@ -833,12 +873,14 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing } private final Runnable initAction = new Runnable() { + @Override public void run() { drawableHelper.init(GLCanvas.this); } }; - + private final Runnable displayAction = new Runnable() { + @Override public void run() { if (sendReshape) { if(DEBUG) { @@ -855,6 +897,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing }; private final Runnable swapBuffersAction = new Runnable() { + @Override public void run() { drawable.swapBuffers(); } @@ -863,16 +906,18 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing // Workaround for ATI driver bugs related to multithreading issues // like simultaneous rendering via Animators to canvases that are // being resized on the AWT event dispatch thread - private final Runnable displayOnEventDispatchThreadAction = new Runnable() { + private final Runnable displayOnEDTAction = new Runnable() { + @Override public void run() { drawableHelper.invokeGL(drawable, context, displayAction, initAction); } }; - - private final Runnable swapBuffersOnEventDispatchThreadAction = new Runnable() { + + private final Runnable swapBuffersOnEDTAction = new Runnable() { + @Override public void run() { drawableHelper.invokeGL(drawable, context, swapBuffersAction, initAction); - } + } }; // Disables the AWT's erasing of this Canvas's background on Windows @@ -886,6 +931,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing if (!disableBackgroundEraseInitialized) { try { AccessController.doPrivileged(new PrivilegedAction<Object>() { + @Override public Object run() { try { Class<?> clazz = getToolkit().getClass(); @@ -946,7 +992,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing return null; } - final AbstractGraphicsScreen aScreen = null != device ? + final AbstractGraphicsScreen aScreen = null != device ? AWTGraphicsScreen.createScreenDevice(device, AbstractGraphicsDevice.DEFAULT_UNIT): AWTGraphicsScreen.createDefault(); AWTGraphicsConfiguration config = null; @@ -960,6 +1006,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing try { final ArrayList<AWTGraphicsConfiguration> bucket = new ArrayList<AWTGraphicsConfiguration>(1); EventQueue.invokeAndWait(new Runnable() { + @Override public void run() { AWTGraphicsConfiguration c = (AWTGraphicsConfiguration) GraphicsConfigurationFactory.getFactory(AWTGraphicsDevice.class).chooseGraphicsConfiguration(capsChosen, @@ -982,11 +1029,11 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing return config; } - + protected static String getThreadName() { return Thread.currentThread().getName(); } - + /** * A most simple JOGL AWT test entry */ @@ -1006,17 +1053,22 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing frame.setSize(128, 128); glCanvas.addGLEventListener(new GLEventListener() { + @Override public void init(GLAutoDrawable drawable) { GL gl = drawable.getGL(); System.err.println(JoglVersion.getGLInfo(gl, null)); } + @Override public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { } + @Override public void display(GLAutoDrawable drawable) { } + @Override public void dispose(GLAutoDrawable drawable) { } }); try { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + @Override public void run() { frame.setVisible(true); }}); @@ -1026,6 +1078,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing glCanvas.display(); try { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + @Override public void run() { frame.dispose(); }}); diff --git a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java index 167b99374..152326006 100644 --- a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java +++ b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java @@ -1,22 +1,22 @@ /* * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Copyright (c) 2010 JogAmp Community. All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: - * + * * - Redistribution of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. - * + * * - Redistribution in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * + * * Neither the name of Sun Microsystems, Inc. or the names of * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. - * + * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A @@ -29,21 +29,17 @@ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * + * * You acknowledge that this software is not designed or intended for use * in the design, construction, operation or maintenance of any nuclear * facility. - * + * * Sun gratefully acknowledges that this software was originally authored * and developed by Kenneth Bradley Russell and Christopher John Kline. */ package javax.media.opengl.awt; -import java.nio.ByteBuffer; -import java.nio.IntBuffer; -import java.beans.Beans; - import java.awt.Color; import java.awt.EventQueue; import java.awt.FontMetrics; @@ -55,13 +51,13 @@ import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.awt.image.DataBufferByte; import java.awt.image.DataBufferInt; -import javax.swing.JPanel; +import java.beans.Beans; +import java.nio.ByteBuffer; +import java.nio.IntBuffer; -import javax.media.nativewindow.WindowClosingProtocol; import javax.media.nativewindow.AbstractGraphicsDevice; import javax.media.nativewindow.NativeSurface; -import javax.media.nativewindow.WindowClosingProtocol.WindowClosingMode; - +import javax.media.nativewindow.WindowClosingProtocol; import javax.media.opengl.DefaultGLCapabilitiesChooser; import javax.media.opengl.GL; import javax.media.opengl.GL2; @@ -80,10 +76,7 @@ import javax.media.opengl.GLPbuffer; import javax.media.opengl.GLProfile; import javax.media.opengl.GLRunnable; import javax.media.opengl.Threading; - -import com.jogamp.nativewindow.awt.AWTWindowClosingProtocol; -import com.jogamp.opengl.util.FBObject; -import com.jogamp.opengl.util.GLBuffers; +import javax.swing.JPanel; import jogamp.opengl.Debug; import jogamp.opengl.GLContextImpl; @@ -93,6 +86,10 @@ import jogamp.opengl.GLDrawableImpl; import jogamp.opengl.awt.Java2D; import jogamp.opengl.awt.Java2DGLContext; +import com.jogamp.nativewindow.awt.AWTWindowClosingProtocol; +import com.jogamp.opengl.util.FBObject; +import com.jogamp.opengl.util.GLBuffers; + // FIXME: Subclasses need to call resetGLFunctionAvailability() on their // context whenever the displayChanged() function is called on their // GLEventListeners @@ -107,9 +104,9 @@ import jogamp.opengl.awt.Java2DGLContext; #setOpaque}(false). Pixels with resulting OpenGL alpha values less than 1.0 will be overlaid on any underlying Swing rendering. </P> <P> - Notes specific to the Reference Implementation: This component - attempts to use hardware-accelerated rendering via pbuffers and - falls back on to software rendering if problems occur. + Notes specific to the Reference Implementation: This component + attempts to use hardware-accelerated rendering via pbuffers and + falls back on to software rendering if problems occur. Note that because this component attempts to use pbuffers for rendering, and because pbuffers can not be resized, somewhat surprising behavior may occur during resize operations; the {@link @@ -138,7 +135,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing private GLCapabilitiesChooser chooser; private GLContext shareWith; private int additionalCtxCreationFlags = 0; - + // Width of the actual GLJPanel private int panelWidth = 0; private int panelHeight = 0; @@ -180,6 +177,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing private AWTWindowClosingProtocol awtWindowClosingProtocol = new AWTWindowClosingProtocol(this, new Runnable() { + @Override public void run() { GLJPanel.this.destroy(); } @@ -198,7 +196,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing /** Creates a new GLJPanel component with a default set of OpenGL capabilities and using the default OpenGL capabilities selection - mechanism. + mechanism. * @throws GLException if no default profile is available for the default desktop device. */ public GLJPanel() throws GLException { @@ -207,7 +205,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing /** Creates a new GLJPanel component with the requested set of OpenGL capabilities, using the default OpenGL capabilities - selection mechanism. + selection mechanism. * @throws GLException if no GLCapabilities are given and no default profile is available for the default desktop device. */ public GLJPanel(GLCapabilitiesImmutable userCapsRequest) throws GLException { @@ -229,8 +227,8 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing since J2D GL Context must be shared and we can only share one context. * @throws GLException if no GLCapabilities are given and no default profile is available for the default desktop device. */ - public GLJPanel(GLCapabilitiesImmutable userCapsRequest, GLCapabilitiesChooser chooser, GLContext shareWith) - throws GLException + public GLJPanel(GLCapabilitiesImmutable userCapsRequest, GLCapabilitiesChooser chooser, GLContext shareWith) + throws GLException { super(); @@ -252,6 +250,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing this.shareWith = shareWith; } + @Override public void display() { if (EventQueue.isDispatchThread()) { // Want display() to be synchronous, so call paintImmediately() @@ -280,7 +279,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing animatorPaused = animator.pause(); } - if(backend.getContext().isCreated()) { + if(backend.getContext().isCreated()) { Threading.invoke(true, disposeAction, getTreeLock()); } if(null != backend) { @@ -291,9 +290,9 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing if(animatorPaused) { animator.resume(); - } + } } - + if(DEBUG) { System.err.println(getThreadName()+": GLJPanel.dispose() - stop"); } @@ -302,6 +301,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing /** * Just an alias for removeNotify */ + @Override public void destroy() { removeNotify(); } @@ -352,11 +352,11 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing } updater.setGraphics(g); - + backend.doPaintComponent(g); } - + /** Overridden to track when this component is added to a container. Subclasses which override this method must call super.addNotify() in their addNotify() method in order to @@ -393,7 +393,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing <DL><DD><CODE>reshape</CODE> in class <CODE>java.awt.Component</CODE></DD></DL> */ @SuppressWarnings("deprecation") @Override -public void reshape(int x, int y, int width, int height) { + public void reshape(int x, int y, int width, int height) { super.reshape(x, y, width, height); // reshapeX = x; @@ -411,41 +411,51 @@ public void reshape(int x, int y, int width, int height) { super.setOpaque(opaque); } + @Override public void addGLEventListener(GLEventListener listener) { drawableHelper.addGLEventListener(listener); } + @Override public void addGLEventListener(int index, GLEventListener listener) { drawableHelper.addGLEventListener(index, listener); } + @Override public void removeGLEventListener(GLEventListener listener) { drawableHelper.removeGLEventListener(listener); } + @Override public void setAnimator(GLAnimatorControl animatorControl) { drawableHelper.setAnimator(animatorControl); } + @Override public GLAnimatorControl getAnimator() { return drawableHelper.getAnimator(); } + @Override public void invoke(boolean wait, GLRunnable glRunnable) { drawableHelper.invoke(this, wait, glRunnable); } + @Override public GLContext createContext(GLContext shareWith) { return (null != backend) ? backend.createContext(shareWith) : null; } + @Override public void setRealized(boolean realized) { } + @Override public boolean isRealized() { return isInitialized; } + @Override public void setContext(GLContext ctx) { if (backend == null) { return; @@ -456,6 +466,7 @@ public void reshape(int x, int y, int width, int height) { backend.setContext(ctx); } + @Override public GLContext getContext() { if (backend == null) { return null; @@ -463,6 +474,7 @@ public void reshape(int x, int y, int width, int height) { return backend.getContext(); } + @Override public GL getGL() { if (Beans.isDesignTime()) { return null; @@ -471,6 +483,7 @@ public void reshape(int x, int y, int width, int height) { return (context == null) ? null : context.getGL(); } + @Override public GL setGL(GL gl) { GLContext context = getContext(); if (context != null) { @@ -480,6 +493,7 @@ public void reshape(int x, int y, int width, int height) { return null; } + @Override public void setAutoSwapBufferMode(boolean onOrOff) { // In the current implementation this is a no-op. Both the pbuffer // and pixmap based rendering paths use a single-buffered surface @@ -488,6 +502,7 @@ public void reshape(int x, int y, int width, int height) { // Swing portion of the GLJPanel in any of the rendering paths. } + @Override public boolean getAutoSwapBufferMode() { // In the current implementation this is a no-op. Both the pbuffer // and pixmap based rendering paths use a single-buffered surface @@ -496,7 +511,8 @@ public void reshape(int x, int y, int width, int height) { // Swing portion of the GLJPanel in any of the rendering paths. return true; } - + + @Override public void swapBuffers() { // In the current implementation this is a no-op. Both the pbuffer // and pixmap based rendering paths use a single-buffered surface @@ -505,14 +521,16 @@ public void reshape(int x, int y, int width, int height) { // Swing portion of the GLJPanel in any of the rendering paths. } + @Override public void setContextCreationFlags(int flags) { additionalCtxCreationFlags = flags; } - + + @Override public int getContextCreationFlags() { - return additionalCtxCreationFlags; + return additionalCtxCreationFlags; } - + /** For a translucent GLJPanel (one for which {@link #setOpaque setOpaque}(false) has been called), indicates whether the application should preserve the OpenGL color buffer @@ -529,22 +547,27 @@ public void reshape(int x, int y, int width, int height) { return oglPipelineEnabled; } + @Override public GLCapabilitiesImmutable getChosenGLCapabilities() { return backend.getChosenGLCapabilities(); } + @Override public final GLProfile getGLProfile() { return glProfile; } + @Override public NativeSurface getNativeSurface() { throw new GLException("FIXME"); } + @Override public long getHandle() { throw new GLException("FIXME"); } + @Override public final GLDrawableFactory getFactory() { return factory; } @@ -597,10 +620,12 @@ public void reshape(int x, int y, int width, int height) { awtWindowClosingProtocol.addClosingListenerOneShot(); } + @Override public WindowClosingMode getDefaultCloseOperation() { return awtWindowClosingProtocol.getDefaultCloseOperation(); } + @Override public WindowClosingMode setDefaultCloseOperation(WindowClosingMode op) { return awtWindowClosingProtocol.setDefaultCloseOperation(op); } @@ -618,7 +643,7 @@ public void reshape(int x, int y, int width, int height) { backend.handleReshape(); handleReshape = false; } - + // This is used as the GLEventListener for the pbuffer-based backend // as well as the callback mechanism for the other backends class Updater implements GLEventListener { @@ -628,6 +653,7 @@ public void reshape(int x, int y, int width, int height) { this.g = g; } + @Override public void init(GLAutoDrawable drawable) { if (!backend.preGL(g)) { return; @@ -636,10 +662,12 @@ public void reshape(int x, int y, int width, int height) { backend.postGL(g, false); } + @Override public void dispose(GLAutoDrawable drawable) { drawableHelper.dispose(GLJPanel.this); } + @Override public void display(GLAutoDrawable drawable) { if (!backend.preGL(g)) { return; @@ -656,6 +684,7 @@ public void reshape(int x, int y, int width, int height) { backend.postGL(g, true); } + @Override public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { // This is handled above and dispatched directly to the appropriate context } @@ -664,43 +693,49 @@ public void reshape(int x, int y, int width, int height) { } } + @Override public String toString() { return "AWT-GLJPanel[ "+((null!=backend)?backend.getDrawable().getClass().getName():"null-drawable")+"]"; } private final Runnable postDisposeAction = new Runnable() { + @Override public void run() { if (backend != null && !backend.isUsingOwnThreadManagment()) { backend.destroy(); backend = null; - isInitialized = false; + isInitialized = false; } } - }; + }; private final Runnable disposeAction = new Runnable() { + @Override public void run() { drawableHelper.disposeGL(GLJPanel.this, backend.getDrawable(), backend.getContext(), postDisposeAction); } - }; + }; private final Runnable updaterInitAction = new Runnable() { + @Override public void run() { updater.init(GLJPanel.this); } }; private final Runnable updaterDisplayAction = new Runnable() { + @Override public void run() { updater.display(GLJPanel.this); } }; private final Runnable paintImmediatelyAction = new Runnable() { + @Override public void run() { paintImmediately(0, 0, getWidth(), getHeight()); } - }; + }; private int getNextPowerOf2(int number) { // Workaround for problems where 0 width or height are transiently @@ -720,7 +755,7 @@ public void reshape(int x, int y, int width, int height) { protected static String getThreadName() { return Thread.currentThread().getName(); } - + //---------------------------------------------------------------------- // Implementations of the various backends // @@ -731,7 +766,7 @@ public void reshape(int x, int y, int width, int height) { static interface Backend { // Create, Destroy, .. public boolean isUsingOwnThreadManagment(); - + // Called each time the backend needs to initialize itself public void initialize(); @@ -801,6 +836,7 @@ public void reshape(int x, int y, int width, int height) { private int[] skippixels = new int[1]; private int[] alignment = new int[1]; + @Override public void setOpaque(boolean opaque) { if (opaque != isOpaque()) { if (offscreenImage != null) { @@ -810,11 +846,13 @@ public void reshape(int x, int y, int width, int height) { } } + @Override public boolean preGL(Graphics g) { // Empty in this implementation return true; } + @Override public void postGL(Graphics g, boolean isDisplay) { if (isDisplay) { // Must now copy pixels from offscreen context into surface @@ -938,6 +976,7 @@ public void reshape(int x, int y, int width, int height) { } } + @Override public void doPaintComponent(Graphics g) { doPaintComponentImpl(); if (offscreenImage != null) { @@ -959,8 +998,10 @@ public void reshape(int x, int y, int width, int height) { private GLDrawableImpl offscreenDrawable; private GLContextImpl offscreenContext; + @Override public boolean isUsingOwnThreadManagment() { return false; } - + + @Override public void initialize() { if(DEBUG) { System.err.println(getThreadName()+": SoftwareBackend: initialize()"); @@ -975,10 +1016,11 @@ public void reshape(int x, int y, int width, int height) { offscreenDrawable.setRealized(true); offscreenContext = (GLContextImpl) offscreenDrawable.createContext(shareWith); offscreenContext.setContextCreationFlags(additionalCtxCreationFlags); - + isInitialized = true; } + @Override public void destroy() { if(DEBUG) { System.err.println(getThreadName()+": SoftwareBackend: destroy() - offscreenContext: "+(null!=offscreenContext)+" - offscreenDrawable: "+(null!=offscreenDrawable)); @@ -997,22 +1039,27 @@ public void reshape(int x, int y, int width, int height) { } } + @Override public GLContext createContext(GLContext shareWith) { return (null != offscreenDrawable) ? offscreenDrawable.createContext(shareWith) : null; } + @Override public void setContext(GLContext ctx) { offscreenContext=(GLContextImpl)ctx; } + @Override public GLContext getContext() { return offscreenContext; } + @Override public GLDrawable getDrawable() { return offscreenDrawable; } + @Override public GLCapabilitiesImmutable getChosenGLCapabilities() { if (offscreenDrawable == null) { return null; @@ -1020,6 +1067,7 @@ public void reshape(int x, int y, int width, int height) { return offscreenDrawable.getChosenGLCapabilities(); } + @Override public GLProfile getGLProfile() { if (offscreenDrawable == null) { return null; @@ -1027,6 +1075,7 @@ public void reshape(int x, int y, int width, int height) { return offscreenDrawable.getGLProfile(); } + @Override public void handleReshape() { destroy(); initialize(); @@ -1039,14 +1088,17 @@ public void reshape(int x, int y, int width, int height) { } } + @Override protected void doPaintComponentImpl() { drawableHelper.invokeGL(offscreenDrawable, offscreenContext, updaterDisplayAction, updaterInitAction); } + @Override protected int getGLPixelType() { return offscreenContext.getOffscreenContextPixelDataType(); } + @Override protected boolean flipVertically() { return offscreenContext.offscreenImageNeedsVerticalFlip(); } @@ -1057,8 +1109,10 @@ public void reshape(int x, int y, int width, int height) { private int pbufferWidth = 256; private int pbufferHeight = 256; + @Override public boolean isUsingOwnThreadManagment() { return false; } - + + @Override public void initialize() { if (pbuffer != null) { throw new InternalError("Creating pbuffer twice without destroying it (memory leak / correctness bug)"); @@ -1073,7 +1127,7 @@ public void reshape(int x, int y, int width, int height) { pbufferWidth, pbufferHeight, shareWith); - pbuffer.setContextCreationFlags(additionalCtxCreationFlags); + pbuffer.setContextCreationFlags(additionalCtxCreationFlags); pbuffer.addGLEventListener(updater); isInitialized = true; } catch (GLException e) { @@ -1088,6 +1142,7 @@ public void reshape(int x, int y, int width, int height) { } } + @Override public void destroy() { if(DEBUG) { System.err.println(getThreadName()+": PbufferBackend: destroy() - pbuffer: "+(null!=pbuffer)); @@ -1098,10 +1153,12 @@ public void reshape(int x, int y, int width, int height) { } } + @Override public GLContext createContext(GLContext shareWith) { return (null != pbuffer) ? pbuffer.createContext(shareWith) : null; } + @Override public void setContext(GLContext ctx) { if (pbuffer == null && Beans.isDesignTime()) { return; @@ -1109,6 +1166,7 @@ public void reshape(int x, int y, int width, int height) { pbuffer.setContext(ctx); } + @Override public GLContext getContext() { // Workaround for crashes in NetBeans GUI builder if (pbuffer == null && Beans.isDesignTime()) { @@ -1117,24 +1175,28 @@ public void reshape(int x, int y, int width, int height) { return pbuffer.getContext(); } + @Override public GLDrawable getDrawable() { return pbuffer; } + @Override public GLCapabilitiesImmutable getChosenGLCapabilities() { if (pbuffer == null) { return null; } return pbuffer.getChosenGLCapabilities(); } - + + @Override public GLProfile getGLProfile() { if (pbuffer == null) { return null; } return pbuffer.getGLProfile(); } - + + @Override public void handleReshape() { // Use factor larger than 2 during shrinks for some hysteresis float shrinkFactor = 2.5f; @@ -1192,15 +1254,18 @@ public void reshape(int x, int y, int width, int height) { } } + @Override protected void doPaintComponentImpl() { pbuffer.display(); } + @Override protected int getGLPixelType() { // This seems to be a good choice on all platforms return GL2.GL_UNSIGNED_INT_8_8_8_8_REV; } + @Override protected boolean flipVertically() { return true; } @@ -1255,8 +1320,10 @@ public void reshape(int x, int y, int width, int height) { // comment related to Issue 274 below private GraphicsConfiguration workaroundConfig; + @Override public boolean isUsingOwnThreadManagment() { return true; } - + + @Override public void initialize() { if(DEBUG) { System.err.println(getThreadName()+": J2DOGL: initialize()"); @@ -1265,8 +1332,10 @@ public void reshape(int x, int y, int width, int height) { isInitialized = true; } + @Override public void destroy() { Java2D.invokeWithOGLContextCurrent(null, new Runnable() { + @Override public void run() { if(DEBUG) { System.err.println(getThreadName()+": J2DOGL: destroy() - joglContext: "+(null!=joglContext)+" - joglDrawable: "+(null!=joglDrawable)); @@ -1284,10 +1353,12 @@ public void reshape(int x, int y, int width, int height) { }); } + @Override public void setOpaque(boolean opaque) { // Empty in this implementation } + @Override public GLContext createContext(GLContext shareWith) { if(null != shareWith) { throw new GLException("J2DOGLBackend cannot create context w/ additional shared context, since it already needs to share the context w/ J2D."); @@ -1295,32 +1366,39 @@ public void reshape(int x, int y, int width, int height) { return (null != joglDrawable && null != j2dContext) ? joglDrawable.createContext(j2dContext) : null; } + @Override public void setContext(GLContext ctx) { joglContext=ctx; } + @Override public GLContext getContext() { return joglContext; } + @Override public GLDrawable getDrawable() { return joglDrawable; } + @Override public GLCapabilitiesImmutable getChosenGLCapabilities() { // FIXME: should do better than this; is it possible to using only platform-independent code? return new GLCapabilities(null); } + @Override public GLProfile getGLProfile() { // FIXME: should do better than this; is it possible to using only platform-independent code? return GLProfile.getDefault(GLProfile.getDefaultDevice()); } + @Override public void handleReshape() { // Empty in this implementation } + @Override public boolean preGL(Graphics g) { GL2 gl = joglContext.getGL().getGL2(); // Set up needed state in JOGL context from Java2D context @@ -1403,13 +1481,13 @@ public void reshape(int x, int y, int width, int height) { int[] height = new int[1]; gl.glGetTexLevelParameteriv(fboTextureTarget, 0, GL2.GL_TEXTURE_WIDTH, width, 0); gl.glGetTexLevelParameteriv(fboTextureTarget, 0, GL2.GL_TEXTURE_HEIGHT, height, 0); - + gl.glGenRenderbuffers(1, frameBufferDepthBuffer, 0); if (DEBUG) { System.err.println(getThreadName()+": GLJPanel: Generated frameBufferDepthBuffer " + frameBufferDepthBuffer[0] + " with width " + width[0] + ", height " + height[0]); } - + gl.glBindRenderbuffer(GL.GL_RENDERBUFFER, frameBufferDepthBuffer[0]); // FIXME: may need a loop here like in Java2D gl.glRenderbufferStorage(GL.GL_RENDERBUFFER, GL2GL3.GL_DEPTH_COMPONENT24, width[0], height[0]); @@ -1457,6 +1535,7 @@ public void reshape(int x, int y, int width, int height) { return true; } + @Override public void postGL(Graphics g, boolean isDisplay) { // Cause OpenGL pipeline to flush its results because // otherwise it's possible we will buffer up multiple frames' @@ -1473,6 +1552,7 @@ public void reshape(int x, int y, int width, int height) { } } + @Override public void doPaintComponent(final Graphics g) { // This is a workaround for an issue in the Java 2D / JOGL // bridge (reported by an end user as JOGL Issue 274) where Java @@ -1498,10 +1578,12 @@ public void reshape(int x, int y, int width, int height) { getDefaultScreenDevice(). getDefaultConfiguration(); } - Java2D.invokeWithOGLSharedContextCurrent(workaroundConfig, new Runnable() { public void run() {}}); + Java2D.invokeWithOGLSharedContextCurrent(workaroundConfig, new Runnable() { @Override + public void run() {}}); } Java2D.invokeWithOGLContextCurrent(g, new Runnable() { + @Override public void run() { if (DEBUG) { System.err.println(getThreadName()+": GLJPanel.invokeWithOGLContextCurrent"); |