From c3098619080d10e5bec8b52999117002b16f3ff5 Mon Sep 17 00:00:00 2001
From: Sven Gothel <sgothel@jausoft.com>
Date: Sat, 25 Feb 2012 18:30:25 +0100
Subject: X11/GLX: Query X Server whether GLX is available
 (X11/SharedResourceRunner) ; Minor cleanups.

Before gathering GLX details and actually instantiate a X11/GLX shared resource,
we shall query whether GLX is actually available.

Since GLX availability is being queried on the server side,
more changes are required for the X11GLX* impl,
eg. not using X11GLXGraphicsConfigurationFactory and fall back to
X11GraphicsConfigurationFactory.
---
 .../classes/jogamp/opengl/x11/glx/GLXUtil.java     | 30 +++++++++++++---------
 .../opengl/x11/glx/X11GLXDrawableFactory.java      |  5 +++-
 2 files changed, 22 insertions(+), 13 deletions(-)

(limited to 'src/jogl/classes/jogamp/opengl/x11')

diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/GLXUtil.java b/src/jogl/classes/jogamp/opengl/x11/glx/GLXUtil.java
index 33e85dd0b..8b90d6887 100644
--- a/src/jogl/classes/jogamp/opengl/x11/glx/GLXUtil.java
+++ b/src/jogl/classes/jogamp/opengl/x11/glx/GLXUtil.java
@@ -90,22 +90,29 @@ public class GLXUtil {
     }
     public static VersionNumber getClientVersionNumber() {
         return clientVersionNumber;
-    }    
-    public static synchronized boolean initGLXClientDataSingleton(X11GraphicsDevice x11Device) { 
+    }
+    
+    public static synchronized boolean isGLXAvailable(long handle) {
+        if(0 == handle) {
+            throw new IllegalArgumentException("null X11 display handle");
+        }        
+        boolean glXAvailable = false;
+        try {
+            glXAvailable = GLX.glXQueryExtension(handle, null, 0, null, 0);
+        } catch (Throwable t) { /* n/a */ }
+        return glXAvailable;        
+    }
+    
+    public static synchronized void initGLXClientDataSingleton(X11GraphicsDevice x11Device) { 
         if(null != clientVendorName) {
-            return false;
-        }
-        if(DEBUG) {
-            System.err.println("initGLXClientDataSingleton: "+x11Device);
-            Thread.dumpStack();
+            return; // already initialized
         }
         if(null == x11Device) {
-            throw new GLException("null X11GraphicsDevice");
+            throw new IllegalArgumentException("null X11GraphicsDevice");
         }
         if(0 == x11Device.getHandle()) {
-            throw new GLException("null X11GraphicsDevice display handle");
-        }
-        
+            throw new IllegalArgumentException("null X11GraphicsDevice display handle");
+        }        
         clientMultisampleAvailable = isMultisampleAvailable(GLX.glXGetClientString(x11Device.getHandle(), GLX.GLX_EXTENSIONS));
         clientVendorName = GLX.glXGetClientString(x11Device.getHandle(), GLX.GLX_VENDOR);
         
@@ -121,7 +128,6 @@ public class GLXUtil {
               minor[0] = 2;
         }
         clientVersionNumber = new VersionNumber(major[0], minor[0], 0);
-        return true;
     }
     private static boolean clientMultisampleAvailable = false;
     private static String clientVendorName = null;
diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java
index 4f333406f..2ba067b02 100644
--- a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java
+++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java
@@ -103,7 +103,7 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl {
     
     defaultDevice = new X11GraphicsDevice(X11Util.getNullDisplayName(), AbstractGraphicsDevice.DEFAULT_UNIT);
     
-    if(null!=x11GLXDynamicLookupHelper) {        
+    if(null!=x11GLXDynamicLookupHelper) {
         // Register our GraphicsConfigurationFactory implementations
         // The act of constructing them causes them to be registered
         X11GLXGraphicsConfigurationFactory.registerFactory();
@@ -220,6 +220,9 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl {
                     //                       NativeWindowFactory.getNullToolkitLock(), true); // own non-shared display connection, no locking
             sharedDevice.lock();
             try {
+                if(!GLXUtil.isGLXAvailable(sharedDevice.getHandle())) {
+                    throw new GLException("GLX not available on device: "+sharedDevice);
+                }
                 GLXUtil.initGLXClientDataSingleton(sharedDevice);                
                 final String glXServerVendorName = GLX.glXQueryServerString(sharedDevice.getHandle(), 0, GLX.GLX_VENDOR);
                 final VersionNumber glXServerVersion = GLXUtil.getGLXServerVersionNumber(sharedDevice.getHandle());
-- 
cgit v1.2.3