aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xmake/build.xml1
-rw-r--r--make/gluegen.compiler.xml2
-rw-r--r--src/java/com/sun/gluegen/JavaConfiguration.java11
-rw-r--r--src/java/com/sun/gluegen/JavaEmitter.java6
-rwxr-xr-xsrc/java/com/sun/gluegen/opengl/GLConfiguration.java15
-rw-r--r--src/java/com/sun/gluegen/opengl/GLEmitter.java288
-rwxr-xr-xsrc/java/com/sun/gluegen/procaddress/ProcAddressConfiguration.java9
-rwxr-xr-xsrc/java/com/sun/gluegen/procaddress/ProcAddressEmitter.java12
-rw-r--r--src/java/com/sun/gluegen/runtime/ProcAddressHelper.java31
-rw-r--r--src/java/com/sun/gluegen/runtime/opengl/GLProcAddressHelper.java112
-rw-r--r--src/java/com/sun/gluegen/runtime/opengl/GLUnifiedName.java222
11 files changed, 558 insertions, 151 deletions
diff --git a/make/build.xml b/make/build.xml
index f978f8b..1ff74b8 100755
--- a/make/build.xml
+++ b/make/build.xml
@@ -468,6 +468,7 @@
<jar destfile="${build}/gluegen-rt.jar">
<fileset dir="${classes}">
<include name="com/sun/gluegen/runtime/*.class" />
+ <include name="com/sun/gluegen/runtime/opengl/*.class" />
</fileset>
</jar>
diff --git a/make/gluegen.compiler.xml b/make/gluegen.compiler.xml
index bfab59e..c911553 100644
--- a/make/gluegen.compiler.xml
+++ b/make/gluegen.compiler.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="GlueGen-cpptasks" basedir="." >
-<target name="gluegen.cpptasks.configure.compiler">
+<target name="gluegen.cpptasks.configure.compiler" depends="setup.java.home.dir">
<compiler id="compiler.cfg.linux" name="gcc">
<compilerarg value="-m32" />
<compilerarg value="-Wall" />
diff --git a/src/java/com/sun/gluegen/JavaConfiguration.java b/src/java/com/sun/gluegen/JavaConfiguration.java
index 3ce8ecb..e7787fc 100644
--- a/src/java/com/sun/gluegen/JavaConfiguration.java
+++ b/src/java/com/sun/gluegen/JavaConfiguration.java
@@ -546,14 +546,23 @@ public class JavaConfiguration {
return (String) parentClass.get(className);
}
+ public void dumpIgnores() {
+ System.err.println("Ignores: ");
+ for (Iterator iter = ignores.iterator(); iter.hasNext(); ) {
+ System.err.println("\t"+(String)iter.next());
+ }
+ }
+
/** Returns true if this #define, function, struct, or field within
a struct should be ignored during glue code generation. */
public boolean shouldIgnore(String symbol) {
- //System.err.println("CHECKING IGNORE: " + symbol);
+ // System.err.println("CHECKING IGNORE: " + symbol);
// Simple case; the entire symbol is in the ignore table.
if (ignores.contains(symbol)) {
+ // System.err.println("Ignore: "+symbol);
+ // dumpIgnores();
return true;
}
diff --git a/src/java/com/sun/gluegen/JavaEmitter.java b/src/java/com/sun/gluegen/JavaEmitter.java
index 9c5e786..fa0c783 100644
--- a/src/java/com/sun/gluegen/JavaEmitter.java
+++ b/src/java/com/sun/gluegen/JavaEmitter.java
@@ -318,6 +318,8 @@ public class JavaEmitter implements GlueEmitter {
}
}
+ validateFunctionsToBind(funcsToBindSet);
+
ArrayList funcsToBind = new ArrayList(funcsToBindSet.size());
funcsToBind.addAll(funcsToBindSet);
// sort functions to make them easier to find in native code
@@ -611,6 +613,10 @@ public class JavaEmitter implements GlueEmitter {
}
}
+ protected void validateFunctionsToBind(Set/*FunctionSymbol*/ funcsSet) {
+ // nothing to be done per default
+ }
+
/**
* Generate all appropriate Java bindings for the specified C function
* symbols.
diff --git a/src/java/com/sun/gluegen/opengl/GLConfiguration.java b/src/java/com/sun/gluegen/opengl/GLConfiguration.java
index e331d16..4538fae 100755
--- a/src/java/com/sun/gluegen/opengl/GLConfiguration.java
+++ b/src/java/com/sun/gluegen/opengl/GLConfiguration.java
@@ -173,12 +173,25 @@ public class GLConfiguration extends ProcAddressConfiguration {
return res;
}
+ public void dumpIgnores() {
+ System.err.println("GL Ignores: ");
+ for (Iterator iter = ignoredExtensions.iterator(); iter.hasNext(); ) {
+ System.err.println("\t"+(String)iter.next());
+ }
+ }
+
public boolean shouldIgnore(String symbol) {
+ return shouldIgnore(symbol, false);
+ }
+
+ public boolean shouldIgnore(String symbol, boolean skipExtensionCheck) {
// Check ignored extensions based on our knowledge of the static GL info
- if (glInfo != null) {
+ if (!skipExtensionCheck && glInfo != null) {
String extension = glInfo.getExtension(symbol);
if (extension != null &&
ignoredExtensions.contains(extension)) {
+ // System.err.println("GL Ignore: "+symbol+" within extension "+extension);
+ // dumpIgnores();
return true;
}
}
diff --git a/src/java/com/sun/gluegen/opengl/GLEmitter.java b/src/java/com/sun/gluegen/opengl/GLEmitter.java
index 2666aa4..fb6c0dd 100644
--- a/src/java/com/sun/gluegen/opengl/GLEmitter.java
+++ b/src/java/com/sun/gluegen/opengl/GLEmitter.java
@@ -46,6 +46,7 @@ import com.sun.gluegen.*;
import com.sun.gluegen.cgram.types.*;
import com.sun.gluegen.procaddress.*;
import com.sun.gluegen.runtime.*;
+import com.sun.gluegen.runtime.opengl.GLUnifiedName;
/**
* A subclass of ProcAddressEmitter with special OpenGL-specific
@@ -72,119 +73,16 @@ public class GLEmitter extends ProcAddressEmitter
super.beginEmission(controls);
}
- static class UnifiedExtensionName implements Cloneable {
- public UnifiedExtensionName(String name) {
- this(name, normalizeARB(name));
- }
-
- protected UnifiedExtensionName(String orig, String uni) {
- this.nameOrig=orig;
- this.nameUni=uni;
- }
-
- public void useOriginal() {
- nameUni=nameOrig;
- }
-
- public void addOrig(String name) {
- if(nameOrig.indexOf(name)<0) {
- nameOrig = nameOrig.concat(", "+name);
- }
- }
-
- public void normalizeVEN() {
- nameUni=normalizeVEN(nameUni);
- }
-
- public boolean isExtensionVEN() {
- return isExtensionVEN(nameUni);
- }
-
- public boolean equals(Object obj) {
- if(null==obj || !(obj instanceof UnifiedExtensionName)) return false;
- UnifiedExtensionName uen = (UnifiedExtensionName) obj;
- return nameUni.equals(uen.nameUni);
- }
-
- public String getCommentString() {
- if(nameOrig.equals(nameUni)) {
- return new String();
- }
- return " /** " + nameUni + ": Alias of: " + nameOrig + " */";
- }
-
- public String toString() {
- if(nameOrig.equals(nameUni)) {
- return nameUni;
- }
- return nameUni + " /* " + nameOrig + " */";
- }
-
- public Object clone() {
- return new UnifiedExtensionName(nameOrig, nameUni);
- }
-
- //GL_XYZ : GL_XYZ, GL_XYZ_GL2, GL_XYZ_ARB, GL_XYZ_OES, GL_XYZ_OML
- //GL_XYZ : GL_XYZ, GL_GL2_XYZ, GL_ARB_XYZ, GL_OES_XYZ, GL_OML_XYZ
- //
- // Pass-1 Unify ARB extensions with the same value
- // Pass-2 Unify vendor extensions,
- // if exist as an ARB extension with the same value.
- // Pass-3 Emit
-
- public static String[] extensionsARB = { "GL2", "ARB", "OES", "OML" };
- public static String[] extensionsVEN = { "EXT", "NV", "ATI", "SGI", "SGIS", "SGIX", "HP", "IBM", "WIN" };
-
- public static boolean isExtension(String[] extensions, String str) {
- for(int i = extensions.length - 1 ; i>=0 ; i--) {
- if(str.endsWith("_"+extensions[i])) {
- return true;
- }
- if(str.startsWith("GL_"+extensions[i]+"_")) {
- return true;
- }
- }
- return false;
- }
-
- public static String normalize(String[] extensions, String str) {
- boolean touched = false;
- for(int i = extensions.length - 1 ; !touched && i>=0 ; i--) {
- if(str.endsWith("_"+extensions[i])) {
- str = str.substring(0, str.length()-1-extensions[i].length());
- touched=true;
- }
- if(str.startsWith("GL_"+extensions[i]+"_")) {
- str = "GL_"+str.substring(4+extensions[i].length());
- touched=true;
- }
- }
- return str;
- }
- public static String normalizeARB(String str) {
- return normalize(extensionsARB, str);
- }
- public static String normalizeVEN(String str) {
- return normalize(extensionsVEN, str);
- }
- public static boolean isExtensionVEN(String str) {
- return isExtension(extensionsVEN, str);
- }
-
- protected String nameOrig;
- protected String nameUni;
- }
-
static class DefineEntry implements Cloneable {
public DefineEntry(String namestr, String valuestr, String optionalComment) {
- this.name=new UnifiedExtensionName(namestr);
+ this.name=new GLUnifiedName(namestr);
this.value=getJavaValue(namestr, valuestr);
this.type=getJavaType(namestr, this.value);
this.radix=getJavaRadix(namestr, valuestr);
this.optionalComment=optionalComment;
}
- protected DefineEntry(UnifiedExtensionName name, String type, Object value, int radix, String optionalComment) {
+ protected DefineEntry(GLUnifiedName name, String type, Object value, int radix, String optionalComment) {
this.name=name;
this.value=value;
this.type=type;
@@ -193,10 +91,13 @@ public class GLEmitter extends ProcAddressEmitter
}
public Object clone() {
- return new DefineEntry((UnifiedExtensionName)name.clone(), type, value, radix, optionalComment);
+ return new DefineEntry((GLUnifiedName)name.clone(), type, value, radix, optionalComment);
}
public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
if(null==obj || !(obj instanceof DefineEntry)) return false;
DefineEntry de = (DefineEntry) obj;
return name.equals(de.name) &&
@@ -238,14 +139,25 @@ public class GLEmitter extends ProcAddressEmitter
public void normalizeVEN() {
name.normalizeVEN();
}
+ public boolean shouldIgnore(GLConfiguration cfg) {
+ return GLEmitter.shouldIgnore(name, cfg);
+ }
- protected UnifiedExtensionName name;
+ protected GLUnifiedName name;
protected Object value;
protected String type;
protected int radix;
protected String optionalComment;
}
+ protected static boolean shouldIgnore(GLUnifiedName name, GLConfiguration cfg) {
+ boolean res = cfg.shouldIgnore(name.getUni(), false);
+ for (Iterator iter = name.getOrig().iterator(); !res && iter.hasNext(); ) {
+ res = cfg.shouldIgnore((String)iter.next(), true);
+ }
+ return res;
+ }
+
protected LinkedHashMap/*<String name, DefineEntry entry>*/ defineMap = new LinkedHashMap();
public void beginDefines() throws Exception
@@ -256,28 +168,25 @@ public class GLEmitter extends ProcAddressEmitter
/**
* Pass-1 Unify ARB extensions with the same value
*/
- public void emitDefine(String name, String value, String optionalComment) throws Exception
- {
+ public void emitDefine(String name, String value, String optionalComment) throws Exception {
if (cfg.allStatic() || cfg.emitInterface()) {
- if (!cfg.shouldIgnore(name)) {
- DefineEntry deNew = new DefineEntry(name, value, optionalComment);
- DefineEntry deExist = (DefineEntry) defineMap.get(deNew.name.nameUni);
- if(deExist!=null) {
- if(deNew.equals(deExist)) {
- if(deNew.getOptCommentString().length()>deExist.getOptCommentString().length()) {
- deExist.optionalComment=deNew.optionalComment;
- }
- deExist.addOrigName(deNew.name.nameOrig);
- return; // done ..
+ DefineEntry deNew = new DefineEntry(name, value, optionalComment);
+ DefineEntry deExist = (DefineEntry) defineMap.get(deNew.name.getUni());
+ if(deExist!=null) {
+ if(deNew.equals(deExist)) {
+ if(deNew.getOptCommentString().length()>deExist.getOptCommentString().length()) {
+ deExist.optionalComment=deNew.optionalComment;
}
- deNew.name.useOriginal();
- System.err.println("WARNING: Normalized entry with different value exists:"+
- "\n\tDef: "+deExist+
- "\n\tNew: "+deNew+
- "\n\t using original ARB entry");
+ deExist.addOrigName(name);
+ return; // done ..
}
- defineMap.put(deNew.name.nameUni, deNew);
+ deNew.name.resetUni();
+ System.err.println("WARNING: Normalized entry with different value exists:"+
+ "\n\tDef: "+deExist+
+ "\n\tNew: "+deNew+
+ "\n\t using original ARB entry");
}
+ defineMap.put(deNew.name.getUni(), deNew);
}
}
@@ -297,14 +206,14 @@ public class GLEmitter extends ProcAddressEmitter
if(de.isExtensionVEN()) {
DefineEntry deUni = (DefineEntry) de.clone();
deUni.normalizeVEN();
- DefineEntry deExist = (DefineEntry) defineMap.get(deUni.name.nameUni);
+ DefineEntry deExist = (DefineEntry) defineMap.get(deUni.name.getUni());
if(null!=deExist) {
if(deUni.equals(deExist)) {
if(deUni.getOptCommentString().length()>deExist.getOptCommentString().length()) {
deExist.optionalComment=deUni.optionalComment;
}
deIter.remove();
- deExist.addOrigName(deUni.name.nameOrig);
+ deExist.addOrigName(de.name.getUni());
} else {
System.err.println("INFO: Normalized entry with different value exists:"+
"\n\tDef: "+deExist+
@@ -318,12 +227,16 @@ public class GLEmitter extends ProcAddressEmitter
deIter = defineMap.values().iterator();
while( deIter.hasNext() ) {
DefineEntry de = (DefineEntry) deIter.next();
+ if (de.shouldIgnore((GLConfiguration)cfg)) {
+ continue;
+ }
String comment = de.getOptCommentString();
if (comment.length() != 0) {
javaWriter().println(comment);
} else {
comment = de.name.getCommentString();
if (comment.length() != 0) {
+ de.name.resetOriginal(); // just shorten the comment space
javaWriter().println(comment);
}
}
@@ -410,6 +323,56 @@ public class GLEmitter extends ProcAddressEmitter
//----------------------------------------------------------------------
// Internals only below this point
//
+
+ protected void validateFunctionsToBind(Set/*FunctionSymbol*/ funcsSet) {
+ ArrayList newUniFuncs = new ArrayList();
+ for (Iterator iter = funcsSet.iterator(); iter.hasNext(); ) {
+ FunctionSymbol fsOrig = (FunctionSymbol) iter.next();
+ GLUnifiedName uniName = new GLUnifiedName(fsOrig.getName());
+ if (GLEmitter.shouldIgnore(uniName, (GLConfiguration)cfg)) {
+ iter.remove(); // remove ignored function
+ } else {
+ if( uniName.isExtensionARB() &&
+ !((GLConfiguration)cfg).skipProcAddressGen(fsOrig.getName()) ) {
+ FunctionSymbol fsUni = new FunctionSymbol(uniName.getUni(), fsOrig.getType());
+ if(!funcsSet.contains(fsUni)) {
+ newUniFuncs.add(fsUni); // add new uni name
+ System.err.println("INFO: New ARB Normalized Function:"+
+ "\n\tARB: "+fsOrig+
+ "\n\tUNI: "+fsUni);
+ } else {
+ System.err.println("INFO: Dub ARB Normalized Function:"+
+ "\n\tARB: "+fsOrig+
+ "\n\tDUB: "+fsUni);
+ }
+ iter.remove(); // remove ARB function
+ // make the function being dynamical fetched, due to it's dynamic naming scheme
+ ((GLConfiguration)cfg).addForceProcAddressGen(uniName.getUni());
+ }
+ }
+ }
+ funcsSet.addAll(newUniFuncs);
+
+ for (Iterator iter = funcsSet.iterator(); iter.hasNext(); ) {
+ FunctionSymbol fsOrig = (FunctionSymbol) iter.next();
+ GLUnifiedName uniName = new GLUnifiedName(fsOrig.getName());
+ if(uniName.isExtensionVEN()) {
+ uniName.normalizeVEN();
+ if (GLEmitter.shouldIgnore(uniName, (GLConfiguration)cfg)) {
+ iter.remove(); // remove ignored function
+ } else {
+ FunctionSymbol fsUni = new FunctionSymbol(uniName.getUni(), fsOrig.getType());
+ if(funcsSet.contains(fsUni)) {
+ iter.remove(); // remove VEN function (already incl. as ARB)
+ System.err.println("INFO: Dub VEN Function:"+
+ "\n\tVEN: "+fsOrig+
+ "\n\tDUB: "+fsUni);
+ }
+ }
+ }
+ }
+ }
+
protected void generateModifiedEmitters(JavaMethodBindingEmitter baseJavaEmitter, List emitters) {
List superEmitters = new ArrayList();
@@ -439,4 +402,75 @@ public class GLEmitter extends ProcAddressEmitter
protected GLConfiguration getGLConfig() {
return (GLConfiguration) getConfig();
}
+
+ protected void endProcAddressTable() throws Exception
+ {
+ PrintWriter w = tableWriter;
+
+ w.println(" /**");
+ w.println(" * This is a convenience method to get (by name) the native function");
+ w.println(" * pointer for a given function. It lets you avoid having to");
+ w.println(" * manually compute the &quot;" + PROCADDRESS_VAR_PREFIX + " + ");
+ w.println(" * &lt;functionName&gt;&quot; member variable name and look it up via");
+ w.println(" * reflection; it also will throw an exception if you try to get the");
+ w.println(" * address of an unknown function, or one that is statically linked");
+ w.println(" * and therefore does not have a function pointer in this table.");
+ w.println(" *");
+ w.println(" * @throws RuntimeException if the function pointer was not found in");
+ w.println(" * this table, either because the function was unknown or because");
+ w.println(" * it was statically linked.");
+ w.println(" */");
+ w.println(" public long getAddressFor(String functionNameUsr) {");
+ w.println(" String functionNameBase = com.sun.gluegen.runtime.opengl.GLUnifiedName.normalizeVEN(com.sun.gluegen.runtime.opengl.GLUnifiedName.normalizeARB(functionNameUsr));");
+ w.println(" String addressFieldNameBase = " + getProcAddressConfig().gluegenRuntimePackage() + ".ProcAddressHelper.PROCADDRESS_VAR_PREFIX + functionNameBase;");
+ w.println(" java.lang.reflect.Field addressField = null;");
+ w.println(" int funcNamePermNum = com.sun.gluegen.runtime.opengl.GLUnifiedName.getNamePermutationNumber(functionNameBase);");
+ w.println(" for(int i = 0; null==addressField && i < funcNamePermNum; i++) {");
+ w.println(" String addressFieldName = com.sun.gluegen.runtime.opengl.GLUnifiedName.getNamePermutation(addressFieldNameBase, i);");
+ w.println(" try {");
+ w.println(" addressField = getClass().getField(addressFieldName);");
+ w.println(" } catch (Exception e) { }");
+ w.println(" }");
+ w.println("");
+ w.println(" if(null==addressField) {");
+ w.println(" // The user is calling a bogus function or one which is not");
+ w.println(" // runtime linked");
+ w.println(" throw new RuntimeException(");
+ w.println(" \"WARNING: Address field query failed for \\\"\" + functionNameBase + \"\\\"/\\\"\" + functionNameUsr +");
+ w.println(" \"\\\"; it's either statically linked or address field is not a known \" +");
+ w.println(" \"function\");");
+ w.println(" } ");
+ w.println(" try {");
+ w.println(" return addressField.getLong(this);");
+ w.println(" } catch (Exception e) {");
+ w.println(" throw new RuntimeException(");
+ w.println(" \"WARNING: Address query failed for \\\"\" + functionNameBase + \"\\\"/\\\"\" + functionNameUsr +");
+ w.println(" \"\\\"; it's either statically linked or is not a known \" +");
+ w.println(" \"function\", e);");
+ w.println(" }");
+ w.println(" }");
+
+ w.println("} // end of class " + tableClassName);
+ w.flush();
+ w.close();
+ }
+
+ protected void emitProcAddressTableEntryForSymbol(FunctionSymbol cFunc)
+ {
+ emitProcAddressTableEntryForString(cFunc.getName());
+ }
+
+ protected void emitProcAddressTableEntryForString(String str)
+ {
+ // Deal gracefully with forced proc address generation in the face
+ // of having the function pointer typedef in the header file too
+ if (emittedTableEntries.contains(str))
+ return;
+ emittedTableEntries.add(str);
+ tableWriter.print(" public long ");
+ tableWriter.print(PROCADDRESS_VAR_PREFIX);
+ tableWriter.print(str);
+ tableWriter.println(";");
+ }
+
}
diff --git a/src/java/com/sun/gluegen/procaddress/ProcAddressConfiguration.java b/src/java/com/sun/gluegen/procaddress/ProcAddressConfiguration.java
index e5edd0d..de4000c 100755
--- a/src/java/com/sun/gluegen/procaddress/ProcAddressConfiguration.java
+++ b/src/java/com/sun/gluegen/procaddress/ProcAddressConfiguration.java
@@ -77,9 +77,7 @@ public class ProcAddressConfiguration extends JavaConfiguration
}
else if (cmd.equalsIgnoreCase("ForceProcAddressGen"))
{
- String sym = readString("ForceProcAddressGen", tok, filename, lineNo);
- forceProcAddressGen.add(sym);
- forceProcAddressGenSet.add(sym);
+ addForceProcAddressGen( readString("ForceProcAddressGen", tok, filename, lineNo) );
}
else if (cmd.equalsIgnoreCase("GetProcAddressTableExpr"))
{
@@ -258,4 +256,9 @@ public class ProcAddressConfiguration extends JavaConfiguration
public boolean forceProcAddressGen(String funcName) {
return forceProcAddressGenSet.contains(funcName);
}
+
+ public void addForceProcAddressGen(String funcName) {
+ forceProcAddressGen.add(funcName);
+ forceProcAddressGenSet.add(funcName);
+ }
}
diff --git a/src/java/com/sun/gluegen/procaddress/ProcAddressEmitter.java b/src/java/com/sun/gluegen/procaddress/ProcAddressEmitter.java
index bb81961..6b837c1 100755
--- a/src/java/com/sun/gluegen/procaddress/ProcAddressEmitter.java
+++ b/src/java/com/sun/gluegen/procaddress/ProcAddressEmitter.java
@@ -57,10 +57,10 @@ public class ProcAddressEmitter extends JavaEmitter
public static final String PROCADDRESS_VAR_PREFIX = ProcAddressHelper.PROCADDRESS_VAR_PREFIX;
protected static final String WRAP_PREFIX = "dispatch_";
private TypeDictionary typedefDictionary;
- private PrintWriter tableWriter;
- private Set emittedTableEntries;
- private String tableClassPackage;
- private String tableClassName;
+ protected PrintWriter tableWriter;
+ protected Set emittedTableEntries;
+ protected String tableClassPackage;
+ protected String tableClassName;
public void beginFunctions(TypeDictionary typedefDictionary,
TypeDictionary structDictionary,
@@ -283,7 +283,7 @@ public class ProcAddressEmitter extends JavaEmitter
return shouldWrap;
}
- private void beginProcAddressTable() throws Exception
+ protected void beginProcAddressTable() throws Exception
{
tableClassPackage = getProcAddressConfig().tableClassPackage();
tableClassName = getProcAddressConfig().tableClassName();
@@ -332,7 +332,7 @@ public class ProcAddressEmitter extends JavaEmitter
}
}
- private void endProcAddressTable() throws Exception
+ protected void endProcAddressTable() throws Exception
{
PrintWriter w = tableWriter;
diff --git a/src/java/com/sun/gluegen/runtime/ProcAddressHelper.java b/src/java/com/sun/gluegen/runtime/ProcAddressHelper.java
index 5c3c034..7e2708f 100644
--- a/src/java/com/sun/gluegen/runtime/ProcAddressHelper.java
+++ b/src/java/com/sun/gluegen/runtime/ProcAddressHelper.java
@@ -49,9 +49,9 @@ import java.io.*;
public class ProcAddressHelper {
public static final String PROCADDRESS_VAR_PREFIX = "_addressof_";
- private static boolean DEBUG;
- private static String DEBUG_PREFIX;
- private static int debugNum;
+ protected static boolean DEBUG;
+ protected static String DEBUG_PREFIX;
+ protected static int debugNum;
static {
AccessController.doPrivileged(new PrivilegedAction() {
@@ -65,12 +65,8 @@ public class ProcAddressHelper {
});
}
- public static void resetProcAddressTable(Object table,
- DynamicLookupHelper lookup) throws RuntimeException {
- Class tableClass = table.getClass();
- java.lang.reflect.Field[] fields = tableClass.getFields();
+ protected static PrintStream getDebugOutStream() {
PrintStream out = null;
-
if (DEBUG) {
if (DEBUG_PREFIX != null) {
try {
@@ -83,7 +79,18 @@ public class ProcAddressHelper {
} else {
out = System.err;
}
- out.println("ProcAddressHelper.resetProcAddressTable(" + table.getClass().getName() + ")");
+ }
+ return out;
+ }
+
+ public static void resetProcAddressTable(Object table,
+ DynamicLookupHelper lookup) throws RuntimeException {
+ Class tableClass = table.getClass();
+ java.lang.reflect.Field[] fields = tableClass.getFields();
+ PrintStream dout = getDebugOutStream();
+
+ if (DEBUG) {
+ dout.println("ProcAddressHelper.resetProcAddressTable(" + table.getClass().getName() + ")");
}
for (int i = 0; i < fields.length; ++i) {
String addressFieldName = fields[i].getName();
@@ -100,7 +107,7 @@ public class ProcAddressHelper {
// set the current value of the proc address variable in the table object
addressField.setLong(table, newProcAddress);
if (DEBUG) {
- out.println(" " + addressField.getName() + " = 0x" + Long.toHexString(newProcAddress));
+ dout.println(" " + addressField.getName() + " = 0x" + Long.toHexString(newProcAddress));
}
} catch (Exception e) {
throw new RuntimeException("Can not get proc address for method \"" +
@@ -109,9 +116,9 @@ public class ProcAddressHelper {
}
}
if (DEBUG) {
- out.flush();
+ dout.flush();
if (DEBUG_PREFIX != null) {
- out.close();
+ dout.close();
}
}
}
diff --git a/src/java/com/sun/gluegen/runtime/opengl/GLProcAddressHelper.java b/src/java/com/sun/gluegen/runtime/opengl/GLProcAddressHelper.java
new file mode 100644
index 0000000..f8858d2
--- /dev/null
+++ b/src/java/com/sun/gluegen/runtime/opengl/GLProcAddressHelper.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 2003-2005 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.
+ */
+
+package com.sun.gluegen.runtime.opengl;
+
+import com.sun.gluegen.runtime.*;
+
+import java.security.*;
+
+// Debugging only
+import java.io.PrintStream;
+
+/** Helper class containing constants and methods to assist with the
+ manipulation of auto-generated ProcAddressTables. */
+
+public class GLProcAddressHelper extends ProcAddressHelper {
+
+ public static void resetProcAddressTable(Object table,
+ DynamicLookupHelper lookup) throws RuntimeException {
+ Class tableClass = table.getClass();
+ java.lang.reflect.Field[] fields = tableClass.getFields();
+ PrintStream dout = getDebugOutStream();
+
+ if (DEBUG) {
+ dout.println("ProcAddressHelper.resetProcAddressTable(" + table.getClass().getName() + ")");
+ }
+ for (int i = 0; i < fields.length; ++i) {
+ String addressFieldName = fields[i].getName();
+ if (!addressFieldName.startsWith(ProcAddressHelper.PROCADDRESS_VAR_PREFIX)) {
+ // not a proc address variable
+ continue;
+ }
+ int startOfMethodName = ProcAddressHelper.PROCADDRESS_VAR_PREFIX.length();
+ String funcNameBase = addressFieldName.substring(startOfMethodName);
+ java.lang.reflect.Field addressField;
+ try {
+ addressField = fields[i];
+ assert(addressField.getType() == Long.TYPE);
+ } catch (Exception e) {
+ throw new RuntimeException("Can not get proper proc address field for method \"" +
+ funcNameBase + "\": Couldn't get field \"" + addressFieldName +
+ "\" in class " + tableClass.getName(), e);
+ }
+ long newProcAddress = 0;
+ int funcNamePermNum = GLUnifiedName.getNamePermutationNumber(funcNameBase);
+ for(int j = 0; 0==newProcAddress && j < funcNamePermNum; j++) {
+ String funcName = GLUnifiedName.getNamePermutation(funcNameBase, j);
+ try {
+ if (DEBUG) {
+ dout.println(" try function lookup: " + funcName + " / " + funcNameBase);
+ }
+ newProcAddress = lookup.dynamicLookupFunction(funcName);
+ } catch (Exception e) {
+ if (DEBUG) {
+ dout.println(e);
+ e.printStackTrace();
+ }
+ }
+ }
+ try {
+ // set the current value of the proc address variable in the table object
+ addressField.setLong(table, newProcAddress);
+ if (DEBUG) {
+ dout.println(" " + addressField.getName() + " = 0x" + Long.toHexString(newProcAddress));
+ }
+ } catch (Exception e) {
+ throw new RuntimeException("Can not set proc address field for method \"" +
+ funcNameBase + "\": Couldn't set field \"" + addressFieldName +
+ "\" in class " + tableClass.getName(), e);
+ }
+ }
+ if (DEBUG) {
+ dout.flush();
+ if (DEBUG_PREFIX != null) {
+ dout.close();
+ }
+ }
+ }
+}
diff --git a/src/java/com/sun/gluegen/runtime/opengl/GLUnifiedName.java b/src/java/com/sun/gluegen/runtime/opengl/GLUnifiedName.java
new file mode 100644
index 0000000..44b5b1b
--- /dev/null
+++ b/src/java/com/sun/gluegen/runtime/opengl/GLUnifiedName.java
@@ -0,0 +1,222 @@
+/*
+ * Copyright (c) 2003-2005 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.
+ *
+ */
+
+package com.sun.gluegen.runtime.opengl;
+
+import java.util.*;
+import com.sun.gluegen.runtime.*;
+
+public class GLUnifiedName implements Cloneable {
+ //GL_XYZ : GL_XYZ, GL_XYZ_GL2, GL_XYZ_ARB, GL_XYZ_OES, GL_XYZ_OML
+ //GL_XYZ : GL_XYZ, GL_GL2_XYZ, GL_ARB_XYZ, GL_OES_XYZ, GL_OML_XYZ
+ //
+ // Pass-1 Unify ARB extensions with the same value
+ // Pass-2 Unify vendor extensions,
+ // if exist as an ARB extension with the same value.
+ // Pass-3 Emit
+
+ public static final String[] extensionsARB = { "GL2", "ARB", "OES", "OML" };
+ public static final String[] extensionsVEN = { "EXT", "SGI", "SGIS", "SGIX", "NV", "AMD", "ATI", "HP", "IBM", "WIN" };
+
+ public static final boolean isExtension(String[] extensions, String str) {
+ for(int i = extensions.length - 1 ; i>=0 ; i--) {
+ if(str.endsWith(extensions[i])) {
+ return true;
+ }
+ if(str.startsWith("GL_"+extensions[i]+"_")) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static final String normalize(String[] extensions, String str) {
+ boolean touched = false;
+ for(int i = extensions.length - 1 ; !touched && i>=0 ; i--) {
+ if(str.endsWith("_"+extensions[i])) {
+ // enums
+ str = str.substring(0, str.length()-1-extensions[i].length());
+ touched=true;
+ } else if(str.endsWith(extensions[i])) {
+ // functions
+ str = str.substring(0, str.length()-extensions[i].length());
+ touched=true;
+ }
+ if(str.startsWith("GL_"+extensions[i]+"_")) {
+ str = "GL_"+str.substring(4+extensions[i].length());
+ touched=true;
+ }
+ }
+ return str;
+ }
+ public static final String normalizeARB(String str) {
+ return normalize(extensionsARB, str);
+ }
+ public static final boolean isExtensionARB(String str) {
+ return isExtension(extensionsARB, str);
+ }
+ public static final String normalizeVEN(String str) {
+ return normalize(extensionsVEN, str);
+ }
+ public static final boolean isExtensionVEN(String str) {
+ return isExtension(extensionsVEN, str);
+ }
+
+ public static final int getNamePermutationNumber(String name) {
+ if(isExtensionARB(name) || isExtensionVEN(name)) {
+ // no name permutation, if it's already a known extension
+ return 1;
+ }
+ return 1 + extensionsARB.length + extensionsVEN.length;
+ }
+
+ public static final String getNamePermutation(String name, int i) {
+ // identity
+ if(i==0) {
+ return name;
+ }
+ if(0>i || i>=(1+extensionsARB.length + extensionsVEN.length)) {
+ throw new RuntimeException("Index out of range [0.."+(1+extensionsARB.length+extensionsVEN.length-1)+"]: "+i);
+ }
+ // ARB
+ i-=1;
+ if(i<extensionsARB.length) {
+ return name+extensionsARB[i];
+ }
+ // VEN
+ i-=extensionsARB.length;
+ return name+extensionsVEN[i];
+ }
+
+ /**
+ */
+
+ public GLUnifiedName(String name) {
+ this(name, normalizeARB(name));
+ }
+
+ protected GLUnifiedName(String orig, String uni) {
+ this.nameOrig=new ArrayList();
+ this.nameOrig.add(orig);
+ this.nameUni=uni;
+ }
+
+ protected GLUnifiedName(List origs, String uni) {
+ this.nameOrig=new ArrayList();
+ this.nameOrig.addAll(origs);
+ this.nameUni=uni;
+ }
+
+ public void resetUni() {
+ nameUni=(String)nameOrig.get(0);
+ }
+ public void resetOriginal() {
+ nameOrig.clear();
+ nameOrig.add(nameUni);
+ }
+
+ public void addOrig(String name) {
+ if(!nameOrig.contains(name)) {
+ nameOrig.add(name);
+ }
+ }
+
+ public boolean isExtensionARB() {
+ boolean res = false;
+ for (Iterator iter = nameOrig.iterator(); !res && iter.hasNext(); ) {
+ res = isExtensionARB((String)iter.next());
+ }
+ return res;
+ }
+
+ public void normalizeVEN() {
+ nameUni=normalizeVEN(nameUni);
+ }
+
+ public boolean isExtensionVEN() {
+ boolean res = false;
+ for (Iterator iter = nameOrig.iterator(); !res && iter.hasNext(); ) {
+ res = isExtensionVEN((String)iter.next());
+ }
+ return res;
+ }
+
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if(null==obj || !(obj instanceof GLUnifiedName)) return false;
+ GLUnifiedName uen = (GLUnifiedName) obj;
+ return nameUni.equals(uen.nameUni);
+ }
+
+ public String getCommentString() {
+ if(nameOrig.size()==1 && ((String)nameOrig.get(0)).equals(nameUni)) {
+ return new String();
+ }
+ String res = " /** " + nameUni + ": Alias of: ";
+ for (Iterator iter = nameOrig.iterator(); iter.hasNext(); ) {
+ res = res.concat((String)iter.next()+", ");
+ }
+ res = res.concat(" */");
+ return res;
+ }
+
+ public String toString() {
+ if(nameOrig.size()==1 && ((String)nameOrig.get(0)).equals(nameUni)) {
+ return nameUni;
+ }
+ String res = nameUni + " /* " ;
+ for (Iterator iter = nameOrig.iterator(); iter.hasNext(); ) {
+ res = res.concat((String)iter.next()+", ");
+ }
+ res = res.concat(" */");
+ return res;
+ }
+
+ public Object clone() {
+ return new GLUnifiedName(nameOrig, nameUni);
+ }
+
+ public String getUni() { return nameUni; }
+ public List getOrig() { return nameOrig; }
+ public String getOrig(int i) { return (String)nameOrig.get(i); }
+
+ private List nameOrig;
+ private String nameUni;
+}
+