diff options
author | Sven Gothel <[email protected]> | 2015-01-23 22:03:45 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2015-01-23 22:03:45 +0100 |
commit | 2120be14c7525ef051d105f9bb02294f78d17d28 (patch) | |
tree | 7ee43c5ce7253fa85b75a417ae9279301867e484 /src/jogl/classes/jogamp/opengl/windows/wgl | |
parent | 474ada7c9fa2c9e47232abfde66353af58ea35f2 (diff) |
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
Diffstat (limited to 'src/jogl/classes/jogamp/opengl/windows/wgl')
3 files changed, 76 insertions, 38 deletions
diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java index 4edd080d2..c9d78b116 100644 --- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java @@ -51,7 +51,6 @@ import javax.media.nativewindow.NativeSurface; import javax.media.opengl.GLContext; import javax.media.opengl.GLException; import javax.media.opengl.GLCapabilitiesImmutable; -import javax.media.opengl.GLProfile; import com.jogamp.common.nio.Buffers; import com.jogamp.gluegen.runtime.ProcAddressTable; @@ -152,17 +151,34 @@ public class WindowsWGLContext extends GLContextImpl { // should not happen due to 'isGLReadDrawableAvailable()' query in GLContextImpl throw new InternalError("Given readDrawable but no driver support"); } - final int werr = ( !ok ) ? GDI.GetLastError() : GDI.ERROR_SUCCESS; if(DEBUG && !ok) { - final Throwable t = new Throwable ("Info: wglMakeContextCurrent draw "+ + final Throwable t = new Throwable ("Info: wglMakeContextCurrent NOK: draw "+ GLContext.toHexString(hDrawDC) + ", read " + GLContext.toHexString(hReadDC) + - ", ctx " + GLContext.toHexString(ctx) + ", werr " + werr); + ", ctx " + GLContext.toHexString(ctx) + ", werr " + GDI.GetLastError()); t.printStackTrace(); } - if(!ok && 0==hDrawDC && 0==hReadDC) { + return ok; + } + + private final boolean wglReleaseContext(final long ctx) { + boolean ok = false; + if(wglGLReadDrawableAvailable) { + // needs initilized WGL ProcAddress table + ok = getWGLExt().wglMakeContextCurrent(0, 0, ctx); + } else { + ok = WGL.wglMakeCurrent(0, ctx); + } + if( !ok ) { + final int werr = GDI.GetLastError(); + final boolean ok2 = werr == GDI.ERROR_SUCCESS; + if(DEBUG) { + final Throwable t = new Throwable ("Info: wglReleaseContext NOK: ctx " + GLContext.toHexString(ctx) + + ", werr " + werr + " -> ok "+ok2); + t.printStackTrace(); + } // Some GPU's falsely fails with a zero error code (success), // in case this is a release context request we tolerate this - return werr == GDI.ERROR_SUCCESS ; + return ok2 ; } return ok; } @@ -414,7 +430,7 @@ public class WindowsWGLContext extends GLContextImpl { @Override protected void releaseImpl() throws GLException { - if (!wglMakeContextCurrent(0, 0, 0)) { + if (!wglReleaseContext(0)) { throw new GLException("Error freeing OpenGL context, werr: " + GDI.GetLastError()); } } diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java index 7b14a03c8..1f7e652b6 100644 --- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java @@ -326,53 +326,70 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { } @Override - public SharedResourceRunner.Resource createSharedResource(final AbstractGraphicsDevice device) { - final WindowsGraphicsDevice sharedDevice = new WindowsGraphicsDevice(device.getConnection(), device.getUnitID()); - sharedDevice.lock(); + public SharedResourceRunner.Resource createSharedResource(final AbstractGraphicsDevice adevice) { + final WindowsGraphicsDevice device = new WindowsGraphicsDevice(adevice.getConnection(), adevice.getUnitID()); + GLContextImpl context = null; + boolean contextIsCurrent = false; + device.lock(); try { - final AbstractGraphicsScreen absScreen = new DefaultGraphicsScreen(sharedDevice, 0); - final GLProfile glp = GLProfile.get(sharedDevice, GLProfile.GL_PROFILE_LIST_MIN_DESKTOP, false); + final AbstractGraphicsScreen absScreen = new DefaultGraphicsScreen(device, 0); + final GLProfile glp = GLProfile.get(device, GLProfile.GL_PROFILE_LIST_MIN_DESKTOP, false); if (null == glp) { - throw new GLException("Couldn't get default GLProfile for device: "+sharedDevice); + throw new GLException("Couldn't get default GLProfile for device: "+device); } final GLCapabilitiesImmutable caps = new GLCapabilities(glp); - final GLDrawableImpl sharedDrawable = createOnscreenDrawableImpl(createDummySurfaceImpl(sharedDevice, false, caps, caps, null, 64, 64)); - sharedDrawable.setRealized(true); + final GLDrawableImpl drawable = createOnscreenDrawableImpl(createDummySurfaceImpl(device, false, caps, caps, null, 64, 64)); + drawable.setRealized(true); - final GLContextImpl sharedContext = (GLContextImpl) sharedDrawable.createContext(null); - if (null == sharedContext) { - throw new GLException("Couldn't create shared context for drawable: "+sharedDrawable); + context = (GLContextImpl) drawable.createContext(null); + if (null == context) { + throw new GLException("Couldn't create shared context for drawable: "+drawable); } - boolean hasARBPixelFormat; - boolean hasARBMultisample; - boolean hasARBPBuffer; - boolean hasARBReadDrawableAvailable; - sharedContext.makeCurrent(); - try { - hasARBPixelFormat = sharedContext.isExtensionAvailable(WGL_ARB_pixel_format); - hasARBMultisample = sharedContext.isExtensionAvailable(WGL_ARB_multisample); - hasARBPBuffer = sharedContext.isExtensionAvailable(GLExtensions.ARB_pbuffer); - hasARBReadDrawableAvailable = sharedContext.isExtensionAvailable(WGL_ARB_make_current_read) && - sharedContext.isFunctionAvailable(wglMakeContextCurrent); - } finally { - sharedContext.release(); + contextIsCurrent = GLContext.CONTEXT_NOT_CURRENT != context.makeCurrent(); + + final boolean allowsSurfacelessCtx; + final boolean hasARBPixelFormat; + final boolean hasARBMultisample; + final boolean hasARBPBuffer; + final boolean hasARBReadDrawableAvailable; + if( contextIsCurrent ) { + if( context.getGLVersionNumber().compareTo(GLContext.Version3_0) >= 0 ) { + allowsSurfacelessCtx = probeSurfacelessCtx(context, true /* restoreDrawable */); + } else { + allowsSurfacelessCtx = false; + } + hasARBPixelFormat = context.isExtensionAvailable(WGL_ARB_pixel_format); + hasARBMultisample = context.isExtensionAvailable(WGL_ARB_multisample); + hasARBPBuffer = context.isExtensionAvailable(GLExtensions.ARB_pbuffer); + hasARBReadDrawableAvailable = context.isExtensionAvailable(WGL_ARB_make_current_read) && + context.isFunctionAvailable(wglMakeContextCurrent); + } else { + allowsSurfacelessCtx = false; + hasARBPixelFormat = false; + hasARBMultisample = false; + hasARBPBuffer = false; + hasARBReadDrawableAvailable = false; } - if (DEBUG) { - System.err.println("SharedDevice: " + sharedDevice); + if ( DEBUG_SHAREDCTX ) { + System.err.println("SharedDevice: " + device); System.err.println("SharedScreen: " + absScreen); - System.err.println("SharedContext: " + sharedContext); + System.err.println("SharedContext: " + context + ", madeCurrent " + contextIsCurrent); + System.err.println(" allowsSurfacelessCtx "+allowsSurfacelessCtx); System.err.println("pixelformat: " + hasARBPixelFormat); System.err.println("multisample: " + hasARBMultisample); System.err.println("pbuffer: " + hasARBPBuffer); System.err.println("readDrawable: " + hasARBReadDrawableAvailable); } - return new SharedResource(sharedDevice, absScreen, sharedDrawable, sharedContext, + return new SharedResource(device, absScreen, drawable, context, hasARBPixelFormat, hasARBMultisample, hasARBPBuffer, hasARBReadDrawableAvailable); } catch (final Throwable t) { - throw new GLException("WindowsWGLDrawableFactory - Could not initialize shared resources for "+device, t); + throw new GLException("WindowsWGLDrawableFactory - Could not initialize shared resources for "+adevice, t); } finally { - sharedDevice.unlock(); + if ( contextIsCurrent ) { + context.release(); + } + device.unlock(); } } diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java index 7c387827a..b688b288c 100644 --- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java @@ -42,6 +42,7 @@ import javax.media.nativewindow.GraphicsConfigurationFactory; import javax.media.nativewindow.CapabilitiesImmutable; import javax.media.nativewindow.NativeSurface; import javax.media.nativewindow.NativeWindowFactory; +import javax.media.nativewindow.ProxySurface; import javax.media.nativewindow.VisualIDHolder; import javax.media.opengl.GLCapabilitiesImmutable; import javax.media.opengl.GLCapabilitiesChooser; @@ -222,7 +223,11 @@ public class WindowsWGLGraphicsConfigurationFactory extends GLGraphicsConfigurat try { final long hdc = ns.getSurfaceHandle(); if (0 == hdc) { - throw new GLException("Error: HDC is null"); + if( !(ns instanceof ProxySurface) || + !((ProxySurface)ns).containsUpstreamOptionBits( ProxySurface.OPT_UPSTREAM_SURFACELESS ) ) { + throw new GLException(String.format("non-surfaceless drawable has zero-handle (HDC): %s", ns.toString())); + } + return; // NOP .. will reach ns.unlockSurface() } final WindowsWGLGraphicsConfiguration config = (WindowsWGLGraphicsConfiguration) ns.getGraphicsConfiguration(); |