diff options
Diffstat (limited to 'src/jogl/classes/jogamp/opengl/x11/glx')
5 files changed, 241 insertions, 180 deletions
diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/GLXUtil.java b/src/jogl/classes/jogamp/opengl/x11/glx/GLXUtil.java index e95c80205..33e85dd0b 100644 --- a/src/jogl/classes/jogamp/opengl/x11/glx/GLXUtil.java +++ b/src/jogl/classes/jogamp/opengl/x11/glx/GLXUtil.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2010 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -32,14 +33,40 @@ package jogamp.opengl.x11.glx; -import javax.media.opengl.*; +import javax.media.nativewindow.x11.X11GraphicsDevice; +import javax.media.opengl.GLException; +import jogamp.opengl.Debug; + +import com.jogamp.common.util.VersionNumber; public class GLXUtil { - public static String getExtension(long display) { - return GLX.glXGetClientString(display, GLX.GLX_EXTENSIONS); - } + public static final boolean DEBUG = Debug.debug("GLXUtil"); + + public static VersionNumber getGLXServerVersionNumber(long display) { + int[] major = new int[1]; + int[] minor = new int[1]; + + if (!GLX.glXQueryVersion(display, major, 0, minor, 0)) { + throw new GLException("glXQueryVersion failed"); + } + // Work around bugs in ATI's Linux drivers where they report they + // only implement GLX version 1.2 on the server side + if (major[0] == 1 && minor[0] == 2) { + String str = GLX.glXGetClientString(display, GLX.GLX_VERSION); + try { + // e.g. "1.3" + major[0] = Integer.valueOf(str.substring(0, 1)).intValue(); + minor[0] = Integer.valueOf(str.substring(2, 3)).intValue(); + } catch (Exception e) { + major[0] = 1; + minor[0] = 2; + } + } + return new VersionNumber(major[0], minor[0], 0); + } + public static boolean isMultisampleAvailable(String extensions) { if (extensions != null) { return (extensions.indexOf("GLX_ARB_multisample") >= 0); @@ -47,16 +74,6 @@ public class GLXUtil { return false; } - public static boolean isMultisampleAvailable(long display) { - return isMultisampleAvailable(getExtension(display)); - } - - /** Workaround for apparent issue with ATI's proprietary drivers - where direct contexts still send GLX tokens for GL calls */ - public static String getVendorName(long display) { - return GLX.glXGetClientString(display, GLX.GLX_VENDOR); - } - public static boolean isVendorNVIDIA(String vendor) { return vendor != null && vendor.startsWith("NVIDIA") ; } @@ -65,38 +82,48 @@ public class GLXUtil { return vendor != null && vendor.startsWith("ATI") ; } - public static boolean isVendorATI(long display) { - return isVendorATI(getVendorName(display)); + public static boolean isClientMultisampleAvailable() { + return clientMultisampleAvailable; } - - public static boolean isVendorNVIDIA(long display) { - return isVendorNVIDIA(getVendorName(display)); + public static String getClientVendorName() { + return clientVendorName; } - - public static void getGLXVersion(long display, int major[], int minor[]) { - if(0 == display) { - throw new GLException("null display handle"); + public static VersionNumber getClientVersionNumber() { + return clientVersionNumber; + } + public static synchronized boolean initGLXClientDataSingleton(X11GraphicsDevice x11Device) { + if(null != clientVendorName) { + return false; } - if(major.length<1||minor.length<1) { - throw new GLException("passed int arrays size is not >= 1"); + if(DEBUG) { + System.err.println("initGLXClientDataSingleton: "+x11Device); + Thread.dumpStack(); } - - if (!GLX.glXQueryVersion(display, major, 0, minor, 0)) { - throw new GLException("glXQueryVersion failed"); + if(null == x11Device) { + throw new GLException("null X11GraphicsDevice"); } - - // Work around bugs in ATI's Linux drivers where they report they - // only implement GLX version 1.2 on the server side - if (major[0] == 1 && minor[0] == 2) { - String str = GLX.glXGetClientString(display, GLX.GLX_VERSION); - try { + if(0 == x11Device.getHandle()) { + throw new GLException("null X11GraphicsDevice display handle"); + } + + clientMultisampleAvailable = isMultisampleAvailable(GLX.glXGetClientString(x11Device.getHandle(), GLX.GLX_EXTENSIONS)); + clientVendorName = GLX.glXGetClientString(x11Device.getHandle(), GLX.GLX_VENDOR); + + int[] major = new int[1]; + int[] minor = new int[1]; + final String str = GLX.glXGetClientString(x11Device.getHandle(), GLX.GLX_VERSION); + try { // e.g. "1.3" major[0] = Integer.valueOf(str.substring(0, 1)).intValue(); minor[0] = Integer.valueOf(str.substring(2, 3)).intValue(); - } catch (Exception e) { + } catch (Exception e) { major[0] = 1; minor[0] = 2; - } } + clientVersionNumber = new VersionNumber(major[0], minor[0], 0); + return true; } + private static boolean clientMultisampleAvailable = false; + private static String clientVendorName = null; + private static VersionNumber clientVersionNumber = null; } diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java index 51cd018f4..092086112 100644 --- a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java @@ -40,28 +40,33 @@ package jogamp.opengl.x11.glx; -import java.nio.*; -import java.util.*; +import java.nio.ByteBuffer; +import java.nio.IntBuffer; +import java.util.HashMap; +import java.util.Map; + +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.NativeSurface; +import javax.media.opengl.GLCapabilitiesImmutable; +import javax.media.opengl.GLContext; +import javax.media.opengl.GLException; +import javax.media.opengl.GLProfile; -import javax.media.opengl.*; -import javax.media.nativewindow.*; -import javax.media.nativewindow.x11.X11GraphicsDevice; +import jogamp.nativewindow.x11.X11Util; +import jogamp.opengl.GLContextImpl; +import jogamp.opengl.GLContextShareSet; +import jogamp.opengl.GLDrawableImpl; import com.jogamp.common.nio.Buffers; -import com.jogamp.common.util.VersionNumber; -import jogamp.opengl.*; import com.jogamp.gluegen.runtime.ProcAddressTable; import com.jogamp.gluegen.runtime.opengl.GLProcAddressResolver; -import jogamp.nativewindow.x11.X11Util; public abstract class X11GLXContext extends GLContextImpl { protected static final boolean TRACE_CONTEXT_CURRENT = false; // true; private static final Map<String, String> functionNameMap; private static final Map<String, String> extensionNameMap; - private VersionNumber glXVersion; - private boolean glXVersionOneOneCapable; - private boolean glXVersionOneThreeCapable; private GLXExt _glXExt; // Table that holds the addresses of the native C-language entry points for // GLX extension functions. @@ -91,9 +96,6 @@ public abstract class X11GLXContext extends GLContextImpl { @Override protected void resetStates() { - glXVersion = null; - glXVersionOneOneCapable = false; - glXVersionOneThreeCapable = false; // no inner state _glXExt=null; glXExtProcAddressTable = null; hasSwapIntervalSGI = 0; @@ -125,25 +127,10 @@ public abstract class X11GLXContext extends GLContextImpl { protected Map<String, String> getExtensionNameMap() { return extensionNameMap; } - private final void initGLXVersion() { - if(null == glXVersion) { - X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)drawable.getNativeSurface().getGraphicsConfiguration(); - X11GraphicsDevice device = (X11GraphicsDevice) config.getScreen().getDevice(); - - glXVersion = X11GLXDrawableFactory.getGLXVersion(device); - glXVersionOneOneCapable = ( null != glXVersion ) ? glXVersion.compareTo(GLDrawableFactoryImpl.versionOneOne) >= 0 : false ; - glXVersionOneThreeCapable = ( null != glXVersion ) ? glXVersion.compareTo(GLDrawableFactoryImpl.versionOneThree) >= 0 : false ; - } - } - public final boolean isGLXVersionGreaterEqualOneOne() { - initGLXVersion(); - return glXVersionOneOneCapable; - } - public final boolean isGLXVersionGreaterEqualOneThree() { - initGLXVersion(); - return glXVersionOneThreeCapable; + protected final boolean isGLXVersionGreaterEqualOneThree() { + return ((X11GLXDrawableFactory)drawable.getFactoryImpl()).isGLXVersionGreaterEqualOneThree(drawable.getNativeSurface().getGraphicsConfiguration().getScreen().getDevice()); } - + public final boolean isGLReadDrawableAvailable() { return isGLXVersionGreaterEqualOneThree(); } @@ -154,10 +141,10 @@ public abstract class X11GLXContext extends GLContextImpl { try { if(TRACE_CONTEXT_CURRENT) { Throwable t = new Throwable(Thread.currentThread()+" - glXMakeContextCurrent("+toHexString(dpy)+", "+ - toHexString(writeDrawable)+", "+toHexString(readDrawable)+", "+toHexString(ctx)+") - GLX >= 1.3 "+ glXVersionOneThreeCapable); + toHexString(writeDrawable)+", "+toHexString(readDrawable)+", "+toHexString(ctx)+") - GLX >= 1.3 "+ isGLXVersionGreaterEqualOneThree()); t.printStackTrace(); } - if ( glXVersionOneThreeCapable ) { + if ( isGLXVersionGreaterEqualOneThree() ) { res = GLX.glXMakeContextCurrent(dpy, writeDrawable, readDrawable, ctx); } else if ( writeDrawable == readDrawable ) { res = GLX.glXMakeCurrent(dpy, writeDrawable, ctx); @@ -294,8 +281,6 @@ public abstract class X11GLXContext extends GLContextImpl { X11GLXContext sharedContext = (X11GLXContext) factory.getOrCreateSharedContextImpl(device); long display = device.getHandle(); - isGLReadDrawableAvailable(); // trigger setup glXVersionOneThreeCapable - X11GLXContext other = (X11GLXContext) GLContextShareSet.getShareContext(this); long share = 0; if (other != null) { @@ -493,10 +478,12 @@ public abstract class X11GLXContext extends GLContextImpl { protected final StringBuffer getPlatformExtensionsStringImpl() { StringBuffer sb = new StringBuffer(); if (DEBUG) { - System.err.println("!!! GLX Version "+glXVersion); + System.err.println("!!! GLX Version client version "+ GLXUtil.getClientVersionNumber()+ + ", server: "+ + ((X11GLXDrawableFactory)drawable.getFactoryImpl()).getGLXVersionNumber(drawable.getNativeSurface().getGraphicsConfiguration().getScreen().getDevice())); } - if(isGLXVersionGreaterEqualOneOne()) { - final NativeSurface ns = drawable.getNativeSurface(); + final NativeSurface ns = drawable.getNativeSurface(); + if(((X11GLXDrawableFactory)drawable.getFactoryImpl()).isGLXVersionGreaterEqualOneOne(ns.getGraphicsConfiguration().getScreen().getDevice())) { { final String ret = GLX.glXGetClientString(ns.getDisplayHandle(), GLX.GLX_EXTENSIONS); if (DEBUG) { diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java index c43bc7864..5dfbffeaf 100644 --- a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java @@ -37,24 +37,47 @@ package jogamp.opengl.x11.glx; +import java.nio.Buffer; +import java.nio.ShortBuffer; import java.util.Collection; import java.util.HashMap; import java.util.List; -import java.nio.*; -import javax.media.nativewindow.*; -import javax.media.nativewindow.x11.*; -import javax.media.opengl.*; +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.AbstractGraphicsScreen; +import javax.media.nativewindow.NativeSurface; +import javax.media.nativewindow.NativeWindowFactory; +import javax.media.nativewindow.ProxySurface; +import javax.media.nativewindow.x11.X11GraphicsDevice; +import javax.media.nativewindow.x11.X11GraphicsScreen; +import javax.media.opengl.GLCapabilitiesChooser; +import javax.media.opengl.GLCapabilitiesImmutable; +import javax.media.opengl.GLContext; +import javax.media.opengl.GLDrawable; +import javax.media.opengl.GLException; +import javax.media.opengl.GLProfile; -import jogamp.opengl.*; - -import com.jogamp.common.util.*; import jogamp.nativewindow.WrappedSurface; -import jogamp.nativewindow.x11.*; +import jogamp.nativewindow.x11.X11Util; +import jogamp.opengl.DesktopGLDynamicLookupHelper; +import jogamp.opengl.GLContextImpl; +import jogamp.opengl.GLDrawableFactoryImpl; +import jogamp.opengl.GLDrawableImpl; +import jogamp.opengl.GLDynamicLookupHelper; +import jogamp.opengl.SharedResourceRunner; + +import com.jogamp.common.util.VersionNumber; public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { private static final DesktopGLDynamicLookupHelper x11GLXDynamicLookupHelper; + + public static final VersionNumber versionOneZero = new VersionNumber(1, 0, 0); + public static final VersionNumber versionOneOne = new VersionNumber(1, 1, 0); + public static final VersionNumber versionOneTwo = new VersionNumber(1, 2, 0); + public static final VersionNumber versionOneThree = new VersionNumber(1, 3, 0); + public static final VersionNumber versionOneFour = new VersionNumber(1, 4, 0); static { DesktopGLDynamicLookupHelper tmp = null; @@ -71,13 +94,6 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { } } - public static VersionNumber getGLXVersion(X11GraphicsDevice device) { - int[] major = new int[1]; - int[] minor = new int[1]; - GLXUtil.getGLXVersion(device.getHandle(), major, minor); - return new VersionNumber(major[0], minor[0], 0); - } - public GLDynamicLookupHelper getGLDynamicLookupHelper(int profile) { return x11GLXDynamicLookupHelper; } @@ -110,35 +126,41 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { X11GraphicsScreen screen; X11DummyGLXDrawable drawable; X11GLXContext context; - String glXVendorName; - boolean isGLXVendorATI; - boolean isGLXVendorNVIDIA; - VersionNumber glXVersion; + String glXServerVendorName; + boolean isGLXServerVendorATI; + boolean isGLXServerVendorNVIDIA; + VersionNumber glXServerVersion; + boolean glXServerVersionOneOneCapable; + boolean glXServerVersionOneThreeCapable; + boolean glXMultisampleAvailable; SharedResource(X11GraphicsDevice dev, X11GraphicsScreen scrn, X11DummyGLXDrawable draw, X11GLXContext ctx, - VersionNumber glXVer, String glXVendor) { + VersionNumber glXServerVer, String glXServerVendor, boolean glXServerMultisampleAvail) { device = dev; screen = scrn; drawable = draw; context = ctx; - glXVersion = glXVer; - glXVendorName = glXVendor; - isGLXVendorATI = GLXUtil.isVendorATI(glXVendorName); - isGLXVendorNVIDIA = GLXUtil.isVendorNVIDIA(glXVendorName); + glXServerVersion = glXServerVer; + glXServerVersionOneOneCapable = glXServerVersion.compareTo(versionOneOne) >= 0 ; + glXServerVersionOneThreeCapable = glXServerVersion.compareTo(versionOneThree) >= 0 ; + glXServerVendorName = glXServerVendor; + isGLXServerVendorATI = GLXUtil.isVendorATI(glXServerVendorName); + isGLXServerVendorNVIDIA = GLXUtil.isVendorNVIDIA(glXServerVendorName); + glXMultisampleAvailable = glXServerMultisampleAvail; } final public AbstractGraphicsDevice getDevice() { return device; } final public AbstractGraphicsScreen getScreen() { return screen; } final public GLDrawableImpl getDrawable() { return drawable; } final public GLContextImpl getContext() { return context; } - final String getGLXVendorName() { return glXVendorName; } - final boolean isGLXVendorATI() { return isGLXVendorATI; } - final boolean isGLXVendorNVIDIA() { return isGLXVendorNVIDIA; } - final VersionNumber getGLXVersion() { return glXVersion; } - final boolean isGLXVersionGreaterEqualOneThree() { - return ( null != glXVersion ) ? glXVersion.compareTo(versionOneThree) >= 0 : false ; - } + final String getGLXVendorName() { return glXServerVendorName; } + final boolean isGLXVendorATI() { return isGLXServerVendorATI; } + final boolean isGLXVendorNVIDIA() { return isGLXServerVendorNVIDIA; } + final VersionNumber getGLXVersion() { return glXServerVersion; } + final boolean isGLXVersionGreaterEqualOneOne() { return glXServerVersionOneOneCapable; } + final boolean isGLXVersionGreaterEqualOneThree() { return glXServerVersionOneThreeCapable; } + final boolean isGLXMultisampleAvailable() { return glXMultisampleAvailable; } } class SharedResourceImplementation implements SharedResourceRunner.Implementation { @@ -169,8 +191,11 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { NativeWindowFactory.getNullToolkitLock(), true); // own non-shared display connection, no locking sharedDevice.lock(); try { - String glXVendorName = GLXUtil.getVendorName(sharedDevice.getHandle()); - if(X11Util.ATI_HAS_XCLOSEDISPLAY_BUG && GLXUtil.isVendorATI(glXVendorName)) { + GLXUtil.initGLXClientDataSingleton(sharedDevice); + final String glXServerVendorName = GLX.glXQueryServerString(sharedDevice.getHandle(), 0, GLX.GLX_VENDOR); + final VersionNumber glXServerVersion = GLXUtil.getGLXServerVersionNumber(sharedDevice.getHandle()); + final boolean glXServerMultisampleAvailable = GLXUtil.isMultisampleAvailable(GLX.glXQueryServerString(sharedDevice.getHandle(), 0, GLX.GLX_EXTENSIONS)); + if(X11Util.ATI_HAS_XCLOSEDISPLAY_BUG && GLXUtil.isVendorATI(glXServerVendorName)) { X11Util.setMarkAllDisplaysUnclosable(true); X11Util.markDisplayUncloseable(sharedDevice.getHandle()); } @@ -189,7 +214,6 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { throw new GLException("Couldn't create shared context for drawable: "+sharedDrawable); } sharedContext.setSynchronized(true); - VersionNumber glXVersion = getGLXVersion(sharedDevice); boolean madeCurrent = false; sharedContext.makeCurrent(); try { @@ -201,11 +225,16 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { System.err.println("!!! SharedDevice: " + sharedDevice); System.err.println("!!! SharedScreen: " + sharedScreen); System.err.println("!!! SharedContext: " + sharedContext + ", madeCurrent " + madeCurrent); - System.err.println("!!! GLX Vendor: " + glXVendorName); - System.err.println("!!! GLX Version: " + glXVersion - + " >= 1.3: " + (glXVersion.compareTo(versionOneThree) >= 0)); + System.err.println("!!! GLX Server Vendor: " + glXServerVendorName); + System.err.println("!!! GLX Server Version: " + glXServerVersion); + System.err.println("!!! GLX Server Multisample: " + glXServerMultisampleAvailable); + System.err.println("!!! GLX Client Vendor: " + GLXUtil.getClientVendorName()); + System.err.println("!!! GLX Client Version: " + GLXUtil.getClientVersionNumber()); + System.err.println("!!! GLX Client Multisample: " + GLXUtil.isClientMultisampleAvailable()); } - return new SharedResource(sharedDevice, sharedScreen, sharedDrawable, sharedContext, glXVersion, glXVendorName); + return new SharedResource(sharedDevice, sharedScreen, sharedDrawable, sharedContext, + glXServerVersion, glXServerVendorName, + glXServerMultisampleAvailable && GLXUtil.isClientMultisampleAvailable()); } catch (Throwable t) { throw new GLException("X11GLXDrawableFactory - Could not initialize shared resources for "+connection, t); } finally { @@ -291,39 +320,6 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { return (SharedResource) sharedResourceRunner.getOrCreateShared(device); } - public final String getGLXVendorName(AbstractGraphicsDevice device) { - if(null != device) { - SharedResourceRunner.Resource sr = sharedResourceRunner.getOrCreateShared(device); - if(null!=sr) { - return ((SharedResource)sr).getGLXVendorName(); - } - return GLXUtil.getVendorName(device.getHandle()); - } - return null; - } - - public final boolean isGLXVendorATI(AbstractGraphicsDevice device) { - if(null != device) { - SharedResourceRunner.Resource sr = sharedResourceRunner.getOrCreateShared(device); - if(null!=sr) { - return ((SharedResource)sr).isGLXVendorATI(); - } - return GLXUtil.isVendorATI(device.getHandle()); - } - return false; - } - - public final boolean isGLXVendorNVIDIA(AbstractGraphicsDevice device) { - if(null != device) { - SharedResourceRunner.Resource sr = sharedResourceRunner.getOrCreateShared(device); - if(null!=sr) { - return ((SharedResource)sr).isGLXVendorNVIDIA(); - } - return GLXUtil.isVendorNVIDIA(device.getHandle()); - } - return false; - } - protected final void shutdownInstance() { sharedResourceRunner.releaseAndWait(); @@ -377,6 +373,43 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { return pbufferDrawable; } + public final boolean isGLXMultisampleAvailable(AbstractGraphicsDevice device) { + if(null != device) { + SharedResource sr = (SharedResource) sharedResourceRunner.getOrCreateShared(device); + if(null!=sr) { + return sr.isGLXMultisampleAvailable(); + } + } + return false; + } + + public final VersionNumber getGLXVersionNumber(AbstractGraphicsDevice device) { + if(null != device) { + SharedResource sr = (SharedResource) sharedResourceRunner.getOrCreateShared(device); + if(null!=sr) { + return sr.getGLXVersion(); + } + if( device instanceof X11GraphicsDevice ) { + return GLXUtil.getGLXServerVersionNumber(device.getHandle()); + } + } + return null; + } + + public final boolean isGLXVersionGreaterEqualOneOne(AbstractGraphicsDevice device) { + if(null != device) { + SharedResource sr = (SharedResource) sharedResourceRunner.getOrCreateShared(device); + if(null!=sr) { + return sr.isGLXVersionGreaterEqualOneOne(); + } + if( device instanceof X11GraphicsDevice ) { + final VersionNumber glXServerVersion = GLXUtil.getGLXServerVersionNumber(device.getHandle()); + return glXServerVersion.compareTo(versionOneOne) >= 0; + } + } + return false; + } + public final boolean isGLXVersionGreaterEqualOneThree(AbstractGraphicsDevice device) { if(null != device) { SharedResource sr = (SharedResource) sharedResourceRunner.getOrCreateShared(device); @@ -384,8 +417,8 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { return sr.isGLXVersionGreaterEqualOneThree(); } if( device instanceof X11GraphicsDevice ) { - VersionNumber v = getGLXVersion( (X11GraphicsDevice) device); - return ( null != v ) ? v.compareTo(versionOneThree) >= 0 : false ; + final VersionNumber glXServerVersion = GLXUtil.getGLXServerVersionNumber(device.getHandle()); + return glXServerVersion.compareTo(versionOneThree) >= 0; } } return false; diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXGraphicsConfiguration.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXGraphicsConfiguration.java index 68b8135d0..c7c28e2d9 100644 --- a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXGraphicsConfiguration.java +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXGraphicsConfiguration.java @@ -35,13 +35,27 @@ package jogamp.opengl.x11.glx; import java.util.ArrayList; -import javax.media.nativewindow.*; -import javax.media.nativewindow.x11.*; -import javax.media.opengl.*; +import javax.media.nativewindow.GraphicsConfigurationFactory; +import javax.media.nativewindow.x11.X11GraphicsConfiguration; +import javax.media.nativewindow.x11.X11GraphicsScreen; +import javax.media.opengl.DefaultGLCapabilitiesChooser; +import javax.media.opengl.GL; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLCapabilitiesChooser; +import javax.media.opengl.GLCapabilitiesImmutable; +import javax.media.opengl.GLDrawableFactory; +import javax.media.opengl.GLException; +import javax.media.opengl.GLProfile; + +import jogamp.nativewindow.x11.X11Lib; +import jogamp.nativewindow.x11.X11Util; +import jogamp.nativewindow.x11.XRenderDirectFormat; +import jogamp.nativewindow.x11.XRenderPictFormat; +import jogamp.nativewindow.x11.XVisualInfo; +import jogamp.opengl.Debug; +import jogamp.opengl.GLGraphicsConfigurationUtil; import com.jogamp.common.nio.PointerBuffer; -import jogamp.opengl.*; -import jogamp.nativewindow.x11.*; public class X11GLXGraphicsConfiguration extends X11GraphicsConfiguration implements Cloneable { protected static final boolean DEBUG = Debug.debug("GraphicsConfiguration"); @@ -56,19 +70,20 @@ public class X11GLXGraphicsConfiguration extends X11GraphicsConfiguration implem } static X11GLXGraphicsConfiguration create(GLProfile glp, X11GraphicsScreen x11Screen, int fbcfgID) { - long display = x11Screen.getDevice().getHandle(); + final long display = x11Screen.getDevice().getHandle(); if(0==display) { throw new GLException("Display null of "+x11Screen); } - int screen = x11Screen.getIndex(); - long fbcfg = glXFBConfigID2FBConfig(display, screen, fbcfgID); + final int screen = x11Screen.getIndex(); + final long fbcfg = glXFBConfigID2FBConfig(display, screen, fbcfgID); if(0==fbcfg) { throw new GLException("FBConfig null of "+toHexString(fbcfgID)); } if(null==glp) { glp = GLProfile.getDefault(x11Screen.getDevice()); } - X11GLCapabilities caps = GLXFBConfig2GLCapabilities(glp, display, fbcfg, true, true, true, GLXUtil.isMultisampleAvailable(display)); + final X11GLXDrawableFactory factory = (X11GLXDrawableFactory) GLDrawableFactory.getDesktopFactory(); + final X11GLCapabilities caps = GLXFBConfig2GLCapabilities(glp, display, fbcfg, true, true, true, factory.isGLXMultisampleAvailable(x11Screen.getDevice())); if(null==caps) { throw new GLException("GLCapabilities null of "+toHexString(fbcfg)); } @@ -100,10 +115,6 @@ public class X11GLXGraphicsConfiguration extends X11GraphicsConfiguration implem } } - private static int nonZeroOrDontCare(int value) { - return value != 0 ? value : (int)GLX.GLX_DONT_CARE ; - } - static int[] GLCapabilities2AttribList(GLCapabilitiesImmutable caps, boolean forFBAttr, boolean isMultisampleAvailable, diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXGraphicsConfigurationFactory.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXGraphicsConfigurationFactory.java index 126efad8d..be7348779 100644 --- a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXGraphicsConfigurationFactory.java +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXGraphicsConfigurationFactory.java @@ -103,18 +103,19 @@ public class X11GLXGraphicsConfigurationFactory extends GLGraphicsConfigurationF if(null == sharedResource) { throw new GLException("Shared resource for device n/a: "+device); } - X11GraphicsScreen sharedScreen = (X11GraphicsScreen) sharedResource.getScreen(); - X11GLXDrawable sharedDrawable = (X11GLXDrawable) sharedResource.getDrawable(); - GLCapabilitiesImmutable capsChosen = sharedDrawable.getChosenGLCapabilities(); - GLProfile glp = capsChosen.getGLProfile(); + final X11GraphicsScreen sharedScreen = (X11GraphicsScreen) sharedResource.getScreen(); + final boolean isMultisampleAvailable = factory.isGLXMultisampleAvailable(sharedScreen.getDevice()); + final X11GLXDrawable sharedDrawable = (X11GLXDrawable) sharedResource.getDrawable(); + final GLCapabilitiesImmutable capsChosen = sharedDrawable.getChosenGLCapabilities(); + final GLProfile glp = capsChosen.getGLProfile(); List<GLCapabilitiesImmutable> availableCaps = null; if( sharedResource.isGLXVersionGreaterEqualOneThree() ) { - availableCaps = getAvailableGLCapabilitiesFBConfig(sharedScreen, glp); + availableCaps = getAvailableGLCapabilitiesFBConfig(sharedScreen, glp, isMultisampleAvailable); } if( null == availableCaps || availableCaps.isEmpty() ) { - availableCaps = getAvailableGLCapabilitiesXVisual(sharedScreen, glp); + availableCaps = getAvailableGLCapabilitiesXVisual(sharedScreen, glp, isMultisampleAvailable); } if( null != availableCaps && availableCaps.size() > 1 ) { Collections.sort(availableCaps, XVisualIDComparator); @@ -122,7 +123,7 @@ public class X11GLXGraphicsConfigurationFactory extends GLGraphicsConfigurationF return availableCaps; } - static List<GLCapabilitiesImmutable> getAvailableGLCapabilitiesFBConfig(X11GraphicsScreen x11Screen, GLProfile glProfile) { + static List<GLCapabilitiesImmutable> getAvailableGLCapabilitiesFBConfig(X11GraphicsScreen x11Screen, GLProfile glProfile, boolean isMultisampleAvailable) { PointerBuffer fbcfgsL = null; // Utilizing FBConfig @@ -131,7 +132,6 @@ public class X11GLXGraphicsConfigurationFactory extends GLGraphicsConfigurationF long display = absDevice.getHandle(); int screen = x11Screen.getIndex(); - boolean isMultisampleAvailable = GLXUtil.isMultisampleAvailable(display); int[] count = { -1 }; ArrayList<GLCapabilitiesImmutable> availableCaps = new ArrayList<GLCapabilitiesImmutable>(); @@ -152,12 +152,11 @@ public class X11GLXGraphicsConfigurationFactory extends GLGraphicsConfigurationF return availableCaps; } - static List<GLCapabilitiesImmutable> getAvailableGLCapabilitiesXVisual(X11GraphicsScreen x11Screen, GLProfile glProfile) { + static List<GLCapabilitiesImmutable> getAvailableGLCapabilitiesXVisual(X11GraphicsScreen x11Screen, GLProfile glProfile, boolean isMultisampleAvailable) { AbstractGraphicsDevice absDevice = x11Screen.getDevice(); long display = absDevice.getHandle(); int screen = x11Screen.getIndex(); - boolean isMultisampleAvailable = GLXUtil.isMultisampleAvailable(display); int[] count = new int[1]; XVisualInfo template = XVisualInfo.create(); @@ -215,18 +214,20 @@ public class X11GLXGraphicsConfigurationFactory extends GLGraphicsConfigurationF } static X11GLXGraphicsConfiguration fetchGraphicsConfigurationFBConfig(X11GraphicsScreen x11Screen, int fbID, GLProfile glp) { - AbstractGraphicsDevice absDevice = x11Screen.getDevice(); - long display = absDevice.getHandle(); - int screen = x11Screen.getIndex(); + final AbstractGraphicsDevice absDevice = x11Screen.getDevice(); + final long display = absDevice.getHandle(); + final int screen = x11Screen.getIndex(); - long fbcfg = X11GLXGraphicsConfiguration.glXFBConfigID2FBConfig(display, screen, fbID); + final long fbcfg = X11GLXGraphicsConfiguration.glXFBConfigID2FBConfig(display, screen, fbID); if( 0 == fbcfg || !X11GLXGraphicsConfiguration.GLXFBConfigValid( display, fbcfg ) ) { if(DEBUG) { System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: Failed - GLX FBConfig invalid: ("+x11Screen+","+toHexString(fbID)+"): fbcfg: "+toHexString(fbcfg)); } return null; } - X11GLCapabilities caps = X11GLXGraphicsConfiguration.GLXFBConfig2GLCapabilities(glp, display, fbcfg, true, true, true, GLXUtil.isMultisampleAvailable(display)); + final X11GLXDrawableFactory factory = (X11GLXDrawableFactory) GLDrawableFactory.getDesktopFactory(); + + final X11GLCapabilities caps = X11GLXGraphicsConfiguration.GLXFBConfig2GLCapabilities(glp, display, fbcfg, true, true, true, factory.isGLXMultisampleAvailable(absDevice)); return new X11GLXGraphicsConfiguration(x11Screen, caps, caps, new DefaultGLCapabilitiesChooser()); } @@ -244,9 +245,10 @@ public class X11GLXGraphicsConfigurationFactory extends GLGraphicsConfigurationF // AbstractGraphicsDevice absDevice = x11Screen.getDevice(); long display = absDevice.getHandle(); - int screen = x11Screen.getIndex(); - boolean isMultisampleAvailable = GLXUtil.isMultisampleAvailable(display); + + final X11GLXDrawableFactory factory = (X11GLXDrawableFactory) GLDrawableFactory.getDesktopFactory(); + final boolean isMultisampleAvailable = factory.isGLXMultisampleAvailable(absDevice); int[] attribs = X11GLXGraphicsConfiguration.GLCapabilities2AttribList(capsChosen, true, isMultisampleAvailable, display, screen); int[] count = { -1 }; ArrayList/*<X11GLCapabilities>*/ availableCaps = new ArrayList(); @@ -323,9 +325,10 @@ public class X11GLXGraphicsConfigurationFactory extends GLGraphicsConfigurationF AbstractGraphicsDevice absDevice = x11Screen.getDevice(); long display = absDevice.getHandle(); - int screen = x11Screen.getIndex(); - boolean isMultisampleAvailable = GLXUtil.isMultisampleAvailable(display); + + final X11GLXDrawableFactory factory = (X11GLXDrawableFactory) GLDrawableFactory.getDesktopFactory(); + final boolean isMultisampleAvailable = factory.isGLXMultisampleAvailable(absDevice); int[] attribs = X11GLXGraphicsConfiguration.GLCapabilities2AttribList(capsChosen, false, isMultisampleAvailable, display, screen); // 1st choice: get GLCapabilities based on users GLCapabilities setting recommendedIndex as preferred choice |