Jogamp
FBObject: Fix depth- and stencil bit count selection for attachRenderbuffer(..);
authorSven Gothel <sgothel@jausoft.com>
Sat, 20 Sep 2014 14:06:56 +0000 (16:06 +0200)
committerSven Gothel <sgothel@jausoft.com>
Sat, 20 Sep 2014 14:06:56 +0000 (16:06 +0200)
- Fix depth- and stencil bit count selection for attachRenderbuffer(..)
  - Add generic values: DEFAULT_BITS, REQUESTED_BITS, CHOSEN_BITS, MAXIMUM_BITS

  - Refactor depth- and stencil bit-count -> format into own method

  - Allow depth- and stencil bit-count select a higher bit-count if required (fix)

- GLFBODrawable.FBOMODE_USE_DEPTH is deprecated, using GLCapabilities.[get|set]DepthBits(..)
  - It was an oversight to introduce the bit flag in the first place,
    since we should have used the capabilities depth bit-count

- Graph Test: GLEventListenerButton shall use requested capabilities for FBO drawable.

16 files changed:
jnlp-files/jogl-applet-bug818_gljpanel01.html
make/scripts/tests.sh
src/jogl/classes/com/jogamp/opengl/FBObject.java
src/jogl/classes/com/jogamp/opengl/util/stereo/StereoClientRenderer.java
src/jogl/classes/javax/media/opengl/GLFBODrawable.java
src/jogl/classes/javax/media/opengl/awt/GLJPanel.java
src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java
src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java
src/jogl/classes/jogamp/opengl/GLFBODrawableImpl.java
src/jogl/classes/jogamp/opengl/GLOffscreenAutoDrawableImpl.java
src/test/com/jogamp/opengl/test/junit/graph/demos/ui/GLEventListenerButton.java
src/test/com/jogamp/opengl/test/junit/jogl/acore/TestFBOAutoDrawableFactoryNEWT.java
src/test/com/jogamp/opengl/test/junit/jogl/acore/TestFBOMRTNEWT01.java
src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/FBOMix2DemosES2.java
src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TextureDraw02ES2ListenerFBO.java
src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/awt/Bug818GLJPanelAndGLCanvasApplet.java [moved from src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/awt/Bug818GLJPanelApplet.java with 90% similarity]

index 4bb09d0..0f62062 100644 (file)
@@ -1,24 +1,24 @@
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
 <html>
 <head>
-<title>Bug818 OSX GLJPanel NV GT330 Crash</title>
+<title>Bug818 OSX GLJPanel and GLCanvas NV GT330 Crash</title>
 </head>
 <body  BGCOLOR="#ffffff">
 
 <P>
-Bug818 OSX GLJPanel NV GT330 Crash
+Bug818 OSX GLJPanel and GLCanvas NV GT330 Crash
 </P>
 
 <P>
 <object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
-      width="750" height="350">
-   <param name="code" value="com.jogamp.opengl.test.junit.jogl.demos.gl2.awt.Bug818GLJPanelApplet">
+      width="750" height="650">
+   <param name="code" value="com.jogamp.opengl.test.junit.jogl.demos.gl2.awt.Bug818GLJPanelAndGLCanvasApplet">
    <param name="archive" value="jar/lib/gluegen-rt.jar,
                                 jar/lib/jogl-all.jar,
                                 jar/jogl-test.jar">
    <comment>
-     <embed code="com.jogamp.opengl.test.junit.jogl.demos.gl2.awt.Bug818GLJPanelApplet"
-          width="750" height="350"
+     <embed code="com.jogamp.opengl.test.junit.jogl.demos.gl2.awt.Bug818GLJPanelAndGLCanvasApplet"
+          width="750" height="650"
           type="application/x-java-applet;version=1.6"
           archive="jar/gluegen-rt.jar,
                    jar/jogl-all.jar,
