diff options
Diffstat (limited to 'src')
20 files changed, 429 insertions, 215 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()); diff --git a/src/net/java/games/jogl/GLJPanel.java b/src/net/java/games/jogl/GLJPanel.java index 229cc3446..9fe7ffa6c 100644 --- a/src/net/java/games/jogl/GLJPanel.java +++ b/src/net/java/games/jogl/GLJPanel.java @@ -494,11 +494,11 @@ public final class GLJPanel extends JPanel implements GLDrawable { if (offscreenImage != null) { GL gl = getGL(); // Save current modes - gl.glGetIntegerv(GL.GL_PACK_SWAP_BYTES, swapbytes); - gl.glGetIntegerv(GL.GL_PACK_ROW_LENGTH, rowlength); - gl.glGetIntegerv(GL.GL_PACK_SKIP_ROWS, skiprows); - gl.glGetIntegerv(GL.GL_PACK_SKIP_PIXELS, skippixels); - gl.glGetIntegerv(GL.GL_PACK_ALIGNMENT, alignment); + gl.glGetIntegerv(GL.GL_PACK_SWAP_BYTES, swapbytes, 0); + gl.glGetIntegerv(GL.GL_PACK_ROW_LENGTH, rowlength, 0); + gl.glGetIntegerv(GL.GL_PACK_SKIP_ROWS, skiprows, 0); + gl.glGetIntegerv(GL.GL_PACK_SKIP_PIXELS, skippixels, 0); + gl.glGetIntegerv(GL.GL_PACK_ALIGNMENT, alignment, 0); gl.glPixelStorei(GL.GL_PACK_SWAP_BYTES, GL.GL_FALSE); gl.glPixelStorei(GL.GL_PACK_ROW_LENGTH, offscreenImage.getWidth()); @@ -509,9 +509,9 @@ public final class GLJPanel extends JPanel implements GLDrawable { // Actually read the pixels. gl.glReadBuffer(GL.GL_FRONT); if (dbByte != null) { - gl.glReadPixels(0, 0, offscreenImage.getWidth(), offscreenImage.getHeight(), glFormat, glType, dbByte.getData()); + gl.glReadPixels(0, 0, offscreenImage.getWidth(), offscreenImage.getHeight(), glFormat, glType, dbByte.getData(), 0); } else if (dbInt != null) { - gl.glReadPixels(0, 0, offscreenImage.getWidth(), offscreenImage.getHeight(), glFormat, glType, dbInt.getData()); + gl.glReadPixels(0, 0, offscreenImage.getWidth(), offscreenImage.getHeight(), glFormat, glType, dbInt.getData(), 0); } // Restore saved modes. diff --git a/src/net/java/games/jogl/impl/Project.java b/src/net/java/games/jogl/impl/Project.java index 60e8d5dad..e0bb03190 100755 --- a/src/net/java/games/jogl/impl/Project.java +++ b/src/net/java/games/jogl/impl/Project.java @@ -159,14 +159,13 @@ class Project { * @param in * @param out */ - private void __gluMultMatrixVecd(double[] matrix, double[] in, double[] out) { + private void __gluMultMatrixVecd(double[] matrix, int matrix_offset, double[] in, double[] out) { for (int i = 0; i < 4; i++) { out[i] = - in[0] * matrix[0*4+i] + - in[1] * matrix[1*4+i] + - in[2] * matrix[2*4+i] + - in[3] * matrix[3*4+i]; - + in[0] * matrix[0*4+i+matrix_offset] + + in[1] * matrix[1*4+i+matrix_offset] + + in[2] * matrix[2*4+i+matrix_offset] + + in[3] * matrix[3*4+i+matrix_offset]; } } @@ -245,14 +244,14 @@ class Project { * @param b * @param r */ - private void __gluMultMatricesd(double[] a, double[] b, double[] r) { + private void __gluMultMatricesd(double[] a, int a_offset, double[] b, int b_offset, double[] r) { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { r[i*4+j] = - a[i*4+0]*b[0*4+j] + - a[i*4+1]*b[1*4+j] + - a[i*4+2]*b[2*4+j] + - a[i*4+3]*b[3*4+j]; + a[i*4+0+a_offset]*b[0*4+j+b_offset] + + a[i*4+1+a_offset]*b[1*4+j+b_offset] + + a[i*4+2+a_offset]*b[2*4+j+b_offset] + + a[i*4+3+a_offset]*b[3*4+j+b_offset]; } } } @@ -414,9 +413,13 @@ class Project { double objy, double objz, double[] modelMatrix, + int modelMatrix_offset, double[] projMatrix, + int projMatrix_offset, int[] viewport, - double[] win_pos) { + int viewport_offset, + double[] win_pos, + int win_pos_offset ) { double[] in = this.in; double[] out = this.out; @@ -426,8 +429,8 @@ class Project { in[2] = objz; in[3] = 1.0; - __gluMultMatrixVecd(modelMatrix, in, out); - __gluMultMatrixVecd(projMatrix, out, in); + __gluMultMatrixVecd(modelMatrix, modelMatrix_offset, in, out); + __gluMultMatrixVecd(projMatrix, projMatrix_offset, out, in); if (in[3] == 0.0) return false; @@ -440,9 +443,9 @@ class Project { in[2] = in[2] * in[3] + 0.5f; // Map x,y to viewport - win_pos[0] = in[0] * viewport[2] + viewport[0]; - win_pos[1] = in[1] * viewport[3] + viewport[1]; - win_pos[2] = in[2]; + win_pos[0+win_pos_offset] = in[0] * viewport[2+viewport_offset] + viewport[0+viewport_offset]; + win_pos[1+win_pos_offset] = in[1] * viewport[3+viewport_offset] + viewport[1+viewport_offset]; + win_pos[2+win_pos_offset] = in[2]; return true; } @@ -464,13 +467,17 @@ class Project { double winy, double winz, double[] modelMatrix, + int modelMatrix_offset, double[] projMatrix, + int projMatrix_offset, int[] viewport, - double[] obj_pos) { + int viewport_offset, + double[] obj_pos, + int obj_pos_offset) { double[] in = this.in; double[] out = this.out; - __gluMultMatricesd(modelMatrix, projMatrix, finalMatrix); + __gluMultMatricesd(modelMatrix, modelMatrix_offset, projMatrix, projMatrix_offset, finalMatrix); if (!__gluInvertMatrixd(finalMatrix, finalMatrix)) return false; @@ -481,24 +488,24 @@ class Project { in[3] = 1.0; // Map x and y from window coordinates - in[0] = (in[0] - viewport[0]) / viewport[2]; - in[1] = (in[1] - viewport[1]) / viewport[3]; + in[0] = (in[0] - viewport[0+viewport_offset]) / viewport[2+viewport_offset]; + in[1] = (in[1] - viewport[1+viewport_offset]) / viewport[3+viewport_offset]; // Map to range -1 to 1 in[0] = in[0] * 2 - 1; in[1] = in[1] * 2 - 1; in[2] = in[2] * 2 - 1; - __gluMultMatrixVecd(finalMatrix, in, out); + __gluMultMatrixVecd(finalMatrix, 0, in, out); if (out[3] == 0.0) return false; out[3] = 1.0 / out[3]; - obj_pos[0] = out[0] * out[3]; - obj_pos[1] = out[1] * out[3]; - obj_pos[2] = out[2] * out[3]; + obj_pos[0+obj_pos_offset] = out[0] * out[3]; + obj_pos[1+obj_pos_offset] = out[1] * out[3]; + obj_pos[2+obj_pos_offset] = out[2] * out[3]; return true; } @@ -524,15 +531,19 @@ class Project { double winz, double clipw, double[] modelMatrix, + int modelMatrix_offset, double[] projMatrix, + int projMatrix_offset, int[] viewport, + int viewport_offset, double near, double far, - double[] obj_pos) { + double[] obj_pos, + int obj_pos_offset ) { double[] in = this.in; double[] out = this.out; - __gluMultMatricesd(modelMatrix, projMatrix, finalMatrix); + __gluMultMatricesd(modelMatrix, modelMatrix_offset, projMatrix, projMatrix_offset, finalMatrix); if (!__gluInvertMatrixd(finalMatrix, finalMatrix)) return false; @@ -543,8 +554,8 @@ class Project { in[3] = clipw; // Map x and y from window coordinates - in[0] = (in[0] - viewport[0]) / viewport[2]; - in[1] = (in[1] - viewport[1]) / viewport[3]; + in[0] = (in[0] - viewport[0+viewport_offset]) / viewport[2+viewport_offset]; + in[1] = (in[1] - viewport[1+viewport_offset]) / viewport[3+viewport_offset]; in[2] = (in[2] - near) / (far - near); // Map to range -1 to 1 @@ -552,15 +563,15 @@ class Project { in[1] = in[1] * 2 - 1; in[2] = in[2] * 2 - 1; - __gluMultMatrixVecd(finalMatrix, in, out); + __gluMultMatrixVecd(finalMatrix, 0, in, out); if (out[3] == 0.0) return false; - obj_pos[0] = out[0]; - obj_pos[1] = out[1]; - obj_pos[2] = out[2]; - obj_pos[3] = out[3]; + obj_pos[0+obj_pos_offset] = out[0]; + obj_pos[1+obj_pos_offset] = out[1]; + obj_pos[2+obj_pos_offset] = out[2]; + obj_pos[3+obj_pos_offset] = out[3]; return true; } @@ -578,15 +589,16 @@ class Project { double y, double deltaX, double deltaY, - int[] viewport) { + int[] viewport, + int viewport_offset) { if (deltaX <= 0 || deltaY <= 0) { return; } /* Translate and scale the picked region to the entire window */ - gl.glTranslated((viewport[2] - 2 * (x - viewport[0])) / deltaX, - (viewport[3] - 2 * (y - viewport[1])) / deltaY, + gl.glTranslated((viewport[2+viewport_offset] - 2 * (x - viewport[0+viewport_offset])) / deltaX, + (viewport[3+viewport_offset] - 2 * (y - viewport[1+viewport_offset])) / deltaY, 0); - gl.glScaled(viewport[2] / deltaX, viewport[3] / deltaY, 1.0); + gl.glScaled(viewport[2+viewport_offset] / deltaX, viewport[3+viewport_offset] / deltaY, 1.0); } } diff --git a/src/net/java/games/jogl/impl/Util.java b/src/net/java/games/jogl/impl/Util.java index 80a5d1232..1b2f9ed9f 100755 --- a/src/net/java/games/jogl/impl/Util.java +++ b/src/net/java/games/jogl/impl/Util.java @@ -236,7 +236,7 @@ class Util { * @return int */ protected int glGetIntegerv(GL gl, int what) { - gl.glGetIntegerv(what, scratch); + gl.glGetIntegerv(what, scratch, 0); return scratch[0]; } } diff --git a/src/net/java/games/jogl/impl/mipmap/Mipmap.java b/src/net/java/games/jogl/impl/mipmap/Mipmap.java index a66edfc44..63cf760e2 100644 --- a/src/net/java/games/jogl/impl/mipmap/Mipmap.java +++ b/src/net/java/games/jogl/impl/mipmap/Mipmap.java @@ -257,7 +257,7 @@ public class Mipmap { if( target == GL.GL_TEXTURE_2D || target == GL.GL_PROXY_TEXTURE_2D ) { proxyTarget = GL.GL_PROXY_TEXTURE_2D; gl.glTexImage2D( proxyTarget, 1, internalFormat, widthAtLevelOne, - heightAtLevelOne, 0, format, type, (double[])null ); + heightAtLevelOne, 0, format, type, (double[])null, 0); } else if( (target == GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB) || (target == GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB) || (target == GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB) || @@ -266,14 +266,14 @@ public class Mipmap { (target == GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) ) { proxyTarget = GL.GL_PROXY_TEXTURE_CUBE_MAP_ARB; gl.glTexImage2D( proxyTarget, 1, internalFormat, widthAtLevelOne, - heightAtLevelOne, 0, format, type, (double[])null ); + heightAtLevelOne, 0, format, type, (double[])null , 0); } else { assert( target == GL.GL_TEXTURE_1D || target == GL.GL_PROXY_TEXTURE_1D ); proxyTarget = GL.GL_PROXY_TEXTURE_1D; gl.glTexImage1D( proxyTarget, 1, internalFormat, widthAtLevelOne, - 0, format, type, (double[])null ); + 0, format, type, (double[])null, 0); } - gl.glGetTexLevelParameteriv( proxyTarget, 1, GL.GL_TEXTURE_WIDTH, proxyWidth ); + gl.glGetTexLevelParameteriv( proxyTarget, 1, GL.GL_TEXTURE_WIDTH, proxyWidth, 0 ); // does it fit? if( proxyWidth[0] == 0 ) { // nope, so try again with theses sizes if( widthPowerOf2 == 1 && heightPowerOf2 == 1 ) { @@ -299,7 +299,7 @@ public class Mipmap { } } int[] maxsize = new int[1]; - gl.glGetIntegerv( GL.GL_MAX_TEXTURE_SIZE, maxsize ); + gl.glGetIntegerv( GL.GL_MAX_TEXTURE_SIZE, maxsize , 0); // clamp user's texture sizes to maximum sizes, if necessary newWidth[0] = nearestPower( width ); if( newWidth[0] > maxsize[0] ) { @@ -333,9 +333,9 @@ public class Mipmap { if( target == GL.GL_TEXTURE_3D || target == GL.GL_PROXY_TEXTURE_3D ) { proxyTarget = GL.GL_PROXY_TEXTURE_3D; gl.glTexImage3D( proxyTarget, 1, internalFormat, widthAtLevelOne, - heightAtLevelOne, depthAtLevelOne, 0, format, type, (double[])null ); + heightAtLevelOne, depthAtLevelOne, 0, format, type, (double[])null, 0 ); } - gl.glGetTexLevelParameteriv( proxyTarget, 1, GL.GL_TEXTURE_WIDTH, proxyWidth ); + gl.glGetTexLevelParameteriv( proxyTarget, 1, GL.GL_TEXTURE_WIDTH, proxyWidth, 0 ); // does it fit if( proxyWidth[0] == 0 ) { if( widthPowerOf2 == 1 && heightPowerOf2 == 1 && depthPowerOf2 == 1 ) { @@ -454,67 +454,67 @@ public class Mipmap { public static void retrieveStoreModes( GL gl, PixelStorageModes psm ) { int[] a = new int[1]; - gl.glGetIntegerv( GL.GL_UNPACK_ALIGNMENT, a ); + gl.glGetIntegerv( GL.GL_UNPACK_ALIGNMENT, a, 0); psm.setUnpackAlignment( a[0] ); - gl.glGetIntegerv( GL.GL_UNPACK_ROW_LENGTH, a ); + gl.glGetIntegerv( GL.GL_UNPACK_ROW_LENGTH, a, 0); psm.setUnpackRowLength( a[0] ); - gl.glGetIntegerv( GL.GL_UNPACK_SKIP_ROWS, a ); + gl.glGetIntegerv( GL.GL_UNPACK_SKIP_ROWS, a, 0); psm.setUnpackSkipRows( a[0] ); - gl.glGetIntegerv( GL.GL_UNPACK_SKIP_PIXELS, a ); + gl.glGetIntegerv( GL.GL_UNPACK_SKIP_PIXELS, a, 0); psm.setUnpackSkipPixels( a[0] ); - gl.glGetIntegerv( GL.GL_UNPACK_LSB_FIRST, a ); + gl.glGetIntegerv( GL.GL_UNPACK_LSB_FIRST, a, 0); psm.setUnpackLsbFirst( ( a[0] == 1 ) ); - gl.glGetIntegerv( GL.GL_UNPACK_SWAP_BYTES, a ); + gl.glGetIntegerv( GL.GL_UNPACK_SWAP_BYTES, a, 0); psm.setUnpackSwapBytes( ( a[0] == 1 ) ); - gl.glGetIntegerv( GL.GL_PACK_ALIGNMENT, a ); + gl.glGetIntegerv( GL.GL_PACK_ALIGNMENT, a, 0); psm.setPackAlignment( a[0] ); - gl.glGetIntegerv( GL.GL_PACK_ROW_LENGTH, a ); + gl.glGetIntegerv( GL.GL_PACK_ROW_LENGTH, a, 0); psm.setPackRowLength( a[0] ); - gl.glGetIntegerv( GL.GL_PACK_SKIP_ROWS, a ); + gl.glGetIntegerv( GL.GL_PACK_SKIP_ROWS, a, 0); psm.setPackSkipRows( a[0] ); - gl.glGetIntegerv( GL.GL_PACK_SKIP_PIXELS, a ); + gl.glGetIntegerv( GL.GL_PACK_SKIP_PIXELS, a, 0); psm.setPackSkipPixels( a[0] ); - gl.glGetIntegerv( GL.GL_PACK_LSB_FIRST, a ); + gl.glGetIntegerv( GL.GL_PACK_LSB_FIRST, a, 0); psm.setPackLsbFirst( ( a[0] == 1 ) ); - gl.glGetIntegerv( GL.GL_PACK_SWAP_BYTES, a ); + gl.glGetIntegerv( GL.GL_PACK_SWAP_BYTES, a, 0); psm.setPackSwapBytes( ( a[0] == 1 ) ); } public static void retrieveStoreModes3D( GL gl, PixelStorageModes psm ) { int[] a = new int[1]; - gl.glGetIntegerv( GL.GL_UNPACK_ALIGNMENT, a ); + gl.glGetIntegerv( GL.GL_UNPACK_ALIGNMENT, a, 0); psm.setUnpackAlignment( a[0] ); - gl.glGetIntegerv( GL.GL_UNPACK_ROW_LENGTH, a ); + gl.glGetIntegerv( GL.GL_UNPACK_ROW_LENGTH, a, 0); psm.setUnpackRowLength( a[0] ); - gl.glGetIntegerv( GL.GL_UNPACK_SKIP_ROWS, a ); + gl.glGetIntegerv( GL.GL_UNPACK_SKIP_ROWS, a, 0); psm.setUnpackSkipRows( a[0] ); - gl.glGetIntegerv( GL.GL_UNPACK_SKIP_PIXELS, a ); + gl.glGetIntegerv( GL.GL_UNPACK_SKIP_PIXELS, a, 0); psm.setUnpackSkipPixels( a[0] ); - gl.glGetIntegerv( GL.GL_UNPACK_LSB_FIRST, a ); + gl.glGetIntegerv( GL.GL_UNPACK_LSB_FIRST, a, 0); psm.setUnpackLsbFirst( ( a[0] == 1 ) ); - gl.glGetIntegerv( GL.GL_UNPACK_SWAP_BYTES, a ); + gl.glGetIntegerv( GL.GL_UNPACK_SWAP_BYTES, a, 0); psm.setUnpackSwapBytes( ( a[0] == 1 ) ); - gl.glGetIntegerv( GL.GL_UNPACK_SKIP_IMAGES, a ); + gl.glGetIntegerv( GL.GL_UNPACK_SKIP_IMAGES, a, 0); psm.setUnpackSkipImages( a[0] ); - gl.glGetIntegerv( GL.GL_UNPACK_IMAGE_HEIGHT, a ); + gl.glGetIntegerv( GL.GL_UNPACK_IMAGE_HEIGHT, a, 0); psm.setUnpackImageHeight( a[0] ); - gl.glGetIntegerv( GL.GL_PACK_ALIGNMENT, a ); + gl.glGetIntegerv( GL.GL_PACK_ALIGNMENT, a, 0); psm.setPackAlignment( a[0] ); - gl.glGetIntegerv( GL.GL_PACK_ROW_LENGTH, a ); + gl.glGetIntegerv( GL.GL_PACK_ROW_LENGTH, a, 0); psm.setPackRowLength( a[0] ); - gl.glGetIntegerv( GL.GL_PACK_SKIP_ROWS, a ); + gl.glGetIntegerv( GL.GL_PACK_SKIP_ROWS, a, 0); psm.setPackSkipRows( a[0] ); - gl.glGetIntegerv( GL.GL_PACK_SKIP_PIXELS, a ); + gl.glGetIntegerv( GL.GL_PACK_SKIP_PIXELS, a, 0 ); psm.setPackSkipPixels( a[0] ); - gl.glGetIntegerv( GL.GL_PACK_LSB_FIRST, a ); + gl.glGetIntegerv( GL.GL_PACK_LSB_FIRST, a, 0 ); psm.setPackLsbFirst( ( a[0] == 1 ) ); - gl.glGetIntegerv( GL.GL_PACK_SWAP_BYTES, a ); + gl.glGetIntegerv( GL.GL_PACK_SWAP_BYTES, a, 0 ); psm.setPackSwapBytes( ( a[0] == 1 ) ); - gl.glGetIntegerv( GL.GL_PACK_SKIP_IMAGES, a ); + gl.glGetIntegerv( GL.GL_PACK_SKIP_IMAGES, a, 0 ); psm.setPackSkipImages( a[0] ); - gl.glGetIntegerv( GL.GL_PACK_IMAGE_HEIGHT, a ); + gl.glGetIntegerv( GL.GL_PACK_IMAGE_HEIGHT, a, 0 ); psm.setPackImageHeight( a[0] ); } @@ -602,7 +602,8 @@ public class Mipmap { return( BuildMipmap.gluBuild1DMipmapLevelsCore( gl, target, internalFormat, width, widthPowerOf2[0], format, type, 0, 0, levels, data ) ); } - + + public static int gluBuild2DMipmapLevels( GL gl, int target, int internalFormat, int width, int height, int format, int type, int userLevel, int baseLevel, int maxLevel, Object data ) { @@ -632,32 +633,14 @@ public class Mipmap { ByteBuffer buffer = null; if( data instanceof ByteBuffer ) { buffer = (ByteBuffer)data; - } else if( data instanceof byte[] ) { - byte[] array = (byte[])data; - buffer = ByteBuffer.allocateDirect(array.length); - buffer.put(array); - } else if( data instanceof short[] ) { - short[] array = (short[])data; - buffer = ByteBuffer.allocateDirect( array.length * 2 ); - ShortBuffer sb = buffer.asShortBuffer(); - sb.put( array ); - } else if( data instanceof int[] ) { - int[] array = (int[])data; - buffer = ByteBuffer.allocateDirect( array.length * 4 ); - IntBuffer ib = buffer.asIntBuffer(); - ib.put( array ); - } else if( data instanceof float[] ) { - float[] array = (float[])data; - buffer = ByteBuffer.allocateDirect( array.length * 4 ); - FloatBuffer fb = buffer.asFloatBuffer(); - fb.put( array ); - } + } return( BuildMipmap.gluBuild2DMipmapLevelsCore( gl, target, internalFormat, width, height, width, height, format, type, userLevel, baseLevel, maxLevel, buffer ) ); } - + + public static int gluBuild2DMipmaps( GL gl, int target, int internalFormat, int width, int height, int format, int type, Object data ) { int[] widthPowerOf2 = new int[1]; @@ -686,32 +669,14 @@ public class Mipmap { ByteBuffer buffer = null; if( data instanceof ByteBuffer ) { buffer = (ByteBuffer)data; - } else if( data instanceof byte[] ) { - byte[] array = (byte[])data; - buffer = ByteBuffer.allocateDirect(array.length); - buffer.put(array); - } else if( data instanceof short[] ) { - short[] array = (short[])data; - buffer = ByteBuffer.allocateDirect( array.length * 2 ); - ShortBuffer sb = buffer.asShortBuffer(); - sb.put( array ); - } else if( data instanceof int[] ) { - int[] array = (int[])data; - buffer = ByteBuffer.allocateDirect( array.length * 4 ); - IntBuffer ib = buffer.asIntBuffer(); - ib.put( array ); - } else if( data instanceof float[] ) { - float[] array = (float[])data; - buffer = ByteBuffer.allocateDirect( array.length * 4 ); - FloatBuffer fb = buffer.asFloatBuffer(); - fb.put( array ); - } + } return( BuildMipmap.gluBuild2DMipmapLevelsCore( gl, target, internalFormat, width, height, widthPowerOf2[0], heightPowerOf2[0], format, type, 0, 0, levels, buffer ) ); } - + + public static int gluBuild3DMipmaps( GL gl, int target, int internalFormat, int width, int height, int depth, int format, int type, ByteBuffer data ) { int[] widthPowerOf2 = new int[1]; diff --git a/src/net/java/games/jogl/impl/tesselator/GLUtesselatorImpl.java b/src/net/java/games/jogl/impl/tesselator/GLUtesselatorImpl.java index 90de5bcc9..34638ba51 100644 --- a/src/net/java/games/jogl/impl/tesselator/GLUtesselatorImpl.java +++ b/src/net/java/games/jogl/impl/tesselator/GLUtesselatorImpl.java @@ -231,12 +231,12 @@ public class GLUtesselatorImpl implements GLUtesselator { } /* Returns tessellator property */ - public void gluGetTessProperty(int which, double[] value) { + public void gluGetTessProperty(int which, double[] value, int value_offset) { switch (which) { case GLU.GLU_TESS_TOLERANCE: /* tolerance should be in range [0..1] */ assert (0.0 <= relTolerance && relTolerance <= 1.0); - value[0] = relTolerance; + value[value_offset] = relTolerance; break; case GLU.GLU_TESS_WINDING_RULE: assert (windingRule == GLU.GLU_TESS_WINDING_ODD || @@ -244,14 +244,14 @@ public class GLUtesselatorImpl implements GLUtesselator { windingRule == GLU.GLU_TESS_WINDING_POSITIVE || windingRule == GLU.GLU_TESS_WINDING_NEGATIVE || windingRule == GLU.GLU_TESS_WINDING_ABS_GEQ_TWO); - value[0] = windingRule; + value[value_offset] = windingRule; break; case GLU.GLU_TESS_BOUNDARY_ONLY: assert (boundaryOnly == true || boundaryOnly == false); - value[0] = boundaryOnly ? 1 : 0; + value[value_offset] = boundaryOnly ? 1 : 0; break; default: - value[0] = 0.0; + value[value_offset] = 0.0; callErrorOrErrorData(GLU.GLU_INVALID_ENUM); break; } @@ -386,7 +386,7 @@ public class GLUtesselatorImpl implements GLUtesselator { return true; } - public void gluTessVertex(double[] coords, Object vertexData) { + public void gluTessVertex(double[] coords, int coords_offset, Object vertexData) { int i; boolean tooLarge = false; double x; @@ -402,7 +402,7 @@ public class GLUtesselatorImpl implements GLUtesselator { lastEdge = null; } for (i = 0; i < 3; ++i) { - x = coords[i]; + x = coords[i+coords_offset]; if (x < -GLU.GLU_TESS_MAX_COORD) { x = -GLU.GLU_TESS_MAX_COORD; tooLarge = true; diff --git a/src/net/java/games/jogl/impl/x11/X11GLContext.java b/src/net/java/games/jogl/impl/x11/X11GLContext.java index 4709691f8..22d6c5237 100644 --- a/src/net/java/games/jogl/impl/x11/X11GLContext.java +++ b/src/net/java/games/jogl/impl/x11/X11GLContext.java @@ -234,7 +234,7 @@ public abstract class X11GLContext extends GLContext { } int[] major = new int[1]; int[] minor = new int[1]; - if (!GLX.glXQueryVersion(display, major, minor)) { + if (!GLX.glXQueryVersion(display, major, 0, minor, 0)) { throw new GLException("glXQueryVersion failed"); } if (DEBUG) { @@ -333,7 +333,7 @@ public abstract class X11GLContext extends GLContext { XVisualInfo template = new XVisualInfo(); // FIXME: probably not 64-bit clean template.visualid((int) visualID); - XVisualInfo[] infos = GLX.XGetVisualInfo(display, GLX.VisualIDMask, template, count); + XVisualInfo[] infos = GLX.XGetVisualInfo(display, GLX.VisualIDMask, template, count, 0); if (infos == null || infos.length == 0) { throw new GLException("Error while getting XVisualInfo for visual ID " + visualID); } @@ -352,7 +352,7 @@ public abstract class X11GLContext extends GLContext { int[] count = new int[1]; XVisualInfo template = new XVisualInfo(); template.screen(screen); - XVisualInfo[] infos = GLX.XGetVisualInfo(display, GLX.VisualScreenMask, template, count); + XVisualInfo[] infos = GLX.XGetVisualInfo(display, GLX.VisualScreenMask, template, count, 0); if (infos == null) { throw new GLException("Error while enumerating available XVisualInfos"); } diff --git a/src/net/java/games/jogl/impl/x11/X11GLContextFactory.java b/src/net/java/games/jogl/impl/x11/X11GLContextFactory.java index 3582d51d9..6d7d6f372 100644 --- a/src/net/java/games/jogl/impl/x11/X11GLContextFactory.java +++ b/src/net/java/games/jogl/impl/x11/X11GLContextFactory.java @@ -62,12 +62,12 @@ public class X11GLContextFactory extends GLContextFactory { int[] attribs = glCapabilities2AttribList(capabilities, isMultisampleAvailable()); long display = getDisplayConnection(); - XVisualInfo recommendedVis = GLX.glXChooseVisual(display, screen, attribs); + XVisualInfo recommendedVis = GLX.glXChooseVisual(display, screen, attribs, 0); int recommendedIndex = -1; int[] count = new int[1]; XVisualInfo template = new XVisualInfo(); template.screen(screen); - XVisualInfo[] infos = GLX.XGetVisualInfo(display, GLX.VisualScreenMask, template, count); + XVisualInfo[] infos = GLX.XGetVisualInfo(display, GLX.VisualScreenMask, template, count, 0); if (infos == null) { throw new GLException("Error while enumerating available XVisualInfos"); } @@ -125,37 +125,37 @@ public class X11GLContextFactory extends GLContextFactory { public static GLCapabilities xvi2GLCapabilities(long display, XVisualInfo info) { int[] tmp = new int[1]; - int val = glXGetConfig(display, info, GLX.GLX_USE_GL, tmp); + int val = glXGetConfig(display, info, GLX.GLX_USE_GL, tmp, 0); if (val == 0) { // Visual does not support OpenGL return null; } - val = glXGetConfig(display, info, GLX.GLX_RGBA, tmp); + val = glXGetConfig(display, info, GLX.GLX_RGBA, tmp, 0); if (val == 0) { // Visual does not support RGBA return null; } GLCapabilities res = new GLCapabilities(); - res.setDoubleBuffered(glXGetConfig(display, info, GLX.GLX_DOUBLEBUFFER, tmp) != 0); - res.setStereo (glXGetConfig(display, info, GLX.GLX_STEREO, tmp) != 0); + res.setDoubleBuffered(glXGetConfig(display, info, GLX.GLX_DOUBLEBUFFER, tmp, 0) != 0); + res.setStereo (glXGetConfig(display, info, GLX.GLX_STEREO, tmp, 0) != 0); // Note: use of hardware acceleration is determined by // glXCreateContext, not by the XVisualInfo. Optimistically claim // that all GLCapabilities have the capability to be hardware // accelerated. res.setHardwareAccelerated(true); - res.setDepthBits (glXGetConfig(display, info, GLX.GLX_DEPTH_SIZE, tmp)); - res.setStencilBits (glXGetConfig(display, info, GLX.GLX_STENCIL_SIZE, tmp)); - res.setRedBits (glXGetConfig(display, info, GLX.GLX_RED_SIZE, tmp)); - res.setGreenBits (glXGetConfig(display, info, GLX.GLX_GREEN_SIZE, tmp)); - res.setBlueBits (glXGetConfig(display, info, GLX.GLX_BLUE_SIZE, tmp)); - res.setAlphaBits (glXGetConfig(display, info, GLX.GLX_ALPHA_SIZE, tmp)); - res.setAccumRedBits (glXGetConfig(display, info, GLX.GLX_ACCUM_RED_SIZE, tmp)); - res.setAccumGreenBits(glXGetConfig(display, info, GLX.GLX_ACCUM_GREEN_SIZE, tmp)); - res.setAccumBlueBits (glXGetConfig(display, info, GLX.GLX_ACCUM_BLUE_SIZE, tmp)); - res.setAccumAlphaBits(glXGetConfig(display, info, GLX.GLX_ACCUM_ALPHA_SIZE, tmp)); + res.setDepthBits (glXGetConfig(display, info, GLX.GLX_DEPTH_SIZE, tmp, 0)); + res.setStencilBits (glXGetConfig(display, info, GLX.GLX_STENCIL_SIZE, tmp, 0)); + res.setRedBits (glXGetConfig(display, info, GLX.GLX_RED_SIZE, tmp, 0)); + res.setGreenBits (glXGetConfig(display, info, GLX.GLX_GREEN_SIZE, tmp, 0)); + res.setBlueBits (glXGetConfig(display, info, GLX.GLX_BLUE_SIZE, tmp, 0)); + res.setAlphaBits (glXGetConfig(display, info, GLX.GLX_ALPHA_SIZE, tmp, 0)); + res.setAccumRedBits (glXGetConfig(display, info, GLX.GLX_ACCUM_RED_SIZE, tmp, 0)); + res.setAccumGreenBits(glXGetConfig(display, info, GLX.GLX_ACCUM_GREEN_SIZE, tmp, 0)); + res.setAccumBlueBits (glXGetConfig(display, info, GLX.GLX_ACCUM_BLUE_SIZE, tmp, 0)); + res.setAccumAlphaBits(glXGetConfig(display, info, GLX.GLX_ACCUM_ALPHA_SIZE, tmp, 0)); if (isMultisampleAvailable()) { - res.setSampleBuffers(glXGetConfig(display, info, GLX.GLX_SAMPLE_BUFFERS_ARB, tmp) != 0); - res.setNumSamples (glXGetConfig(display, info, GLX.GLX_SAMPLES_ARB, tmp)); + res.setSampleBuffers(glXGetConfig(display, info, GLX.GLX_SAMPLE_BUFFERS_ARB, tmp, 0) != 0); + res.setNumSamples (glXGetConfig(display, info, GLX.GLX_SAMPLES_ARB, tmp, 0)); } return res; } @@ -241,14 +241,14 @@ public class X11GLContextFactory extends GLContextFactory { } } - public static int glXGetConfig(long display, XVisualInfo info, int attrib, int[] tmp) { + public static int glXGetConfig(long display, XVisualInfo info, int attrib, int[] tmp, int tmp_offset) { if (display == 0) { throw new GLException("No display connection"); } - int res = GLX.glXGetConfig(display, info, attrib, tmp); + int res = GLX.glXGetConfig(display, info, attrib, tmp, tmp_offset); if (res != 0) { throw new GLException("glXGetConfig failed: error code " + glXGetConfigErrorCode(res)); } - return tmp[0]; + return tmp[tmp_offset]; } } diff --git a/src/net/java/games/jogl/impl/x11/X11OffscreenGLContext.java b/src/net/java/games/jogl/impl/x11/X11OffscreenGLContext.java index a22367091..343a69f07 100644 --- a/src/net/java/games/jogl/impl/x11/X11OffscreenGLContext.java +++ b/src/net/java/games/jogl/impl/x11/X11OffscreenGLContext.java @@ -164,7 +164,7 @@ public class X11OffscreenGLContext extends X11GLContext { if (context == 0) { throw new GLException("Unable to create OpenGL context"); } - isDoubleBuffered = (X11GLContextFactory.glXGetConfig(display, vis, GLX.GLX_DOUBLEBUFFER, new int[1]) != 0); + isDoubleBuffered = (X11GLContextFactory.glXGetConfig(display, vis, GLX.GLX_DOUBLEBUFFER, new int[1], 0) != 0); } protected void destroyImpl() { diff --git a/src/net/java/games/jogl/impl/x11/X11PbufferGLContext.java b/src/net/java/games/jogl/impl/x11/X11PbufferGLContext.java index 5b6df1843..5e59329ca 100644 --- a/src/net/java/games/jogl/impl/x11/X11PbufferGLContext.java +++ b/src/net/java/games/jogl/impl/x11/X11PbufferGLContext.java @@ -174,7 +174,7 @@ public class X11PbufferGLContext extends X11GLContext { int screen = 0; // FIXME: provide way to specify this? int[] nelementsTmp = new int[1]; - GLXFBConfig[] fbConfigs = GLX.glXChooseFBConfig(display, screen, iattributes, nelementsTmp); + GLXFBConfig[] fbConfigs = GLX.glXChooseFBConfig(display, screen, iattributes, 0, nelementsTmp, 0); if (fbConfigs == null || fbConfigs.length == 0 || fbConfigs[0] == null) { throw new GLException("pbuffer creation error: glXChooseFBConfig() failed"); } @@ -209,7 +209,7 @@ public class X11PbufferGLContext extends X11GLContext { iattributes[niattribs++] = 0; - long tmpBuffer = GLX.glXCreatePbuffer(display, fbConfig, iattributes); + long tmpBuffer = GLX.glXCreatePbuffer(display, fbConfig, iattributes, 0); if (tmpBuffer == 0) { // FIXME: query X error code for detail error message throw new GLException("pbuffer creation error: glXCreatePbuffer() failed"); @@ -224,9 +224,9 @@ public class X11PbufferGLContext extends X11GLContext { // Determine the actual width and height we were able to create. int[] tmp = new int[1]; - GLX.glXQueryDrawable(display, (int) buffer, GL.GLX_WIDTH, tmp); + GLX.glXQueryDrawable(display, (int) buffer, GL.GLX_WIDTH, tmp, 0); width = tmp[0]; - GLX.glXQueryDrawable(display, (int) buffer, GL.GLX_HEIGHT, tmp); + GLX.glXQueryDrawable(display, (int) buffer, GL.GLX_HEIGHT, tmp, 0); height = tmp[0]; if (DEBUG) { @@ -334,7 +334,7 @@ public class X11PbufferGLContext extends X11GLContext { private int queryFBConfig(long display, GLXFBConfig fbConfig, int attrib) { int[] tmp = new int[1]; - if (GLX.glXGetFBConfigAttrib(display, fbConfig, attrib, tmp) != 0) { + if (GLX.glXGetFBConfigAttrib(display, fbConfig, attrib, tmp, 0) != 0) { throw new GLException("glXGetFBConfigAttrib failed"); } return tmp[0]; diff --git a/src/net/java/games/jogl/util/GLUT.java b/src/net/java/games/jogl/util/GLUT.java index 70144d66e..380b02b9f 100644 --- a/src/net/java/games/jogl/util/GLUT.java +++ b/src/net/java/games/jogl/util/GLUT.java @@ -517,7 +517,7 @@ public class GLUT { int[][] faces = boxFaces; for (int i = 5; i >= 0; i--) { gl.glBegin(type); - gl.glNormal3fv(n[i]); + gl.glNormal3fv(n[i], 0); float[] vt = v[faces[i][0]]; gl.glVertex3f(vt[0] * size, vt[1] * size, vt[2] * size); vt = v[faces[i][1]]; @@ -606,12 +606,12 @@ public class GLUT { normalize(n0); gl.glBegin(shadeType); - gl.glNormal3fv(n0); - gl.glVertex3fv(dodec[a]); - gl.glVertex3fv(dodec[b]); - gl.glVertex3fv(dodec[c]); - gl.glVertex3fv(dodec[d]); - gl.glVertex3fv(dodec[e]); + gl.glNormal3fv(n0, 0); + gl.glVertex3fv(dodec[a], 0); + gl.glVertex3fv(dodec[b], 0); + gl.glVertex3fv(dodec[c], 0); + gl.glVertex3fv(dodec[d], 0); + gl.glVertex3fv(dodec[e], 0); gl.glEnd(); } @@ -643,10 +643,10 @@ public class GLUT { normalize(q1); gl.glBegin(shadeType); - gl.glNormal3fv(q1); - gl.glVertex3fv(n1); - gl.glVertex3fv(n2); - gl.glVertex3fv(n3); + gl.glNormal3fv(q1, 0); + gl.glVertex3fv(n1, 0); + gl.glVertex3fv(n2, 0); + gl.glVertex3fv(n3, 0); gl.glEnd(); } @@ -1016,16 +1016,16 @@ public class GLUT { } } } - gl.glMap2f(GL.GL_MAP2_TEXTURE_COORD_2, 0, 1, 2, 2, 0, 1, 4, 2, teapotTex); - gl.glMap2f(GL.GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, p); + gl.glMap2f(GL.GL_MAP2_TEXTURE_COORD_2, 0, 1, 2, 2, 0, 1, 4, 2, teapotTex, 0); + gl.glMap2f(GL.GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, p, 0); gl.glMapGrid2f(grid, 0.0f, 1.0f, grid, 0.0f, 1.0f); evaluateTeapotMesh(gl, grid, type, i, !backCompatible); - gl.glMap2f(GL.GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, q); + gl.glMap2f(GL.GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, q, 0); evaluateTeapotMesh(gl, grid, type, i, !backCompatible); if (i < 6) { - gl.glMap2f(GL.GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, r); + gl.glMap2f(GL.GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, r, 0); evaluateTeapotMesh(gl, grid, type, i, !backCompatible); - gl.glMap2f(GL.GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, s); + gl.glMap2f(GL.GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, s, 0); evaluateTeapotMesh(gl, grid, type, i, !backCompatible); } } @@ -1093,7 +1093,7 @@ public class GLUT { BitmapCharRec ch = fontinfo.ch[c - fontinfo.first]; if (ch != null) { gl.glBitmap(ch.width, ch.height, ch.xorig, ch.yorig, - ch.advance, 0, ch.bitmap); + ch.advance, 0, ch.bitmap, 0); } } @@ -1157,12 +1157,12 @@ public class GLUT { int[] skiprows, int[] skippixels, int[] alignment) { - gl.glGetIntegerv(GL.GL_UNPACK_SWAP_BYTES, swapbytes); - gl.glGetIntegerv(GL.GL_UNPACK_LSB_FIRST, lsbfirst); - gl.glGetIntegerv(GL.GL_UNPACK_ROW_LENGTH, rowlength); - gl.glGetIntegerv(GL.GL_UNPACK_SKIP_ROWS, skiprows); - gl.glGetIntegerv(GL.GL_UNPACK_SKIP_PIXELS, skippixels); - gl.glGetIntegerv(GL.GL_UNPACK_ALIGNMENT, alignment); + gl.glGetIntegerv(GL.GL_UNPACK_SWAP_BYTES, swapbytes, 0); + gl.glGetIntegerv(GL.GL_UNPACK_LSB_FIRST, lsbfirst, 0); + gl.glGetIntegerv(GL.GL_UNPACK_ROW_LENGTH, rowlength, 0); + gl.glGetIntegerv(GL.GL_UNPACK_SKIP_ROWS, skiprows, 0); + gl.glGetIntegerv(GL.GL_UNPACK_SKIP_PIXELS, skippixels, 0); + gl.glGetIntegerv(GL.GL_UNPACK_ALIGNMENT, alignment, 0); /* Little endian machines (DEC Alpha for example) could benefit from setting GL_UNPACK_LSB_FIRST to GL_TRUE instead of GL_FALSE, but this would require changing the |