summaryrefslogtreecommitdiffstats
path: root/src/net/java/games/gluegen/opengl
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/java/games/gluegen/opengl')
-rw-r--r--src/net/java/games/gluegen/opengl/BuildComposablePipeline.java2
-rw-r--r--src/net/java/games/gluegen/opengl/CGLPAWrapperEmitter.java16
-rw-r--r--src/net/java/games/gluegen/opengl/GLEmitter.java95
-rw-r--r--src/net/java/games/gluegen/opengl/JavaGLPAWrapperEmitter.java11
4 files changed, 94 insertions, 30 deletions
diff --git a/src/net/java/games/gluegen/opengl/BuildComposablePipeline.java b/src/net/java/games/gluegen/opengl/BuildComposablePipeline.java
index 47476a54c..c6ac77c7b 100644
--- a/src/net/java/games/gluegen/opengl/BuildComposablePipeline.java
+++ b/src/net/java/games/gluegen/opengl/BuildComposablePipeline.java
@@ -209,7 +209,7 @@ public class BuildComposablePipeline
{
output.print(" public ");
output.print(' ');
- output.print(m.getReturnType().getName());
+ output.print(JavaType.createForClass(m.getReturnType()).getName());
output.print(' ');
output.print(m.getName());
output.print('(');
diff --git a/src/net/java/games/gluegen/opengl/CGLPAWrapperEmitter.java b/src/net/java/games/gluegen/opengl/CGLPAWrapperEmitter.java
index cd0554dc3..2a1559e52 100644
--- a/src/net/java/games/gluegen/opengl/CGLPAWrapperEmitter.java
+++ b/src/net/java/games/gluegen/opengl/CGLPAWrapperEmitter.java
@@ -68,6 +68,15 @@ public class CGLPAWrapperEmitter extends CMethodBindingEmitter
methodToWrap.getIsJavaMethodStatic(),
methodToWrap.getDefaultOutput()
);
+
+ if (methodToWrap.getReturnValueCapacityExpression() != null) {
+ setReturnValueCapacityExpression(methodToWrap.getReturnValueCapacityExpression());
+ }
+ if (methodToWrap.getReturnValueLengthExpression() != null) {
+ setReturnValueLengthExpression(methodToWrap.getReturnValueLengthExpression());
+ }
+ setTemporaryCVariableDeclarations(methodToWrap.getTemporaryCVariableDeclarations());
+ setTemporaryCVariableAssignments (methodToWrap.getTemporaryCVariableAssignments ());
setCommentEmitter(defaultCommentEmitter);
}
@@ -192,6 +201,13 @@ public class CGLPAWrapperEmitter extends CMethodBindingEmitter
writer.println(");");
}
+ protected String jniMangle(MethodBinding binding) {
+ StringBuffer buf = new StringBuffer();
+ buf.append(super.jniMangle(binding));
+ jniMangle(Long.TYPE, buf);
+ return buf.toString();
+ }
+
/** This class emits the comment for the wrapper method */
private static class CGLPAWrapperCommentEmitter extends CMethodBindingEmitter.DefaultCommentEmitter {
protected void emitBeginning(FunctionEmitter methodEmitter, PrintWriter writer) {
diff --git a/src/net/java/games/gluegen/opengl/GLEmitter.java b/src/net/java/games/gluegen/opengl/GLEmitter.java
index 27cc07e2c..f6e26fd3b 100644
--- a/src/net/java/games/gluegen/opengl/GLEmitter.java
+++ b/src/net/java/games/gluegen/opengl/GLEmitter.java
@@ -44,6 +44,7 @@ import java.text.MessageFormat;
import java.util.*;
import net.java.games.gluegen.*;
import net.java.games.gluegen.cgram.types.*;
+import net.java.games.gluegen.runtime.*;
/**
* A subclass of JavaEmitter that modifies the normal emission of C and Java
@@ -52,11 +53,12 @@ import net.java.games.gluegen.cgram.types.*;
*/
public class GLEmitter extends JavaEmitter
{
- public static final String PROCADDRESS_VAR_PREFIX = "_addressof_";
+ 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 String tableClassName = "ProcAddressTable";
+ private String tableClassPackage;
+ private String tableClassName;
private int numProcAddressEntries;
public void beginFunctions(TypeDictionary typedefDictionary,
@@ -70,7 +72,7 @@ public class GLEmitter extends JavaEmitter
cWriter().println();
}
- if (((GLConfiguration)getConfig()).emitProcAddressTable())
+ if (getGLConfig().emitProcAddressTable())
{
beginGLProcAddressTable();
}
@@ -79,7 +81,7 @@ public class GLEmitter extends JavaEmitter
public void endFunctions() throws Exception
{
- if (((GLConfiguration)getConfig()).emitProcAddressTable())
+ if (getGLConfig().emitProcAddressTable())
{
endGLProcAddressTable();
}
@@ -118,7 +120,7 @@ public class GLEmitter extends JavaEmitter
// 9 is default # expanded bindings for void*
ArrayList modifiedEmitters = new ArrayList(9);
- if (((GLConfiguration)getConfig()).emitProcAddressTable())
+ if (getGLConfig().emitProcAddressTable())
{
// emit an entry in the GL proc address table for this method.
emitGLProcAddressTableEntryForSymbol(sym);
@@ -185,7 +187,7 @@ public class GLEmitter extends JavaEmitter
return null;
return baseJavaEmitter;
}
- return new JavaGLPAWrapperEmitter(baseJavaEmitter);
+ return new JavaGLPAWrapperEmitter(baseJavaEmitter, getGLConfig().getProcAddressTableExpr());
}
private CMethodBindingEmitter generateModifiedEmitter(CMethodBindingEmitter baseCEmitter)
@@ -205,11 +207,17 @@ public class GLEmitter extends JavaEmitter
{
String symName = sym.getName();
+ GLConfiguration config = getGLConfig();
+
// We should only wrap the GL symbol if its function pointer typedef has
// been defined (most likely in glext.h).
String funcPointerTypedefName = getGLFunctionPointerTypedefName(sym);
boolean shouldWrap = typedefDictionary.containsKey(funcPointerTypedefName);
//System.err.println(funcPointerTypedefName + " defined: " + shouldWrap);
+
+ if (config.skipProcAddressGen(symName)) {
+ shouldWrap = false;
+ }
if (!shouldWrap)
{
@@ -221,26 +229,27 @@ public class GLEmitter extends JavaEmitter
private void beginGLProcAddressTable() throws Exception
{
- String implPackageName = getImplPackageName();
+ tableClassPackage = getGLConfig().tableClassPackage();
+ tableClassName = getGLConfig().tableClassName();
+
+ // Table defaults to going into the impl directory unless otherwise overridden
+ String implPackageName = tableClassPackage;
+ if (implPackageName == null) {
+ implPackageName = getImplPackageName();
+ }
String jImplRoot =
getJavaOutputDir() + File.separator +
CodeGenUtils.packageAsPath(implPackageName);
- // HACK: until we have a way to make the impl dir different from the
- // WindowsGLImpl dir and the interface dir
- //tableWriter = openFile(jImplRoot + File.separator + tableClassName + ".java");
- File tmpFile = new File(jImplRoot);
- tmpFile = tmpFile.getParentFile();
- tmpFile = new File(tmpFile, tableClassName + ".java");
- tableWriter = openFile(tmpFile.getPath());
- // tableWriter = openFile(jImplRoot + File.separator + ".." + File.separator + tableClassName + ".java");
+ tableWriter = openFile(jImplRoot + File.separator + tableClassName + ".java");
CodeGenUtils.emitAutogeneratedWarning(tableWriter, this);
- // HACK: until we have a way to make the impl dir different from the
- // WindowsGLImpl dir and the interface dir
- //tableWriter.println("package " + implPackageName + ";");
- tableWriter.println("package " + getJavaPackageName() + ".impl;");
+ tableWriter.println("package " + implPackageName + ";");
+ tableWriter.println();
+ for (Iterator iter = getConfig().imports().iterator(); iter.hasNext(); ) {
+ tableWriter.println("import " + ((String) iter.next()) + ";");
+ }
tableWriter.println();
tableWriter.println("/**");
tableWriter.println(" * This table is a cache of the native pointers to OpenGL extension");
@@ -260,9 +269,6 @@ public class GLEmitter extends JavaEmitter
private void endGLProcAddressTable() throws Exception
{
PrintWriter w = tableWriter;
- w.print(" protected static long __PROCADDRESSINDEX__LASTINDEX = ");
- w.print(numProcAddressEntries-1);
- w.println(';');
w.println();
w.println(" /**");
@@ -301,30 +307,69 @@ public class GLEmitter extends JavaEmitter
private void emitGLProcAddressTableEntryForSymbol(FunctionSymbol cFunc)
{
- tableWriter.print(" public static long ");
+ tableWriter.print(" public long ");
tableWriter.print(PROCADDRESS_VAR_PREFIX);
tableWriter.print(cFunc.getName());
tableWriter.println(";");
++numProcAddressEntries;
}
+ private GLConfiguration getGLConfig() {
+ return (GLConfiguration) getConfig();
+ }
+
protected static class GLConfiguration extends JavaConfiguration
{
private boolean emitProcAddressTable = false;
-
+ private String tableClassPackage;
+ private String tableClassName = "ProcAddressTable";
+ private Set/*<String>*/ skipProcAddressGen = new HashSet();
+ private String getProcAddressTableExpr = "context.getGLProcAddressTable()";
+
protected void dispatch(String cmd, StringTokenizer tok, File file, String filename, int lineNo) throws IOException {
if (cmd.equalsIgnoreCase("EmitProcAddressTable"))
{
emitProcAddressTable =
readBoolean("EmitProcAddressTable", tok, filename, lineNo).booleanValue();
}
+ else if (cmd.equalsIgnoreCase("ProcAddressTablePackage"))
+ {
+ tableClassPackage = readString("ProcAddressTablePackage", tok, filename, lineNo);
+ }
+ else if (cmd.equalsIgnoreCase("ProcAddressTableClassName"))
+ {
+ tableClassName = readString("ProcAddressTableClassName", tok, filename, lineNo);
+ }
+ else if (cmd.equalsIgnoreCase("SkipProcAddressGen"))
+ {
+ String sym = readString("SkipProcAddressGen", tok, filename, lineNo);
+ skipProcAddressGen.add(sym);
+ }
+ else if (cmd.equalsIgnoreCase("GetProcAddressTableExpr"))
+ {
+ getProcAddressTableExpr = readGetProcAddressTableExpr(tok, filename, lineNo);
+ }
else
{
super.dispatch(cmd,tok,file,filename,lineNo);
}
}
- public boolean emitProcAddressTable() { return emitProcAddressTable; }
+ protected String readGetProcAddressTableExpr(StringTokenizer tok, String filename, int lineNo) {
+ try {
+ String restOfLine = tok.nextToken("\n\r\f");
+ return restOfLine.trim();
+ } catch (NoSuchElementException e) {
+ throw new RuntimeException("Error parsing \"GetProcAddressTableExpr\" command at line " + lineNo +
+ " in file \"" + filename + "\"", e);
+ }
+ }
+
+ public boolean emitProcAddressTable() { return emitProcAddressTable; }
+ public String tableClassPackage() { return tableClassPackage; }
+ public String tableClassName() { return tableClassName; }
+ public boolean skipProcAddressGen (String name) { return skipProcAddressGen.contains(name); }
+ public String getProcAddressTableExpr() { return getProcAddressTableExpr; }
} // end class GLConfiguration
}
diff --git a/src/net/java/games/gluegen/opengl/JavaGLPAWrapperEmitter.java b/src/net/java/games/gluegen/opengl/JavaGLPAWrapperEmitter.java
index e0a098f2a..c3b17f6cb 100644
--- a/src/net/java/games/gluegen/opengl/JavaGLPAWrapperEmitter.java
+++ b/src/net/java/games/gluegen/opengl/JavaGLPAWrapperEmitter.java
@@ -50,10 +50,12 @@ public class JavaGLPAWrapperEmitter extends JavaMethodBindingImplEmitter
new WrappedMethodCommentEmitter();
private JavaMethodBindingEmitter emitterBeingWrapped;
+ private String getProcAddressTableExpr;
- public JavaGLPAWrapperEmitter(JavaMethodBindingEmitter methodToWrap)
+ public JavaGLPAWrapperEmitter(JavaMethodBindingEmitter methodToWrap, String getProcAddressTableExpr)
{
super(methodToWrap.getBinding(), methodToWrap.getDefaultOutput(), methodToWrap.getRuntimeExceptionType());
+ this.getProcAddressTableExpr = getProcAddressTableExpr;
if (methodToWrap.getBinding().hasContainingType())
{
@@ -119,6 +121,9 @@ public class JavaGLPAWrapperEmitter extends JavaMethodBindingImplEmitter
// Now make our binding use the original access of the wrapped method
this.addModifier(origAccess);
+ if (emitterBeingWrapped.hasModifier(STATIC)) {
+ this.addModifier(STATIC);
+ }
}
protected boolean needsBody() {
@@ -152,9 +157,7 @@ public class JavaGLPAWrapperEmitter extends JavaMethodBindingImplEmitter
String procAddressVariable =
GLEmitter.PROCADDRESS_VAR_PREFIX + wrappedBinding.getName();
- writer.print(" final long addr = context.getGLProcAddressTable().");
- writer.print(procAddressVariable);
- writer.println(';');
+ writer.println(" final long addr = " + getProcAddressTableExpr + "." + procAddressVariable + ";");
writer.println(" if (addr == 0) {");
writer.println(" throw new GLException(\"Method \\\"" + binding.getName() + "\\\" not available\");");
writer.println(" }");