From e99f5060d62aad25fcc37ebf50c8f2a270c9d5df Mon Sep 17 00:00:00 2001
From: Sven Gothel
- * 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. *
** Use {@link #getDepthAttachment()} and/or {@link #getStencilAttachment()} to retrieve details @@ -1623,68 +1687,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) { diff --git a/src/jogl/classes/com/jogamp/opengl/util/stereo/StereoClientRenderer.java b/src/jogl/classes/com/jogamp/opengl/util/stereo/StereoClientRenderer.java index 8b00aefb7..f70ebf928 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/stereo/StereoClientRenderer.java +++ b/src/jogl/classes/com/jogamp/opengl/util/stereo/StereoClientRenderer.java @@ -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]); -- cgit v1.2.3