index 2245306..60d8c64 100644 (file)
@@ -167,7 +167,7 @@ function jrun() {
     #D_ARGS="-Djogl.debug.GLArrayData"
     #D_ARGS="-Dnewt.debug.Screen -Dnewt.debug.Window"
     #D_ARGS="-Dnewt.debug.Window"
-    D_ARGS="-Dnewt.debug.Screen"
+    #D_ARGS="-Dnewt.debug.Screen"
     #D_ARGS="-Dnewt.test.Screen.disableRandR13"
     #D_ARGS="-Dnewt.test.Screen.disableScreenMode -Dnewt.debug.Screen"
     #D_ARGS="-Dnewt.debug.Screen -Djogl.debug.Animator"
@@ -408,7 +408,7 @@ function testawtswt() {
 #testnoawt com.jogamp.opengl.test.junit.jogl.demos.es1.newt.TestOlympicES1NEWT $*
 #testnoawt com.jogamp.opengl.test.junit.jogl.demos.es1.newt.TestRedSquareES1NEWT $*
 #testawt com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2AWT $*
-testawt com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2GLJPanelAWT $*
+#testawt com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2GLJPanelAWT $*
 #testawt com.jogamp.opengl.test.junit.jogl.awt.ManualHiDPIBufferedImage01AWT $*
 #testawt com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2GLJPanelsAWT $*
 #testawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NewtCanvasAWT $*
@@ -418,7 +418,7 @@ testawt com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2GLJPanelAWT
 #testawtswt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NewtCanvasSWT $*
 #testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestElektronenMultipliziererNEWT $*
 #testnoawtatomics com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT $*
-testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT $*
+#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT $*
 #testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestRedSquareES2NEWT $*
 #testswt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NewtCanvasSWT $*
 #testswt com.jogamp.opengl.test.junit.jogl.demos.es2.swt.TestGearsES2SWT $*
@@ -516,7 +516,7 @@ testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT $*
 
 #testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestFBOOffThreadSharedContextMix2DemosES2NEWT $*
 #testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestFBOOnThreadSharedContext1DemoES2NEWT $*
-#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestFBOAutoDrawableFactoryNEWT $*
+testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestFBOAutoDrawableFactoryNEWT $*
 #testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestFBOMix2DemosES2NEWT $*
 #testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestFBOMRTNEWT01 $*
 
index 2d89b21..58fde80 100644 (file)
@@ -37,6 +37,7 @@ import javax.media.opengl.GL2GL3;
 import javax.media.opengl.GL3;
 import javax.media.opengl.GLBase;
 import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLCapabilitiesImmutable;
 import javax.media.opengl.GLContext;
 import javax.media.opengl.GLException;
 import javax.media.opengl.GLProfile;
@@ -1607,6 +1608,68 @@ public class FBObject {
         return colbuf;
     }
 
+    private final int getDepthIFormat(final int reqBits) {
+        if( 32 <= reqBits && depth32Avail ) {
+            return GL.GL_DEPTH_COMPONENT32;
+        } else if( 24 <= reqBits && ( depth24Avail || depth32Avail ) ) {
+            if( depth24Avail ) {
+                return GL.GL_DEPTH_COMPONENT24;
+            } else {
+                return GL.GL_DEPTH_COMPONENT32;
+            }
+        } else {
+            return GL.GL_DEPTH_COMPONENT16;
+        }
+    }
+    private final int getStencilIFormat(final int reqBits) {
+        if( 16 <= reqBits && stencil16Avail ) {
+            return GL2GL3.GL_STENCIL_INDEX16;
+        } else if( 8 <= reqBits && ( stencil08Avail || stencil16Avail ) ) {
+            if( stencil08Avail ) {
+                return GL.GL_STENCIL_INDEX8;
+            } else {
+                return GL2GL3.GL_STENCIL_INDEX16;
+            }
+        } else if( 4 <= reqBits && ( stencil04Avail || stencil08Avail || stencil16Avail ) ) {
+            if( stencil04Avail ) {
+                return GL.GL_STENCIL_INDEX4;
+            } else if( stencil08Avail ) {
+                return GL.GL_STENCIL_INDEX8;
+            } else {
+                return GL2GL3.GL_STENCIL_INDEX16;
+            }
+        } else if( 1 <= reqBits && ( stencil01Avail || stencil04Avail || stencil08Avail || stencil16Avail ) ) {
+            if( stencil01Avail ) {
+                return GL.GL_STENCIL_INDEX1;
+            } else if( stencil04Avail ) {
+                return GL.GL_STENCIL_INDEX4;
+            } else if( stencil08Avail ) {
+                return GL.GL_STENCIL_INDEX8;
+            } else {
+                return GL2GL3.GL_STENCIL_INDEX16;
+            }
+        } else {
+            throw new GLException("stencil buffer n/a");
+        }
+    }
+
+    /** Request default bit count for depth- or stencil buffer (depth 24 bits, stencil 8 bits), value {@value} */
+    public static final int DEFAULT_BITS = 0;
+
+    /**
+     * Request current context drawable's <i>requested</i>
+     * {@link GLCapabilitiesImmutable#getDepthBits() depth-} or {@link GLCapabilitiesImmutable#getStencilBits() stencil-}bits; value {@value} */
+    public static final int REQUESTED_BITS = -1;
+
+    /**
+     * Request current context drawable's <i>chosen</i>
+     * {@link GLCapabilitiesImmutable#getDepthBits() depth-} or {@link GLCapabilitiesImmutable#getStencilBits() stencil-}bits; value {@value} */
+    public static final int CHOSEN_BITS = -2;
+
+    /** Request maximum bit count for depth- or stencil buffer (depth 32 bits, stencil 16 bits), value {@value} */
+    public static final int MAXIMUM_BITS = -3;
+
+
     /**
      * Attaches one depth, stencil or packed-depth-stencil buffer to this FBO's instance,
      * selecting the internalFormat automatically.
@@ -1614,7 +1677,8 @@ public class FBObject {
      * Stencil and depth buffer can be attached only once.
      * </p>
      * <p>
-     * In case the desired type or bit-number is not supported, the next available one is chosen.
+     * In case the bit-count is not supported,
+     * the next available one is chosen, i.e. next higher (preferred) or lower bit-count.
      * </p>
      * <p>
      * Use {@link #getDepthAttachment()} and/or {@link #getStencilAttachment()} to retrieve details
@@ -1626,68 +1690,58 @@ public class FBObject {
      *
      * @param gl
      * @param atype either {@link Type#DEPTH}, {@link Type#STENCIL} or {@link Type#DEPTH_STENCIL}
-     * @param reqBits desired bits for depth or -1 for default (24 bits)
+     * @param reqBits desired bits for depth or stencil,
+     *                may use generic values {@link #DEFAULT_BITS}, {@link #REQUESTED_BITS}, {@link #CHOSEN_BITS} or {@link #MAXIMUM_BITS}.
      * @throws GLException in case the renderbuffer couldn't be allocated or one is already attached.
      * @throws IllegalArgumentException
      * @see #getDepthAttachment()
      * @see #getStencilAttachment()
      */
-    public final void attachRenderbuffer(final GL gl, final Attachment.Type atype, int reqBits) throws GLException, IllegalArgumentException {
-        if( 0 > reqBits ) {
-            reqBits = 24;
+    public final void attachRenderbuffer(final GL gl, final Attachment.Type atype, final int reqBits) throws GLException, IllegalArgumentException {
+        final int reqDepth, reqStencil;
+        if( MAXIMUM_BITS > reqBits ) {
+            throw new IllegalArgumentException("reqBits out of range, shall be >= "+MAXIMUM_BITS);
+        } else if( MAXIMUM_BITS == reqBits ) {
+            reqDepth = 32;
+            reqStencil = 16;
+        } else if( CHOSEN_BITS == reqBits ) {
+            final GLCapabilitiesImmutable caps = gl.getContext().getGLDrawable().getChosenGLCapabilities();
+            reqDepth = caps.getDepthBits();
+            reqStencil = caps.getStencilBits();
+        } else if( REQUESTED_BITS == reqBits ) {
+            final GLCapabilitiesImmutable caps = gl.getContext().getGLDrawable().getRequestedGLCapabilities();
+            reqDepth = caps.getDepthBits();
+            reqStencil = caps.getStencilBits();
+        } else if( DEFAULT_BITS == reqBits ) {
+            reqDepth = 24;
+            reqStencil = 8;
+        } else {
+            reqDepth = reqBits;
+            reqStencil = reqBits;
         }
         final int internalFormat;
         int internalStencilFormat = -1;
 
         switch ( atype ) {
             case DEPTH:
-                if( 32 <= reqBits && depth32Avail ) {
-                    internalFormat = GL.GL_DEPTH_COMPONENT32;
-                } else if( 24 <= reqBits && depth24Avail ) {
-                    internalFormat = GL.GL_DEPTH_COMPONENT24;
-                } else {
-                    internalFormat = GL.GL_DEPTH_COMPONENT16;
-                }
+                internalFormat = getDepthIFormat(reqDepth);
                 break;
 
             case STENCIL:
-                if( 16 <= reqBits && stencil16Avail ) {
-                    internalFormat = GL2GL3.GL_STENCIL_INDEX16;
-                } else if( 8 <= reqBits && stencil08Avail ) {
-                    internalFormat = GL.GL_STENCIL_INDEX8;
-                } else if( 4 <= reqBits && stencil04Avail ) {
-                    internalFormat = GL.GL_STENCIL_INDEX4;
-                } else if( 1 <= reqBits && stencil01Avail ) {
-                    internalFormat = GL.GL_STENCIL_INDEX1;
-                } else {
-                    throw new GLException("stencil buffer n/a");
-                }
+                internalFormat = getStencilIFormat(reqStencil);
                 break;
 
             case DEPTH_STENCIL:
                 if( packedDepthStencilAvail ) {
                     internalFormat = GL.GL_DEPTH24_STENCIL8;
                 } else {
-                    if( 24 <= reqBits && depth24Avail ) {
-                        internalFormat = GL.GL_DEPTH_COMPONENT24;
-                    } else {
-                        internalFormat = GL.GL_DEPTH_COMPONENT16;
-                    }
-                    if( stencil08Avail ) {
-                        internalStencilFormat = GL.GL_STENCIL_INDEX8;
-                    } else if( stencil04Avail ) {
-                        internalStencilFormat = GL.GL_STENCIL_INDEX4;
-                    } else if( stencil01Avail ) {
-                        internalStencilFormat = GL.GL_STENCIL_INDEX1;
-                    } else {
-                        throw new GLException("stencil buffer n/a");
-                    }
+                    internalFormat = getDepthIFormat(reqDepth);
+                    internalStencilFormat = getStencilIFormat(reqStencil);
                 }
                 break;
             default:
                 throw new IllegalArgumentException("only depth/stencil types allowed, was "+atype+", "+this);
         }
-
         attachRenderbufferImpl(gl, atype, internalFormat);
 
         if(0<=internalStencilFormat) {
index 8b00aef..f70ebf9 100644 (file)
@@ -95,19 +95,19 @@ public class StereoClientRenderer implements GLEventListener {
 
             if(numSamples>0) {
                 fbos[i].attachColorbuffer(gl, 0, true); // MSAA requires alpha
-                fbos[i].attachRenderbuffer(gl, Type.DEPTH, 24);
+                fbos[i].attachRenderbuffer(gl, Type.DEPTH, FBObject.DEFAULT_BITS);
                 final FBObject ssink = new FBObject();
                 {
                     ssink.init(gl, size.getWidth(), size.getHeight(), 0);
                     ssink.attachTexture2D(gl, 0, false, magFilter, minFilter, GL.GL_CLAMP_TO_EDGE, GL.GL_CLAMP_TO_EDGE);
-                    ssink.attachRenderbuffer(gl, Attachment.Type.DEPTH, 24);
+                    ssink.attachRenderbuffer(gl, Attachment.Type.DEPTH, FBObject.DEFAULT_BITS);
                 }
                 fbos[i].setSamplingSink(ssink);
                 fbos[i].resetSamplingSink(gl); // validate
                 fboTexs[i] = fbos[i].getSamplingSink().getTextureAttachment();
             } else {
                 fboTexs[i] = fbos[i].attachTexture2D(gl, 0, false, magFilter, minFilter, GL.GL_CLAMP_TO_EDGE, GL.GL_CLAMP_TO_EDGE);
-                fbos[i].attachRenderbuffer(gl, Type.DEPTH, 24);
+                fbos[i].attachRenderbuffer(gl, Type.DEPTH, FBObject.DEFAULT_BITS);
             }
             fbos[i].unbind(gl);
             System.err.println("FBO["+i+"]: "+fbos[i]);
index e98e5cb..01db60b 100644 (file)
@@ -80,11 +80,14 @@ public interface GLFBODrawable extends GLDrawable {
 
     /** FBO Mode Bit: Use a {@link TextureAttachment} for the {@link #getColorbuffer(int) render colorbuffer} ({@link #FBOMODE_DEFAULT default}), see {@link #setFBOMode(int)}. */
     public static final int FBOMODE_USE_TEXTURE = 1 << 0;
-    /** FBO Mode Bit: Use a depth renderbuffer ({@link #FBOMODE_DEFAULT default}), see {@link #setFBOMode(int)}. */
+    /**
+     * FBO Mode Bit: Use a depth renderbuffer ({@link #FBOMODE_DEFAULT default}), see {@link #setFBOMode(int)}.
+     * @deprecated Use {@link GLCapabilities#setDepthBits(int)}!
+     */
     public static final int FBOMODE_USE_DEPTH   = 1 << 1;
 
-    /** FBO Default Mode Bit: {@link #FBOMODE_USE_TEXTURE} | {@link #FBOMODE_USE_DEPTH}. */
-    public static final int FBOMODE_DEFAULT   = FBOMODE_USE_TEXTURE | FBOMODE_USE_DEPTH;
+    /** FBO Default Mode Bit: {@link #FBOMODE_USE_TEXTURE}. */
+    public static final int FBOMODE_DEFAULT   = FBOMODE_USE_TEXTURE;
 
     /**
      * @return <code>true</code> if initialized, i.e. a {@link GLContext} is bound and made current once, otherwise <code>false</code>.
@@ -101,8 +104,8 @@ public interface GLFBODrawable extends GLDrawable {
      * {@link #FBOMODE_USE_TEXTURE} is always added at initialization.
      * </p>
      *
-     * @param modeBits custom FBO mode bits like {@link #FBOMODE_USE_TEXTURE} and {@link #FBOMODE_USE_DEPTH}.
-     * @throws IllegalStateException if the underlying FBO is already {@link #isInitialized()}.
+     * @param modeBits custom FBO mode bits like {@link #FBOMODE_USE_TEXTURE}.
+     * @throws IllegalStateException if already initialized, see {@link #isInitialized()}.
      */
     void setFBOMode(final int modeBits) throws IllegalStateException;
 
@@ -155,9 +158,9 @@ public interface GLFBODrawable extends GLDrawable {
      * Must be called before {@link #isInitialized() initialization}, otherwise an exception is thrown.
      * </p>
      * @return the new number of buffers (FBO) used, maybe different than the requested <code>bufferCount</code> (see above)
-     * @throws GLException if already initialized, see {@link #isInitialized()}.
+     * @throws IllegalStateException if already initialized, see {@link #isInitialized()}.
      */
-    int setNumBuffers(final int bufferCount) throws GLException;
+    int setNumBuffers(final int bufferCount) throws /* IllegalStateException, */ GLException;
 
     /**
      * @return the number of buffers (FBO) being used. 1 if not using {@link GLCapabilities#getDoubleBuffered() double buffering},
index f079b3d..ff7e197 100644 (file)
@@ -1669,7 +1669,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing
           final boolean useGLSLFlip_pre = flipVertical && offscreenIsFBO && reqOffscreenCaps.getGLProfile().isGL2ES2() && USE_GLSL_TEXTURE_RASTERIZER;
           if( offscreenIsFBO && !useGLSLFlip_pre ) {
               // Texture attachment only required for GLSL vertical flip, hence simply use a color-renderbuffer attachment.
-              ((GLFBODrawable)offscreenDrawable).setFBOMode(GLFBODrawable.FBOMODE_USE_DEPTH);
+              ((GLFBODrawable)offscreenDrawable).setFBOMode(0);
           }
 
           offscreenContext = (GLContextImpl) offscreenDrawable.createContext(shareWith[0]);
index 422714a..fbd40eb 100644 (file)
@@ -459,7 +459,7 @@ public class VBORegion2PMSAAES2  extends GLRegion {
             fbo.attachColorbuffer(gl, 0, true);
             if( !blendingEnabled ) {
                 // no depth-buffer w/ blending
-                fbo.attachRenderbuffer(gl, Attachment.Type.DEPTH, 24);
+                fbo.attachRenderbuffer(gl, Attachment.Type.DEPTH, FBObject.DEFAULT_BITS);
             }
             final FBObject ssink = new FBObject();
             {
@@ -469,7 +469,7 @@ public class VBORegion2PMSAAES2  extends GLRegion {
                 ssink.attachTexture2D(gl, 0, true, GL.GL_NEAREST, GL.GL_NEAREST, GL.GL_CLAMP_TO_EDGE, GL.GL_CLAMP_TO_EDGE);
                 if( !blendingEnabled ) {
                     // no depth-buffer w/ blending
-                    ssink.attachRenderbuffer(gl, Attachment.Type.DEPTH, 24);
+                    ssink.attachRenderbuffer(gl, Attachment.Type.DEPTH, FBObject.DEFAULT_BITS);
                 }
             }
             fbo.setSamplingSink(ssink);
index 5251ade..8f1de91 100644 (file)
@@ -580,7 +580,7 @@ public class VBORegion2PVBAAES2  extends GLRegion {
             texA = fbo.attachTexture2D(gl, 0, true, GL.GL_NEAREST, GL.GL_NEAREST, GL.GL_CLAMP_TO_EDGE, GL.GL_CLAMP_TO_EDGE);
             if( !blendingEnabled ) {
                 // no depth-buffer w/ blending
-                fbo.attachRenderbuffer(gl, Attachment.Type.DEPTH, 24);
+                fbo.attachRenderbuffer(gl, Attachment.Type.DEPTH, FBObject.DEFAULT_BITS);
             }
             if( DEBUG_FBO_1 ) {
                 System.err.printf("XXX.createFBO: %dx%d%n%s%n", fboWidth, fboHeight, fbo.toString());
index 1bdc99a..fdd5aa5 100644 (file)
@@ -91,7 +91,7 @@ public class GLFBODrawableImpl extends GLDrawableImpl implements GLFBODrawable {
                                 final GLCapabilitiesImmutable fboCaps, final int textureUnit) {
         super(factory, surface, fboCaps, false);
         this.initialized = false;
-        this.fboModeBits = FBOMODE_USE_TEXTURE | FBOMODE_USE_DEPTH;
+        this.fboModeBits = FBOMODE_USE_TEXTURE;
 
         this.parent = parent;
         this.origParentChosenCaps = getChosenGLCapabilities(); // just to avoid null, will be reset at initialize(..)
@@ -102,11 +102,14 @@ public class GLFBODrawableImpl extends GLDrawableImpl implements GLFBODrawable {
     }
 
     private final void setupFBO(final GL gl, final int idx, final int width, final int height, final int samples,
-                                final boolean useAlpha, final boolean useStencil, final boolean useDepth, final boolean useTexture,
-                                final boolean realUnbind) {
+                                final boolean useAlpha, final int depthBits, final int stencilBits,
+                                final boolean useTexture, final boolean realUnbind) {
         final FBObject fbo = new FBObject();
         fbos[idx] = fbo;
 
+        final boolean useDepth   = depthBits > 0 || 0 != ( FBOMODE_USE_DEPTH & fboModeBits );
+        final boolean useStencil = stencilBits > 0;
+
         fbo.init(gl, width, height, samples);
         if(fbo.getNumSamples() != samples) {
             throw new InternalError("Sample number mismatch: "+samples+", fbos["+idx+"] "+fbo);
@@ -118,12 +121,12 @@ public class GLFBODrawableImpl extends GLDrawableImpl implements GLFBODrawable {
         }
         if( useStencil ) {
             if( useDepth ) {
-                fbo.attachRenderbuffer(gl, Attachment.Type.DEPTH_STENCIL, 24);
+                fbo.attachRenderbuffer(gl, Attachment.Type.DEPTH_STENCIL, depthBits);
             } else {
-                fbo.attachRenderbuffer(gl, Attachment.Type.STENCIL, 24);
+                fbo.attachRenderbuffer(gl, Attachment.Type.STENCIL, stencilBits);
             }
         } else if( useDepth ) {
-            fbo.attachRenderbuffer(gl, Attachment.Type.DEPTH, 24);
+            fbo.attachRenderbuffer(gl, Attachment.Type.DEPTH, depthBits);
         }
         if(samples > 0) {
             final FBObject ssink = new FBObject();
@@ -136,12 +139,12 @@ public class GLFBODrawableImpl extends GLDrawableImpl implements GLFBODrawable {
                 }
                 if( useStencil ) {
                     if( useDepth ) {
-                        ssink.attachRenderbuffer(gl, Attachment.Type.DEPTH_STENCIL, 24);
+                        ssink.attachRenderbuffer(gl, Attachment.Type.DEPTH_STENCIL, depthBits);
                     } else {
-                        ssink.attachRenderbuffer(gl, Attachment.Type.STENCIL, 24);
+                        ssink.attachRenderbuffer(gl, Attachment.Type.STENCIL, stencilBits);
                     }
                 } else if( useDepth ) {
-                    ssink.attachRenderbuffer(gl, Attachment.Type.DEPTH, 24);
+                    ssink.attachRenderbuffer(gl, Attachment.Type.DEPTH, depthBits);
                 }
             }
             fbo.setSamplingSink(ssink);
@@ -206,14 +209,13 @@ public class GLFBODrawableImpl extends GLDrawableImpl implements GLFBODrawable {
             }
 
             final boolean useTexture = 0 != ( FBOMODE_USE_TEXTURE & fboModeBits );
-            final boolean useDepth   = 0 != ( FBOMODE_USE_DEPTH   & fboModeBits );
-            final boolean useStencil = chosenFBOCaps.getStencilBits() > 0;
             final boolean useAlpha = chosenFBOCaps.getAlphaBits() > 0;
             final int width = getSurfaceWidth();
             final int height = getSurfaceHeight();
 
             for(int i=0; i<fbosN; i++) {
-                setupFBO(gl, i, width, height, samples, useAlpha, useStencil, useDepth, useTexture, fbosN-1==i);
+                setupFBO(gl, i, width, height, samples, useAlpha,
+                         chosenFBOCaps.getDepthBits(), chosenFBOCaps.getStencilBits(), useTexture, fbosN-1==i);
             }
             fbos[0].formatToGLCapabilities(chosenFBOCaps);
             chosenFBOCaps.setDoubleBuffered( chosenFBOCaps.getDoubleBuffered() || samples > 0 );
@@ -239,8 +241,7 @@ public class GLFBODrawableImpl extends GLDrawableImpl implements GLFBODrawable {
     }
 
     private final void reset(final GL gl, final int idx, final int width, final int height, final int samples,
-                             final boolean useAlpha, final boolean useStencil) {
-        final boolean useDepth   = 0 != ( FBOMODE_USE_DEPTH   & fboModeBits );
+                             final boolean useAlpha, final int depthBits, final int stencilBits) {
         if( !fboResetQuirk ) {
             try {
                 fbos[idx].reset(gl, width, height, samples);
@@ -268,7 +269,7 @@ public class GLFBODrawableImpl extends GLDrawableImpl implements GLFBODrawable {
         // resetQuirk fallback
         fbos[idx].destroy(gl);
         final boolean useTexture = 0 != ( FBOMODE_USE_TEXTURE & fboModeBits );
-        setupFBO(gl, idx, width, height, samples, useAlpha, useStencil, useDepth, useTexture, true);
+        setupFBO(gl, idx, width, height, samples, useAlpha, depthBits, stencilBits, useTexture, true);
     }
 
     private final void reset(final GL gl, int newSamples) throws GLException {
@@ -313,7 +314,7 @@ public class GLFBODrawableImpl extends GLDrawableImpl implements GLFBODrawable {
                 final GLCapabilitiesImmutable caps = (GLCapabilitiesImmutable) surface.getGraphicsConfiguration().getChosenCapabilities();
                 for(int i=0; i<fbos.length; i++) {
                     if( pendingFBOReset != i ) {
-                        reset(gl, i, nWidth, nHeight, samples, caps.getAlphaBits()>0, caps.getStencilBits()>0);
+                        reset(gl, i, nWidth, nHeight, samples, caps.getAlphaBits()>0, caps.getDepthBits(), caps.getStencilBits());
                     }
                 }
                 final GLCapabilities fboCapsNative = (GLCapabilities) surface.getGraphicsConfiguration().getChosenCapabilities();
@@ -440,7 +441,8 @@ public class GLFBODrawableImpl extends GLDrawableImpl implements GLFBODrawable {
         // Safely reset the previous front FBO - after completing propagating swap
         if(0 <= pendingFBOReset) {
             final GLCapabilitiesImmutable caps = (GLCapabilitiesImmutable) surface.getGraphicsConfiguration().getChosenCapabilities();
-            reset(glc.getGL(), pendingFBOReset, getSurfaceWidth(), getSurfaceHeight(), samples, caps.getAlphaBits()>0, caps.getStencilBits()>0);
+            reset(glc.getGL(), pendingFBOReset, getSurfaceWidth(), getSurfaceHeight(), samples,
+                  caps.getAlphaBits()>0, caps.getDepthBits(), caps.getStencilBits());
             pendingFBOReset = -1;
         }
     }
@@ -523,9 +525,12 @@ public class GLFBODrawableImpl extends GLDrawableImpl implements GLFBODrawable {
     }
 
     @Override
-    public final int setNumBuffers(final int bufferCount) throws GLException {
+    public final int setNumBuffers(final int bufferCount) throws /* IllegalStateException, */ GLException {
+        if( isInitialized() ) {
+            throw new IllegalStateException("Already initialized: "+this);
+        }
         // FIXME: Implement
-        return bufferCount;
+        return GLFBODrawableImpl.bufferCount;
     }
 
     @Override
index 60cc9f0..721dc73 100644 (file)
@@ -102,7 +102,7 @@ public class GLOffscreenAutoDrawableImpl extends GLAutoDrawableDelegate implemen
         }
 
         @Override
-        public final int setNumBuffers(final int bufferCount) throws GLException {
+        public final int setNumBuffers(final int bufferCount) throws /* IllegalStateException, */ GLException {
             return ((GLFBODrawableImpl)drawable).setNumBuffers(bufferCount);
         }
 
index 06d8692..a8cd320 100644 (file)
@@ -89,8 +89,8 @@ public class GLEventListenerButton extends TextureSeqButton {
 
             final GLContext ctx = gl.getContext();
             final GLDrawable drawable = ctx.getGLDrawable();
-            final GLCapabilitiesImmutable capsHas = drawable.getChosenGLCapabilities();
-            final GLCapabilities caps = (GLCapabilities) capsHas.cloneMutable();
+            final GLCapabilitiesImmutable reqCaps = drawable.getRequestedGLCapabilities();
+            final GLCapabilities caps = (GLCapabilities) reqCaps.cloneMutable();
             caps.setFBO(true);
             caps.setDoubleBuffered(false);
             if( !useAlpha ) {
index 6bbe00f..a46c5a7 100644 (file)
@@ -83,13 +83,14 @@ public class TestFBOAutoDrawableFactoryNEWT extends UITestCase {
         final GLProfile glp = GLProfile.getGL2ES2();
         final GLCapabilities caps = new GLCapabilities(glp);
         caps.setDoubleBuffered(false);
-        testGLFBODrawableImpl(caps, GLFBODrawable.FBOMODE_USE_DEPTH, new GearsES2(0));
+        testGLFBODrawableImpl(caps, 0, new GearsES2(0));
     }
     @Test
     public void test01c_GL2ES2_Demo1_SingleBuffer_NoTexNoDepth() throws InterruptedException {
         final GLProfile glp = GLProfile.getGL2ES2();
         final GLCapabilities caps = new GLCapabilities(glp);
         caps.setDoubleBuffered(false);
+        caps.setDepthBits(0);
         testGLFBODrawableImpl(caps, 0, new GearsES2(0));
     }
 
@@ -115,7 +116,7 @@ public class TestFBOAutoDrawableFactoryNEWT extends UITestCase {
         final GLCapabilities caps = new GLCapabilities(glp);
         caps.setSampleBuffers(true);
         caps.setNumSamples(4);
-        testGLFBODrawableImpl(caps, GLFBODrawable.FBOMODE_USE_DEPTH, new MultisampleDemoES2(true));
+        testGLFBODrawableImpl(caps, 0, new MultisampleDemoES2(true));
     }
     @Test
     public void test03c_GL2ES2_Demo2MSAA4_NoTexNoDepth() throws InterruptedException {
@@ -123,6 +124,7 @@ public class TestFBOAutoDrawableFactoryNEWT extends UITestCase {
         final GLCapabilities caps = new GLCapabilities(glp);
         caps.setSampleBuffers(true);
         caps.setNumSamples(4);
+        caps.setDepthBits(0);
         testGLFBODrawableImpl(caps, 0, new MultisampleDemoES2(true));
     }
 
@@ -179,6 +181,7 @@ public class TestFBOAutoDrawableFactoryNEWT extends UITestCase {
                 factory.createOffscreenAutoDrawable(null, caps, null, widthStep*szStep, heightStep*szStep);
         Assert.assertNotNull(glad);
 
+        System.out.println("Requested:     "+caps);
         System.out.println("Realized GLAD: "+glad);
         System.out.println("Realized GLAD: "+glad.getChosenGLCapabilities());
         Assert.assertTrue("FBO drawable is initialized before ctx creation", !glad.isInitialized());
@@ -192,8 +195,12 @@ public class TestFBOAutoDrawableFactoryNEWT extends UITestCase {
         }
         Assert.assertTrue("FBO drawable is not initialized after ctx creation", glad.isInitialized());
 
-        // final boolean useTexture = 0 != ( GLFBODrawable.FBOMODE_USE_TEXTURE & glad.getFBOMode() );
-        final boolean useDepth = 0 != ( GLFBODrawable.FBOMODE_USE_DEPTH & glad.getFBOMode() );
+        final boolean expDepth = caps.getDepthBits() > 0;
+        final boolean reqDepth = glad.getRequestedGLCapabilities().getDepthBits() > 0;
+        final boolean hasDepth = glad.getChosenGLCapabilities().getDepthBits() > 0;
+        System.out.println("Depth: exp "+expDepth+", req "+reqDepth+", has "+hasDepth);
+        Assert.assertEquals("Depth: expected not passed to requested", expDepth, reqDepth);
+        Assert.assertEquals("Depth: requested not passed to chosen", reqDepth, hasDepth);
 
         //
         // FBO incl. MSAA is fully initialized now
@@ -230,6 +237,13 @@ public class TestFBOAutoDrawableFactoryNEWT extends UITestCase {
             color1 = null;
         }
 
+        final boolean expTexture = 0 != ( GLFBODrawable.FBOMODE_USE_TEXTURE & glad.getFBOMode() );
+        System.out.println("Texture: exp "+expTexture+", hasFront "+color0.isTextureAttachment());
+        Assert.assertEquals("Texture: Front", expTexture, color0.isTextureAttachment());
+        if(0==glad.getNumSamples()) {
+            Assert.assertEquals("Texture: Back", expTexture, color1.isTextureAttachment());
+        }
+
         final FBObject.Colorbuffer colorA, colorB;
         final FBObject.RenderAttachment depthA, depthB;
 
@@ -238,7 +252,14 @@ public class TestFBOAutoDrawableFactoryNEWT extends UITestCase {
         colorB = fboBack.getColorbuffer(0);
         Assert.assertNotNull(colorB);
 
-        if( useDepth ) {
+        Assert.assertEquals("Texture: Front", expTexture, colorA.isTextureAttachment());
+        if(0==glad.getNumSamples()) {
+            Assert.assertEquals("Texture: Back", expTexture, colorB.isTextureAttachment());
+        } else {
+            Assert.assertEquals("Texture: MSAA Back is Texture", false, colorB.isTextureAttachment());
+        }
+
+        if( hasDepth ) {
             depthA = fboFront.getDepthAttachment();
             Assert.assertNotNull(depthA);
             depthB = fboBack.getDepthAttachment();
@@ -254,7 +275,7 @@ public class TestFBOAutoDrawableFactoryNEWT extends UITestCase {
             // double buffer or MSAA
             Assert.assertNotEquals("Color attachments are equal: "+colorB+" == "+colorA, colorA, colorB);
             Assert.assertNotSame(colorB, colorA);
-            if( useDepth ) {
+            if( hasDepth ) {
                 Assert.assertNotEquals("Depth attachments are equal: "+depthB+" == "+depthA, depthA, depthB);
                 Assert.assertNotSame(depthB, depthA);
             }
@@ -343,14 +364,14 @@ public class TestFBOAutoDrawableFactoryNEWT extends UITestCase {
             FBObject.RenderAttachment _depth = _fboFront.getDepthAttachment();
             System.err.println("Resize1.oldDepth "+depthA);
             System.err.println("Resize1.newDepth "+_depth);
-            if( useDepth ) {
+            if( hasDepth ) {
                 Assert.assertNotNull(_depth);
             }
 
             Assert.assertEquals(depthA, _depth);
             Assert.assertSame(depthA, _depth);
             _depth = _fboBack.getDepthAttachment();
-            if( useDepth ) {
+            if( hasDepth ) {
                 Assert.assertNotNull(_depth);
             }
             Assert.assertEquals(depthB, _depth);
@@ -394,14 +415,14 @@ public class TestFBOAutoDrawableFactoryNEWT extends UITestCase {
             Assert.assertSame(colorB, _color);
 
             FBObject.RenderAttachment _depth = fboBack.getDepthAttachment();
-            if( useDepth ) {
+            if( hasDepth ) {
                 Assert.assertNotNull(_depth); // MSAA back w/ depth
             }
             Assert.assertEquals(depthB, _depth);
             Assert.assertSame(depthB, _depth);
 
             _depth = fboFront.getDepthAttachment();
-            if( useDepth ) {
+            if( hasDepth ) {
                 Assert.assertNotNull(_depth);
             }
             Assert.assertEquals(depthA, _depth);
index c115f1e..a293e2c 100644 (file)
@@ -176,7 +176,7 @@ public class TestFBOMRTNEWT01 extends UITestCase {
             texA1 = null;
             System.err.println("FBO supports only one attachment, no MRT available!");
         }
-        fbo_mrt.attachRenderbuffer(gl, Type.DEPTH, 24);
+        fbo_mrt.attachRenderbuffer(gl, Type.DEPTH, FBObject.CHOSEN_BITS);
         Assert.assertTrue( fbo_mrt.isStatusValid() ) ;
         fbo_mrt.unbind(gl);
 
index d99cba5..42f4c5f 100644 (file)
@@ -175,9 +175,9 @@ public class FBOMix2DemosES2 implements GLEventListener {
             fbo1Tex = fbo1.attachTexture2D(gl, 0, true);
         }
         numSamples=fbo0.getNumSamples();
-        fbo0.attachRenderbuffer(gl, Type.DEPTH, 24);
+        fbo0.attachRenderbuffer(gl, Type.DEPTH, FBObject.CHOSEN_BITS);
         fbo0.unbind(gl);
-        fbo1.attachRenderbuffer(gl, Type.DEPTH, 24);
+        fbo1.attachRenderbuffer(gl, Type.DEPTH, FBObject.CHOSEN_BITS);
         fbo1.unbind(gl);
     }
 
index 0660039..27395ea 100644 (file)
@@ -155,7 +155,7 @@ public class TextureDraw02ES2ListenerFBO implements GLEventListener {
             fbo0Tex = fbo0.attachTexture2D(gl, 0, true);
         }
         numSamples=fbo0.getNumSamples();
-        fbo0.attachRenderbuffer(gl, Type.DEPTH, 24);
+        fbo0.attachRenderbuffer(gl, Type.DEPTH, FBObject.CHOSEN_BITS);
         fbo0.unbind(gl);
     }
 
@@ -27,7 +27,9 @@
  */\r
 package com.jogamp.opengl.test.junit.jogl.demos.gl2.awt;\r
 \r
+import java.awt.ComponentOrientation;\r
 import java.awt.Dimension;\r
+import java.awt.GridLayout;\r
 import java.awt.event.WindowAdapter;\r
 import java.awt.event.WindowEvent;\r
 import java.io.InputStream;\r
@@ -47,6 +49,7 @@ import javax.media.opengl.fixedfunc.GLLightingFunc;
 import javax.media.opengl.fixedfunc.GLMatrixFunc;\r
 import javax.media.opengl.fixedfunc.GLPointerFunc;\r
 import javax.swing.JApplet;\r
+import javax.swing.JLabel;\r
 import javax.swing.JPanel;\r
 import javax.swing.JFrame;\r
 \r
@@ -57,7 +60,7 @@ import com.jogamp.opengl.util.texture.Texture;
 import com.jogamp.opengl.util.texture.TextureIO;\r
 \r
 /**\r
- * Bug 818: OSX GLJPanel Crash\r
+ * Bug 818: OSX GLJPanel [and GLCanvas] Crash\r
  * <pre>\r
  *   - NVIDIA GeForce GT 330M\r
  *     - GL_VENDOR: "NVIDIA Corporation"\r
@@ -66,7 +69,7 @@ import com.jogamp.opengl.util.texture.TextureIO;
  *   - Mac OSX 10.6.8\r
  * </pre>\r
  */\r
-public class Bug818GLJPanelApplet extends JApplet {\r
+public class Bug818GLJPanelAndGLCanvasApplet extends JApplet {\r
 \r
     private static final long serialVersionUID = 1L;\r
 \r
@@ -81,7 +84,7 @@ public class Bug818GLJPanelApplet extends JApplet {
   static public void main(final String args[]) {\r
     isApplet = false;\r
 \r
-    final JApplet myApplet = new Bug818GLJPanelApplet();\r
+    final JApplet myApplet = new Bug818GLJPanelAndGLCanvasApplet();\r
 \r
     appletHolder = new JPanel();\r
 \r
@@ -115,19 +118,25 @@ public class Bug818GLJPanelApplet extends JApplet {
     public void init() {\r
 \r
         final JPanel panel = new JPanel();\r
+        panel.setLayout(new GridLayout(2, 2));\r
+        System.err.println("Pre  Orientation L2R: "+panel.getComponentOrientation().isLeftToRight());\r
+        panel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);\r
+        System.err.println("Post Orientation L2R: "+panel.getComponentOrientation().isLeftToRight());\r
         setContentPane(panel);\r
-\r
-        final GLCanvas glCanvas = new GLCanvas();\r
-        glCanvas.addGLEventListener(new JOGLQuad(true));\r
-        animatorCanvas = new Animator(glCanvas);\r
-        glCanvas.setPreferredSize(new Dimension(300, 300));\r
-        panel.add(glCanvas);\r
+        panel.add(new JLabel("GLJPanel"));\r
+        panel.add(new JLabel("GLCanvas"));\r
 \r
         final GLJPanel gljPanel = new GLJPanel();\r
         gljPanel.addGLEventListener(new JOGLQuad(false));\r
         animatorPanel = new Animator(gljPanel);\r
         gljPanel.setPreferredSize(new Dimension(300, 300));\r
         panel.add(gljPanel);\r
+\r
+        final GLCanvas glCanvas = new GLCanvas();\r
+        glCanvas.addGLEventListener(new JOGLQuad(true));\r
+        animatorCanvas = new Animator(glCanvas);\r
+        glCanvas.setPreferredSize(new Dimension(300, 300));\r
+        panel.add(glCanvas);\r
     }\r
 \r
     @Override\r
@@ -271,7 +280,7 @@ public class Bug818GLJPanelApplet extends JApplet {
 \r
             // set the color of the quad\r
             if (canvas) {\r
-                gl.glColor3f(0.2f, 1.0f, 1.0f);\r
+                gl.glColor3f(0.2f, 0.2f, 1.0f);\r
             } else {\r
                 gl.glColor3f(1.0f, 0.2f, 0.2f);\r
             }\r
http://JogAmp.org git info: FAQ, tutorial and man pages.