diff options
Diffstat (limited to 'src/jogl')
7 files changed, 137 insertions, 89 deletions
diff --git a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXContext.java b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXContext.java index 42b0f2a5f..84f32d43e 100644 --- a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXContext.java +++ b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXContext.java @@ -296,7 +296,38 @@ public abstract class X11GLXContext extends GLContextImpl { GLContextShareSet.contextCreated(this); } + // Note: Usually the surface shall be locked within [makeCurrent .. swap .. release] protected int makeCurrentImpl() throws GLException { + int lockRes = drawable.lockSurface(); + boolean exceptionOccurred = false; + try { + if (lockRes == NativeWindow.LOCK_SURFACE_NOT_READY) { + return CONTEXT_NOT_CURRENT; + } + return makeCurrentImplAfterLock(); + } catch (RuntimeException e) { + exceptionOccurred = true; + throw e; + } finally { + if (exceptionOccurred || + (isOptimizable() && lockRes != NativeWindow.LOCK_SURFACE_NOT_READY) && drawable.isSurfaceLocked()) { + drawable.unlockSurface(); + } + } + } + + // Note: Usually the surface shall be locked within [makeCurrent .. swap .. release] + protected void releaseImpl() throws GLException { + try { + releaseImplAfterLock(); + } finally { + if (!isOptimizable() && drawable.isSurfaceLocked()) { + drawable.unlockSurface(); + } + } + } + + protected int makeCurrentImplAfterLock() throws GLException { getDrawableImpl().getFactoryImpl().lockToolkit(); try { if (drawable.getNativeWindow().getSurfaceHandle() == 0) { @@ -341,7 +372,7 @@ public abstract class X11GLXContext extends GLContextImpl { } } - protected void releaseImpl() throws GLException { + protected void releaseImplAfterLock() throws GLException { getDrawableImpl().getFactoryImpl().lockToolkit(); try { if (!GLX.glXMakeContextCurrent(drawable.getNativeWindow().getDisplayHandle(), 0, 0, 0)) { diff --git a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OnscreenGLXContext.java b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OnscreenGLXContext.java index c37ddd49c..a73b41146 100644 --- a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OnscreenGLXContext.java +++ b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OnscreenGLXContext.java @@ -57,37 +57,6 @@ public class X11OnscreenGLXContext extends X11GLXContext { super(drawable, shareWith); } - // Note: Usually the surface shall be locked within [makeCurrent .. swap .. release] - protected int makeCurrentImpl() throws GLException { - int lockRes = drawable.lockSurface(); - boolean exceptionOccurred = false; - try { - if (lockRes == NativeWindow.LOCK_SURFACE_NOT_READY) { - return CONTEXT_NOT_CURRENT; - } - return super.makeCurrentImpl(); - } catch (RuntimeException e) { - exceptionOccurred = true; - throw e; - } finally { - if (exceptionOccurred || - (isOptimizable() && lockRes != NativeWindow.LOCK_SURFACE_NOT_READY) && drawable.isSurfaceLocked()) { - drawable.unlockSurface(); - } - } - } - - // Note: Usually the surface shall be locked within [makeCurrent .. swap .. release] - protected void releaseImpl() throws GLException { - try { - super.releaseImpl(); - } finally { - if (!isOptimizable() && drawable.isSurfaceLocked()) { - drawable.unlockSurface(); - } - } - } - public boolean isOptimizable() { return super.isOptimizable() && !isIndirect; } diff --git a/src/jogl/classes/com/sun/opengl/util/Animator.java b/src/jogl/classes/com/sun/opengl/util/Animator.java index a10717881..1d4b832e8 100755 --- a/src/jogl/classes/com/sun/opengl/util/Animator.java +++ b/src/jogl/classes/com/sun/opengl/util/Animator.java @@ -43,6 +43,8 @@ import java.util.*; import javax.media.opengl.*; +import com.sun.opengl.impl.Debug; + /** <P> An Animator can be attached to one or more {@link GLAutoDrawable}s to drive their display() methods in a loop. </P> @@ -53,7 +55,7 @@ import javax.media.opengl.*; */ public class Animator { - protected static final boolean DEBUG = com.sun.opengl.impl.Debug.debug("Animator"); + protected static final boolean DEBUG = Debug.debug("Animator"); private volatile ArrayList/*<GLAutoDrawable>*/ drawables = new ArrayList(); private AnimatorImpl impl; @@ -67,10 +69,13 @@ public class Animator { /** Creates a new, empty Animator. */ public Animator(ThreadGroup tg) { - try { - // Try to use the AWT-capable Animator implementation by default - impl = (AnimatorImpl) Class.forName("com.sun.opengl.util.awt.AWTAnimatorImpl").newInstance(); - } catch (Exception e) { + + if(GLProfile.isAWTJOGLAvailable()) { + try { + impl = (AnimatorImpl) Class.forName("com.sun.opengl.util.awt.AWTAnimatorImpl").newInstance(); + } catch (Exception e) { } + } + if(null==impl) { impl = new AnimatorImpl(); } threadGroup = tg; diff --git a/src/jogl/classes/com/sun/opengl/util/texture/TextureIO.java.javame_cdc_fp b/src/jogl/classes/com/sun/opengl/util/texture/TextureIO.java.javame_cdc_fp index 1f6b89c7e..e7c80678f 100755 --- a/src/jogl/classes/com/sun/opengl/util/texture/TextureIO.java.javame_cdc_fp +++ b/src/jogl/classes/com/sun/opengl/util/texture/TextureIO.java.javame_cdc_fp @@ -640,6 +640,10 @@ public class TextureIO { } } + write(data, file); + } + + public static void write(TextureData data, File file) throws IOException, GLException { for (Iterator iter = textureWriters.iterator(); iter.hasNext(); ) { TextureWriter writer = (TextureWriter) iter.next(); if (writer.write(file, data)) { @@ -647,9 +651,9 @@ public class TextureIO { } } - throw new IOException("No suitable texture writer found"); + throw new IOException("No suitable texture writer found for "+file.getAbsolutePath()); } - + //---------------------------------------------------------------------- // SPI support // @@ -710,15 +714,17 @@ public class TextureIO { static { /* - // ImageIO provider, the fall-back, must be the first one added - try { - // Use reflection to avoid compile-time dependencies on AWT-related classes - TextureProvider provider = (TextureProvider) - Class.forName("com.sun.opengl.util.texture.spi.awt.IIOTextureProvider").newInstance(); - addTextureProvider(provider); - } catch (Exception e) { - if (DEBUG) { - e.printStackTrace(); + if(GLProfile.isAWTJOGLAvailable()) { + // ImageIO provider, the fall-back, must be the first one added + try { + // Use reflection to avoid compile-time dependencies on AWT-related classes + TextureProvider provider = (TextureProvider) + Class.forName("com.sun.opengl.util.texture.spi.awt.IIOTextureProvider").newInstance(); + addTextureProvider(provider); + } catch (Exception e) { + if (DEBUG) { + e.printStackTrace(); + } } } */ @@ -730,14 +736,16 @@ public class TextureIO { /* // ImageIO writer, the fall-back, must be the first one added - try { - // Use reflection to avoid compile-time dependencies on AWT-related classes - TextureWriter writer = (TextureWriter) - Class.forName("com.sun.opengl.util.texture.spi.awt.IIOTextureWriter").newInstance(); - addTextureWriter(writer); - } catch (Exception e) { - if (DEBUG) { - e.printStackTrace(); + if(GLProfile.isAWTJOGLAvailable()) { + try { + // Use reflection to avoid compile-time dependencies on AWT-related classes + TextureWriter writer = (TextureWriter) + Class.forName("com.sun.opengl.util.texture.spi.awt.IIOTextureWriter").newInstance(); + addTextureWriter(writer); + } catch (Exception e) { + if (DEBUG) { + e.printStackTrace(); + } } } */ @@ -746,6 +754,7 @@ public class TextureIO { addTextureWriter(new DDSTextureWriter()); addTextureWriter(new SGITextureWriter()); addTextureWriter(new TGATextureWriter()); + addTextureWriter(new NetPbmTextureWriter()); } // Implementation methods @@ -772,7 +781,7 @@ public class TextureIO { } } - throw new IOException("No suitable reader for given file"); + throw new IOException("No suitable reader for given file "+file.getAbsolutePath()); } private static TextureData newTextureDataImpl(InputStream stream, @@ -829,7 +838,7 @@ public class TextureIO { } } - throw new IOException("No suitable reader for given URL"); + throw new IOException("No suitable reader for given URL "+url); } //---------------------------------------------------------------------- diff --git a/src/jogl/classes/com/sun/opengl/util/texture/TextureIO.java.javase b/src/jogl/classes/com/sun/opengl/util/texture/TextureIO.java.javase index 2b2f123a0..556d51343 100755 --- a/src/jogl/classes/com/sun/opengl/util/texture/TextureIO.java.javase +++ b/src/jogl/classes/com/sun/opengl/util/texture/TextureIO.java.javase @@ -640,6 +640,10 @@ public class TextureIO { } } + write(data, file); + } + + public static void write(TextureData data, File file) throws IOException, GLException { for (Iterator iter = textureWriters.iterator(); iter.hasNext(); ) { TextureWriter writer = (TextureWriter) iter.next(); if (writer.write(file, data)) { @@ -647,7 +651,7 @@ public class TextureIO { } } - throw new IOException("No suitable texture writer found"); + throw new IOException("No suitable texture writer found for "+file.getAbsolutePath()); } //---------------------------------------------------------------------- @@ -710,14 +714,16 @@ public class TextureIO { static { // ImageIO provider, the fall-back, must be the first one added - try { - // Use reflection to avoid compile-time dependencies on AWT-related classes - TextureProvider provider = (TextureProvider) - Class.forName("com.sun.opengl.util.texture.spi.awt.IIOTextureProvider").newInstance(); - addTextureProvider(provider); - } catch (Exception e) { - if (DEBUG) { - e.printStackTrace(); + if(GLProfile.isAWTJOGLAvailable()) { + try { + // Use reflection to avoid compile-time dependencies on AWT-related classes + TextureProvider provider = (TextureProvider) + Class.forName("com.sun.opengl.util.texture.spi.awt.IIOTextureProvider").newInstance(); + addTextureProvider(provider); + } catch (Exception e) { + if (DEBUG) { + e.printStackTrace(); + } } } @@ -727,18 +733,20 @@ public class TextureIO { addTextureProvider(new TGATextureProvider()); // ImageIO writer, the fall-back, must be the first one added - try { - // Use reflection to avoid compile-time dependencies on AWT-related classes - TextureWriter writer = (TextureWriter) - Class.forName("com.sun.opengl.util.texture.spi.awt.IIOTextureWriter").newInstance(); - addTextureWriter(writer); - } catch (Exception e) { - if (DEBUG) { - e.printStackTrace(); - } - } catch (Error e) { - if (DEBUG) { - e.printStackTrace(); + if(GLProfile.isAWTJOGLAvailable()) { + try { + // Use reflection to avoid compile-time dependencies on AWT-related classes + TextureWriter writer = (TextureWriter) + Class.forName("com.sun.opengl.util.texture.spi.awt.IIOTextureWriter").newInstance(); + addTextureWriter(writer); + } catch (Exception e) { + if (DEBUG) { + e.printStackTrace(); + } + } catch (Error e) { + if (DEBUG) { + e.printStackTrace(); + } } } @@ -746,6 +754,7 @@ public class TextureIO { addTextureWriter(new DDSTextureWriter()); addTextureWriter(new SGITextureWriter()); addTextureWriter(new TGATextureWriter()); + addTextureWriter(new NetPbmTextureWriter()); } // Implementation methods @@ -772,7 +781,7 @@ public class TextureIO { } } - throw new IOException("No suitable reader for given file"); + throw new IOException("No suitable reader for given file "+file.getAbsolutePath()); } private static TextureData newTextureDataImpl(InputStream stream, @@ -829,7 +838,7 @@ public class TextureIO { } } - throw new IOException("No suitable reader for given URL"); + throw new IOException("No suitable reader for given URL "+url); } //---------------------------------------------------------------------- diff --git a/src/jogl/classes/com/sun/opengl/util/texture/spi/NetPbmTextureWriter.java b/src/jogl/classes/com/sun/opengl/util/texture/spi/NetPbmTextureWriter.java index f771e0a3d..18df1dc55 100644 --- a/src/jogl/classes/com/sun/opengl/util/texture/spi/NetPbmTextureWriter.java +++ b/src/jogl/classes/com/sun/opengl/util/texture/spi/NetPbmTextureWriter.java @@ -58,7 +58,7 @@ public class NetPbmTextureWriter implements TextureWriter { /** * supported magic values are:<br> * <pre> - * magic 0 - auto + * magic 0 - detect by file suffix (TextureIO compliant) * magic 6 - PPM binary RGB * magic 7 - PAM binary RGB or RGBA * </pre> @@ -77,13 +77,25 @@ public class NetPbmTextureWriter implements TextureWriter { public int getMagic() { return magic; } - public static String getPPMSuffix() { return "ppm"; } - public static String getPAMSuffix() { return "pam"; } + public static final String PPM = "ppm"; + public static final String PAM = "pam"; - public String getSuffix() { return (magic==6)?getPPMSuffix():getPAMSuffix(); } + public String getSuffix() { return (magic==6)?PPM:PAM; } public boolean write(File file, TextureData data) throws IOException { + + // file suffix selection + if (0==magic) { + if (PPM.equals(FileUtil.getFileSuffix(file))) { + magic = 6; + } else if (PAM.equals(FileUtil.getFileSuffix(file))) { + magic = 7; + } else { + return false; + } + } + int pixelFormat = data.getPixelFormat(); int pixelType = data.getPixelType(); if ((pixelFormat == GL.GL_RGB || @@ -93,10 +105,6 @@ public class NetPbmTextureWriter implements TextureWriter { int comps = ( pixelFormat == GL.GL_RGBA ) ? 4 : 3 ; - if(0==magic) { - magic = ( comps == 4 ) ? 7 : 6 ; - } - if(magic==6 && comps==4) { throw new IOException("NetPbmTextureWriter magic 6 (PPM) doesn't RGBA pixel format, use magic 7 (PAM)"); } diff --git a/src/jogl/classes/javax/media/opengl/GLProfile.java b/src/jogl/classes/javax/media/opengl/GLProfile.java index 756c80009..abb6ca4f3 100644 --- a/src/jogl/classes/javax/media/opengl/GLProfile.java +++ b/src/jogl/classes/javax/media/opengl/GLProfile.java @@ -605,6 +605,9 @@ public class GLProfile implements Cloneable { // This is here only to avoid having separate GL2ES1Impl and GL2ES2Impl classes private static final String GL2ES12 = "GL2ES12"; + private static final boolean isAWTAvailable; + private static final boolean isAWTJOGLAvailable; + private static final boolean hasGL3Impl; private static final boolean hasGL2Impl; private static final boolean hasGL2ES12Impl; @@ -624,6 +627,15 @@ public class GLProfile implements Cloneable { static { JVMUtil.initSingleton(); + AccessControlContext acc = AccessController.getContext(); + + isAWTAvailable = !Debug.getBooleanProperty("java.awt.headless", true, acc) && + NWReflection.isClassAvailable("java.awt.Component") ; + + isAWTJOGLAvailable = isAWTAvailable && + NWReflection.isClassAvailable("javax.media.nativewindow.awt.AWTGraphicsDevice") && // NativeWindow + NWReflection.isClassAvailable("javax.media.opengl.awt.GLCanvas") ; // JOGL + boolean hasDesktopGL = false; boolean hasDesktopGLES12 = false; boolean hasNativeOSFactory = false; @@ -711,6 +723,8 @@ public class GLProfile implements Cloneable { hasGLES1Impl = btest; if (DEBUG) { + System.err.println("GLProfile.static isAWTAvailable "+isAWTAvailable); + System.err.println("GLProfile.static isAWTJOGLAvailable "+isAWTJOGLAvailable); System.err.println("GLProfile.static hasNativeOSFactory "+hasNativeOSFactory); System.err.println("GLProfile.static hasDesktopGLES12 "+hasDesktopGLES12); System.err.println("GLProfile.static hasDesktopGL "+hasDesktopGL); @@ -799,6 +813,9 @@ public class GLProfile implements Cloneable { return null; } + public static boolean isAWTAvailable() { return isAWTAvailable; } + public static boolean isAWTJOGLAvailable() { return isAWTJOGLAvailable; } + public static String getGLTypeName(int type) { switch (type) { case GL.GL_UNSIGNED_BYTE: |