From 2120be14c7525ef051d105f9bb02294f78d17d28 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 23 Jan 2015 22:03:45 +0100 Subject: Bug 1068 - Unify Surfaceless probing; Fix Surfaceless for OSX and Windows (probing, etc) - Unify surfaceless probing GLDrawableFactoryImpl.probeSurfacelessCtx(..) implements surfaceless probing for all platforms - Fix Surfaceless for OSX (probing, etc) - Handle 'surfaceless' mode in MacOSXCGLContext impl - MacOSXCGLDrawableFactory.getOrCreateSharedResourceImpl adds surfaceless probing - Fix Surfaceless for Windows (probing, etc) - WindowsWGLContext.wglMakeContextCurrent(..) - Split release code into WindowsWGLContext.wglReleaseContext(..) allowing to handle zero HDC. - WindowsWGLGraphicsConfigurationFactory.updateGraphicsConfiguration(..) - Skip HDC -> PFD handling for - WindowsWGLDrawableFactory.createSharedResource adds surfaceless probing --- .../jogamp/opengl/egl/EGLDrawableFactory.java | 123 ++++++++++----------- 1 file changed, 56 insertions(+), 67 deletions(-) (limited to 'src/jogl/classes/jogamp/opengl/egl') diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java index 37e061367..acff455a6 100644 --- a/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java +++ b/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java @@ -632,7 +632,6 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { NativeSurface surface = null; ProxySurface upstreamSurface = null; // X11, GLX, .. ProxySurface downstreamSurface = null; // EGL - boolean allowsSurfacelessCtx = false; boolean success = false; try { final GLCapabilities reqCapsAny = new GLCapabilities(glp); @@ -718,80 +717,70 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { } if(null != surface) { - GLDrawableImpl zeroDrawable = null; - final EGLDrawable drawable = (EGLDrawable) createOnscreenDrawableImpl ( surface ); - drawable.setRealized(true); - final EGLContext context = (EGLContext) drawable.createContext(null); - if (null != context) { - try { - if( GLContext.CONTEXT_NOT_CURRENT != context.makeCurrent() ) { // could cause exception - // context.isCurrent() ! - final String glVersionString = context.getGL().glGetString(GL.GL_VERSION); - if(null != glVersionString) { - context.mapCurrentAvailableGLESVersion(eglDevice); - if(eglDevice != adevice) { - context.mapCurrentAvailableGLESVersion(adevice); - } + EGLDrawable drawable = null; + GLDrawable zeroDrawable = null; + EGLContext context = null; + try { + drawable = (EGLDrawable) createOnscreenDrawableImpl ( surface ); + drawable.setRealized(true); + + context = (EGLContext) drawable.createContext(null); + if (null == context) { + throw new GLException("Couldn't create shared context for drawable: "+drawable); + } - if( eglFeatures.hasKHRSurfaceless && - !context.hasRendererQuirk(GLRendererQuirks.NoSurfacelessCtx) ) - { - try { - final ProxySurface zeroSurface = createSurfacelessImpl(eglDevice, true, reqCapsAny, reqCapsAny, null, 64, 64); - zeroDrawable = createOnscreenDrawableImpl(zeroSurface); - zeroDrawable.setRealized(true); - - // Since sharedContext is still current, - // will keep sharedContext current w/ zeroDrawable or throws GLException - context.setGLDrawable(zeroDrawable, false); - allowsSurfacelessCtx = true; // if setGLDrawable is successful, i.e. no GLException - - // no switch back, will be destroyed anyways - // context.setGLDrawable(drawable, false); - } catch (final Throwable t) { - if( DEBUG ) { - ExceptionUtils.dumpThrowable("", t); - } - } - } - if( !allowsSurfacelessCtx ) { - final int quirk = GLRendererQuirks.NoSurfacelessCtx; - if(DEBUG) { - System.err.println("Quirk: "+GLRendererQuirks.toString(quirk)+" -> "+eglDevice+": cause: probe"); - } - final GLRendererQuirks glrq = context.getRendererQuirks(); - if( null != glrq ) { - glrq.addQuirk(quirk); - } - GLRendererQuirks.addStickyDeviceQuirk(eglDevice, quirk); - } - rendererQuirks[0] = context.getRendererQuirks(); - ctxProfile[0] = context.getContextOptions(); - majorVersion[0] = context.getGLVersionNumber().getMajor(); - minorVersion[0] = context.getGLVersionNumber().getMinor(); - success = true; - } else { - // Oops .. something is wrong - if(DEBUG) { - System.err.println("EGLDrawableFactory.mapAvailableEGLESConfig: "+eglDevice+", "+context.getGLVersion()+" - VERSION is null, dropping availability!"); + if( GLContext.CONTEXT_NOT_CURRENT != context.makeCurrent() ) { // could cause exception + // context.isCurrent() ! + final String glVersionString = context.getGL().glGetString(GL.GL_VERSION); + if(null != glVersionString) { + context.mapCurrentAvailableGLESVersion(eglDevice); + if(eglDevice != adevice) { + context.mapCurrentAvailableGLESVersion(adevice); + } + + if( eglFeatures.hasKHRSurfaceless && + ( context.isGLES() || context.getGLVersionNumber().compareTo(GLContext.Version3_0) >= 0 ) + ) + { + if( probeSurfacelessCtx(context, false /* restoreDrawable */) ) { + zeroDrawable = context.getGLDrawable(); } } + rendererQuirks[0] = context.getRendererQuirks(); + ctxProfile[0] = context.getContextOptions(); + majorVersion[0] = context.getGLVersionNumber().getMajor(); + minorVersion[0] = context.getGLVersionNumber().getMinor(); + success = true; + } else { + // Oops .. something is wrong + if ( DEBUG_SHAREDCTX ) { + System.err.println("EGLDrawableFactory.mapAvailableEGLESConfig: "+eglDevice+", "+context.getGLVersion()+" - VERSION is null, dropping availability!"); + } } - } catch (final Throwable t) { - if (DEBUG) { - System.err.println("EGLDrawableFactory.mapAvailableEGLESConfig: INFO: context create/makeCurrent failed"); - t.printStackTrace(); - } - } finally { - if( context.isCreated() ) { + } + } catch (final Throwable t) { + if ( DEBUG_SHAREDCTX ) { + System.err.println("EGLDrawableFactory.mapAvailableEGLESConfig: INFO: context create/makeCurrent failed"); + t.printStackTrace(); + } + } finally { + if( null != context ) { + try { context.destroy(); + } catch (final GLException gle) { + if ( DEBUG_SHAREDCTX ) { + System.err.println("EGLDrawableFactory.mapAvailableEGLESConfig: INFO: destroy caught exception:"); + gle.printStackTrace(); + } } } + if( null != zeroDrawable ) { + zeroDrawable.setRealized(false); + } + if( null != drawable ) { + drawable.setRealized(false); + } } - if( null != zeroDrawable ) { - zeroDrawable.setRealized(false); - } - drawable.setRealized(false); } } catch (final Throwable t) { if ( DEBUG_SHAREDCTX ) { -- cgit v1.2.3