diff options
Diffstat (limited to 'src/net/java/games/gluegen')
10 files changed, 268 insertions, 31 deletions
diff --git a/src/net/java/games/gluegen/CMethodBindingEmitter.java b/src/net/java/games/gluegen/CMethodBindingEmitter.java index 9272b9669..9156d68f8 100644 --- a/src/net/java/games/gluegen/CMethodBindingEmitter.java +++ b/src/net/java/games/gluegen/CMethodBindingEmitter.java @@ -55,7 +55,7 @@ public class CMethodBindingEmitter extends FunctionEmitter protected static final String arrayRes = "_array_res"; protected static final String arrayIdx = "_array_idx"; - private MethodBinding binding; + protected MethodBinding binding; /** Name of the package in which the corresponding Java method resides.*/ private String packageName; @@ -304,6 +304,7 @@ public class CMethodBindingEmitter extends FunctionEmitter protected int emitArguments(PrintWriter writer) { int numBufferOffsetArgs = 0, numBufferOffsetArrayArgs = 0; + writer.print("JNIEnv *env, "); int numEmitted = 1; // initially just the JNIEnv if (isJavaMethodStatic && !binding.hasContainingType()) @@ -352,7 +353,13 @@ public class CMethodBindingEmitter extends FunctionEmitter writer.print(", jintArray " + byteOffsetArrayConversionArgName(numBufferOffsetArrayArgs)); } - } + } + + // Add array primitive index/offset parameter + if(javaArgType.isArray() && !javaArgType.isNIOBufferArray() && !javaArgType.isStringArray()) { + writer.print(", jint " + binding.getArgumentName(i) + "_offset"); + } + } return numEmitted; } @@ -563,6 +570,9 @@ public class CMethodBindingEmitter extends FunctionEmitter writer.print(") (*env)->GetPrimitiveArrayCritical(env, "); writer.print(binding.getArgumentName(i)); writer.println(", NULL);"); +//if(cargtypename is void*) +// _ptrX = ((char*)convName + index1*sizeof(thisArgsJavaType)); + } else { // Handle the case where the array elements are of a type that needs a // data copy operation to convert from the java memory model to the C @@ -867,6 +877,7 @@ public class CMethodBindingEmitter extends FunctionEmitter protected void emitBodyCallCFunction(PrintWriter writer) { + // Make the call to the actual C function writer.print(" "); @@ -909,10 +920,28 @@ public class CMethodBindingEmitter extends FunctionEmitter writer.print("(intptr_t) "); } if (javaArgType.isArray() || javaArgType.isNIOBuffer()) { - writer.print(pointerConversionArgumentName(i)); - if (javaArgTypeNeedsDataCopy(javaArgType)) { - writer.print("_copy"); - } + + // Add special code for accounting for array offsets + // + // For mapping from byte primitive array type to type* case produces code: + // (GLtype*)((char*)_ptr0 + varName_offset) + // where varName_offset is the number of bytes offset as calculated in Java code + if(javaArgType.isArray() && !javaArgType.isNIOBufferArray() && !javaArgType.isStringArray()) { + writer.print("( (char*)"); + } + /* End of this section of new code for array offsets */ + + writer.print(pointerConversionArgumentName(i)); + if (javaArgTypeNeedsDataCopy(javaArgType)) { + writer.print("_copy"); + } + + /* Continuation of special code for accounting for array offsets */ + if(javaArgType.isArray() && !javaArgType.isNIOBufferArray() && !javaArgType.isStringArray()) { + writer.print(" + " + binding.getArgumentName(i) + "_offset)"); + } + /* End of this section of new code for array offsets */ + } else { if (javaArgType.isString()) { writer.print("_UTF8"); } writer.print(binding.getArgumentName(i)); @@ -1066,7 +1095,6 @@ public class CMethodBindingEmitter extends FunctionEmitter protected String jniMangle(MethodBinding binding) { StringBuffer buf = new StringBuffer(); - int numBufferOffsetArgs = 0; buf.append(jniMangle(binding.getName())); buf.append("__"); for (int i = 0; i < binding.getNumArguments(); i++) { @@ -1083,6 +1111,9 @@ public class CMethodBindingEmitter extends FunctionEmitter c = intArrayType.getClass(); jniMangle(c , buf); } + if(type.isArray() && !type.isNIOBufferArray()) { + jniMangle(Integer.TYPE, buf); + } } else { // FIXME: add support for char* -> String conversion throw new RuntimeException("Unknown kind of JavaType: name="+type.getName()); diff --git a/src/net/java/games/gluegen/CMethodBindingImplEmitter.java b/src/net/java/games/gluegen/CMethodBindingImplEmitter.java index 43e4f4d86..98c5c1b4a 100644 --- a/src/net/java/games/gluegen/CMethodBindingImplEmitter.java +++ b/src/net/java/games/gluegen/CMethodBindingImplEmitter.java @@ -48,8 +48,11 @@ public class CMethodBindingImplEmitter extends CMethodBindingEmitter protected static final CommentEmitter defaultCImplCommentEmitter = new CImplCommentEmitter(); + protected boolean arrayImplRoutine = false; + public CMethodBindingImplEmitter(MethodBinding binding, boolean isOverloadedBinding, + boolean arrayImpl, String javaPackageName, String javaClassName, boolean isJavaMethodStatic, @@ -59,13 +62,17 @@ public class CMethodBindingImplEmitter extends CMethodBindingEmitter javaPackageName, javaClassName, isJavaMethodStatic, output); setCommentEmitter(defaultCImplCommentEmitter); + arrayImplRoutine = arrayImpl; } protected void emitName(PrintWriter writer) { super.emitName(writer); if (!getIsOverloadedBinding()) { - writer.print("0"); + if(!arrayImplRoutine) + writer.print("0"); + else + writer.print("1"); } } @@ -76,7 +83,12 @@ public class CMethodBindingImplEmitter extends CMethodBindingEmitter protected String jniMangle(MethodBinding binding) { StringBuffer buf = new StringBuffer(); buf.append(jniMangle(binding.getName())); - buf.append("0"); + + if(!arrayImplRoutine) + buf.append("0"); + else + buf.append("1"); + buf.append("__"); for (int i = 0; i < binding.getNumArguments(); i++) { JavaType type = binding.getJavaArgumentType(i); @@ -91,6 +103,9 @@ public class CMethodBindingImplEmitter extends CMethodBindingEmitter c = intArrayType.getClass(); jniMangle(c , buf); } + if(type.isArray() && !type.isNIOBufferArray() && !type.isStringArray()) { + jniMangle(Integer.TYPE, buf); + } } else { // FIXME: add support for char* -> String conversion throw new RuntimeException("Unknown kind of JavaType: name="+type.getName()); diff --git a/src/net/java/games/gluegen/JavaEmitter.java b/src/net/java/games/gluegen/JavaEmitter.java index 0b0186cdd..cdf9b63b5 100644 --- a/src/net/java/games/gluegen/JavaEmitter.java +++ b/src/net/java/games/gluegen/JavaEmitter.java @@ -364,11 +364,19 @@ public class JavaEmitter implements GlueEmitter { // Generate the emitter for the method which may do conversion // from type wrappers to NIO Buffers or which may call the // underlying function directly + + boolean arrayImplMethod = false; + if(binding.signatureUsesPrimitiveArrays()) { + //overloaded = true; + arrayImplMethod = true; + } + JavaMethodBindingImplEmitter entryPoint = new JavaMethodBindingImplEmitter(binding, (cfg.allStatic() ? javaWriter() : javaImplWriter()), cfg.runtimeExceptionType(), - isUnimplemented); + isUnimplemented, + arrayImplMethod); entryPoint.addModifier(JavaMethodBindingEmitter.PUBLIC); if (cfg.allStatic()) { entryPoint.addModifier(JavaMethodBindingEmitter.STATIC); @@ -393,12 +401,20 @@ public class JavaEmitter implements GlueEmitter { // If the user has stated that the function will be // manually implemented, then don't auto-generate a function body. if (!cfg.manuallyImplement(sym.getName()) && !isUnimplemented) { + // need to check if should create CMethodBindingImplEmitter instead of just + // CMethodBindingEmitter. Basically adds a "0" to JNI method name + boolean arrayImplMethod = false; + if (bindingNeedsBody(binding)) { // Generate the method which calls the underlying C function // after unboxing has occurred PrintWriter output = cfg.allStatic() ? javaWriter() : javaImplWriter(); + if(binding.signatureUsesPrimitiveArrays()) { + arrayImplMethod = true; + } JavaMethodBindingEmitter wrappedEntryPoint = - new JavaMethodBindingEmitter(specialBinding, output, cfg.runtimeExceptionType(), true); + new JavaMethodBindingEmitter(specialBinding, output, cfg.runtimeExceptionType(), true, + arrayImplMethod); wrappedEntryPoint.addModifier(JavaMethodBindingEmitter.PRIVATE); wrappedEntryPoint.addModifier(JavaMethodBindingEmitter.STATIC); // Doesn't really matter wrappedEntryPoint.addModifier(JavaMethodBindingEmitter.NATIVE); @@ -409,6 +425,7 @@ public class JavaEmitter implements GlueEmitter { makeCEmitter(specialBinding, overloaded, (binding != specialBinding), + arrayImplMethod, cfg.implPackageName(), cfg.implClassName(), cWriter()); allEmitters.add(cEmitter); @@ -574,7 +591,7 @@ public class JavaEmitter implements GlueEmitter { } entryPoint.emit(); - JavaMethodBindingEmitter wrappedEntryPoint = new JavaMethodBindingEmitter(specialBinding, writer, cfg.runtimeExceptionType(), true); + JavaMethodBindingEmitter wrappedEntryPoint = new JavaMethodBindingEmitter(specialBinding, writer, cfg.runtimeExceptionType(), true, false); wrappedEntryPoint.addModifier(JavaMethodBindingEmitter.PRIVATE); wrappedEntryPoint.addModifier(JavaMethodBindingEmitter.NATIVE); wrappedEntryPoint.emit(); @@ -582,7 +599,8 @@ public class JavaEmitter implements GlueEmitter { CMethodBindingEmitter cEmitter = makeCEmitter(specialBinding, false, // overloaded - true, // doing impl routine? + true, // doing NIO impl routine? + false, // array impl method ? structClassPkg, containingTypeName, cWriter); @@ -677,12 +695,13 @@ public class JavaEmitter implements GlueEmitter { protected boolean bindingNeedsBody(MethodBinding binding) { // We need to perform NIO checks and conversions and array length // checks - return binding.signatureUsesNIO() || binding.signatureUsesCArrays(); + return binding.signatureUsesNIO() || binding.signatureUsesCArrays() || binding.signatureUsesPrimitiveArrays(); } private CMethodBindingEmitter makeCEmitter(MethodBinding binding, boolean overloaded, - boolean doingImplRoutine, + boolean doingNIOImplRoutine, + boolean doingArrayImplRoutine, String bindingJavaPackageName, String bindingJavaClassName, PrintWriter output) { @@ -703,8 +722,9 @@ public class JavaEmitter implements GlueEmitter { } } CMethodBindingEmitter cEmitter; - if (doingImplRoutine) { + if (doingNIOImplRoutine || doingArrayImplRoutine) { cEmitter = new CMethodBindingImplEmitter(binding, overloaded, + doingArrayImplRoutine, bindingJavaPackageName, bindingJavaClassName, cfg.allStatic(), output); diff --git a/src/net/java/games/gluegen/JavaMethodBindingEmitter.java b/src/net/java/games/gluegen/JavaMethodBindingEmitter.java index d6a34c1d3..59c862d67 100644 --- a/src/net/java/games/gluegen/JavaMethodBindingEmitter.java +++ b/src/net/java/games/gluegen/JavaMethodBindingEmitter.java @@ -67,6 +67,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter protected MethodBinding binding; protected boolean forImplementingMethodCall; + protected boolean forArrayImplementingMethodCall = false; protected boolean prefixedMethod = false; @@ -79,14 +80,15 @@ public class JavaMethodBindingEmitter extends FunctionEmitter public JavaMethodBindingEmitter(MethodBinding binding, PrintWriter output, String runtimeExceptionType) { - this(binding, output, runtimeExceptionType, false); + this(binding, output, runtimeExceptionType, false, false); } - public JavaMethodBindingEmitter(MethodBinding binding, PrintWriter output, String runtimeExceptionType, boolean forImplementingMethodCall) + public JavaMethodBindingEmitter(MethodBinding binding, PrintWriter output, String runtimeExceptionType, boolean forImplementingMethodCall, boolean forArrayImplementingMethodCall) { super(output); this.binding = binding; this.forImplementingMethodCall = forImplementingMethodCall; + this.forArrayImplementingMethodCall = forArrayImplementingMethodCall; this.runtimeExceptionType = runtimeExceptionType; setCommentEmitter(defaultInterfaceCommentEmitter); } @@ -190,6 +192,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter writer.print(binding.getArgumentName(i)); ++numEmitted; needComma = true; + // Add Buffer offset argument to store the buffer offset if((forImplementingMethodCall || prefixedMethod) && (type.isNIOBuffer() || type.isNIOBufferArray())) { @@ -202,6 +205,12 @@ public class JavaMethodBindingEmitter extends FunctionEmitter byteOffsetArrayConversionArgName(numBufferOffsetArrayArgs)); } } + + // Add array index offset argument after each primitive array + if( type.isArray() && !type.isNIOBufferArray() && !type.isStringArray()) { + writer.print(", int " + binding.getArgumentName(i) + "_offset"); + } + } return numEmitted; } @@ -209,7 +218,10 @@ public class JavaMethodBindingEmitter extends FunctionEmitter protected String getImplMethodName() { - return binding.getName() + "0"; + if(!forArrayImplementingMethodCall) + return binding.getName() + "0"; + else + return binding.getName() + "1"; } diff --git a/src/net/java/games/gluegen/JavaMethodBindingImplEmitter.java b/src/net/java/games/gluegen/JavaMethodBindingImplEmitter.java index c1f05b564..d3fb88f93 100644 --- a/src/net/java/games/gluegen/JavaMethodBindingImplEmitter.java +++ b/src/net/java/games/gluegen/JavaMethodBindingImplEmitter.java @@ -44,6 +44,7 @@ import java.util.*; import java.text.MessageFormat; import net.java.games.gluegen.cgram.types.*; +import net.java.games.jogl.util.BufferUtils; /** Emits the Java-side component of the Java<->C JNI binding. */ public class JavaMethodBindingImplEmitter extends JavaMethodBindingEmitter @@ -52,17 +53,19 @@ public class JavaMethodBindingImplEmitter extends JavaMethodBindingEmitter public JavaMethodBindingImplEmitter(MethodBinding binding, PrintWriter output, String runtimeExceptionType) { - this(binding, output, runtimeExceptionType, false); + this(binding, output, runtimeExceptionType, false, false); } public JavaMethodBindingImplEmitter(MethodBinding binding, PrintWriter output, String runtimeExceptionType, - boolean isUnimplemented) + boolean isUnimplemented, + boolean arrayImplExpansion) { super(binding, output, runtimeExceptionType); setCommentEmitter(defaultJavaCommentEmitter); this.isUnimplemented = isUnimplemented; + this.forArrayImplementingMethodCall = arrayImplExpansion; } public JavaMethodBindingImplEmitter(JavaMethodBindingEmitter arg) { @@ -99,6 +102,7 @@ public class JavaMethodBindingImplEmitter extends JavaMethodBindingEmitter return (isUnimplemented || getBinding().signatureUsesNIO() || getBinding().signatureUsesCArrays() || + getBinding().signatureUsesPrimitiveArrays() || getBinding().hasContainingType()); } @@ -112,13 +116,13 @@ public class JavaMethodBindingImplEmitter extends JavaMethodBindingEmitter // Check lengths of any incoming arrays if necessary for (int i = 0; i < binding.getNumArguments(); i++) { Type type = binding.getCArgumentType(i); + JavaType javaType = binding.getJavaArgumentType(i); if (type.isArray()) { ArrayType arrayType = type.asArray(); writer.println(" if (" + binding.getArgumentName(i) + ".length < " + arrayType.getLength() + ")"); writer.println(" throw new " + getRuntimeExceptionType() + "(\"Length of array \\\"" + binding.getArgumentName(i) + "\\\" was less than the required " + arrayType.getLength() + "\");"); } else { - JavaType javaType = binding.getJavaArgumentType(i); if (javaType.isNIOBuffer()) { writer.println(" if (!BufferFactory.isDirect(" + binding.getArgumentName(i) + "))"); writer.println(" throw new " + getRuntimeExceptionType() + "(\"Argument \\\"" + @@ -141,6 +145,12 @@ public class JavaMethodBindingImplEmitter extends JavaMethodBindingEmitter writer.println(argName + "[_ctr]);"); writer.println(" }"); writer.println(" }"); + } else if (javaType.isArray() && !javaType.isNIOBufferArray() &&!javaType.isStringArray()) { + String argName = binding.getArgumentName(i); + String offsetArg = argName + "_offset"; + writer.println(" if(" + argName + ".length <= " + offsetArg + ")"); + writer.print(" throw new " + getRuntimeExceptionType()); + writer.println("(\"array offset argument \\\"" + offsetArg + "\\\" equals or exceeds array length\");"); } } } @@ -175,6 +185,7 @@ public class JavaMethodBindingImplEmitter extends JavaMethodBindingEmitter boolean needComma = false; int numArgsEmitted = 0; int numBufferOffsetArgs = 0, numBufferOffsetArrayArgs = 0; + if (binding.hasContainingType()) { // Emit this pointer assert(binding.getContainingType().isCompoundTypeWrapper()); @@ -228,6 +239,28 @@ public class JavaMethodBindingImplEmitter extends JavaMethodBindingEmitter writer.print(", " + byteOffsetArrayConversionArgName(numBufferOffsetArrayArgs)); } } + + // Add Array offset parameter for primitive arrays + if(type.isArray() && !type.isNIOBufferArray() && !type.isStringArray()) { + // writer.print(", " + binding.getArgumentName(i) + "_offset"); + if(type.isFloatArray()) { + writer.print(", BufferFactory.SIZEOF_FLOAT * " + binding.getArgumentName(i) + "_offset"); + } else if(type.isDoubleArray()) { + writer.print(", BufferFactory.SIZEOF_DOUBLE * " + binding.getArgumentName(i) + "_offset"); + } else if(type.isByteArray()) { + writer.print(", " + binding.getArgumentName(i) + "_offset"); + } else if(type.isLongArray()) { + writer.print(", BufferFactory.SIZEOF_LONG * " + binding.getArgumentName(i) + "_offset"); + } else if(type.isShortArray()) { + writer.print(", BufferFactory.SIZEOF_SHORT * " + binding.getArgumentName(i) + "_offset"); + } else if(type.isIntArray()) { + writer.print(", BufferFactory.SIZEOF_INT * " + binding.getArgumentName(i) + "_offset"); + } else { + throw new RuntimeException("Unsupported type for calculating array offset argument for " + + binding.getArgumentName(i) + "-- error occurred while processing Java glue code for " + binding.getName()); + } + } + } return numArgsEmitted; } diff --git a/src/net/java/games/gluegen/JavaType.java b/src/net/java/games/gluegen/JavaType.java index b879187ef..03dd95a83 100644 --- a/src/net/java/games/gluegen/JavaType.java +++ b/src/net/java/games/gluegen/JavaType.java @@ -98,6 +98,10 @@ public class JavaType { return clazz.hashCode(); } + public JavaType getElementType() { + return new JavaType(elementType); + } + /** Creates a JavaType corresponding to the given Java type. This can be used to represent arrays of primitive values or Strings; the emitters understand how to perform proper conversion from @@ -321,6 +325,35 @@ public class JavaType { return ((clazz != null) && clazz.isArray()); } + public boolean isFloatArray() { + return(clazz.isArray() && clazz.getComponentType() == Float.TYPE); + } + + public boolean isDoubleArray() { + return(clazz.isArray() && clazz.getComponentType() == Double.TYPE); + } + + public boolean isByteArray() { + return(clazz.isArray() && clazz.getComponentType() == Byte.TYPE); + } + + public boolean isIntArray() { + return(clazz.isArray() && clazz.getComponentType() == Integer.TYPE); + } + + public boolean isShortArray() { + return(clazz.isArray() && clazz.getComponentType() == Short.TYPE); + } + + public boolean isLongArray() { + return(clazz.isArray() && clazz.getComponentType() == Long.TYPE); + } + + public boolean isStringArray() { + return(clazz.isArray() && clazz.getComponentType() == java.lang.String.class); + } + + public boolean isPrimitive() { return ((clazz != null) && !isArray() && clazz.isPrimitive() && (clazz != Void.TYPE)); } @@ -329,6 +362,30 @@ public class JavaType { return (isArray() && (clazz.getComponentType().isPrimitive())); } + public boolean isShort() { + return (clazz == Short.TYPE); + } + + public boolean isFloat() { + return (clazz == Float.TYPE); + } + + public boolean isDouble() { + return (clazz == Double.TYPE); + } + + public boolean isByte() { + return (clazz == Byte.TYPE); + } + + public boolean isLong() { + return (clazz == Long.TYPE); + } + + public boolean isInt() { + return (clazz == Integer.TYPE); + } + public boolean isVoid() { return (clazz == Void.TYPE); } diff --git a/src/net/java/games/gluegen/MethodBinding.java b/src/net/java/games/gluegen/MethodBinding.java index b7117185d..2c0083b8f 100644 --- a/src/net/java/games/gluegen/MethodBinding.java +++ b/src/net/java/games/gluegen/MethodBinding.java @@ -233,7 +233,7 @@ public class MethodBinding { signatureUsesCArrays = true; } - if (javaArgType.isPrimitiveArray()) { + if (javaArgType.isPrimitiveArray() && !javaArgType.isStringArray() ) { // Needs getPrimitiveArrayCritical or similar construct // depending on native code calling convention signatureUsesPrimitiveArrays = true; diff --git a/src/net/java/games/gluegen/opengl/CGLPAWrapperEmitter.java b/src/net/java/games/gluegen/opengl/CGLPAWrapperEmitter.java index bb80190d3..82ba9f0f9 100644 --- a/src/net/java/games/gluegen/opengl/CGLPAWrapperEmitter.java +++ b/src/net/java/games/gluegen/opengl/CGLPAWrapperEmitter.java @@ -54,8 +54,10 @@ public class CGLPAWrapperEmitter extends CMethodBindingEmitter private static String procAddressJavaTypeName = JavaType.createForClass(Long.TYPE).jniTypeName(); + protected boolean arrayImplRoutine = false; + public CGLPAWrapperEmitter(CMethodBindingEmitter methodToWrap) - { + { super( new MethodBinding(methodToWrap.getBinding()) { public String getName() { @@ -69,6 +71,9 @@ public class CGLPAWrapperEmitter extends CMethodBindingEmitter methodToWrap.getDefaultOutput() ); +// if(binding.signatureUsesPrimitiveArrays()) +// arrayImplRoutine = true; + if (methodToWrap.getReturnValueCapacityExpression() != null) { setReturnValueCapacityExpression(methodToWrap.getReturnValueCapacityExpression()); } @@ -194,10 +199,31 @@ public class CGLPAWrapperEmitter extends CMethodBindingEmitter writer.print("(intptr_t) "); } if (javaType.isArray() || javaType.isNIOBuffer()) { - writer.print(pointerConversionArgumentName(i)); - if (javaArgTypeNeedsDataCopy(javaType)) { - writer.print("_copy"); - } + + Type cArgType = binding.getCSymbol().getArgumentType(i); + boolean containsVoid = false; + // Add special code for accounting for array offsets + // + // For mapping from byte primitive array type to type* case produces code: + // (GLtype*)((char*)_ptr0 + varName_offset) + // where varName_offset is the number of bytes offset as calculated in Java code + + if(javaType.isArray() && !javaType.isNIOBufferArray() && !javaType.isStringArray()) { + writer.print("( (char*)"); + } + /* End of special code section for accounting for array offsets */ + + writer.print(pointerConversionArgumentName(i)); + if (javaArgTypeNeedsDataCopy(javaType)) { + writer.print("_copy"); + } + + /* Add special code for accounting for array offsets */ + if(javaType.isArray() && !javaType.isNIOBufferArray() && !javaType.isStringArray()) { + writer.print(" + " + binding.getArgumentName(i) + "_offset)"); + } + /* End of special code section for accounting for array offsets */ + } else { if (javaType.isString()) { writer.print("_UTF8"); } writer.print(binding.getArgumentName(i)); @@ -209,8 +235,36 @@ public class CGLPAWrapperEmitter extends CMethodBindingEmitter protected String jniMangle(MethodBinding binding) { StringBuffer buf = new StringBuffer(); - buf.append(super.jniMangle(binding)); - jniMangle(Long.TYPE, buf); + buf.append(jniMangle(binding.getName())); + + if(binding.signatureUsesPrimitiveArrays()) + buf.append("1"); + + buf.append("__"); + for (int i = 0; i < binding.getNumArguments(); i++) { + JavaType type = binding.getJavaArgumentType(i); + Class c = type.getJavaClass(); + if (c != null) { + jniMangle(c, buf); + // If Buffer offset arguments were added, we need to mangle the JNI for the + // extra arguments + if(type.isNIOBuffer()) { + jniMangle(Integer.TYPE, buf); + } else if (type.isNIOBufferArray()) { + int[] intArrayType = new int[0]; + c = intArrayType.getClass(); + jniMangle(c , buf); + } + if(type.isArray() && !type.isNIOBufferArray() && !type.isStringArray()) { + jniMangle(Integer.TYPE, buf); + } + } else { + // FIXME: add support for char* -> String conversion + throw new RuntimeException("Unknown kind of JavaType: name="+type.getName()); + } + } + + jniMangle(Long.TYPE, buf); // to account for the additional _addr_ parameter return buf.toString(); } diff --git a/src/net/java/games/gluegen/opengl/JavaGLPAWrapperEmitter.java b/src/net/java/games/gluegen/opengl/JavaGLPAWrapperEmitter.java index c0bfef081..f45fcd3c7 100644 --- a/src/net/java/games/gluegen/opengl/JavaGLPAWrapperEmitter.java +++ b/src/net/java/games/gluegen/opengl/JavaGLPAWrapperEmitter.java @@ -75,10 +75,15 @@ public class JavaGLPAWrapperEmitter extends JavaMethodBindingImplEmitter methodToWrap.getDefaultOutput(), methodToWrap.getRuntimeExceptionType()) { + protected void emitName(PrintWriter writer) { writer.print(GLEmitter.WRAP_PREFIX); super.emitName(writer); + + if(getBinding().signatureUsesPrimitiveArrays()) + writer.print("1"); + } protected int emitArguments(PrintWriter writer) { @@ -135,7 +140,10 @@ public class JavaGLPAWrapperEmitter extends JavaMethodBindingImplEmitter } protected String getImplMethodName() { - return GLEmitter.WRAP_PREFIX + getBinding().getName(); + if(getBinding().signatureUsesPrimitiveArrays()) + return GLEmitter.WRAP_PREFIX + getBinding().getName() + "1"; + else + return GLEmitter.WRAP_PREFIX + getBinding().getName(); } public void emit(PrintWriter writer) diff --git a/src/net/java/games/gluegen/runtime/BufferFactory.java b/src/net/java/games/gluegen/runtime/BufferFactory.java index 67205db5f..52779cb60 100644 --- a/src/net/java/games/gluegen/runtime/BufferFactory.java +++ b/src/net/java/games/gluegen/runtime/BufferFactory.java @@ -43,6 +43,13 @@ import java.nio.*; import net.java.games.jogl.util.BufferUtils; public class BufferFactory { + + public static int SIZEOF_FLOAT = BufferUtils.SIZEOF_FLOAT; + public static int SIZEOF_DOUBLE = BufferUtils.SIZEOF_DOUBLE; + public static int SIZEOF_INT = BufferUtils.SIZEOF_INT; + public static int SIZEOF_SHORT = BufferUtils.SIZEOF_SHORT; + public static int SIZEOF_LONG = BufferUtils.SIZEOF_LONG; + public static ByteBuffer newDirectByteBuffer(int size) { ByteBuffer buf = ByteBuffer.allocateDirect(size); buf.order(ByteOrder.nativeOrder()); |