diff options
Diffstat (limited to 'src/jogl')
5 files changed, 87 insertions, 46 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/FBObject.java b/src/jogl/classes/com/jogamp/opengl/FBObject.java index 7d0fcfa38..6f2ac3e35 100644 --- a/src/jogl/classes/com/jogamp/opengl/FBObject.java +++ b/src/jogl/classes/com/jogamp/opengl/FBObject.java @@ -835,6 +835,8 @@ public class FBObject { checkPreGLError(gl); + if( 0 >= width ) { width = 1; } + if( 0 >= height ) { height = 1; } this.width = width; this.height = height; this.samples = samples <= maxSamples ? samples : maxSamples; @@ -941,7 +943,7 @@ public class FBObject { * @throws GLException in case of an error, i.e. size too big, etc .. */ public final void reset(GL gl, int newWidth, int newHeight, int newSamples, boolean resetSamplingSink) { - if(!initialized) { + if( !initialized ) { init(gl, newWidth, newHeight, newSamples); return; } @@ -949,10 +951,10 @@ public class FBObject { newSamples = newSamples <= maxSamples ? newSamples : maxSamples; // clamp if( newWidth != width || newHeight != height || newSamples != samples ) { - if(0>=newWidth) { newWidth = 1; } - if(0>=newHeight) { newHeight = 1; } - if(newWidth > 2 + maxTextureSize || newHeight> 2 + maxTextureSize || - newWidth > maxRenderbufferSize || newHeight> maxRenderbufferSize ) { + if( 0 >= newWidth ) { newWidth = 1; } + if( 0 >= newHeight ) { newHeight = 1; } + if( newWidth > 2 + maxTextureSize || newHeight > 2 + maxTextureSize || + newWidth > maxRenderbufferSize || newHeight > maxRenderbufferSize ) { throw new GLException("size "+width+"x"+height+" exceeds on of the maxima [texture "+maxTextureSize+", renderbuffer "+maxRenderbufferSize+"]"); } diff --git a/src/jogl/classes/jogamp/opengl/GLBufferStateTracker.java b/src/jogl/classes/jogamp/opengl/GLBufferStateTracker.java index 4a1a81bcb..7f5316fbd 100644 --- a/src/jogl/classes/jogamp/opengl/GLBufferStateTracker.java +++ b/src/jogl/classes/jogamp/opengl/GLBufferStateTracker.java @@ -91,6 +91,7 @@ public class GLBufferStateTracker { bindingMap.setKeyNotFoundValue(0xFFFFFFFF); // Start with known unbound targets for known keys + // setBoundBufferObject(GL2GL3.GL_VERTEX_ARRAY_BINDING, 0); // not using default VAO (removed in GL3 core) - only explicit setBoundBufferObject(GL.GL_ARRAY_BUFFER, 0); setBoundBufferObject(GL.GL_ELEMENT_ARRAY_BUFFER, 0); setBoundBufferObject(GL2.GL_PIXEL_PACK_BUFFER, 0); @@ -120,6 +121,7 @@ public class GLBufferStateTracker { boolean gotQueryTarget = true; int queryTarget = 0; switch (target) { + case GL2GL3.GL_VERTEX_ARRAY_BINDING: queryTarget = GL2GL3.GL_VERTEX_ARRAY_BINDING; break; case GL.GL_ARRAY_BUFFER: queryTarget = GL.GL_ARRAY_BUFFER_BINDING; break; case GL.GL_ELEMENT_ARRAY_BUFFER: queryTarget = GL.GL_ELEMENT_ARRAY_BUFFER_BINDING; break; case GL2.GL_PIXEL_PACK_BUFFER: queryTarget = GL2.GL_PIXEL_PACK_BUFFER_BINDING; break; diff --git a/src/jogl/classes/jogamp/opengl/GLContextImpl.java b/src/jogl/classes/jogamp/opengl/GLContextImpl.java index 0d8b193af..9f7c9cf57 100644 --- a/src/jogl/classes/jogamp/opengl/GLContextImpl.java +++ b/src/jogl/classes/jogamp/opengl/GLContextImpl.java @@ -342,23 +342,24 @@ public abstract class GLContextImpl extends GLContext { @Override public final void destroy() { - if ( null == drawable ) { - throw new GLException("Drawable is null: "+toString()); - } if ( DEBUG_TRACE_SWITCH ) { + final long drawH = null != drawable ? drawable.getHandle() : 0; System.err.println(getThreadName() + ": GLContextImpl.destroy.0: obj " + toHexString(hashCode()) + ", ctx " + toHexString(contextHandle) + - ", surf "+toHexString(drawable.getHandle())+", isShared "+GLContextShareSet.isShared(this)+" - "+lock); + ", surf "+toHexString(drawH)+", isShared "+GLContextShareSet.isShared(this)+" - "+lock); } - if ( 0 != contextHandle ) { + if ( 0 != contextHandle ) { // isCreated() ? + if ( null == drawable ) { + throw new GLException("GLContext created but drawable is null: "+toString()); + } final int lockRes = drawable.lockSurface(); if ( NativeSurface.LOCK_SURFACE_NOT_READY >= lockRes ) { // this would be odd .. throw new GLException("Surface not ready to lock: "+drawable); } - Throwable drawableContextRealizedException = null; + Throwable associateDrawableException = null; try { if ( !drawable.isRealized() ) { - throw new GLException("Drawable not realized: "+toString()); + throw new GLException("GLContext created but drawable not realized: "+toString()); } // Must hold the lock around the destroy operation to make sure we // don't destroy the context while another thread renders to it. @@ -380,7 +381,7 @@ public abstract class GLContextImpl extends GLContext { try { associateDrawable(false); } catch (Throwable t) { - drawableContextRealizedException = t; + associateDrawableException = t; } if ( 0 != defaultVAO ) { int[] tmp = new int[] { defaultVAO }; @@ -410,8 +411,8 @@ public abstract class GLContextImpl extends GLContext { } finally { drawable.unlockSurface(); } - if(null != drawableContextRealizedException) { - throw new GLException("GLContext.destroy() during GLDrawableImpl.contextRealized(this, false)", drawableContextRealizedException); + if( null != associateDrawableException ) { + throw new GLException("GLContext.destroy() during associateDrawable(false)", associateDrawableException); } } resetStates(); @@ -601,6 +602,13 @@ public abstract class GLContextImpl extends GLContext { private final int makeCurrentWithinLock(int surfaceLockRes) throws GLException { if (!isCreated()) { + if( 0 >= drawable.getWidth() || 0 >= drawable.getHeight() ) { + if ( DEBUG_TRACE_SWITCH ) { + System.err.println(getThreadName() + ": Create GL context REJECTED (zero surface size) obj " + toHexString(hashCode()) + ", surf "+toHexString(drawable.getHandle())+" for " + getClass().getName()); + System.err.println(drawable.toString()); + } + return CONTEXT_NOT_CURRENT; + } if(DEBUG_GL) { // only impacts w/ createContextARB(..) additionalCtxCreationFlags |= GLContext.CTX_OPTION_DEBUG ; @@ -1782,6 +1790,10 @@ public abstract class GLContextImpl extends GLContext { public final GLStateTracker getGLStateTracker() { return glStateTracker; } + + public final boolean isDefaultVAO(int vao) { + return defaultVAO == vao; + } //--------------------------------------------------------------------------- // Helpers for context optimization where the last context is left diff --git a/src/jogl/classes/jogamp/opengl/GLFBODrawableImpl.java b/src/jogl/classes/jogamp/opengl/GLFBODrawableImpl.java index ac10e2728..85f63b52c 100644 --- a/src/jogl/classes/jogamp/opengl/GLFBODrawableImpl.java +++ b/src/jogl/classes/jogamp/opengl/GLFBODrawableImpl.java @@ -335,16 +335,17 @@ public class GLFBODrawableImpl extends GLDrawableImpl implements GLFBODrawable { protected final void contextMadeCurrent(GLContext glc, boolean current) { final GL gl = glc.getGL(); if(current) { + if( !initialized ) { + throw new GLException("Not initialized: "+this); + } fbos[fboIBack].bind(gl); fboBound = true; - } else { - if(fboBound) { - swapFBOImpl(glc); - swapFBOImplPost(glc); - fboBound=false; - if(DEBUG_SWAP) { - System.err.println("Post FBO swap(@release): done"); - } + } else if( fboBound ) { + swapFBOImpl(glc); + swapFBOImplPost(glc); + fboBound=false; + if(DEBUG_SWAP) { + System.err.println("Post FBO swap(@release): done"); } } } @@ -353,17 +354,15 @@ public class GLFBODrawableImpl extends GLDrawableImpl implements GLFBODrawable { protected void swapBuffersImpl(boolean doubleBuffered) { final GLContext ctx = GLContext.getCurrent(); boolean doPostSwap = false; - if(null!=ctx && ctx.getGLDrawable()==this) { - if(fboBound) { - swapFBOImpl(ctx); - doPostSwap = true; - fboBound=false; - if(DEBUG_SWAP) { - System.err.println("Post FBO swap(@swap): done"); - } + if( null != ctx && ctx.getGLDrawable() == this && fboBound ) { + swapFBOImpl(ctx); + doPostSwap = true; + fboBound=false; + if(DEBUG_SWAP) { + System.err.println("Post FBO swap(@swap): done"); } } - if(null != swapBufferContext) { + if( null != swapBufferContext ) { swapBufferContext.swapBuffers(doubleBuffered); } if(doPostSwap) { diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java index a197bd51f..6cab369cf 100644 --- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java @@ -622,7 +622,7 @@ public abstract class MacOSXCGLContext extends GLContextImpl * Hence this method blocks the main-thread only for a short period of time. * </p> */ - class AttachNSOpenGLLayer implements Runnable { + class AttachGLLayerCmd implements Runnable { final OffscreenLayerSurface ols; final long ctx; final int shaderProgram; @@ -637,7 +637,7 @@ public abstract class MacOSXCGLContext extends GLContextImpl /** Synchronized by instance's monitor */ boolean valid; - AttachNSOpenGLLayer(OffscreenLayerSurface ols, long ctx, int shaderProgram, long pfmt, long pbuffer, int texID, boolean isOpaque, int width, int height) { + AttachGLLayerCmd(OffscreenLayerSurface ols, long ctx, int shaderProgram, long pfmt, long pbuffer, int texID, boolean isOpaque, int width, int height) { this.ols = ols; this.ctx = ctx; this.shaderProgram = shaderProgram; @@ -651,6 +651,15 @@ public abstract class MacOSXCGLContext extends GLContextImpl this.nsOpenGLLayer = 0; } + public final String contentToString() { + return "valid "+valid+", size "+width+"x"+height+", ctx "+toHexString(ctx)+", opaque "+isOpaque+", texID "+texID+", pbuffer "+toHexString(pbuffer)+", nsOpenGLLayer "+toHexString(nsOpenGLLayer); + } + + @Override + public final String toString() { + return "AttachGLLayerCmd["+contentToString()+"]"; + } + @Override public void run() { synchronized(this) { @@ -693,14 +702,20 @@ public abstract class MacOSXCGLContext extends GLContextImpl } } } - AttachNSOpenGLLayer attachCALayerCmd = null; + AttachGLLayerCmd attachGLLayerCmd = null; - class DetachNSOpenGLLayer implements Runnable { - final AttachNSOpenGLLayer cmd; + class DetachGLLayerCmd implements Runnable { + final AttachGLLayerCmd cmd; - DetachNSOpenGLLayer(AttachNSOpenGLLayer cmd) { + DetachGLLayerCmd(AttachGLLayerCmd cmd) { this.cmd = cmd; } + + @Override + public final String toString() { + return "DetachGLLayerCmd["+cmd.contentToString()+"]"; + } + @Override public void run() { synchronized( cmd ) { @@ -734,7 +749,8 @@ public abstract class MacOSXCGLContext extends GLContextImpl backingLayerHost = NativeWindowFactory.getOffscreenLayerSurface(drawable.getNativeSurface(), true); if(DEBUG) { - System.err.println("MaxOSXCGLContext.NSOpenGLImpl.associateDrawable: "+bound+", ctx "+toHexString(contextHandle)+", hasBackingLayerHost "+(null!=backingLayerHost)); + System.err.println("MaxOSXCGLContext.NSOpenGLImpl.associateDrawable: "+bound+", ctx "+toHexString(contextHandle)+ + ", hasBackingLayerHost "+(null!=backingLayerHost)+", attachGLLayerCmd "+attachGLLayerCmd); // Thread.dumpStack(); } @@ -785,10 +801,13 @@ public abstract class MacOSXCGLContext extends GLContextImpl } // All CALayer lifecycle ops are deferred on main-thread - attachCALayerCmd = new AttachNSOpenGLLayer( + attachGLLayerCmd = new AttachGLLayerCmd( backingLayerHost, ctx, gl3ShaderProgramName, pixelFormat, pbufferHandle, texID, chosenCaps.isBackgroundOpaque(), lastWidth, lastHeight ); - OSXUtil.RunOnMainThread(false, attachCALayerCmd); + if(DEBUG) { + System.err.println("MaxOSXCGLContext.NSOpenGLImpl.associateDrawable(true): "+attachGLLayerCmd); + } + OSXUtil.RunOnMainThread(false, attachGLLayerCmd); } else { // -> null == backingLayerHost lastWidth = drawable.getWidth(); lastHeight = drawable.getHeight(); @@ -798,8 +817,11 @@ public abstract class MacOSXCGLContext extends GLContextImpl } } else { // -> !bound if( null != backingLayerHost ) { - final AttachNSOpenGLLayer cmd = attachCALayerCmd; - attachCALayerCmd = null; + final AttachGLLayerCmd cmd = attachGLLayerCmd; + attachGLLayerCmd = null; + if( null == cmd ) { + throw new GLException("Null attachGLLayerCmd: "+drawable); + } if( 0 != cmd.pbuffer ) { CGL.setContextPBuffer(contextHandle, 0); } @@ -808,7 +830,11 @@ public abstract class MacOSXCGLContext extends GLContextImpl cmd.valid = true; // skip pending creation } else { // All CALayer lifecycle ops are deferred on main-thread - OSXUtil.RunOnMainThread(false, new DetachNSOpenGLLayer(cmd)); + final DetachGLLayerCmd dCmd = new DetachGLLayerCmd(cmd); + if(DEBUG) { + System.err.println("MaxOSXCGLContext.NSOpenGLImpl.associateDrawable(false): "+dCmd); + } + OSXUtil.RunOnMainThread(false, dCmd); if( null != gl3ShaderProgram ) { gl3ShaderProgram.destroy(MacOSXCGLContext.this.gl.getGL3()); gl3ShaderProgram = null; @@ -903,7 +929,7 @@ public abstract class MacOSXCGLContext extends GLContextImpl @Override public boolean setSwapInterval(int interval) { - final AttachNSOpenGLLayer cmd = attachCALayerCmd; + final AttachGLLayerCmd cmd = attachGLLayerCmd; if(null != cmd) { synchronized(cmd) { if( cmd.valid && 0 != cmd.nsOpenGLLayer) { @@ -932,7 +958,7 @@ public abstract class MacOSXCGLContext extends GLContextImpl @Override public boolean swapBuffers() { - final AttachNSOpenGLLayer cmd = attachCALayerCmd; + final AttachGLLayerCmd cmd = attachGLLayerCmd; if(null != cmd) { synchronized(cmd) { if( cmd.valid && 0 != cmd.nsOpenGLLayer) { |