summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/javax/media
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2010-04-20 11:46:26 +0200
committerSven Gothel <[email protected]>2010-04-20 11:46:26 +0200
commit32790c376583beccd030eecd7c56cbe66d380172 (patch)
tree894613c7fc6a598aed59db87e5812ef6a44b83dd /src/jogl/classes/javax/media
parentaa7084700bbf74d8bcc98cf0239f57cff2983423 (diff)
JOGL GL4 preperation (cont):
- All available OpenGL versions (native/platform) are verified at GLProfile initialization and can be queried .. A mapping of major,compat -> major,minor,options is created. - Removal of temp context creation, when creating a context. This was necessary to query general availability of ARB_create_context. Due to the shared context of X11GLXDrawableFactory and WindowsWGLDrawableFactory, this is no more necessary. Due to the version mapping, the ARB_create_context paramters are known. - NativeWindow X11Lib: Added X11ErrorHandler, throwing a RuntimeException. Necessary to catch BadMatch .. etc X11 errors, eg for glXCreateContextAttribsARB Hence all X11 calls are covered now. - X11DummyGLXDrawable needs to use an own Window, otherwise GLn n>2 fails - Flattening the desktop GL* implementation, all use GL4bcImpl, which reduces the footprint dramatically. - GL*Impl.isGL*() (desktop) utilizes the GLContext.isGL*(), hence the results reflect the actual native context version. - GLContextImpl makeCurrent/create: Added workflow documentation, clarified code, defined abstract methods to have a protocol. - Removed moved files (from here to gluegen), see gluegen a01cb3d59715a41153380f1977ec75263b762dc6 - NativeLibLoader -> <TYPE>JNILibLoader - Fixed Exception Handling (as in gluegen bce53b52c8638729750c4286dbc04cb14329fd34), ie removed empty catch Throwable .. - GLContext.setSwapInterval(): Nop in offscreen case, otherwise X11IOError (NVIDIA Bug) Test: Tests - Junit - demos.gears.Gears - demos.jrefract.JRefract Platforms - Linux 64/32 ATI/NVidia - MacOsX - Windows (virtualbox 3.1.6, offscreen failed) TODO/BUGS: - FIXME ATI GLn n>2 with AWT, can't make context current, works well on NVIDIA though - FIXME GL3GL4: Due to GL3 and GL4 implementation bugs, we still choose GL2 first, if available! - Add GL 3.3 to GL3/gl3ext.h - Add GL 4.0 to GL3/gl3ext.h and fix the GL3/GL4 seperation - Rename jogl.gl2.jar -> jogl.gldesktop.jar (as done with it's native lib already)
Diffstat (limited to 'src/jogl/classes/javax/media')
-rw-r--r--src/jogl/classes/javax/media/opengl/GL4.java5
-rw-r--r--src/jogl/classes/javax/media/opengl/GL4bc.java5
-rw-r--r--src/jogl/classes/javax/media/opengl/GLContext.java187
-rw-r--r--src/jogl/classes/javax/media/opengl/GLDrawableFactory.java62
-rw-r--r--src/jogl/classes/javax/media/opengl/GLProfile.java534
5 files changed, 527 insertions, 266 deletions
diff --git a/src/jogl/classes/javax/media/opengl/GL4.java b/src/jogl/classes/javax/media/opengl/GL4.java
deleted file mode 100644
index 29a316333..000000000
--- a/src/jogl/classes/javax/media/opengl/GL4.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package javax.media.opengl;
-
-public interface GL4 extends GLBase {
-}
-
diff --git a/src/jogl/classes/javax/media/opengl/GL4bc.java b/src/jogl/classes/javax/media/opengl/GL4bc.java
deleted file mode 100644
index be1131e91..000000000
--- a/src/jogl/classes/javax/media/opengl/GL4bc.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package javax.media.opengl;
-
-public interface GL4bc extends GL4 {
-}
-
diff --git a/src/jogl/classes/javax/media/opengl/GLContext.java b/src/jogl/classes/javax/media/opengl/GLContext.java
index 833ebf192..e5b499af9 100644
--- a/src/jogl/classes/javax/media/opengl/GLContext.java
+++ b/src/jogl/classes/javax/media/opengl/GLContext.java
@@ -40,6 +40,7 @@
package javax.media.opengl;
import java.util.HashMap;
+import com.jogamp.common.util.IntIntHashMap;
/** Abstraction for an OpenGL rendering context. In order to perform
OpenGL rendering, a context must be "made current" on the current
@@ -261,6 +262,12 @@ public abstract class GLContext {
StringBuffer sb = new StringBuffer();
sb.append(getClass().getName());
sb.append(" [OpenGL ");
+ sb.append(getGLVersionMajor());
+ sb.append(".");
+ sb.append(getGLVersionMinor());
+ sb.append(", options 0x");
+ sb.append(Integer.toHexString(ctxOptions));
+ sb.append(", ");
sb.append(getGLVersion());
sb.append(", ");
sb.append(getGL());
@@ -284,7 +291,7 @@ public abstract class GLContext {
public abstract String getPlatformExtensionsString();
public final int getGLVersionMajor() { return ctxMajorVersion; }
- public final int getGLVersionMinor() { return ctxMajorVersion; }
+ public final int getGLVersionMinor() { return ctxMinorVersion; }
public final boolean isGLCompatibilityProfile() { return ( 0 != ( CTX_PROFILE_COMPAT & ctxOptions ) ); }
public final boolean isGLForwardCompatible() { return ( 0 != ( CTX_OPTION_FORWARD & ctxOptions ) ); }
public final boolean isCreatedWithARBMethod() { return ( 0 != ( CTX_IS_ARB_CREATED & ctxOptions ) ); }
@@ -342,9 +349,181 @@ public abstract class GLContext {
/** <code>ARB_create_context</code> related: core profile */
protected static final int CTX_PROFILE_CORE = 1 << 2;
/** <code>ARB_create_context</code> related: flag forward compatible */
- protected static final int CTX_OPTION_FORWARD = 1 << 3;
+ protected static final int CTX_PROFILE_ES = 1 << 3;
+ /** <code>ARB_create_context</code> related: flag forward compatible */
+ protected static final int CTX_OPTION_FORWARD = 1 << 4;
/** <code>ARB_create_context</code> related: not flag forward compatible */
- protected static final int CTX_OPTION_ANY = 1 << 4;
+ protected static final int CTX_OPTION_ANY = 1 << 5;
/** <code>ARB_create_context</code> related: flag debug */
- protected static final int CTX_OPTION_DEBUG = 1 << 5;
+ protected static final int CTX_OPTION_DEBUG = 1 << 6;
+
+
+ public final boolean isGL4bc() {
+ return ctxMajorVersion>=4 && CTX_PROFILE_COMPAT==(ctxOptions & (CTX_PROFILE_COMPAT|CTX_PROFILE_ES));
+ }
+
+ public final boolean isGL4() {
+ return ctxMajorVersion>=4 && 0==(ctxOptions & (CTX_PROFILE_ES));
+ }
+
+ public final boolean isGL3bc() {
+ return ctxMajorVersion>=3 && CTX_PROFILE_COMPAT==(ctxOptions & (CTX_PROFILE_COMPAT|CTX_PROFILE_ES));
+ }
+
+ public final boolean isGL3() {
+ return ctxMajorVersion>=3 && 0==(ctxOptions & (CTX_PROFILE_ES));
+ }
+
+ public final boolean isGL2() {
+ return ctxMajorVersion>=1 && CTX_PROFILE_COMPAT==(ctxOptions & (CTX_PROFILE_COMPAT|CTX_PROFILE_ES));
+ }
+
+ public final boolean isGLES1() {
+ return ctxMajorVersion==1 && CTX_PROFILE_ES==(ctxOptions & CTX_PROFILE_ES);
+ }
+
+ public final boolean isGLES2() {
+ return ctxMajorVersion==2 && CTX_PROFILE_ES==(ctxOptions & CTX_PROFILE_ES);
+ }
+
+ public final boolean isGLES() {
+ return CTX_PROFILE_ES==(ctxOptions & CTX_PROFILE_ES);
+ }
+
+ public final boolean isGL2ES1() {
+ return isGL2() || isGLES1() ;
+ }
+
+ public final boolean isGL2ES2() {
+ return isGL2() || isGL3() || isGLES2() ;
+ }
+
+ public final boolean isGL2GL3() {
+ return isGL2() || isGL3();
+ }
+
+ public final boolean hasGLSL() {
+ return isGL2ES2() ;
+ }
+
+ public static final int GL_VERSIONS[][] = {
+ /* 0.*/ { -1 },
+ /* 1.*/ { 0, 1, 2, 3, 4, 5 },
+ /* 2.*/ { 0, 1 },
+ /* 3.*/ { 0, 1, 2, 3 },
+ /* 4.*/ { 0 } };
+
+ public static final int getMaxMajor() {
+ return GL_VERSIONS.length-1;
+ }
+
+ public static final int getMaxMinor(int major) {
+ if(1>major || major>=GL_VERSIONS.length) return -1;
+ return GL_VERSIONS[major].length-1;
+ }
+
+ public static final boolean isValidGLVersion(int major, int minor) {
+ if(1>major || major>=GL_VERSIONS.length) return false;
+ if(0>minor || minor>=GL_VERSIONS[major].length) return false;
+ return true;
+ }
+
+ public static final boolean decrementGLVersion(int major[], int minor[]) {
+ if(null==major || major.length<1 ||null==minor || minor.length<1) {
+ throw new GLException("invalid array arguments");
+ }
+ int m = major[0];
+ int n = minor[0];
+ if(!isValidGLVersion(m, n)) return false;
+
+ // decrement ..
+ n -= 1;
+ if(n < 0) {
+ m -= 1;
+ n = GL_VERSIONS[m].length-1;
+ }
+ if(!isValidGLVersion(m, n)) return false;
+ major[0]=m;
+ minor[0]=n;
+
+ return true;
+ }
+
+ public static final boolean isGLVersionAvailable(int major, boolean compatibility) {
+ int key = compose8bit(major, compatibility?CTX_PROFILE_COMPAT:CTX_PROFILE_CORE, 0, 0);
+ int val = mappedVersionsAvailable.get( key );
+ return val>0;
+ }
+ public static final boolean isGL4bcAvailable() { return isGLVersionAvailable(4, true); }
+ public static final boolean isGL4Available() { return isGLVersionAvailable(4, false); }
+ public static final boolean isGL3bcAvailable() { return isGLVersionAvailable(3, true); }
+ public static final boolean isGL3Available() { return isGLVersionAvailable(3, false); }
+ public static final boolean isGL2Available() { return isGLVersionAvailable(2, true); }
+
+ protected static final IntIntHashMap mappedVersionsAvailable;
+ protected static volatile boolean mappedVersionsAvailableSet;
+ protected static Object mappedVersionsAvailableLock;
+
+ static {
+ mappedVersionsAvailableLock = new Object();
+ mappedVersionsAvailableSet = false;
+ mappedVersionsAvailable = new IntIntHashMap();
+ mappedVersionsAvailable.setKeyNotFoundValue(-1);
+ }
+
+ /**
+ * Called by {@link GLContextImpl#createContextARBMapVersionsAvailable} not intendet to be used by
+ * implementations. However, if {@link #createContextARB} is not being used within the
+ * {@link GLDrawableImpl} constructor, GLProfile has to map the available versions.
+ *
+ * @see #createContextARBMapVersionsAvailable
+ */
+ protected static void mapVersionAvailable(int reqMajor, boolean reqCompat, int resMajor, int resMinor, int resCtp)
+ {
+ int key = compose8bit(reqMajor, reqCompat?CTX_PROFILE_COMPAT:CTX_PROFILE_CORE, 0, 0);
+ int val = compose8bit(resMajor, resMinor, resCtp, 0);
+ mappedVersionsAvailable.put( key, val );
+ }
+
+ protected static int compose8bit(int one, int two, int three, int four) {
+ return ( ( one & 0x000000FF ) << 24 ) |
+ ( ( two & 0x000000FF ) << 16 ) |
+ ( ( three & 0x000000FF ) << 8 ) |
+ ( ( four & 0x000000FF ) ) ;
+ }
+
+ protected static int getComposed8bit(int bits32, int which ) {
+ switch (which) {
+ case 1: return ( bits32 & 0xFF000000 ) >> 24 ;
+ case 2: return ( bits32 & 0x00FF0000 ) >> 16 ;
+ case 3: return ( bits32 & 0x0000FF00 ) >> 8 ;
+ case 4: return ( bits32 & 0xFF0000FF ) ;
+ }
+ throw new GLException("argument which out of range: "+which);
+ }
+
+ protected static String composed8BitToString(int bits32, boolean hex1, boolean hex2, boolean hex3, boolean hex4) {
+ int a = getComposed8bit(bits32, 1);
+ int b = getComposed8bit(bits32, 2);
+ int c = getComposed8bit(bits32, 3);
+ int d = getComposed8bit(bits32, 4);
+ return "["+toString(a, hex1)+", "+toString(b, hex2)+", "+toString(c, hex3)+", "+toString(d, hex4)+"]";
+ }
+
+ protected static String toString(int val, boolean hex) {
+ if(hex) {
+ return "0x" + Integer.toHexString(val);
+ }
+ return String.valueOf(val);
+ }
+
+ protected static String toHexString(int hex) {
+ return "0x" + Integer.toHexString(hex);
+ }
+
+ protected static String toHexString(long hex) {
+ return "0x" + Long.toHexString(hex);
+ }
+
}
+
diff --git a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java
index 80c2c10e2..b02bffb61 100644
--- a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java
+++ b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java
@@ -42,8 +42,9 @@ package javax.media.opengl;
import javax.media.nativewindow.*;
import java.security.*;
+import com.jogamp.common.JogampRuntimeException;
+import com.jogamp.common.util.*;
import com.jogamp.opengl.impl.*;
-import com.jogamp.nativewindow.impl.NWReflection;
/** <P> Provides a virtual machine- and operating system-independent
mechanism for creating {@link GLDrawable}s. </P>
@@ -96,51 +97,50 @@ public abstract class GLDrawableFactory {
static {
GLDrawableFactory tmp = null;
try {
- tmp = (GLDrawableFactory) NWReflection.createInstance("com.jogamp.opengl.impl.egl.EGLDrawableFactory");
- } catch (Throwable t) {
+ tmp = (GLDrawableFactory) ReflectionUtil.createInstance("com.jogamp.opengl.impl.egl.EGLDrawableFactory");
+ } catch (JogampRuntimeException jre) {
if (GLProfile.DEBUG) {
System.err.println("GLDrawableFactory.static - EGLDrawableFactory - not available");
- t.printStackTrace();
+ jre.printStackTrace();
}
}
eglFactory = tmp;
nativeOSType = NativeWindowFactory.getNativeWindowType(true);
- String factoryClassName = null;
tmp = null;
- try {
- factoryClassName = Debug.getProperty("jogl.gldrawablefactory.class.name", true, AccessController.getContext());
- if (null == factoryClassName) {
- if ( nativeOSType.equals(NativeWindowFactory.TYPE_X11) ) {
- factoryClassName = "com.jogamp.opengl.impl.x11.glx.X11GLXDrawableFactory";
- } else if ( nativeOSType.equals(NativeWindowFactory.TYPE_WINDOWS) ) {
- factoryClassName = "com.jogamp.opengl.impl.windows.wgl.WindowsWGLDrawableFactory";
- } else if ( nativeOSType.equals(NativeWindowFactory.TYPE_MACOSX) ) {
- if(NWReflection.isClassAvailable(macosxFactoryClassNameAWTCGL)) {
- factoryClassName = macosxFactoryClassNameAWTCGL;
- } else {
- factoryClassName = macosxFactoryClassNameCGL;
- }
+ String factoryClassName = Debug.getProperty("jogl.gldrawablefactory.class.name", true, AccessController.getContext());
+ if (null == factoryClassName) {
+ if ( nativeOSType.equals(NativeWindowFactory.TYPE_X11) ) {
+ factoryClassName = "com.jogamp.opengl.impl.x11.glx.X11GLXDrawableFactory";
+ } else if ( nativeOSType.equals(NativeWindowFactory.TYPE_WINDOWS) ) {
+ factoryClassName = "com.jogamp.opengl.impl.windows.wgl.WindowsWGLDrawableFactory";
+ } else if ( nativeOSType.equals(NativeWindowFactory.TYPE_MACOSX) ) {
+ if(ReflectionUtil.isClassAvailable(macosxFactoryClassNameAWTCGL)) {
+ factoryClassName = macosxFactoryClassNameAWTCGL;
} else {
- // may use egl*Factory ..
- if (GLProfile.DEBUG) {
- System.err.println("GLDrawableFactory.static - No native OS Factory for: "+nativeOSType+"; May use EGLDrawableFactory, if available." );
- }
+ factoryClassName = macosxFactoryClassNameCGL;
}
- }
- if (null != factoryClassName) {
+ } else {
+ // may use egl*Factory ..
if (GLProfile.DEBUG) {
- System.err.println("GLDrawableFactory.static - Native OS Factory for: "+nativeOSType+": "+factoryClassName);
+ System.err.println("GLDrawableFactory.static - No native OS Factory for: "+nativeOSType+"; May use EGLDrawableFactory, if available." );
}
- tmp = (GLDrawableFactory) NWReflection.createInstance(factoryClassName);
- }
- } catch (Throwable t) {
- if (GLProfile.DEBUG) {
- System.err.println("GLDrawableFactory.static - Native Platform: "+nativeOSType+" - not available: "+factoryClassName);
- t.printStackTrace();
}
}
+ if (null != factoryClassName) {
+ if (GLProfile.DEBUG) {
+ System.err.println("GLDrawableFactory.static - Native OS Factory for: "+nativeOSType+": "+factoryClassName);
+ }
+ try {
+ tmp = (GLDrawableFactory) ReflectionUtil.createInstance(factoryClassName);
+ } catch (JogampRuntimeException jre) {
+ if (GLProfile.DEBUG) {
+ System.err.println("GLDrawableFactory.static - Native Platform: "+nativeOSType+" - not available: "+factoryClassName);
+ jre.printStackTrace();
+ }
+ }
+ }
nativeOSFactory = tmp;
}
diff --git a/src/jogl/classes/javax/media/opengl/GLProfile.java b/src/jogl/classes/javax/media/opengl/GLProfile.java
index e1fc9f53f..9e3a532e6 100644
--- a/src/jogl/classes/javax/media/opengl/GLProfile.java
+++ b/src/jogl/classes/javax/media/opengl/GLProfile.java
@@ -36,12 +36,13 @@
package javax.media.opengl;
+import com.jogamp.common.util.*;
import com.jogamp.opengl.impl.DRIHack;
import com.jogamp.opengl.impl.Debug;
-import com.jogamp.opengl.impl.NativeLibLoader;
-import com.jogamp.nativewindow.impl.NWReflection;
-import com.jogamp.nativewindow.impl.jvm.JVMUtil;
+import com.jogamp.opengl.impl.GLJNILibLoader;
+import com.jogamp.common.jvm.JVMUtil;
import java.util.HashMap;
+import java.util.Iterator;
import java.security.AccessControlContext;
import java.security.AccessController;
import javax.media.opengl.fixedfunc.GLPointerFunc;
@@ -59,6 +60,45 @@ public class GLProfile implements Cloneable {
public static final boolean DEBUG = Debug.debug("GLProfile");
//
+ // Query platform available OpenGL implementation
+ //
+
+ public static final boolean isGL4bcAvailable() { return hasGL4bcImpl; }
+ public static final boolean isGL4Available() { return hasGL4Impl; }
+ public static final boolean isGL3bcAvailable() { return hasGL3bcImpl; }
+ public static final boolean isGL3Available() { return hasGL3Impl; }
+ public static final boolean isGL2Available() { return hasGL2Impl; }
+ public static final boolean isGLES2Available() { return hasGLES2Impl; }
+ public static final boolean isGLES1Available() { return hasGLES1Impl; }
+ public static final String glAvailabilityToString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("GLAvailability[Native[GL4bc ");
+ sb.append(hasGL4bcImpl);
+ sb.append(", GL4 ");
+ sb.append(hasGL4Impl);
+ sb.append(", GL3bc ");
+ sb.append(hasGL3bcImpl);
+ sb.append(", GL3 ");
+ sb.append(hasGL3Impl);
+ sb.append(", GL2 ");
+ sb.append(hasGL2Impl);
+ sb.append(", GLES1 ");
+ sb.append(hasGLES1Impl);
+ sb.append(", GLES2 ");
+ sb.append(hasGLES2Impl);
+ sb.append("], Profiles[");
+ for(Iterator i=mappedProfiles.values().iterator(); i.hasNext(); ) {
+ sb.append(((GLProfile)i.next()).toString());
+ sb.append(", ");
+ }
+ sb.append(", default ");
+ sb.append(defaultGLProfile);
+ sb.append("]]");
+
+ return sb.toString();
+ }
+
+ //
// Public (user-visible) profiles
//
@@ -95,22 +135,92 @@ public class GLProfile implements Cloneable {
public static final String GL2GL3 = "GL2GL3";
/**
- * All GL Profiles in the order of default detection: GL2, GL2ES2, GL2ES1, GLES2, GLES1, GL2GL3, GL3
+ * All GL Profiles in the order of default detection.
+ * Desktop compatibility profiles (the one with fixed function pipeline) comes first.
+ *
+ * FIXME GL3GL4: Due to GL3 and GL4 implementation bugs, we still choose GL2 first, if available!
+ *
+ * <ul>
+ * <li> GL2
+ * <li> GL3bc
+ * <li> GL4bc
+ * <li> GL2GL3
+ * <li> GL3
+ * <li> GL4
+ * <li> GL2ES2
+ * <li> GLES2
+ * <li> GL2ES1
+ * <li> GLES1
+ * </ul>
+ *
*/
- public static final String[] GL_PROFILE_LIST_ALL = new String[] { GL2, GL2ES2, GL2ES1, GLES2, GLES1, GL2GL3, GL4bc, GL3bc, GL4, GL3 };
+ public static final String[] GL_PROFILE_LIST_ALL = new String[] { GL2, GL3bc, GL4bc, GL2GL3, GL3, GL4, GL2ES2, GLES2, GL2ES1, GLES1 };
/**
- * All GL2ES2 Profiles in the order of default detection: GL2ES2, GL2, GLES2, GL3
+ * Order of maximum fixed function profiles
+ *
+ * <ul>
+ * <li> GL4bc
+ * <li> GL3bc
+ * <li> GL2
+ * <li> GL2ES1
+ * <li> GLES1
+ * </ul>
+ *
+ */
+ public static final String[] GL_PROFILE_LIST_MAX_FIXEDFUNC = new String[] { GL4bc, GL3bc, GL2, GL2ES1, GLES1 };
+
+ /**
+ * Order of maximum programmable shader profiles
+ *
+ * <ul>
+ * <li> GL4
+ * <li> GL4bc
+ * <li> GL3
+ * <li> GL3bc
+ * <li> GL2
+ * <li> GL2ES2
+ * <li> GLES2
+ * </ul>
+ *
+ */
+ public static final String[] GL_PROFILE_LIST_MAX_PROGSHADER = new String[] { GL4, GL4bc, GL3, GL3bc, GL2, GL2ES2, GLES2 };
+
+ /**
+ * All GL2ES2 Profiles in the order of default detection.
+ *
+ * FIXME GL3GL4: Due to GL3 and GL4 implementation bugs, we still choose GL2 first, if available!
+ *
+ * <ul>
+ * <li> GL2ES2
+ * <li> GL2
+ * <li> GL3
+ * <li> GL4
+ * <li> GLES2
+ * </ul>
+ *
*/
- public static final String[] GL_PROFILE_LIST_GL2ES2 = new String[] { GL2ES2, GL2, GLES2, GL4bc, GL3bc, GL4, GL3 };
+ public static final String[] GL_PROFILE_LIST_GL2ES2 = new String[] { GL2ES2, GL2, GL3, GL4, GLES2 };
/**
- * All GL2ES1 Profiles in the order of default detection: GL2ES1, GL2, GLES1
+ * All GL2ES1 Profiles in the order of default detection.
+ *
+ * FIXME GL3GL4: Due to GL3 and GL4 implementation bugs, we still choose GL2 first, if available!
+ *
+ * <ul>
+ * <li> GL2ES1
+ * <li> GL2
+ * <li> GL3bc
+ * <li> GL4bc
+ * <li> GLES1
+ * </ul>
+ *
*/
- public static final String[] GL_PROFILE_LIST_GL2ES1 = new String[] { GL2ES1, GL2, GLES1 };
+ public static final String[] GL_PROFILE_LIST_GL2ES1 = new String[] { GL2ES1, GL2, GL3bc, GL4bc, GLES1 };
/** Returns a default GLProfile object, reflecting the best for the running platform.
* It selects the first of the set {@link GLProfile#GL_PROFILE_LIST_ALL}
+ * @see #GL_PROFILE_LIST_ALL
*/
public static final GLProfile getDefault() {
if(null==defaultGLProfile) {
@@ -119,22 +229,30 @@ public class GLProfile implements Cloneable {
return defaultGLProfile;
}
- /** Returns a GLProfile object.
- * Verfifies the given profile and chooses an apropriate implementation.
- * A generic value of <code>null</code> or <code>GL</code> will result in
- * the default profile.
+ /**
+ * Returns the highest profile, implementing the fixed function pipeline
+ * It selects the first of the set: {@link GLProfile#GL_PROFILE_LIST_MAX_FIXEDFUNC}
*
* @throws GLException if no implementation for the given profile is found.
+ * @see #GL_PROFILE_LIST_MAX_FIXEDFUNC
*/
- public static final GLProfile get(String profile)
+ public static final GLProfile getMaxFixedFunc()
throws GLException
{
- if(null==profile || profile.equals("GL")) return getDefault();
- GLProfile glProfile = (GLProfile) mappedProfiles.get(profile);
- if(null==glProfile) {
- throw new GLException("No implementation for profile "+profile+" available");
- }
- return glProfile;
+ return get(GL_PROFILE_LIST_MAX_FIXEDFUNC);
+ }
+
+ /**
+ * Returns the highest profile, implementing the programmable shader pipeline.
+ * It selects the first of the set: {@link GLProfile#GL_PROFILE_LIST_MAX_PROGSHADER}
+ *
+ * @throws GLException if no implementation for the given profile is found.
+ * @see #GL_PROFILE_LIST_MAX_PROGSHADER
+ */
+ public static final GLProfile getMaxProgrammable()
+ throws GLException
+ {
+ return get(GL_PROFILE_LIST_MAX_PROGSHADER);
}
/**
@@ -142,6 +260,7 @@ public class GLProfile implements Cloneable {
* It selects the first of the set: {@link GLProfile#GL_PROFILE_LIST_GL2ES1}
*
* @throws GLException if no implementation for the given profile is found.
+ * @see #GL_PROFILE_LIST_GL2ES1
*/
public static final GLProfile getGL2ES1()
throws GLException
@@ -154,6 +273,7 @@ public class GLProfile implements Cloneable {
* It selects the first of the set: {@link GLProfile#GL_PROFILE_LIST_GL2ES2}
*
* @throws GLException if no implementation for the given profile is found.
+ * @see #GL_PROFILE_LIST_GL2ES2
*/
public static final GLProfile getGL2ES2()
throws GLException
@@ -161,6 +281,24 @@ public class GLProfile implements Cloneable {
return get(GL_PROFILE_LIST_GL2ES2);
}
+ /** Returns a GLProfile object.
+ * Verfifies the given profile and chooses an apropriate implementation.
+ * A generic value of <code>null</code> or <code>GL</code> will result in
+ * the default profile.
+ *
+ * @throws GLException if no implementation for the given profile is found.
+ */
+ public static final GLProfile get(String profile)
+ throws GLException
+ {
+ if(null==profile || profile.equals("GL")) return getDefault();
+ GLProfile glProfile = (GLProfile) mappedProfiles.get(profile);
+ if(null==glProfile) {
+ throw new GLException("No implementation for profile "+profile+" available");
+ }
+ return glProfile;
+ }
+
/**
* Returns the first profile from the given list,
* where an implementation is available.
@@ -200,18 +338,12 @@ public class GLProfile implements Cloneable {
}
private static final String getGLImplBaseClassName(String profileImpl) {
- if(GL4bc.equals(profileImpl)) {
+ if ( GL4bc.equals(profileImpl) ||
+ GL4.equals(profileImpl) ||
+ GL3bc.equals(profileImpl) ||
+ GL3.equals(profileImpl) ||
+ GL2.equals(profileImpl) ) {
return "com.jogamp.opengl.impl.gl4.GL4bc";
- } else if(GL4.equals(profileImpl)) {
- return "com.jogamp.opengl.impl.gl4.GL4";
- } else if(GL3bc.equals(profileImpl)) {
- return "com.jogamp.opengl.impl.gl3.GL3bc";
- } else if(GL3.equals(profileImpl)) {
- return "com.jogamp.opengl.impl.gl3.GL3";
- } else if(GL2.equals(profileImpl)) {
- return "com.jogamp.opengl.impl.gl2.GL2";
- } else if(GL2ES12.equals(profileImpl)) {
- return "com.jogamp.opengl.impl.gl2es12.GL2ES12";
} else if(GLES1.equals(profileImpl) || GL2ES1.equals(profileImpl)) {
return "com.jogamp.opengl.impl.es1.GLES1";
} else if(GLES2.equals(profileImpl) || GL2ES2.equals(profileImpl)) {
@@ -285,7 +417,7 @@ public class GLProfile implements Cloneable {
return isGL4() || isGL3bc() || GL3.equals(profile);
}
- /** Indicates whether this profile is capable of GL2. */
+ /** Indicates whether this context is a GL2 context */
public final boolean isGL2() {
return isGL3bc() || GL2.equals(profile);
}
@@ -315,34 +447,9 @@ public class GLProfile implements Cloneable {
return GL2GL3.equals(profile) || isGL2() || isGL3() ;
}
- /** Indicates whether this profile uses the native desktop OpenGL GL4bc implementations. */
- public final boolean usesNativeGL4bc() {
- return GL4bc.equals(profileImpl);
- }
-
- /** Indicates whether this profile uses the native desktop OpenGL GL4 implementations. */
- public final boolean usesNativeGL4() {
- return usesNativeGL4bc() || GL4.equals(profileImpl);
- }
-
- /** Indicates whether this profile uses the native desktop OpenGL GL3bc implementations. */
- public final boolean usesNativeGL3bc() {
- return GL3bc.equals(profileImpl);
- }
-
- /** Indicates whether this profile uses the native desktop OpenGL GL3 implementations. */
- public final boolean usesNativeGL3() {
- return usesNativeGL3bc() || GL3.equals(profileImpl);
- }
-
- /** Indicates whether this profile uses the native desktop OpenGL GL2 implementations. */
- public final boolean usesNativeGL2() {
- return GL2.equals(profileImpl) || GL2ES12.equals(profileImpl) ;
- }
-
- /** Indicates whether this profile uses the native desktop OpenGL GL2 or GL3 implementations. */
- public final boolean usesNativeGL2GL3() {
- return usesNativeGL2() || usesNativeGL3() || usesNativeGL4();
+ /** Indicates whether this profile supports GLSL. */
+ public final boolean hasGLSL() {
+ return isGL2ES2() ;
}
/** Indicates whether this profile uses the native OpenGL ES1 implementations. */
@@ -360,11 +467,6 @@ public class GLProfile implements Cloneable {
return usesNativeGLES2() || usesNativeGLES1();
}
- /** Indicates whether this profile supports GLSL. */
- public final boolean hasGLSL() {
- return isGL2ES2() ;
- }
-
/**
* General validation if type is a valid GL data type
* for the current profile
@@ -665,70 +767,23 @@ public class GLProfile implements Cloneable {
return "GLProfile[" + profile + "/" + profileImpl + "]";
}
- public static final int GL_VERSIONS[][] = {
- /* 0.*/ { -1 },
- /* 1.*/ { 0, 1, 2, 3, 4, 5 },
- /* 2.*/ { 0, 1 },
- /* 3.*/ { 0, 1, 2, 3 },
- /* 4.*/ { 0 } };
-
- public static final int getMaxMajor() {
- return GL_VERSIONS.length-1;
- }
-
- public static final int getMaxMinor(int major) {
- if(1>major || major>=GL_VERSIONS.length) return -1;
- return GL_VERSIONS[major].length-1;
- }
-
- public static final boolean isValidGLVersion(int major, int minor) {
- if(1>major || major>=GL_VERSIONS.length) return false;
- if(0>minor || minor>=GL_VERSIONS[major].length) return false;
- return true;
- }
-
- public static final boolean decrementGLVersion(int major[], int minor[]) {
- if(null==major || major.length<1 ||null==minor || minor.length<1) {
- throw new GLException("invalid array arguments");
- }
- int m = major[0];
- int n = minor[0];
- if(!isValidGLVersion(m, n)) return false;
-
- // decrement ..
- n -= 1;
- if(n < 0) {
- m -= 1;
- n = GL_VERSIONS[m].length-1;
- }
- if(!isValidGLVersion(m, n)) return false;
- major[0]=m;
- minor[0]=n;
-
- return true;
- }
-
- // The intersection between desktop OpenGL and the union of the OpenGL ES profiles
- // This is here only to avoid having separate GL2ES1Impl and GL2ES2Impl classes
- private static final String GL2ES12 = "GL2ES12";
-
private static final boolean isAWTAvailable;
private static final boolean isAWTJOGLAvailable;
- private static final boolean hasGL4bcImpl;
- private static final boolean hasGL4Impl;
- private static final boolean hasGL3bcImpl;
- private static final boolean hasGL3Impl;
- private static final boolean hasGL2Impl;
- private static final boolean hasGL2ES12Impl;
- private static final boolean hasGLES2Impl;
- private static final boolean hasGLES1Impl;
+ private static /*final*/ boolean hasGL234Impl;
+ private static /*final*/ boolean hasGL4bcImpl;
+ private static /*final*/ boolean hasGL4Impl;
+ private static /*final*/ boolean hasGL3bcImpl;
+ private static /*final*/ boolean hasGL3Impl;
+ private static /*final*/ boolean hasGL2Impl;
+ private static /*final*/ boolean hasGLES2Impl;
+ private static /*final*/ boolean hasGLES1Impl;
/** The JVM/process wide default GL profile **/
- private static GLProfile defaultGLProfile;
+ private static /*final*/ GLProfile defaultGLProfile;
/** All GLProfiles */
- private static final HashMap/*<String, GLProfile>*/ mappedProfiles;
+ private static /*final*/ HashMap/*<String, GLProfile>*/ mappedProfiles;
/**
* Tries the profiles implementation and native libraries.
@@ -740,119 +795,174 @@ public class GLProfile implements Cloneable {
AccessControlContext acc = AccessController.getContext();
isAWTAvailable = !Debug.getBooleanProperty("java.awt.headless", true, acc) &&
- NWReflection.isClassAvailable("java.awt.Component") ;
+ ReflectionUtil.isClassAvailable("java.awt.Component") ;
isAWTJOGLAvailable = isAWTAvailable &&
- NWReflection.isClassAvailable("javax.media.nativewindow.awt.AWTGraphicsDevice") && // NativeWindow
- NWReflection.isClassAvailable("javax.media.opengl.awt.GLCanvas") ; // JOGL
+ ReflectionUtil.isClassAvailable("javax.media.nativewindow.awt.AWTGraphicsDevice") && // NativeWindow
+ ReflectionUtil.isClassAvailable("javax.media.opengl.awt.GLCanvas") ; // JOGL
boolean hasDesktopGL = false;
- boolean hasDesktopGLES12 = false;
boolean hasNativeOSFactory = false;
-
+ Throwable t;
+
+ //
+ // First iteration of desktop GL availability detection
+ // - native libs exist
+ // - class exists
+ //
+ t=null;
try {
// See DRIHack.java for an explanation of why this is necessary
DRIHack.begin();
- NativeLibLoader.loadGLDesktop();
+ GLJNILibLoader.loadGLDesktop();
DRIHack.end();
hasDesktopGL = true;
- } catch (Throwable t) {
+ } catch (UnsatisfiedLinkError ule) {
+ t=ule;
+ } catch (SecurityException se) {
+ t=se;
+ } catch (NullPointerException npe) {
+ t=npe;
+ } catch (RuntimeException re) {
+ t=re;
+ }
+ if(null!=t) {
if (DEBUG) {
System.err.println("GLProfile.static Desktop GL Library not available");
t.printStackTrace();
}
}
- try {
- // See DRIHack.java for an explanation of why this is necessary
- DRIHack.begin();
- NativeLibLoader.loadGLDesktopES12();
- DRIHack.end();
- hasDesktopGLES12 = true;
- } catch (Throwable t) {
- if (DEBUG) {
- System.err.println("GLProfile.static Desktop GL ES12 Library not available");
- t.printStackTrace();
+ hasGL234Impl = hasDesktopGL && ReflectionUtil.isClassAvailable("com.jogamp.opengl.impl.gl4.GL4bcImpl");
+ hasGL4bcImpl = hasGL234Impl;
+ hasGL4Impl = hasGL234Impl;
+ hasGL3bcImpl = hasGL234Impl;
+ hasGL3Impl = hasGL234Impl;
+ hasGL2Impl = hasGL234Impl;
+ mappedProfiles = computeProfileMap();
+
+ //
+ // Second iteration of desktop GL availability detection
+ // utilizing the detected GL version in the shared context.
+ //
+ // - Instantiate GLDrawableFactory incl its shared dummy drawable/context,
+ // which will register at GLContext ..
+ //
+
+ if(hasDesktopGL) {
+ // if successfull it has a shared dummy drawable and context created
+ try {
+ hasNativeOSFactory = null != GLDrawableFactory.getFactoryImpl(GL2);
+ } catch (RuntimeException re) {
+ System.err.println("GLProfile.static - Native platform GLDrawable factory not available");
+ re.printStackTrace();
}
}
- if(hasDesktopGL||hasDesktopGLES12) {
- try {
- hasNativeOSFactory = null!=GLDrawableFactory.getFactoryImpl(GL2);
- } catch (Throwable t) {
- if (DEBUG) {
- System.err.println("GLProfile.static - Native platform GLDrawable factory not available");
- t.printStackTrace();
- }
- }
+ if(hasNativeOSFactory && !GLContext.mappedVersionsAvailableSet) {
+ // nobody yet set the available desktop versions, see {@link GLContextImpl#makeCurrent},
+ // so we have to add the usual suspect
+ GLContext.mapVersionAvailable(2, true, 1, 5, GLContext.CTX_PROFILE_COMPAT|GLContext.CTX_OPTION_ANY);
}
if(!hasNativeOSFactory) {
- hasDesktopGLES12=false;
- hasDesktopGL=false;
+ hasDesktopGL = false;
+ hasGL234Impl = false;
+ hasGL4bcImpl = false;
+ hasGL4Impl = false;
+ hasGL3bcImpl = false;
+ hasGL3Impl = false;
+ hasGL2Impl = false;
+ } else {
+ hasGL4bcImpl = GLContext.isGL4bcAvailable();
+ hasGL4Impl = GLContext.isGL4Available();
+ hasGL3bcImpl = GLContext.isGL3bcAvailable();
+ hasGL3Impl = GLContext.isGL3Available();
+ hasGL2Impl = GLContext.isGL2Available();
}
- // FIXME: check for real GL3 availability .. ?
- hasGL4bcImpl = hasDesktopGL && NWReflection.isClassAvailable("com.jogamp.opengl.impl.gl4.GL4bcImpl");
- hasGL4Impl = hasDesktopGL && NWReflection.isClassAvailable("com.jogamp.opengl.impl.gl4.GL4Impl");
- hasGL3bcImpl = hasDesktopGL && NWReflection.isClassAvailable("com.jogamp.opengl.impl.gl3.GL3bcImpl");
- hasGL3Impl = hasDesktopGL && NWReflection.isClassAvailable("com.jogamp.opengl.impl.gl3.GL3Impl");
- hasGL2Impl = hasDesktopGL && NWReflection.isClassAvailable("com.jogamp.opengl.impl.gl2.GL2Impl");
-
- hasGL2ES12Impl = hasDesktopGLES12 && NWReflection.isClassAvailable("com.jogamp.opengl.impl.gl2es12.GL2ES12Impl");
-
boolean btest = false;
- boolean hasEGLDynLookup = NWReflection.isClassAvailable("com.jogamp.opengl.impl.egl.EGLDynamicLookupHelper");
+ boolean hasEGLDynLookup = ReflectionUtil.isClassAvailable("com.jogamp.opengl.impl.egl.EGLDynamicLookupHelper");
boolean hasEGLDrawableFactory = false;
+ t=null;
try {
if(hasEGLDynLookup) {
hasEGLDrawableFactory = null!=GLDrawableFactory.getFactoryImpl(GLES2);
- btest = hasEGLDrawableFactory &&
- NWReflection.isClassAvailable("com.jogamp.opengl.impl.es2.GLES2Impl") &&
- null!=com.jogamp.opengl.impl.egl.EGLDynamicLookupHelper.getDynamicLookupHelper(2);
+ try {
+ btest = hasEGLDrawableFactory &&
+ ReflectionUtil.isClassAvailable("com.jogamp.opengl.impl.es2.GLES2Impl") &&
+ null!=com.jogamp.opengl.impl.egl.EGLDynamicLookupHelper.getDynamicLookupHelper(2);
+ } catch (GLException gle) {
+ // n/a ..
+ }
}
- } catch (Throwable t) {
+ } catch (UnsatisfiedLinkError ule) {
+ t=ule;
+ } catch (SecurityException se) {
+ t=se;
+ } catch (NullPointerException npe) {
+ t=npe;
+ } catch (RuntimeException re) {
+ t=re;
+ }
+ if(null!=t) {
if (DEBUG) {
System.err.println("GLProfile.static - GL ES2 Factory/Library not available");
t.printStackTrace();
}
}
hasGLES2Impl = btest;
+ if(hasGLES2Impl) {
+ GLContext.mapVersionAvailable(2, false, 2, 0, GLContext.CTX_PROFILE_ES|GLContext.CTX_PROFILE_CORE|GLContext.CTX_OPTION_ANY);
+ }
btest = false;
- try {
- if(hasEGLDynLookup) {
+ if(hasEGLDynLookup) {
+ try {
btest = hasEGLDrawableFactory &&
- NWReflection.isClassAvailable("com.jogamp.opengl.impl.es1.GLES1Impl") &&
+ ReflectionUtil.isClassAvailable("com.jogamp.opengl.impl.es1.GLES1Impl") &&
null!=com.jogamp.opengl.impl.egl.EGLDynamicLookupHelper.getDynamicLookupHelper(1);
- }
- } catch (Throwable t) {
- if (DEBUG) {
- System.err.println("GLProfile.static - GL ES1 Factory/Library not available");
- t.printStackTrace();
+ } catch (GLException jre) {
+ /* just not available .. */
}
}
hasGLES1Impl = btest;
+ if(hasGLES1Impl) {
+ GLContext.mapVersionAvailable(1, false, 1, 0, GLContext.CTX_PROFILE_ES|GLContext.CTX_PROFILE_CORE|GLContext.CTX_OPTION_ANY);
+ }
+
+ mappedProfiles = computeProfileMap();
+ if(null==defaultGLProfile) {
+ throw new GLException("No profile available: "+list2String(GL_PROFILE_LIST_ALL));
+ }
if (DEBUG) {
System.err.println("GLProfile.static isAWTAvailable "+isAWTAvailable);
System.err.println("GLProfile.static isAWTJOGLAvailable "+isAWTJOGLAvailable);
System.err.println("GLProfile.static hasNativeOSFactory "+hasNativeOSFactory);
- System.err.println("GLProfile.static hasDesktopGLES12 "+hasDesktopGLES12);
System.err.println("GLProfile.static hasDesktopGL "+hasDesktopGL);
- System.err.println("GLProfile.static hasGL4bcImpl "+hasGL4bcImpl);
- System.err.println("GLProfile.static hasGL4Impl "+hasGL4Impl);
- System.err.println("GLProfile.static hasGL3bcImpl "+hasGL3bcImpl);
- System.err.println("GLProfile.static hasGL3Impl "+hasGL3Impl);
- System.err.println("GLProfile.static hasGL2Impl "+hasGL2Impl);
- System.err.println("GLProfile.static hasGL2ES12Impl "+hasGL2ES12Impl);
System.err.println("GLProfile.static hasEGLDynLookup "+hasEGLDynLookup);
System.err.println("GLProfile.static hasEGLDrawableFactory "+hasEGLDrawableFactory);
- System.err.println("GLProfile.static hasGLES2Impl "+hasGLES2Impl);
- System.err.println("GLProfile.static hasGLES1Impl "+hasGLES1Impl);
+ System.err.println("GLProfile.static hasGL234Impl "+hasGL234Impl);
+ System.err.println("GLProfile.static "+glAvailabilityToString());
+ }
+ }
+
+ private static final String list2String(String[] list) {
+ StringBuffer msg = new StringBuffer();
+ msg.append("[");
+ for (int i = 0; i < list.length; i++) {
+ if (i > 0)
+ msg.append(", ");
+ msg.append(list[i]);
}
+ msg.append("]");
+ return msg.toString();
+ }
+ private static HashMap computeProfileMap() {
+ defaultGLProfile=null;
HashMap/*<String, GLProfile>*/ _mappedProfiles = new HashMap(GL_PROFILE_LIST_ALL.length);
for(int i=0; i<GL_PROFILE_LIST_ALL.length; i++) {
String profile = GL_PROFILE_LIST_ALL[i];
@@ -875,73 +985,55 @@ public class GLProfile implements Cloneable {
}
}
}
- mappedProfiles = _mappedProfiles; // final ..
- if(null==defaultGLProfile) {
- throw new GLException("No profile available: "+list2String(GL_PROFILE_LIST_ALL));
- }
- }
-
- private static final String list2String(String[] list) {
- StringBuffer msg = new StringBuffer();
- msg.append("[");
- for (int i = 0; i < list.length; i++) {
- if (i > 0)
- msg.append(", ");
- msg.append(list[i]);
- }
- msg.append("]");
- return msg.toString();
+ return _mappedProfiles;
}
/**
* Returns the profile implementation
*/
private static String computeProfileImpl(String profile) {
- // FIXME Order of return profiles, after we can test their availability
if (GL2ES1.equals(profile)) {
- if(hasGL2ES12Impl) {
- return GL2ES12;
- } else if(hasGL2Impl) {
+ if(hasGL2Impl) {
return GL2;
+ } else if(hasGL3bcImpl) {
+ return GL3bc;
+ } else if(hasGL4bcImpl) {
+ return GL4bc;
} else if(hasGLES1Impl) {
return GLES1;
}
} else if (GL2ES2.equals(profile)) {
- if(hasGL2ES12Impl) {
- return GL2ES12;
- } else if(hasGL2Impl) {
+ if(hasGL2Impl) {
return GL2;
} else if(hasGL3Impl) {
return GL3;
- } else if(hasGL3bcImpl) {
- return GL3bc;
} else if(hasGL4Impl) {
return GL4;
- } else if(hasGL4bcImpl) {
- return GL4bc;
} else if(hasGLES2Impl) {
return GLES2;
}
- } else if(GL4bc.equals(profile) && hasGL4bcImpl) {
- return GL4bc;
- } else if(GL4.equals(profile)) {
- if(hasGL4Impl) {
- return GL4;
+ } else if(GL2GL3.equals(profile)) {
+ if(hasGL2Impl) {
+ return GL2;
+ } else if(hasGL3bcImpl) {
+ return GL3bc;
} else if(hasGL4bcImpl) {
return GL4bc;
+ } else if(hasGL3Impl) {
+ return GL3;
+ } else if(hasGL4Impl) {
+ return GL4;
}
+ } else if(GL4bc.equals(profile) && hasGL4bcImpl) {
+ return GL4bc;
+ } else if(GL4.equals(profile) && hasGL4Impl) {
+ return GL4;
} else if(GL3bc.equals(profile) && hasGL3bcImpl) {
return GL3bc;
- } else if(GL3.equals(profile)) {
- if(hasGL3Impl) {
- return GL3;
- } else if(hasGL3bcImpl) {
- return GL3bc;
- }
+ } else if(GL3.equals(profile) && hasGL3Impl) {
+ return GL3;
} else if(GL2.equals(profile) && hasGL2Impl) {
return GL2;
- } else if(GL2GL3.equals(profile) && hasGL2Impl) {
- return GL2;
} else if(GLES2.equals(profile) && hasGLES2Impl) {
return GLES2;
} else if(GLES1.equals(profile) && hasGLES1Impl) {