aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/jogamp/opengl
diff options
context:
space:
mode:
Diffstat (limited to 'src/jogl/classes/jogamp/opengl')
-rw-r--r--src/jogl/classes/jogamp/opengl/GLContextImpl.java2
-rw-r--r--src/jogl/classes/jogamp/opengl/GLDrawableFactoryImpl.java67
-rw-r--r--src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java123
-rw-r--r--src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java27
-rw-r--r--src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java107
-rw-r--r--src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java30
-rw-r--r--src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java77
-rw-r--r--src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java7
-rw-r--r--src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java75
9 files changed, 306 insertions, 209 deletions
diff --git a/src/jogl/classes/jogamp/opengl/GLContextImpl.java b/src/jogl/classes/jogamp/opengl/GLContextImpl.java
index bc0603268..1868baaca 100644
--- a/src/jogl/classes/jogamp/opengl/GLContextImpl.java
+++ b/src/jogl/classes/jogamp/opengl/GLContextImpl.java
@@ -531,6 +531,8 @@ public abstract class GLContextImpl extends GLContext {
//----------------------------------------------------------------------
//
+ protected final boolean isSurfacelessOK() { return surfacelessOK; }
+
/**
* {@inheritDoc}
* <p>
diff --git a/src/jogl/classes/jogamp/opengl/GLDrawableFactoryImpl.java b/src/jogl/classes/jogamp/opengl/GLDrawableFactoryImpl.java
index 5078afd78..65f5f444f 100644
--- a/src/jogl/classes/jogamp/opengl/GLDrawableFactoryImpl.java
+++ b/src/jogl/classes/jogamp/opengl/GLDrawableFactoryImpl.java
@@ -88,6 +88,73 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory {
}
/**
+ * Returns {@code true} if context is capable of operating without a surface,
+ * otherwise returns {@code false} and sets the {@link GLRendererQuirks#NoSurfacelessCtx}.
+ * <p>
+ * Method will skip probing in case {@link GLRendererQuirks#NoSurfacelessCtx} has been already set.
+ * </p>
+ * <p>
+ * Caller shall skip probing in case surfaceless support is not possible,
+ * e.g. OpenGL ES without {@code EGL_KHR_surfaceless_context} or EGL &lt; 1.5,
+ * or desktop OpenGL context &lt; 3.0.
+ * </p>
+ *
+ * @param context the context to probe, must be current
+ * @param restoreDrawable If {@code true}, the initial drawable will be restored after probing
+ * and the temporary {@code zeroDrawable} will be released.
+ * If {@code false}, the temporary {@code zeroDrawable} will be kept (bound) to the context.
+ * Restoration may be skipped, if the drawable and context will be destroyed anyways.
+ *
+ * @see GLRendererQuirks#NoSurfacelessCtx
+ */
+ protected final boolean probeSurfacelessCtx(final GLContext context, final boolean restoreDrawable) {
+ final GLDrawable origDrawable = context.getGLDrawable();
+ final AbstractGraphicsDevice device = origDrawable.getNativeSurface().getGraphicsConfiguration().getScreen().getDevice();
+
+ final boolean noSurfacelessCtxQuirk = context.hasRendererQuirk(GLRendererQuirks.NoSurfacelessCtx);
+ boolean allowsSurfacelessCtx = false;
+
+ if( !noSurfacelessCtxQuirk ) {
+ GLDrawable zeroDrawable = null;
+ try {
+ final GLCapabilitiesImmutable caps = origDrawable.getRequestedGLCapabilities();
+ final ProxySurface zeroSurface = createSurfacelessImpl(device, true, caps, caps, null, 64, 64);
+ zeroDrawable = createOnscreenDrawableImpl(zeroSurface);
+ zeroDrawable.setRealized(true);
+
+ // Since context is still current,
+ // will keep context current w/ zeroDrawable or throws GLException
+ context.setGLDrawable(zeroDrawable, false);
+ allowsSurfacelessCtx = true; // if setGLDrawable is successful, i.e. no GLException
+
+ if( restoreDrawable ) {
+ context.setGLDrawable(origDrawable, false);
+ }
+ } catch (final Throwable t) {
+ if( DEBUG || GLContext.DEBUG ) {
+ ExceptionUtils.dumpThrowable("", t);
+ }
+ } finally {
+ if( null != zeroDrawable && restoreDrawable ) {
+ zeroDrawable.setRealized(false);
+ }
+ }
+ }
+ if( !noSurfacelessCtxQuirk && !allowsSurfacelessCtx ) {
+ final int quirk = GLRendererQuirks.NoSurfacelessCtx;
+ if(DEBUG || GLContext.DEBUG) {
+ System.err.println("Quirk: "+GLRendererQuirks.toString(quirk)+" -> "+device+": cause: probe");
+ }
+ final GLRendererQuirks glrq = context.getRendererQuirks();
+ if( null != glrq ) {
+ glrq.addQuirk(quirk);
+ }
+ GLRendererQuirks.addStickyDeviceQuirk(device, quirk);
+ }
+ return allowsSurfacelessCtx;
+ }
+
+ /**
* Returns the shared resource mapped to the <code>device</code> {@link AbstractGraphicsDevice#getConnection()},
* either a pre-existing or newly created, or <code>null</code> if creation failed or not supported.<br>
* Creation of the shared resource is tried only once.
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 ) {
diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java
index 73e01de08..3ff4b6529 100644
--- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java
+++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java
@@ -528,15 +528,16 @@ public class MacOSXCGLContext extends GLContextImpl
public boolean isNSContext() { return true; }
- /** Only returns a valid NSView. If !NSView, return null and mark either pbuffer and FBO. */
- private long getNSViewHandle(final boolean[] isPBuffer, final boolean[] isFBO) {
+ /** Only returns a valid NSView. If !NSView, return null and mark either isPBuffer, isFBO or isSurfaceless. */
+ private long getNSViewHandle(final boolean[] isPBuffer, final boolean[] isFBO, final boolean[] isSurfaceless) {
final long nsViewHandle;
if(drawable instanceof GLFBODrawableImpl) {
nsViewHandle = 0;
isPBuffer[0] = false;
isFBO[0] = true;
+ isSurfaceless[0] = false;
if(DEBUG) {
- System.err.println("NS viewHandle.1: GLFBODrawableImpl drawable: isFBO "+isFBO[0]+", isPBuffer "+isPBuffer[0]+", "+drawable.getClass().getName()+",\n\t"+drawable);
+ System.err.println("NS viewHandle.1: GLFBODrawableImpl drawable: isFBO "+isFBO[0]+", isPBuffer "+isPBuffer[0]+", isSurfaceless "+isSurfaceless[0]+", "+drawable.getClass().getName()+",\n\t"+drawable);
}
} else {
final long drawableHandle = drawable.getHandle();
@@ -544,6 +545,7 @@ public class MacOSXCGLContext extends GLContextImpl
final boolean isNSWindow = OSXUtil.isNSWindow(drawableHandle);
isPBuffer[0] = CGL.isNSOpenGLPixelBuffer(drawableHandle);
isFBO[0] = false;
+ isSurfaceless[0] = false;
if( isNSView ) {
nsViewHandle = drawableHandle;
@@ -551,11 +553,14 @@ public class MacOSXCGLContext extends GLContextImpl
nsViewHandle = OSXUtil.GetNSView(drawableHandle);
} else if( isPBuffer[0] ) {
nsViewHandle = 0;
+ } else if( isSurfacelessOK() ) {
+ isSurfaceless[0] = true;
+ nsViewHandle = 0;
} else {
- throw new RuntimeException("Drawable's handle neither NSView, NSWindow nor PBuffer: drawableHandle "+toHexString(drawableHandle)+", isNSView "+isNSView+", isNSWindow "+isNSWindow+", isFBO "+isFBO[0]+", isPBuffer "+isPBuffer[0]+", "+drawable.getClass().getName()+",\n\t"+drawable);
+ throw new GLException("Drawable's handle neither NSView, NSWindow nor PBuffer: drawableHandle "+toHexString(drawableHandle)+", isNSView "+isNSView+", isNSWindow "+isNSWindow+", isFBO "+isFBO[0]+", isPBuffer "+isPBuffer[0]+", "+drawable.getClass().getName()+",\n\t"+drawable);
}
if(DEBUG) {
- System.err.println("NS viewHandle.2: drawableHandle "+toHexString(drawableHandle)+" -> nsViewHandle "+toHexString(nsViewHandle)+": isNSView "+isNSView+", isNSWindow "+isNSWindow+", isFBO "+isFBO[0]+", isPBuffer "+isPBuffer[0]+", "+drawable.getClass().getName()+",\n\t"+drawable);
+ System.err.println("NS viewHandle.2: drawableHandle "+toHexString(drawableHandle)+" -> nsViewHandle "+toHexString(nsViewHandle)+": isNSView "+isNSView+", isNSWindow "+isNSWindow+", isFBO "+isFBO[0]+", isPBuffer "+isPBuffer[0]+", isSurfaceless "+isSurfaceless[0]+", "+drawable.getClass().getName()+",\n\t"+drawable);
}
}
needsSetContextPBuffer = isPBuffer[0];
@@ -571,12 +576,15 @@ public class MacOSXCGLContext extends GLContextImpl
final long nsViewHandle;
final boolean isPBuffer;
final boolean isFBO;
+ final boolean isSurfaceless;
{
final boolean[] _isPBuffer = { false };
final boolean[] _isFBO = { false };
- nsViewHandle = getNSViewHandle(_isPBuffer, _isFBO);
+ final boolean[] _isSurfaceless = { false };
+ nsViewHandle = getNSViewHandle(_isPBuffer, _isFBO, _isSurfaceless);
isPBuffer = _isPBuffer[0];
isFBO = _isFBO[0];
+ isSurfaceless = _isSurfaceless[0];
}
final OffscreenLayerSurface backingLayerHost = NativeWindowFactory.getOffscreenLayerSurface(surface, true);
@@ -612,7 +620,7 @@ public class MacOSXCGLContext extends GLContextImpl
// determine on-/offscreen caps, since pformat is ambiguous
_fixedCaps.setPBuffer( isPBuffer ); // exclusive
_fixedCaps.setBitmap( false ); // n/a in our OSX impl.
- _fixedCaps.setOnscreen( !isFBO && !isPBuffer );
+ _fixedCaps.setOnscreen( !isFBO && !isPBuffer && !isSurfaceless );
fixedCaps = GLGraphicsConfigurationUtil.fixOpaqueGLCapabilities(_fixedCaps, chosenCaps.isBackgroundOpaque());
}
final int sRefreshRate = OSXUtil.GetScreenRefreshRate(drawable.getNativeSurface().getGraphicsConfiguration().getScreen().getIndex());
@@ -625,7 +633,7 @@ public class MacOSXCGLContext extends GLContextImpl
System.err.println("NS create backingLayerHost: "+backingLayerHost);
System.err.println("NS create share: "+share);
System.err.println("NS create drawable type: "+drawable.getClass().getName());
- System.err.println("NS create drawable handle: isPBuffer "+isPBuffer+", isFBO "+isFBO);
+ System.err.println("NS create drawable handle: isPBuffer "+isPBuffer+", isFBO "+isFBO+", isSurfaceless "+isSurfaceless);
System.err.println("NS create pixelFormat: "+toHexString(pixelFormat));
System.err.println("NS create chosenCaps: "+chosenCaps);
System.err.println("NS create fixedCaps: "+fixedCaps);
@@ -873,7 +881,8 @@ public class MacOSXCGLContext extends GLContextImpl
lastHeight = drawable.getSurfaceHeight();
final boolean[] isPBuffer = { false };
final boolean[] isFBO = { false };
- CGL.setContextView(contextHandle, getNSViewHandle(isPBuffer, isFBO));
+ final boolean[] isSurfaceless = { false };
+ CGL.setContextView(contextHandle, getNSViewHandle(isPBuffer, isFBO, isSurfaceless));
}
} else { // -> !bound
if( null != backingLayerHost ) {
diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java
index 933b8eef9..d9f9f0399 100644
--- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java
+++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java
@@ -245,43 +245,71 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl {
}
if(null==sr && !getDeviceTried(connection)) {
addDeviceTried(connection);
- final MacOSXGraphicsDevice sharedDevice = new MacOSXGraphicsDevice(adevice.getUnitID());
- GLRendererQuirks glRendererQuirks = null;
- boolean isValid = false;
- boolean hasNPOTTextures = false;
- boolean hasRECTTextures = false;
- boolean hasAppleFloatPixels = false;
- {
- final GLProfile glp = GLProfile.get(sharedDevice, GLProfile.GL_PROFILE_LIST_MIN_DESKTOP, false);
+ final MacOSXGraphicsDevice device = new MacOSXGraphicsDevice(adevice.getUnitID());
+ GLDrawable drawable = null;
+ GLDrawable zeroDrawable = null;
+ GLContextImpl context = null;
+ boolean contextIsCurrent = false;
+ device.lock();
+ try {
+ 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);
+ drawable = createOnscreenDrawableImpl(createDummySurfaceImpl(device, false, caps, caps, null, 64, 64));
+ drawable.setRealized(true);
- final MacOSXCGLContext sharedContext = (MacOSXCGLContext) sharedDrawable.createContext(null);
- if (null == sharedContext) {
- throw new GLException("Couldn't create shared context for drawable: "+sharedDrawable);
+ context = (MacOSXCGLContext) drawable.createContext(null);
+ if (null == context) {
+ throw new GLException("Couldn't create shared context for drawable: "+drawable);
}
-
- try {
- isValid = GLContext.CONTEXT_NOT_CURRENT != sharedContext.makeCurrent(); // could cause exception
- if(isValid) {
- final GL gl = sharedContext.getGL();
- hasNPOTTextures = gl.isNPOTTextureAvailable();
- hasRECTTextures = gl.isExtensionAvailable(GLExtensions.EXT_texture_rectangle);
- hasAppleFloatPixels = gl.isExtensionAvailable(GLExtensions.APPLE_float_pixels);
- glRendererQuirks = sharedContext.getRendererQuirks();
- }
- } catch (final GLException gle) {
- if (DEBUG) {
- System.err.println("MacOSXCGLDrawableFactory.createShared: INFO: makeCurrent caught exception:");
- gle.printStackTrace();
+ contextIsCurrent = GLContext.CONTEXT_NOT_CURRENT != context.makeCurrent();
+
+ final boolean allowsSurfacelessCtx;
+ final boolean hasNPOTTextures;
+ final boolean hasRECTTextures;
+ final boolean hasAppleFloatPixels;
+ final GLRendererQuirks glRendererQuirks;
+ if( contextIsCurrent ) {
+ // We allow probing surfaceless for even the compatible 2.1 context,
+ // which we probably have right here - since OSX may support this.
+ // Otherwise, we cannot map the quirk to the device.
+ if( probeSurfacelessCtx(context, false /* restoreDrawable */) ) {
+ allowsSurfacelessCtx = true;
+ zeroDrawable = context.getGLDrawable();
+ } else {
+ allowsSurfacelessCtx = false;
}
- } finally {
+ final GL gl = context.getGL();
+ hasNPOTTextures = gl.isNPOTTextureAvailable();
+ hasRECTTextures = gl.isExtensionAvailable(GLExtensions.EXT_texture_rectangle);
+ hasAppleFloatPixels = gl.isExtensionAvailable(GLExtensions.APPLE_float_pixels);
+ glRendererQuirks = context.getRendererQuirks();
+ } else {
+ allowsSurfacelessCtx = false;
+ hasNPOTTextures = false;
+ hasRECTTextures = false;
+ hasAppleFloatPixels = false;
+ glRendererQuirks = null;
+ }
+ sr = new SharedResource(device, contextIsCurrent, hasNPOTTextures, hasRECTTextures, hasAppleFloatPixels, glRendererQuirks);
+ if ( DEBUG_SHAREDCTX ) {
+ System.err.println("SharedDevice: " + device);
+ System.err.println("SharedContext: " + context + ", madeCurrent " + contextIsCurrent);
+ System.err.println(" NPOT "+hasNPOTTextures+", RECT "+hasRECTTextures+", FloatPixels "+hasAppleFloatPixels);
+ System.err.println(" allowsSurfacelessCtx "+allowsSurfacelessCtx);
+ System.err.println(" glRendererQuirks "+glRendererQuirks);
+ }
+ synchronized(sharedMap) {
+ sharedMap.put(connection, sr);
+ }
+ } catch (final Throwable t) {
+ throw new GLException("MacOSXCGLDrawableFactory - Could not initialize shared resources for "+adevice, t);
+ } finally {
+ if( null != context ) {
try {
- sharedContext.destroy();
+ context.destroy();
} catch (final GLException gle) {
if ( DEBUG_SHAREDCTX ) {
System.err.println("MacOSXCGLDrawableFactory.createShared: INFO: destroy caught exception:");
@@ -289,17 +317,14 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl {
}
}
}
- sharedDrawable.setRealized(false);
- }
- sr = new SharedResource(sharedDevice, isValid, hasNPOTTextures, hasRECTTextures, hasAppleFloatPixels, glRendererQuirks);
- synchronized(sharedMap) {
- sharedMap.put(connection, sr);
- }
- removeDeviceTried(connection);
- if (DEBUG) {
- System.err.println("MacOSXCGLDrawableFactory.createShared: device: " + sharedDevice);
- System.err.println("MacOSXCGLDrawableFactory.createShared: context: madeCurrent " + isValid + ", NPOT "+hasNPOTTextures+
- ", RECT "+hasRECTTextures+", FloatPixels "+hasAppleFloatPixels+", "+glRendererQuirks);
+ if( null != zeroDrawable ) {
+ zeroDrawable.setRealized(false);
+ }
+ if( null != drawable ) {
+ drawable.setRealized(false);
+ }
+ device.unlock();
+ removeDeviceTried(connection);
}
}
return sr;
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();
diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java
index 35cb7d02f..7142dd7a8 100644
--- a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java
+++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java
@@ -263,24 +263,24 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl {
@Override
public SharedResourceRunner.Resource createSharedResource(final AbstractGraphicsDevice adevice) {
- final X11GraphicsDevice x11Device = new X11GraphicsDevice(X11Util.openDisplay(adevice.getConnection()), adevice.getUnitID(), true /* owner */);
+ final X11GraphicsDevice device = new X11GraphicsDevice(X11Util.openDisplay(adevice.getConnection()), adevice.getUnitID(), true /* owner */);
GLContextImpl context = null;
boolean contextIsCurrent = false;
- x11Device.lock();
+ device.lock();
try {
- final X11GraphicsScreen screen = new X11GraphicsScreen(x11Device, x11Device.getDefaultScreen());
+ final X11GraphicsScreen screen = new X11GraphicsScreen(device, device.getDefaultScreen());
- GLXUtil.initGLXClientDataSingleton(x11Device);
- final String glXServerVendorName = GLX.glXQueryServerString(x11Device.getHandle(), 0, GLX.GLX_VENDOR);
- final boolean glXServerMultisampleAvailable = GLXUtil.isMultisampleAvailable(GLX.glXQueryServerString(x11Device.getHandle(), 0, GLX.GLX_EXTENSIONS));
+ GLXUtil.initGLXClientDataSingleton(device);
+ final String glXServerVendorName = GLX.glXQueryServerString(device.getHandle(), 0, GLX.GLX_VENDOR);
+ final boolean glXServerMultisampleAvailable = GLXUtil.isMultisampleAvailable(GLX.glXQueryServerString(device.getHandle(), 0, GLX.GLX_EXTENSIONS));
- final GLProfile glp = GLProfile.get(x11Device, GLProfile.GL_PROFILE_LIST_MIN_DESKTOP, false);
+ 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: "+x11Device);
+ throw new GLException("Couldn't get default GLProfile for device: "+device);
}
final GLCapabilitiesImmutable caps = new GLCapabilities(glp);
- final GLDrawableImpl drawable = createOnscreenDrawableImpl(createDummySurfaceImpl(x11Device, false, caps, caps, null, 64, 64));
+ final GLDrawableImpl drawable = createOnscreenDrawableImpl(createDummySurfaceImpl(device, false, caps, caps, null, 64, 64));
drawable.setRealized(true);
final X11GLCapabilities chosenCaps = (X11GLCapabilities) drawable.getChosenGLCapabilities();
final boolean glxForcedOneOne = !chosenCaps.hasFBConfig();
@@ -288,7 +288,7 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl {
if( glxForcedOneOne ) {
glXServerVersion = versionOneOne;
} else {
- glXServerVersion = GLXUtil.getGLXServerVersionNumber(x11Device);
+ glXServerVersion = GLXUtil.getGLXServerVersionNumber(device);
}
context = (GLContextImpl) drawable.createContext(null);
if (null == context) {
@@ -296,54 +296,21 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl {
}
contextIsCurrent = GLContext.CONTEXT_NOT_CURRENT != context.makeCurrent();
- final boolean noSurfacelessCtxQuirk = context.hasRendererQuirk(GLRendererQuirks.NoSurfacelessCtx);
- boolean allowsSurfacelessCtx = false;
-
- if( contextIsCurrent &&
- context.getGLVersionNumber().compareTo(GLContext.Version3_0) >= 0 &&
- !noSurfacelessCtxQuirk )
- {
- GLDrawableImpl zeroDrawable = null;
- try {
- final ProxySurface zeroSurface = createSurfacelessImpl(x11Device, true, caps, caps, 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
-
- // switch back
- context.setGLDrawable(drawable, false);
- } catch (final Throwable t) {
- if( DEBUG ) {
- ExceptionUtils.dumpThrowable("", t);
- }
- } finally {
- if( null != zeroDrawable ) {
- zeroDrawable.setRealized(false);
- }
- }
+ final boolean allowsSurfacelessCtx;
+ if( contextIsCurrent && context.getGLVersionNumber().compareTo(GLContext.Version3_0) >= 0 ) {
+ allowsSurfacelessCtx = probeSurfacelessCtx(context, true /* restoreDrawable */);
+ } else {
+ allowsSurfacelessCtx = false;
}
+
if( context.hasRendererQuirk( GLRendererQuirks.DontCloseX11Display ) ) {
X11Util.markAllDisplaysUnclosable();
}
- if( !noSurfacelessCtxQuirk && !allowsSurfacelessCtx ) {
- final int quirk = GLRendererQuirks.NoSurfacelessCtx;
- if(DEBUG) {
- System.err.println("Quirk: "+GLRendererQuirks.toString(quirk)+" -> "+x11Device+": cause: probe");
- }
- final GLRendererQuirks glrq = context.getRendererQuirks();
- if( null != glrq ) {
- glrq.addQuirk(quirk);
- }
- GLRendererQuirks.addStickyDeviceQuirk(x11Device, quirk);
- }
- if (DEBUG) {
- System.err.println("SharedDevice: " + x11Device);
+ if ( DEBUG_SHAREDCTX ) {
+ System.err.println("SharedDevice: " + device);
System.err.println("SharedScreen: " + screen);
System.err.println("SharedContext: " + context + ", madeCurrent " + contextIsCurrent);
+ System.err.println(" allowsSurfacelessCtx "+allowsSurfacelessCtx);
System.err.println("GLX Server Vendor: " + glXServerVendorName);
System.err.println("GLX Server Version: " + glXServerVersion + ", forced "+glxForcedOneOne);
System.err.println("GLX Server Multisample: " + glXServerMultisampleAvailable);
@@ -351,7 +318,7 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl {
System.err.println("GLX Client Version: " + GLXUtil.getClientVersionNumber());
System.err.println("GLX Client Multisample: " + GLXUtil.isClientMultisampleAvailable());
}
- return new SharedResource(x11Device, screen, drawable, context,
+ return new SharedResource(device, screen, drawable, context,
glXServerVersion, glXServerVendorName,
glXServerMultisampleAvailable && GLXUtil.isClientMultisampleAvailable());
} catch (final Throwable t) {
@@ -360,7 +327,7 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl {
if ( contextIsCurrent ) {
context.release();
}
- x11Device.unlock();
+ device.unlock();
}
}