From 7da8654b49aa3ddd01fbc64a710b5efe04529381 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 20 Sep 2012 19:03:26 +0200 Subject: GLFBODrawableImpl: Fix garbage @ swap, add [disabled] reset-quirk for testing Fix garbage @ swap: Reset the front buffer _after_ swap. Add [disabled] reset-quirk for testing: On some OSX GPUs (old NV 7xxx only ?), reconfig/resize of FBO fails, recreate whole FBO w/ quirk enabled. --- .../classes/jogamp/opengl/GLFBODrawableImpl.java | 65 ++++++++++++++++------ 1 file changed, 48 insertions(+), 17 deletions(-) (limited to 'src/jogl/classes/jogamp') diff --git a/src/jogl/classes/jogamp/opengl/GLFBODrawableImpl.java b/src/jogl/classes/jogamp/opengl/GLFBODrawableImpl.java index de45466f3..d7de7ca50 100644 --- a/src/jogl/classes/jogamp/opengl/GLFBODrawableImpl.java +++ b/src/jogl/classes/jogamp/opengl/GLFBODrawableImpl.java @@ -46,7 +46,7 @@ public class GLFBODrawableImpl extends GLDrawableImpl implements GLFBODrawable { private FBObject[] fbos; private int fboIBack; // points to GL_BACK buffer private int fboIFront; // points to GL_FRONT buffer - private FBObject pendingFBOReset = null; + private int pendingFBOReset = -1; private boolean fboBound; private static final int bufferCount = 2; // number of FBOs for double buffering. TODO: Possible to configure! @@ -132,7 +132,7 @@ public class GLFBODrawableImpl extends GLDrawableImpl implements GLFBODrawable { } fbos=null; fboBound = false; - pendingFBOReset = null; + pendingFBOReset = -1; } if(DEBUG) { System.err.println("GLFBODrawableImpl.initialize("+realize+"): "+this); @@ -144,13 +144,34 @@ public class GLFBODrawableImpl extends GLDrawableImpl implements GLFBODrawable { swapBufferContext = sbc; } - private static final void reset(GL gl, FBObject fbo, int fboIdx, int width, int height, int samples) { - fbo.reset(gl, width, height, samples); // implicit glClear(..) - if(fbo.getNumSamples() != samples) { - throw new InternalError("Sample number mismatch: "+samples+", fbos["+fboIdx+"] "+fbo); - } - } + static final boolean FBOResetQuirk = false; + private final void reset(GL gl, int idx, int width, int height, int samples, int alphaBits, int stencilBits) { + if( !FBOResetQuirk ) { + fbos[idx].reset(gl, width, height, samples); // implicit glClear(..) + if(fbos[idx].getNumSamples() != samples) { + throw new InternalError("Sample number mismatch: "+samples+", fbos["+idx+"] "+fbos[idx]); + } + } else { + fbos[idx].destroy(gl); + fbos[idx] = new FBObject(); + fbos[idx].reset(gl, getWidth(), getHeight(), samples); + if(fbos[idx].getNumSamples() != samples) { + throw new InternalError("Sample number mismatch: "+samples+", fbos["+idx+"] "+fbos[idx]); + } + if(samples > 0) { + fbos[idx].attachColorbuffer(gl, 0, alphaBits>0); + } else { + fbos[idx].attachTexture2D(gl, 0, alphaBits>0); + } + if( stencilBits > 0 ) { + fbos[idx].attachRenderbuffer(gl, Attachment.Type.DEPTH_STENCIL, 24); + } else { + fbos[idx].attachRenderbuffer(gl, Attachment.Type.DEPTH, 24); + } + } + } + private final void reset(GL gl, int newSamples) throws GLException { if(!initialized) { // NOP if not yet initializes @@ -187,10 +208,11 @@ public class GLFBODrawableImpl extends GLDrawableImpl implements GLFBODrawable { final int nWidth = getWidth(); final int nHeight = getHeight(); samples = newSamples; - pendingFBOReset = ( 1 < fbos.length ) ? fbos[fboIFront] : null; // pending-front reset only w/ double buffering (or zero samples) + pendingFBOReset = ( 1 < fbos.length ) ? fboIFront : -1; // pending-front reset only w/ double buffering (or zero samples) + final GLCapabilitiesImmutable caps = (GLCapabilitiesImmutable) surface.getGraphicsConfiguration().getChosenCapabilities(); for(int i=0; i