diff options
-rw-r--r-- | make/build.xml | 22 | ||||
-rwxr-xr-x | make/egl.cfg | 2 | ||||
-rw-r--r-- | make/gl-common.cfg | 32 | ||||
-rwxr-xr-x | make/gl-if-gl2_es2.cfg | 1 | ||||
-rwxr-xr-x | make/glxext.cfg | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/ExtensionAvailabilityCache.java | 121 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/FunctionAvailabilityCache.java | 390 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/GLContextImpl.java | 42 | ||||
-rwxr-xr-x | src/classes/com/sun/opengl/impl/egl/EGLContext.java | 97 | ||||
-rwxr-xr-x | src/classes/com/sun/opengl/impl/egl/EGLDrawable.java | 8 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/macosx/cgl/MacOSXCGLContext.java | 13 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLContext.java | 13 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/x11/glx/X11GLXContext.java | 22 | ||||
-rw-r--r-- | src/classes/javax/media/opengl/GLContext.java | 6 | ||||
-rw-r--r-- | src/classes/javax/media/opengl/GLProfile.java | 9 |
15 files changed, 299 insertions, 481 deletions
diff --git a/make/build.xml b/make/build.xml index b6c120caf..0dddeb43c 100644 --- a/make/build.xml +++ b/make/build.xml @@ -491,6 +491,7 @@ <target name="declare.gl.gles" unless="jogl.noes" depends="declare.gl.gles1, declare.gl.gles2"> <!-- Prepare to build the EGL interface --> <property name="window.es.cfg" value="${config}/egl.cfg" /> + <property name="window.es.ext.cfg" value="${config}/eglext.cfg" /> <property name="window.es.system" value="gluegen_egl"/> </target> @@ -745,6 +746,17 @@ </gluegen> </target> + <target name="java.generate.window.system.es.ext" if="window.es.ext.cfg" unless="jogl.noes"> + <echo message="Generating EGLExt implementation class" /> + <dirset id="stub.includes.fileset.platform" dir="." includes="${stub.includes.dir}/${window.es.system}/**" /> + <gluegen src="${stub.includes.dir}/${window.es.system}/window-system-ext.c" + config="${window.es.ext.cfg}" + includeRefid="stub.includes.fileset.platform" + emitter="com.sun.gluegen.opengl.GLEmitter"> + <classpath refid="gluegen.classpath" /> + </gluegen> + </target> + <target name="java.generate.window.system.os" if="window.os.cfg" unless="jogl.nogl2"> <echo message="Generating WGL/GLX/CGL/EGL implementation class" /> <gluegen src="${stub.includes.dir}/${window.os.system}/window-system.c" @@ -843,7 +855,8 @@ <antcall target="java.generate.gl.all" inheritRefs="true" /> <!--antcall target="java.generate.gl.nsig" inheritRefs="true" /--> - <antcall target="java.generate.window.system.es" inheritRefs="true" /> + <antcall target="java.generate.window.system.es" inheritRefs="true" /> + <antcall target="java.generate.window.system.es.ext" inheritRefs="true" /> <echo message="Generating platform-specifics: X11" /> <antcall target="java.generate.gl.platforms" inheritRefs="true"> @@ -876,13 +889,6 @@ <param name="jawt.platform.header" value="${stub.includes.dir}/jni/macosx/jawt_md.h" /> </antcall> - <echo message="Generating StaticGLInfo class" /> - <staticglgen package="com.sun.opengl.impl" - headers="${gl2.headers} ${gles1.headers} ${gles2.headers}" - outputdir="${src.generated.java}/com/sun/opengl/impl"> - <classpath refid="gluegen.classpath" /> - </staticglgen> - <!-- Generate GLU class --> <antcall target="java.generate.glu.base" inheritrefs="true" /> <antcall target="java.generate.glu.GL2ES1" inheritrefs="true" /> diff --git a/make/egl.cfg b/make/egl.cfg index 5e2e108fe..53dfd1603 100755 --- a/make/egl.cfg +++ b/make/egl.cfg @@ -38,12 +38,14 @@ ForceProcAddressGen __ALL__ # Treat all of the EGL types as opaque longs # Opaque long EGLConfig +Opaque long EGLConfig Opaque long EGLContext Opaque long EGLDisplay Opaque long EGLSurface Opaque long EGLNativeDisplayType Opaque long EGLNativeWindowType Opaque long EGLNativePixmapType +Opaque long EGLClientBuffer # Opaque long EGLClientBuffer diff --git a/make/gl-common.cfg b/make/gl-common.cfg index 7bba60ab0..1b857198b 100644 --- a/make/gl-common.cfg +++ b/make/gl-common.cfg @@ -509,36 +509,12 @@ CustomJavaCode GL * met if the function is either part of the core OpenGL ver CustomJavaCode GL * both the host and display, or it is an OpenGL extension function that both CustomJavaCode GL * the host and display support. <P> CustomJavaCode GL * -CustomJavaCode GL * A GL function is <i>callable</i> if it is statically linked, or can be -CustomJavaCode GL * dynamically linked at runtime. +CustomJavaCode GL * A GL function is <i>callable</i> if it is successfully linked at runtime, +CustomJavaCode GL * hence the GLContext must be made current at least once. CustomJavaCode GL * -CustomJavaCode GL * Whether or not a GL function is <i>available</i> is determined as follows: -CustomJavaCode GL * <ul> -CustomJavaCode GL * <li>If the function is an OpenGL core function (i.e., not an -CustomJavaCode GL * extension), <code>glGetString(GL_VERSION)</code> is used to determine the -CustomJavaCode GL * version number of the highest OpenGL specification version that both host -CustomJavaCode GL * and display support, and then the function name is cross-referenced -CustomJavaCode GL * with that specification version to see if it is part of that version. - -CustomJavaCode GL * <li> If the function is an OpenGL extension, the function name is -CustomJavaCode GL * cross-referenced with the list returned by -CustomJavaCode GL * <code>glGetString(GL_EXTENSIONS)</code> to see if the function is one of -CustomJavaCode GL * the extensions that is supported on both host and display. -CustomJavaCode GL * </ul> -CustomJavaCode GL * -CustomJavaCode GL * <b>NOTE:</b>The availability of a function may change at runtime in -CustomJavaCode GL * response to changes in the display environment. For example, when a window -CustomJavaCode GL * is dragged from one display to another on a multi-display system, or when -CustomJavaCode GL * the properties of the display device are modified (e.g., changing the color -CustomJavaCode GL * depth of the display). Any application that is concerned with handling -CustomJavaCode GL * these situations correctly should confirm availability after a display -CustomJavaCode GL * change before calling a questionable OpenGL function. To detect a change in -CustomJavaCode GL * the display device, please see {@link -CustomJavaCode GL * GLEventListener#displayChanged(GLAutoDrawable,boolean,boolean)}. -CustomJavaCode GL * CustomJavaCode GL * @param glFunctionName the name of the OpenGL function (e.g., use -CustomJavaCode GL * "glBindRenderbufferEXT" to check if {@link -CustomJavaCode GL * #glBindRenderbufferEXT(int,int)} is available). +CustomJavaCode GL * "glBindRenderbufferEXT" or "glBindRenderbuffer" to check if {@link +CustomJavaCode GL * #glBindRenderbuffer(int,int)} is available). CustomJavaCode GL */ CustomJavaCode GL public boolean isFunctionAvailable(String glFunctionName); diff --git a/make/gl-if-gl2_es2.cfg b/make/gl-if-gl2_es2.cfg index 1ad1ac8de..b8fa3f8c6 100755 --- a/make/gl-if-gl2_es2.cfg +++ b/make/gl-if-gl2_es2.cfg @@ -5,7 +5,6 @@ JavaClass GL2ES2 Extends GL2ES2 GL ExtendedInterfaceSymbols ../build/gensrc/classes/javax/media/opengl/GL.java - HierarchicalNativeOutput false Include gl-common.cfg Include gl-common-extensions.cfg diff --git a/make/glxext.cfg b/make/glxext.cfg index 1c93a063c..1e8b7bb44 100755 --- a/make/glxext.cfg +++ b/make/glxext.cfg @@ -8,6 +8,8 @@ Style InterfaceAndImpl JavaClass GLXExt ImplPackage com.sun.opengl.impl.x11.glx ImplJavaClass GLXExtImpl + +ExtendedInterfaceSymbols ../build/gensrc/classes/com/sun/opengl/impl/x11/glx/GLX.java Include gl-common-gl2.cfg Include gl-desktop.cfg diff --git a/src/classes/com/sun/opengl/impl/ExtensionAvailabilityCache.java b/src/classes/com/sun/opengl/impl/ExtensionAvailabilityCache.java new file mode 100644 index 000000000..527ace2a6 --- /dev/null +++ b/src/classes/com/sun/opengl/impl/ExtensionAvailabilityCache.java @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.sun.opengl.impl; + +import javax.media.opengl.*; +import java.util.*; +// FIXME: refactor Java SE dependencies +//import java.util.regex.*; +import java.lang.reflect.*; + +/** + * A utility object intended to be used by implementations to act as a cache + * of which OpenGL extensions are currently available on both the host machine + * and display. + */ +public final class ExtensionAvailabilityCache { + private static final boolean DEBUG = Debug.debug("ExtensionAvailabilityCache"); + + ExtensionAvailabilityCache(GLContextImpl context) + { + this.context = context; + } + + /** + * Flush the cache. The cache will be rebuilt lazily as calls to {@link + * #isExtensionAvailable(String)} are received. + */ + public void flush() + { + availableExtensionCache.clear(); + } + + public boolean isExtensionAvailable(String glExtensionName) { + initAvailableExtensions(); + return availableExtensionCache.contains(mapGLExtensionName(glExtensionName)); + } + + protected void initAvailableExtensions() { + // if hash is empty (meaning it was flushed), pre-cache it with the list + // of extensions that are in the GL_EXTENSIONS string + if (availableExtensionCache.isEmpty()) { + GL gl = context.getGL(); + if (DEBUG) { + System.err.println("!!! Pre-caching extension availability"); + } + String allAvailableExtensions = + gl.glGetString(GL.GL_EXTENSIONS) + " " + context.getPlatformExtensionsString(); + if (DEBUG) { + System.err.println("!!! Available extensions: " + allAvailableExtensions); + System.err.println("!!! GL vendor: " + gl.glGetString(GL.GL_VENDOR)); + } + StringTokenizer tok = new StringTokenizer(allAvailableExtensions); + while (tok.hasMoreTokens()) { + String availableExt = tok.nextToken().trim(); + availableExt = availableExt.intern(); + availableExtensionCache.add(availableExt); + if (DEBUG) { + System.err.println("!!! Available: " + availableExt); + } + } + + // put a dummy var in here so that the cache is no longer empty even if + // no extensions are in the GL_EXTENSIONS string + availableExtensionCache.add("<INTERNAL_DUMMY_PLACEHOLDER>"); + } + } + + // FIXME: hack to re-enable GL_NV_vertex_array_range extension after + // recent upgrade to new wglext.h and glxext.h headers + private static String mapGLExtensionName(String extensionName) { + if (extensionName != null && + (extensionName.equals("WGL_NV_vertex_array_range") || + extensionName.equals("GLX_NV_vertex_array_range"))) + return "GL_NV_vertex_array_range"; + return extensionName; + } + + //---------------------------------------------------------------------- + // Internals only below this point + // + + private HashSet availableExtensionCache = new HashSet(50); + private GLContextImpl context; +} diff --git a/src/classes/com/sun/opengl/impl/FunctionAvailabilityCache.java b/src/classes/com/sun/opengl/impl/FunctionAvailabilityCache.java deleted file mode 100644 index cf201e963..000000000 --- a/src/classes/com/sun/opengl/impl/FunctionAvailabilityCache.java +++ /dev/null @@ -1,390 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package com.sun.opengl.impl; - -import javax.media.opengl.*; -import java.util.*; -// FIXME: refactor Java SE dependencies -//import java.util.regex.*; -import java.lang.reflect.*; - -/** - * A utility object intended to be used by implementations to act as a cache - * of which OpenGL functions are currently available on both the host machine - * and display. - */ -public final class FunctionAvailabilityCache { - private static final boolean DEBUG = Debug.debug("FunctionAvailabilityCache"); - - FunctionAvailabilityCache(GLContextImpl context) - { - this.context = context; - } - - /** - * Flush the cache. The cache will be rebuilt lazily as calls to {@link - * #isFunctionAvailable(String)} are received. - */ - public void flush() - { - availabilityCache.clear(); - availableExtensionCache.clear(); - } - - public boolean isFunctionAvailable(String glFunctionName) - { - if (DEBUG) { - System.err.println("!!! CHECKING FOR AVAILABILITY OF: "+ glFunctionName); - } - - Boolean available = (Boolean)availabilityCache.get(glFunctionName); - - if (available == null) // not in availabilityCache - { - if (isPartOfAvailableExtensions(glFunctionName) || - isPartOfGLCore(context.getGL().glGetString(GL.GL_VERSION), glFunctionName)) - { - available = Boolean.TRUE; - } - else - { - available = Boolean.FALSE; - } - - availabilityCache.put(glFunctionName, available); - } - - if (DEBUG) { - System.err.println("!!! AVAILABILITY OF "+ glFunctionName + ": " + available.booleanValue()); - } - - return available.booleanValue(); - } - - public boolean isExtensionAvailable(String glExtensionName) { - initAvailableExtensions(); - return availableExtensionCache.contains(mapGLExtensionName(glExtensionName)); - } - - protected void initAvailableExtensions() { - // if hash is empty (meaning it was flushed), pre-cache it with the list - // of extensions that are in the GL_EXTENSIONS string - if (availableExtensionCache.isEmpty()) { - GL gl = context.getGL(); - if (DEBUG) { - System.err.println("!!! Pre-caching extension availability"); - } - String allAvailableExtensions = - gl.glGetString(GL.GL_EXTENSIONS) + " " + context.getPlatformExtensionsString(); - if (DEBUG) { - System.err.println("!!! Available extensions: " + allAvailableExtensions); - System.err.println("!!! GL vendor: " + gl.glGetString(GL.GL_VENDOR)); - } - StringTokenizer tok = new StringTokenizer(allAvailableExtensions); - while (tok.hasMoreTokens()) { - String availableExt = tok.nextToken().trim(); - availableExt = availableExt.intern(); - availableExtensionCache.add(availableExt); - if (DEBUG) { - System.err.println("!!! Available: " + availableExt); - } - } - - // Put GL version strings in the table as well - Version version = new Version(gl.glGetString(GL.GL_VERSION)); - int major = version.getMajor(); - int minor = version.getMinor(); - // FIXME: this needs to be adjusted when the major rev changes - // beyond the known ones - while (major > 0) { - while (minor >= 0) { - availableExtensionCache.add("GL_VERSION_" + major + "_" + minor); - if (DEBUG) { - System.err.println("!!! Added GL_VERSION_" + major + "_" + minor + " to known extensions"); - } - --minor; - } - - switch (major) { - case 2: - // Restart loop at version 1.5 - minor = 5; - break; - case 1: - break; - } - - --major; - } - - // put a dummy var in here so that the cache is no longer empty even if - // no extensions are in the GL_EXTENSIONS string - availableExtensionCache.add("<INTERNAL_DUMMY_PLACEHOLDER>"); - } - } - - protected boolean isPartOfAvailableExtensions(String glFunctionName) - { - initAvailableExtensions(); - - // First, find the extension to which the function corresponds - String extensionName = getExtensionCorrespondingToFunction(glFunctionName); - - // Now see if that extension is available - boolean extensionAvailable = availableExtensionCache.contains(extensionName); - - return extensionAvailable; - } - - /** - * Returns true if the given OpenGL function is part of the OpenGL core - * that corresponds to the give OpenGL version string. - * - * @param glVersionString must be of the form "X" or "X.Y" or "X.Y.Z", where - * X, Y, and Z are integers - * @exception GLException if the glFunctionName passed in is - * not the name of any known OpenGL extension function. - */ - public static boolean isPartOfGLCore(String glVersionString, String glFunctionName) - { - String funcCoreVersionString = - StaticGLInfo.getFunctionAssociation(glFunctionName); - - if (funcCoreVersionString == null) { - // No extension string was found in the glext.h/wglext.h/glxext.h - // headers when building the StaticGLInfo class. So either it's a new - // extension that's not in those headers, or it's not an opengl - // extension. Either way it's an illegal argument. - throw new GLException( - "Function \"" + glFunctionName + "\" does not " + - "correspond to any known OpenGL extension or core version."); - } - - Version actualVersion; - try - { - actualVersion = new Version(funcCoreVersionString); - } - catch (IllegalArgumentException e) - { - // funcCoreVersionString is not an OpenGL version identifier (i.e., not - // of the form GL_VERSION_XXX or X.Y). - // - // Since the association string returned from - // StaticGLInfo.getFunctionAssociation() was not null, this function - // must be an OpenGL extension function. - // - // Therefore this function can't be part of any OpenGL core. - return false; - } - - Version versionToCheck; - try - { - versionToCheck = new Version(glVersionString); - } - catch (IllegalArgumentException e) - { - // user did not supply a valid OpenGL version identifier - throw new IllegalArgumentException( - "Illegally formatted OpenGL version identifier: \"" + glVersionString + "\""); - } - - // See if the version number of glVersionString is less than or equal to - // the OpenGL specification number to which the given function actually - // belongs. - if (actualVersion.compareTo(versionToCheck) <= 0) - { - if (DEBUG) { - System.err.println( - glFunctionName + " is in core OpenGL " + glVersionString + - " because it is in OpenGL " + funcCoreVersionString); - } - return true; - } - - if (DEBUG) { - System.err.println( - glFunctionName + " is NOT a part of the OpenGL " + glVersionString + " core" + - "; it is part of OpenGL " + funcCoreVersionString); - } - - return false; - } - - /** Returns the extension name that corresponds to the given extension - * function. For example, it will return "GL_EXT_vertex_array" when the - * argument is "glNormalPointerEXT". - * - * Please see http://oss.sgi.com/projects/ogl-sample/registry/index.html for - * a list of extension names and the functions they expose. - */ - protected static String getExtensionCorrespondingToFunction(String glFunctionName) - { - return mapGLExtensionName(StaticGLInfo.getFunctionAssociation(glFunctionName)); - } - - // FIXME: hack to re-enable GL_NV_vertex_array_range extension after - // recent upgrade to new wglext.h and glxext.h headers - private static String mapGLExtensionName(String extensionName) { - if (extensionName != null && - (extensionName.equals("WGL_NV_vertex_array_range") || - extensionName.equals("GLX_NV_vertex_array_range"))) - return "GL_NV_vertex_array_range"; - return extensionName; - } - - //---------------------------------------------------------------------- - // Internals only below this point - // - - private HashMap availabilityCache = new HashMap(50); - private HashSet availableExtensionCache = new HashSet(50); - private GLContextImpl context; - - /** - * A class for storing and comparing revision version numbers. - */ - private static class Version implements Comparable - { - private int major, minor, sub; - public Version(int majorRev, int minorRev, int subMinorRev) - { - major = majorRev; - minor = minorRev; - sub = subMinorRev; - } - - /** - * @param versionString must be of the form "GL_VERSION_X" or - * "GL_VERSION_X_Y" or "GL_VERSION_X_Y_Z" or "X.Y", where X, Y, - * and Z are integers. - * - * @exception IllegalArgumentException if the argument is not a valid - * OpenGL version identifier - */ - public Version(String versionString) - { - try - { - if (versionString.startsWith("GL_VERSION_")) - { - StringTokenizer tok = new StringTokenizer(versionString, "_"); - - tok.nextToken(); // GL_ - tok.nextToken(); // VERSION_ - if (!tok.hasMoreTokens()) { major = 0; return; } - major = Integer.valueOf(tok.nextToken()).intValue(); - if (!tok.hasMoreTokens()) { minor = 0; return; } - minor = Integer.valueOf(tok.nextToken()).intValue(); - if (!tok.hasMoreTokens()) { sub = 0; return; } - sub = Integer.valueOf(tok.nextToken()).intValue(); - } - else - { - StringTokenizer tok = new StringTokenizer(versionString, ". "); - major = Integer.valueOf(tok.nextToken()).intValue(); - minor = Integer.valueOf(tok.nextToken()).intValue(); - - /* - // See if there's version-specific information which might - // imply a more recent OpenGL version - tok = new StringTokenizer(versionString, " "); - if (tok.hasMoreTokens()) { - tok.nextToken(); - if (tok.hasMoreTokens()) { - Pattern p = Pattern.compile("\\D*(\\d+)\\.(\\d+)\\.?(\\d*).*"); - Matcher m = p.matcher(tok.nextToken()); - if (m.matches()) { - int altMajor = Integer.valueOf(m.group(1)).intValue(); - int altMinor = Integer.valueOf(m.group(2)).intValue(); - // Avoid possibly confusing situations by putting some - // constraints on the upgrades we do to the major and - // minor versions - if ((altMajor == major && altMinor > minor) || - altMajor == major + 1) { - major = altMajor; - minor = altMinor; - } - } - } - } - */ - } - } - catch (Exception e) - { - // FIXME: refactor desktop OpenGL dependencies and make this - // class work properly for OpenGL ES - System.err.println("FunctionAvailabilityCache.Version.<init>: "+e); - major = 1; - minor = 0; - /* - throw (IllegalArgumentException) - new IllegalArgumentException( - "Illegally formatted version identifier: \"" + versionString + "\"") - .initCause(e); - */ - } - } - - public int compareTo(Object o) - { - Version vo = (Version)o; - if (major > vo.major) return 1; - else if (major < vo.major) return -1; - else if (minor > vo.minor) return 1; - else if (minor < vo.minor) return -1; - else if (sub > vo.sub) return 1; - else if (sub < vo.sub) return -1; - - return 0; // they are equal - } - - public int getMajor() { - return major; - } - - public int getMinor() { - return minor; - } - - } // end class Version -} diff --git a/src/classes/com/sun/opengl/impl/GLContextImpl.java b/src/classes/com/sun/opengl/impl/GLContextImpl.java index 75b24c0af..de9f73e6e 100644 --- a/src/classes/com/sun/opengl/impl/GLContextImpl.java +++ b/src/classes/com/sun/opengl/impl/GLContextImpl.java @@ -64,7 +64,7 @@ public abstract class GLContextImpl extends GLContext { // Cache of the functions that are available to be called at the current // moment in time - protected FunctionAvailabilityCache functionAvailability; + protected ExtensionAvailabilityCache extensionAvailability; // Table that holds the addresses of the native C-language entry points for // OpenGL functions. private ProcAddressTable glProcAddressTable; @@ -76,7 +76,7 @@ public abstract class GLContextImpl extends GLContext { protected GL gl; public GLContextImpl(GLContext shareWith) { - functionAvailability = new FunctionAvailabilityCache(this); + extensionAvailability = new ExtensionAvailabilityCache(this); if (shareWith != null) { GLContextShareSet.registerSharing(this, shareWith); } @@ -249,6 +249,12 @@ public abstract class GLContextImpl extends GLContext { } /** + * Shall return the platform extension ProcAddressTable, + * ie for GLXExt, EGLExt, .. + */ + public abstract ProcAddressTable getPlatformExtProcAddressTable(); + + /** * Pbuffer support; given that this is a GLContext associated with a * pbuffer, binds this pbuffer to its texture target. */ @@ -280,12 +286,6 @@ public abstract class GLContextImpl extends GLContext { and "WGL_ARB_pixel_format" (not yet mapped to X11). */ protected abstract String mapToRealGLExtensionName(String glExtensionName); - /** Returns a non-null (but possibly empty) string containing the - space-separated list of available platform-dependent (e.g., WGL, - GLX) extensions. Can only be called while this context is - current. */ - public abstract String getPlatformExtensionsString(); - /** Helper routine which resets a ProcAddressTable generated by the GLEmitter by looking up anew all of its function pointers. */ protected void resetProcAddressTable(Object table) { @@ -309,7 +309,7 @@ public abstract class GLContextImpl extends GLContext { // actual GL object in the GLDrawable as well setGL(createGL()); - functionAvailability.flush(); + extensionAvailability.flush(); if (DEBUG) { System.err.println(getThreadName() + ": !!! Initializing OpenGL extension address table for " + this); } @@ -329,11 +329,25 @@ public abstract class GLContextImpl extends GLContext { * See {@link GL#isFunctionAvailable(String)} for more details. * * @param glFunctionName the name of the OpenGL function (e.g., use - * "glPolygonOffsetEXT" to check if the {@link - * javax.media.opengl.GL#glPolygonOffsetEXT(float,float)} is available). + * "glPolygonOffsetEXT" or "glPolygonOffset" to check if the {@link + * javax.media.opengl.GL#glPolygonOffset(float,float)} is available). */ public boolean isFunctionAvailable(String glFunctionName) { - return functionAvailability.isFunctionAvailable(mapToRealGLFunctionName(glFunctionName)); + if(isCreated()) { + ProcAddressTable pTable = getGLProcAddressTable(); + try { + if(0!=pTable.getAddressFor(glFunctionName)) { + return true; + } + } catch (Exception e) {} + pTable = getPlatformExtProcAddressTable(); + try { + if(0!=pTable.getAddressFor(glFunctionName)) { + return true; + } + } catch (Exception e) {} + } + return false; } /** @@ -347,7 +361,7 @@ public abstract class GLContextImpl extends GLContext { * "GL_VERTEX_PROGRAM_ARB"). */ public boolean isExtensionAvailable(String glExtensionName) { - return functionAvailability.isExtensionAvailable(mapToRealGLExtensionName(glExtensionName)); + return extensionAvailability.isExtensionAvailable(glExtensionName); } /** Indicates which floating-point pbuffer implementation is in @@ -405,7 +419,7 @@ public abstract class GLContextImpl extends GLContext { } public GLContextImpl(GLContext shareWith, boolean dontShareWithJava2D) { - functionAvailability = new FunctionAvailabilityCache(this); + extensionAvailability = new ExtensionAvailabilityCache(this); GLContext shareContext = shareWith; if (!dontShareWithJava2D) { shareContext = Java2D.filterShareContext(shareWith); diff --git a/src/classes/com/sun/opengl/impl/egl/EGLContext.java b/src/classes/com/sun/opengl/impl/egl/EGLContext.java index 3a23483cb..bb36082f5 100755 --- a/src/classes/com/sun/opengl/impl/egl/EGLContext.java +++ b/src/classes/com/sun/opengl/impl/egl/EGLContext.java @@ -37,21 +37,56 @@ package com.sun.opengl.impl.egl; import javax.media.opengl.*; import com.sun.opengl.impl.*; +import com.sun.gluegen.runtime.ProcAddressTable; import java.nio.*; +import java.util.*; public class EGLContext extends GLContextImpl { private EGLDrawable drawable; private long context; + private boolean eglQueryStringInitialized; + private boolean eglQueryStringAvailable; + private EGLExt eglExt; + // Table that holds the addresses of the native C-language entry points for + // EGL extension functions. + private EGLExtProcAddressTable eglExtProcAddressTable; public EGLContext(EGLDrawable drawable, GLContext shareWith) { super(shareWith); this.drawable = drawable; } + public Object getPlatformGLExtensions() { + return getEGLExt(); + } + + public EGLExt getEGLExt() { + if (eglExt == null) { + eglExt = new EGLExtImpl(this); + } + return eglExt; + } + + public final ProcAddressTable getPlatformExtProcAddressTable() { + return eglExtProcAddressTable; + } + + public final EGLExtProcAddressTable getEGLExtProcAddressTable() { + return eglExtProcAddressTable; + } + public GLDrawable getGLDrawable() { return drawable; } + protected String mapToRealGLFunctionName(String glFunctionName) { + return glFunctionName; + } + + protected String mapToRealGLExtensionName(String glExtensionName) { + return glExtensionName; + } + public long getContext() { return context; } @@ -146,13 +181,13 @@ public class EGLContext extends GLContextImpl { protected void create() throws GLException { long display = drawable.getDisplay(); - _EGLConfig config = drawable.getConfig(); + long config = drawable.getConfig(); long shareWith = 0; if (display == 0) { throw new GLException("Error: attempted to create an OpenGL context without a display connection"); } - if (config == null) { + if (config == 0) { throw new GLException("Error: attempted to create an OpenGL context without a graphics configuration"); } EGLContext other = (EGLContext) GLContextShareSet.getShareContext(this); @@ -189,14 +224,52 @@ public class EGLContext extends GLContextImpl { return (context != 0); } + protected void resetGLFunctionAvailability() { + super.resetGLFunctionAvailability(); + if (DEBUG) { + System.err.println(getThreadName() + ": !!! Initializing EGL extension address table"); + } + if (eglExtProcAddressTable == null) { + // FIXME: cache ProcAddressTables by capability bits so we can + // share them among contexts with the same capabilities + eglExtProcAddressTable = new EGLExtProcAddressTable(); + } + resetProcAddressTable(getEGLExtProcAddressTable()); + } + + public synchronized String getPlatformExtensionsString() { + if (!eglQueryStringInitialized) { + eglQueryStringAvailable = + ((GLDrawableFactoryImpl)getGLDrawable().getFactory()).dynamicLookupFunction("eglQueryString") != 0; + eglQueryStringInitialized = true; + } + if (eglQueryStringAvailable) { + GLDrawableFactory factory = getGLDrawable().getFactory(); + boolean wasLocked = factory.isToolkitLocked(); + if(!wasLocked) { + factory.lockToolkit(); + } + try { + String ret = EGL.eglQueryString(drawable.getNativeWindow().getDisplayHandle(), + EGL.EGL_EXTENSIONS); + if (DEBUG) { + System.err.println("!!! EGL extensions: " + ret); + } + return ret; + } finally { + if(!wasLocked) { + factory.unlockToolkit(); + } + } + } else { + return ""; + } + } + //---------------------------------------------------------------------- // Currently unimplemented stuff // - public Object getPlatformGLExtensions() { - return null; - } - public void copy(GLContext source, int mask) throws GLUnsupportedException { throw new GLUnsupportedException("Not yet implemented"); } @@ -213,18 +286,6 @@ public class EGLContext extends GLContextImpl { throw new GLException("Should not call this"); } - protected String mapToRealGLFunctionName(String glFunctionName) { - return glFunctionName; - } - - protected String mapToRealGLExtensionName(String glExtensionName) { - return glExtensionName; - } - - public String getPlatformExtensionsString() { - return ""; - } - public boolean offscreenImageNeedsVerticalFlip() { throw new GLException("Should not call this"); } diff --git a/src/classes/com/sun/opengl/impl/egl/EGLDrawable.java b/src/classes/com/sun/opengl/impl/egl/EGLDrawable.java index 60aed64be..edf793c29 100755 --- a/src/classes/com/sun/opengl/impl/egl/EGLDrawable.java +++ b/src/classes/com/sun/opengl/impl/egl/EGLDrawable.java @@ -42,7 +42,7 @@ import javax.media.opengl.*; public class EGLDrawable extends GLDrawableImpl { private GLCapabilitiesChooser chooser; private long display; - private _EGLConfig config; + private long config; private long surface; private int[] tmp = new int[1]; @@ -63,11 +63,11 @@ public class EGLDrawable extends GLDrawableImpl { throw new GLException("eglInitialize failed"); } int[] attrs = factory.glCapabilities2AttribList(capabilities); - _EGLConfig[] configs = new _EGLConfig[1]; + long[] configs = new long[1]; int[] numConfigs = new int[1]; if (!EGL.eglChooseConfig(display, attrs, 0, - configs, 1, + configs, 0, 1, numConfigs, 0)) { throw new GLException("Graphics configuration selection (eglChooseConfig) failed"); } @@ -90,7 +90,7 @@ public class EGLDrawable extends GLDrawableImpl { super.destroy(); } - public _EGLConfig getConfig() { + public long getConfig() { return config; } diff --git a/src/classes/com/sun/opengl/impl/macosx/cgl/MacOSXCGLContext.java b/src/classes/com/sun/opengl/impl/macosx/cgl/MacOSXCGLContext.java index 8bf82b3d2..4959c308f 100644 --- a/src/classes/com/sun/opengl/impl/macosx/cgl/MacOSXCGLContext.java +++ b/src/classes/com/sun/opengl/impl/macosx/cgl/MacOSXCGLContext.java @@ -43,6 +43,7 @@ import java.nio.*; import java.util.*; import javax.media.opengl.*; import com.sun.opengl.impl.*; +import com.sun.gluegen.runtime.ProcAddressTable; public abstract class MacOSXCGLContext extends GLContextImpl { @@ -71,6 +72,14 @@ public abstract class MacOSXCGLContext extends GLContextImpl return cglExt; } + public final ProcAddressTable getPlatformExtProcAddressTable() { + return getCGLExtProcAddressTable(); + } + + public final CGLExtProcAddressTable getCGLExtProcAddressTable() { + return cglExtProcAddressTable; + } + public GLDrawable getGLDrawable() { return drawable; } @@ -309,10 +318,6 @@ public abstract class MacOSXCGLContext extends GLContextImpl resetProcAddressTable(getCGLExtProcAddressTable()); } - public final CGLExtProcAddressTable getCGLExtProcAddressTable() { - return cglExtProcAddressTable; - } - public String getPlatformExtensionsString() { return ""; diff --git a/src/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLContext.java b/src/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLContext.java index 87c6bde78..a02634a26 100644 --- a/src/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLContext.java +++ b/src/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLContext.java @@ -43,6 +43,7 @@ import java.nio.*; import java.util.*; import javax.media.opengl.*; import com.sun.opengl.impl.*; +import com.sun.gluegen.runtime.ProcAddressTable; public class WindowsWGLContext extends GLContextImpl { protected WindowsWGLDrawable drawable; @@ -84,6 +85,14 @@ public class WindowsWGLContext extends GLContextImpl { return wglExt; } + public final ProcAddressTable getPlatformExtProcAddressTable() { + return getWGLExtProcAddressTable(); + } + + public final WGLExtProcAddressTable getWGLExtProcAddressTable() { + return wglExtProcAddressTable; + } + public GLDrawable getGLDrawable() { return drawable; } @@ -225,10 +234,6 @@ public class WindowsWGLContext extends GLContextImpl { resetProcAddressTable(getWGLExtProcAddressTable()); } - public final WGLExtProcAddressTable getWGLExtProcAddressTable() { - return wglExtProcAddressTable; - } - public String getPlatformExtensionsString() { if (!wglGetExtensionsStringEXTInitialized) { wglGetExtensionsStringEXTAvailable = (WGL.wglGetProcAddress("wglGetExtensionsStringEXT") != 0); diff --git a/src/classes/com/sun/opengl/impl/x11/glx/X11GLXContext.java b/src/classes/com/sun/opengl/impl/x11/glx/X11GLXContext.java index f7ce249cb..097cc6e71 100644 --- a/src/classes/com/sun/opengl/impl/x11/glx/X11GLXContext.java +++ b/src/classes/com/sun/opengl/impl/x11/glx/X11GLXContext.java @@ -44,6 +44,7 @@ import java.util.*; import javax.media.opengl.*; import com.sun.opengl.impl.*; import com.sun.opengl.impl.x11.*; +import com.sun.gluegen.runtime.ProcAddressTable; public abstract class X11GLXContext extends GLContextImpl { protected X11GLXDrawable drawable; @@ -68,6 +69,14 @@ public abstract class X11GLXContext extends GLContextImpl { this.drawable = drawable; } + public final ProcAddressTable getPlatformExtProcAddressTable() { + return getGLXExtProcAddressTable(); + } + + public final GLXExtProcAddressTable getGLXExtProcAddressTable() { + return glXExtProcAddressTable; + } + public Object getPlatformGLExtensions() { return getGLXExt(); } @@ -233,10 +242,6 @@ public abstract class X11GLXContext extends GLContextImpl { resetProcAddressTable(getGLXExtProcAddressTable()); } - public final GLXExtProcAddressTable getGLXExtProcAddressTable() { - return glXExtProcAddressTable; - } - public synchronized String getPlatformExtensionsString() { if (!glXQueryExtensionsStringInitialized) { glXQueryExtensionsStringAvailable = @@ -247,7 +252,7 @@ public abstract class X11GLXContext extends GLContextImpl { GLDrawableFactory factory = getGLDrawable().getFactory(); boolean wasLocked = factory.isToolkitLocked(); if(!wasLocked) { - getGLDrawable().getFactory().lockToolkit(); + factory.lockToolkit(); } try { String ret = GLX.glXQueryExtensionsString(drawable.getNativeWindow().getDisplayHandle(), @@ -258,7 +263,7 @@ public abstract class X11GLXContext extends GLContextImpl { return ret; } finally { if(!wasLocked) { - getGLDrawable().getFactory().unlockToolkit(); + factory.unlockToolkit(); } } } else { @@ -266,6 +271,9 @@ public abstract class X11GLXContext extends GLContextImpl { } } + /** + * using dynamic ProcAddressTable verification always + * public boolean isFunctionAvailable(String glFunctionName) { boolean available = super.isFunctionAvailable(glFunctionName); @@ -280,7 +288,7 @@ public abstract class X11GLXContext extends GLContextImpl { ); return available; - } + }*/ public boolean isExtensionAvailable(String glExtensionName) { if (glExtensionName.equals("GL_ARB_pbuffer") || diff --git a/src/classes/javax/media/opengl/GLContext.java b/src/classes/javax/media/opengl/GLContext.java index 998ede419..ae9c11786 100644 --- a/src/classes/javax/media/opengl/GLContext.java +++ b/src/classes/javax/media/opengl/GLContext.java @@ -194,6 +194,12 @@ public abstract class GLContext { " Factory: "+ getGLDrawable().getFactory().getClass().getName()+")"; } + /** Returns a non-null (but possibly empty) string containing the + space-separated list of available platform-dependent (e.g., WGL, + GLX) extensions. Can only be called while this context is + current. */ + public abstract String getPlatformExtensionsString(); + /** * Mapping fixed function (client) array indices to * GLSL array attribute names. diff --git a/src/classes/javax/media/opengl/GLProfile.java b/src/classes/javax/media/opengl/GLProfile.java index 14a57cc8c..0d1c73d07 100644 --- a/src/classes/javax/media/opengl/GLProfile.java +++ b/src/classes/javax/media/opengl/GLProfile.java @@ -123,23 +123,26 @@ public class GLProfile { /** * Selects a profile, implementing the interface GL2ES1. + * Order: GL2, GL2ES12, GLES1 */ public static synchronized final void setProfileGL2ES1() { - setProfile(new String[] { GLES1, GL2ES12, GL2 }); + setProfile(new String[] { GL2, GL2ES12, GLES1 }); } /** * Selects a profile, implementing the interface GL2ES2. + * Order: GL2, GL2ES12, GLES2 */ public static synchronized final void setProfileGL2ES2() { - setProfile(new String[] { GLES2, GL2ES12, GL2 }); + setProfile(new String[] { GL2, GL2ES12, GLES2 }); } /** * Selects a profile, implementing the interface GL + * Order: GL2, GL2ES12, GLES2, GLES1 */ public static synchronized final void setProfileGLAny() { - setProfile(new String[] { GLES2, GLES1, GL2ES12, GL2 }); + setProfile(new String[] { GL2, GL2ES12, GLES2, GLES1 }); } public static final String getProfile() { |