From 5f67805a1cba7390cde0f862cbe4d4fcce3396ee Mon Sep 17 00:00:00 2001
From: Sven Gothel <sgothel@jausoft.com>
Date: Sun, 19 Dec 2010 00:29:04 +0100
Subject: GLDrawableFactory: Add getFactory(AbstractGraphicsDevice device)

---
 .../javax/media/opengl/GLDrawableFactory.java       | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

(limited to 'src/jogl/classes')

diff --git a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java
index f9591e84d..78ca24be0 100644
--- a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java
+++ b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java
@@ -47,7 +47,6 @@ import com.jogamp.common.util.ReflectionUtil;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.ArrayList;
-import java.util.HashSet;
 
 import javax.media.nativewindow.AbstractGraphicsDevice;
 import javax.media.nativewindow.NativeSurface;
@@ -298,6 +297,26 @@ public abstract class GLDrawableFactory {
     throw new GLException("No native platform GLDrawableFactory, nor EGLDrawableFactory available: "+glProfileImplName);
   }
 
+  /**
+   * Returns the sole GLDrawableFactory instance.
+   *
+   * @param device AbstractGraphicsDevice to determine the factory type, ie EGLDrawableFactory,
+   *                or one of the native GLDrawableFactory's, ie X11/GLX, Windows/WGL or MacOSX/CGL.
+   */
+  public static GLDrawableFactory getFactory(AbstractGraphicsDevice device) throws GLException {
+    return getFactoryImpl(device);
+  }
+
+  protected static GLDrawableFactory getFactoryImpl(AbstractGraphicsDevice device) throws GLException {
+    if(null != nativeOSFactory && nativeOSFactory.getIsDeviceCompatible(device)) {
+        return nativeOSFactory;
+    }
+    if(null != eglFactory && eglFactory.getIsDeviceCompatible(device)) {
+        return eglFactory;
+    }
+    throw new GLException("No native platform GLDrawableFactory, nor EGLDrawableFactory available: "+device);
+  }
+
   //----------------------------------------------------------------------
   // Methods to create high-level objects
 
-- 
cgit v1.2.3