diff options
author | Travis Bryson <[email protected]> | 2005-08-23 00:34:32 +0000 |
---|---|---|
committer | Travis Bryson <[email protected]> | 2005-08-23 00:34:32 +0000 |
commit | 6b9841f75655fabd491f7410643272d36eddc77e (patch) | |
tree | 70dbc4ef0d81aa765164fe9b3f381abc46fd6d80 | |
parent | 7197a255a1688551a4861ca221233956b8fd21c0 (diff) |
This putback may break Windows/Mac build temporarily for a few hours
until we synchronize with builds on all of our target platforms as we are
rushing this a bit so that we can properly reorganize the workspace shortly,
and with such fundamental changes, this is considered a "risky" putback.
So advising to hold off on bringover a few hours for non-X11 targets.
This is the majority of changes required for Native I/O IndirectBuffer
support for JSR 231. The changes are not yet complete, and Indirect
Buffers (buffers backed by an array) should not yet be used (although
what is being putback here has been tested and is working).
IndirectBuffer support is being added in JSR 231 since this will
be the method often used to send down arrays to the public API,
by "wrapping" them, enabling us to eliminate many of the API
"explosions" that happen in the older, JOGL approach, enabling
the number of public APIs in JSR 231 to be greatly reduced, and
map more cleanly to native OpenGL. Soon we
will be removing the old API explosions and Indirect Buffers will
be the only way to send down an array to many APIs, but at this
point there are no public API changes putback for this. We will
be providing code samples. The changes to any program source
code are *very* straightforward.
Offsets into Native I/O buffers and offsets within the arrays that
back them are also supported. We will also provide code examples
for this. So, for example, you do not need to rewrap an array when
you want to send down its elements but starting at somewhere besides
the zeroth index.
This putback adds the support for all methods not accessed internally by
function pointers (dispatch methods in the expanded code). The
support for function pointers (mostly APIs that were later additions
to OpenGL, mostly things that are or originally were extensions) will
come in a subsequent putback. The native code for the dispatch methods
is mostly generated, however (just never called currently). The Java
part for dispatch methods is not complete yet, and is not yet generated.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JSR-231@352 232f8b59-042b-4e1e-8c03-345bb8c30851
8 files changed, 314 insertions, 43 deletions
diff --git a/src/net/java/games/gluegen/CMethodBindingEmitter.java b/src/net/java/games/gluegen/CMethodBindingEmitter.java index 5cf2833d9..2616f151b 100644 --- a/src/net/java/games/gluegen/CMethodBindingEmitter.java +++ b/src/net/java/games/gluegen/CMethodBindingEmitter.java @@ -57,6 +57,8 @@ public class CMethodBindingEmitter extends FunctionEmitter protected MethodBinding binding; + protected boolean indirectBufferInterface = false; + /** Name of the package in which the corresponding Java method resides.*/ private String packageName; @@ -137,6 +139,17 @@ public class CMethodBindingEmitter extends FunctionEmitter public final MethodBinding getBinding() { return binding; } + + public boolean isIndirectBufferInterface() { + return indirectBufferInterface; + } + + + public void setIndirectBufferInterface(boolean indirect) { + indirectBufferInterface = indirect; + } + + public String getName() { return binding.getName(); } @@ -343,8 +356,10 @@ public class CMethodBindingEmitter extends FunctionEmitter writer.print(" "); writer.print(binding.getArgumentName(i)); ++numEmitted; - // Add Buffer offset argument immediately after any Buffer arguments - if(javaArgType.isNIOBuffer() || javaArgType.isNIOBufferArray()) { + + // Replace following for indirect buffer case + // if(javaArgType.isNIOBuffer() || javaArgType.isNIOBufferArray()) { + if((javaArgType.isNIOBuffer() && !isIndirectBufferInterface()) || javaArgType.isNIOBufferArray()) { if(!javaArgType.isArray()) { numBufferOffsetArgs++; writer.print(", jint " + byteOffsetConversionArgName(numBufferOffsetArgs)); @@ -355,6 +370,10 @@ public class CMethodBindingEmitter extends FunctionEmitter } } + // indirect buffer case needs same offset syntax as arrays + if(javaArgType.isNIOBuffer() && isIndirectBufferInterface()) + writer.print(", jint " + binding.getArgumentName(i) + "_offset"); + // Add array primitive index/offset parameter if(javaArgType.isArray() && !javaArgType.isNIOBufferArray() && !javaArgType.isStringArray()) { writer.print(", jint " + binding.getArgumentName(i) + "_offset"); @@ -499,7 +518,8 @@ public class CMethodBindingEmitter extends FunctionEmitter // Convert all Buffers to pointers first so we don't have to // call ReleasePrimitiveArrayCritical for any arrays if any // incoming buffers aren't direct - if (binding.hasContainingType()) { + // we don't want to fall in here for indirectBuffer case, since its an array + if (binding.hasContainingType() && !isIndirectBufferInterface()) { byteOffsetCounter++; emitPointerConversion(writer, binding, binding.getContainingType(), @@ -514,7 +534,8 @@ public class CMethodBindingEmitter extends FunctionEmitter if (type.isJNIEnv() || binding.isArgumentThisPointer(i)) { continue; } - if (type.isNIOBuffer()) { + + if (type.isNIOBuffer() && !isIndirectBufferInterface()) { byteOffsetCounter++; emitPointerConversion(writer, binding, type, binding.getCArgumentType(i), @@ -533,6 +554,12 @@ public class CMethodBindingEmitter extends FunctionEmitter continue; } + // create array replacement type for Buffer for indirect Buffer case + if(isIndirectBufferInterface() && javaArgType.isNIOBuffer()) { + float[] c = new float[1]; + javaArgType = JavaType.createForClass(c.getClass()); + } + if (javaArgType.isArray()) { boolean needsDataCopy = javaArgTypeNeedsDataCopy(javaArgType); Class subArrayElementJavaType = javaArgType.getJavaClass().getComponentType(); @@ -755,6 +782,14 @@ public class CMethodBindingEmitter extends FunctionEmitter if (javaArgType.isJNIEnv() || binding.isArgumentThisPointer(i)) { continue; } + + + // create array type for Indirect Buffer case + if(isIndirectBufferInterface() && javaArgType.isNIOBuffer()) { + float[] c = new float[1]; + javaArgType = JavaType.createForClass(c.getClass()); + } + if (javaArgType.isArray()) { boolean needsDataCopy = javaArgTypeNeedsDataCopy(javaArgType); Class subArrayElementJavaType = javaArgType.getJavaClass().getComponentType(); @@ -936,7 +971,10 @@ public class CMethodBindingEmitter extends FunctionEmitter // 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()) { + // also, output same for indirect buffer as for array + if(javaArgType.isNIOBuffer() && isIndirectBufferInterface()) + writer.print("( (char*)"); + else if(javaArgType.isArray() && !javaArgType.isNIOBufferArray() && !javaArgType.isStringArray()) { writer.print("( (char*)"); } /* End of this section of new code for array offsets */ @@ -947,7 +985,9 @@ public class CMethodBindingEmitter extends FunctionEmitter } /* Continuation of special code for accounting for array offsets */ - if(javaArgType.isArray() && !javaArgType.isNIOBufferArray() && !javaArgType.isStringArray()) { + if(javaArgType.isNIOBuffer() && isIndirectBufferInterface()) + writer.print(" + " + binding.getArgumentName(i) + "_offset)"); + else if(javaArgType.isArray() && !javaArgType.isNIOBufferArray() && !javaArgType.isStringArray()) { writer.print(" + " + binding.getArgumentName(i) + "_offset)"); } /* End of this section of new code for array offsets */ @@ -1148,9 +1188,15 @@ public class CMethodBindingEmitter extends FunctionEmitter else if (c == Double.TYPE) res.append("D"); else throw new InternalError("Illegal primitive type"); } else { - res.append("L"); - res.append(c.getName().replace('.', '_')); - res.append("_2"); + if(!isIndirectBufferInterface()) { + res.append("L"); + res.append(c.getName().replace('.', '_')); + res.append("_2"); + } else { // indirect buffer sends array as object + res.append("L"); + res.append("java_lang_Object"); + res.append("_2"); + } } } diff --git a/src/net/java/games/gluegen/CMethodBindingImplEmitter.java b/src/net/java/games/gluegen/CMethodBindingImplEmitter.java index 2052bcf98..3f3505896 100644 --- a/src/net/java/games/gluegen/CMethodBindingImplEmitter.java +++ b/src/net/java/games/gluegen/CMethodBindingImplEmitter.java @@ -69,7 +69,9 @@ public class CMethodBindingImplEmitter extends CMethodBindingEmitter { super.emitName(writer); if (!getIsOverloadedBinding()) { - if(!arrayImplRoutine) + if( isIndirectBufferInterface() ) + writer.print("2"); + else if(!arrayImplRoutine) writer.print("0"); else writer.print("1"); @@ -84,7 +86,9 @@ public class CMethodBindingImplEmitter extends CMethodBindingEmitter StringBuffer buf = new StringBuffer(); buf.append(jniMangle(binding.getName())); - if(!arrayImplRoutine) + if( isIndirectBufferInterface() ) + buf.append("2"); + else if(!arrayImplRoutine) buf.append("0"); else buf.append("1"); @@ -92,6 +96,7 @@ public class CMethodBindingImplEmitter extends CMethodBindingEmitter 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); diff --git a/src/net/java/games/gluegen/JavaEmitter.java b/src/net/java/games/gluegen/JavaEmitter.java index 1203bd1fb..dad954db2 100644 --- a/src/net/java/games/gluegen/JavaEmitter.java +++ b/src/net/java/games/gluegen/JavaEmitter.java @@ -351,7 +351,8 @@ public class JavaEmitter implements GlueEmitter { // the binding like any normal binding because no special binding // generation (wrapper methods, etc) will be necessary. MethodBinding specialBinding = binding.createNIOBufferVariant(); - + + if (cfg.allStatic() && binding.hasContainingType()) { // This should not currently happen since structs are emitted using a different mechanism throw new IllegalArgumentException("Cannot create binding in AllStatic mode because method has containing type: \"" + @@ -359,7 +360,8 @@ public class JavaEmitter implements GlueEmitter { } boolean isUnimplemented = cfg.isUnimplemented(binding.getName()); - + JavaMethodBindingImplEmitter entryPoint=null; + if (cfg.emitImpl()) { // Generate the emitter for the method which may do conversion // from type wrappers to NIO Buffers or which may call the @@ -371,8 +373,7 @@ public class JavaEmitter implements GlueEmitter { arrayImplMethod = true; } - JavaMethodBindingImplEmitter entryPoint = - new JavaMethodBindingImplEmitter(binding, + entryPoint = new JavaMethodBindingImplEmitter(binding, (cfg.allStatic() ? javaWriter() : javaImplWriter()), cfg.runtimeExceptionType(), isUnimplemented, @@ -419,8 +420,24 @@ public class JavaEmitter implements GlueEmitter { wrappedEntryPoint.addModifier(JavaMethodBindingEmitter.STATIC); // Doesn't really matter wrappedEntryPoint.addModifier(JavaMethodBindingEmitter.NATIVE); allEmitters.add(wrappedEntryPoint); + + String bindingName = specialBinding.getName(); + if(binding != specialBinding && bindingName.contains("gl") && !bindingName.contains("glX") + && !bindingName.contains("wgl") && !bindingName.contains("CGL")) { + JavaMethodBindingEmitter wrappedEntryPoint2 = + new JavaMethodBindingEmitter(specialBinding, output, cfg.runtimeExceptionType(), + true, arrayImplMethod); + wrappedEntryPoint2.addModifier(JavaMethodBindingEmitter.PRIVATE); + wrappedEntryPoint2.addModifier(JavaMethodBindingEmitter.STATIC); // Doesn't really matter + wrappedEntryPoint2.addModifier(JavaMethodBindingEmitter.NATIVE); + + entryPoint.setGenerateIndirectBufferInterface(true); + wrappedEntryPoint2.setIndirectBufferInterface(true); + allEmitters.add(wrappedEntryPoint2); + } + } - + CMethodBindingEmitter cEmitter = makeCEmitter(specialBinding, overloaded, @@ -429,6 +446,23 @@ public class JavaEmitter implements GlueEmitter { cfg.implPackageName(), cfg.implClassName(), cWriter()); allEmitters.add(cEmitter); + + String bindingName = specialBinding.getName(); + if(binding != specialBinding && bindingName.contains("gl") && !bindingName.contains("glX") + && !bindingName.contains("wgl") && !bindingName.contains("CGL") ) { + + CMethodBindingEmitter cEmitter2 = + makeCEmitter(specialBinding, + //overloaded, + true, + true, + arrayImplMethod, + cfg.implPackageName(), cfg.implClassName(), + cWriter()); + cEmitter2.setIndirectBufferInterface(true); + allEmitters.add(cEmitter2); + } + } } } // end iteration over expanded bindings @@ -1351,6 +1385,7 @@ public class JavaEmitter implements GlueEmitter { } } + // NIO variants for non-void* C primitive pointer types if ((cfg.nioMode() == JavaConfiguration.NIO_MODE_ALL_POINTERS && !cfg.noNio(mb.getCSymbol().getName())) || diff --git a/src/net/java/games/gluegen/JavaMethodBindingEmitter.java b/src/net/java/games/gluegen/JavaMethodBindingEmitter.java index 993133d48..1d227dfc9 100644 --- a/src/net/java/games/gluegen/JavaMethodBindingEmitter.java +++ b/src/net/java/games/gluegen/JavaMethodBindingEmitter.java @@ -71,6 +71,8 @@ public class JavaMethodBindingEmitter extends FunctionEmitter protected boolean prefixedMethod = false; + protected boolean indirectBufferInterface = false; + // A non-null value indicates that rather than returning a compound // type accessor we are returning an array of such accessors; this // expression is a MessageFormat string taking the names of the @@ -109,6 +111,15 @@ public class JavaMethodBindingEmitter extends FunctionEmitter return binding.getName(); } + public boolean isIndirectBufferInterface() { + return indirectBufferInterface; + } + + + public void setIndirectBufferInterface(boolean indirect) { + indirectBufferInterface = indirect; + } + /** The type of exception (must subclass <code>java.lang.RuntimeException</code>) raised if runtime @@ -134,7 +145,8 @@ public class JavaMethodBindingEmitter extends FunctionEmitter } protected String getReturnTypeString(boolean skipArray) { - if (skipArray || (getReturnedArrayLengthExpression() == null && !binding.getJavaReturnType().isArrayOfCompoundTypeWrappers())) { + if (skipArray || (getReturnedArrayLengthExpression() == null && + !binding.getJavaReturnType().isArrayOfCompoundTypeWrappers())) { return binding.getJavaReturnType().getName(); } return binding.getJavaReturnType().getName() + "[]"; @@ -186,10 +198,18 @@ public class JavaMethodBindingEmitter extends FunctionEmitter if (needComma) { writer.print(", "); } - + + // indirect buffer array sent down as object + if(isIndirectBufferInterface() && type.isNIOBuffer() ) { + writer.print(" Object "); + } else { writer.print(type.getName()); + } + writer.print(" "); writer.print(binding.getArgumentName(i)); + + ++numEmitted; needComma = true; @@ -218,10 +238,12 @@ public class JavaMethodBindingEmitter extends FunctionEmitter protected String getImplMethodName() { - if(!forArrayImplementingMethodCall) - return binding.getName() + "0"; + if( isIndirectBufferInterface() ) + return binding.getName() + "2"; + else if(!forArrayImplementingMethodCall) + return binding.getName() + "0"; else - return binding.getName() + "1"; + return binding.getName() + "1"; } diff --git a/src/net/java/games/gluegen/JavaMethodBindingImplEmitter.java b/src/net/java/games/gluegen/JavaMethodBindingImplEmitter.java index 922f60794..3cbc8081d 100644 --- a/src/net/java/games/gluegen/JavaMethodBindingImplEmitter.java +++ b/src/net/java/games/gluegen/JavaMethodBindingImplEmitter.java @@ -85,8 +85,8 @@ public class JavaMethodBindingImplEmitter extends JavaMethodBindingEmitter writer.println(" throw new " + getRuntimeExceptionType() + "(\"Unimplemented\");"); } else { emitPreCallSetup(binding, writer); - emitReturnVariableSetup(binding, writer); - emitCall(binding, writer); + //emitReturnVariableSetup(binding, writer); + emitReturnVariableSetupAndCall(binding, writer); } writer.println(" }"); } else { @@ -94,6 +94,18 @@ public class JavaMethodBindingImplEmitter extends JavaMethodBindingEmitter } } + + protected boolean generateIndirectBufferInterface = false; + + public boolean isGenerateIndirectBufferInterface() { + return generateIndirectBufferInterface; + } + + public void setGenerateIndirectBufferInterface(boolean generateIndirect) { + generateIndirectBufferInterface = generateIndirect; + } + + protected boolean isUnimplemented() { return isUnimplemented; } @@ -107,7 +119,12 @@ public class JavaMethodBindingImplEmitter extends JavaMethodBindingEmitter } protected void emitPreCallSetup(MethodBinding binding, PrintWriter writer) { - emitArrayLengthAndNIOBufferChecks(binding, writer); + if(isGenerateIndirectBufferInterface()) { + // case for when indirect Buffer is a possibility + emitArrayLengthAndNIOInDirectBufferChecks(binding, writer); + } else { + emitArrayLengthAndNIOBufferChecks(binding, writer); + } } @@ -141,7 +158,7 @@ public class JavaMethodBindingImplEmitter extends JavaMethodBindingEmitter binding.getArgumentName(i) + "\\\" was not a direct buffer\");"); writer.println(" }"); // get the Buffer Array offset values and save them into another array to send down to JNI - writer.print(" " + arrayName + "[_ctr] = BufferFactory.getPositionByteOffset("); + writer.print(" " + arrayName + "[_ctr] = BufferFactory.getDirectBufferByteOffset("); writer.println(argName + "[_ctr]);"); writer.println(" }"); writer.println(" }"); @@ -156,6 +173,75 @@ public class JavaMethodBindingImplEmitter extends JavaMethodBindingEmitter } } + + protected void emitArrayLengthAndNIOInDirectBufferChecks(MethodBinding binding, PrintWriter writer) { + int numBufferOffsetArrayArgs = 0; + boolean firstBuffer = true; + // Check lengths of any incoming arrays if necessary + for (int i = 0; i < binding.getNumArguments(); i++) { + Type type = binding.getCArgumentType(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()) { + if(firstBuffer == true) { + firstBuffer = false; + writer.println(" boolean direct = true, firstTime = true, result = true;"); + } + writer.println(" result = BufferFactory.isDirect(" + binding.getArgumentName(i) + ");"); + writer.println(" if(firstTime == true) {"); + writer.println(" direct = result;"); + writer.println(" firstTime = false;"); + writer.println(" } else {"); + writer.println(" if(direct != result)"); + writer.println(" throw new " + getRuntimeExceptionType() + + "(\"Argument \\\"" + binding.getArgumentName(i) + + "\\\" :Not all Buffers in this method were direct or indirect\");"); + writer.println(" }"); + } else if (javaType.isNIOBufferArray()) { + if(firstBuffer == true) { + firstBuffer = false; + writer.println(" boolean direct = true, firstTime = true, result = true;"); + } + numBufferOffsetArrayArgs++; + String argName = binding.getArgumentName(i); + String arrayName = byteOffsetArrayConversionArgName(numBufferOffsetArrayArgs); + writer.println(" int[] " + arrayName + " = new int[" + argName + ".length];"); + writer.println(" if (" + argName + " != null) {"); + // Check direct/indirect buffer properties of all buffers within + writer.println(" for (int _ctr = 0; _ctr < " + argName + ".length; _ctr++) {"); + writer.println(" result = BufferFactory.isDirect(" + argName + "[_ctr]);"); + + writer.println(" if(firstTime == true) {"); + writer.println(" direct = result;"); + writer.println(" firstTime = false;"); + writer.println(" } else {"); + writer.println(" if(direct != result)"); + writer.println(" throw new " + getRuntimeExceptionType() + "(\"Element \" + _ctr + \" of argument \\\"" + binding.getArgumentName(i) + "\\\":Mixture of Direct/Indirect Buffers in Method Args\");"); + writer.println(" }"); + // get the Buffer Array offset values and save them into another array to send down to JNI + writer.println(" if(direct)"); + writer.print(" " + arrayName + "[_ctr] = BufferFactory.getDirectBufferByteOffset("); + writer.println(argName + "[_ctr]);"); + writer.println(" else"); + writer.print(" " + arrayName + "[_ctr] = BufferFactory.getIndirectBufferByteOffset("); + writer.println(argName + "[_ctr]);"); + writer.println(" }"); + writer.println(" }"); + } + } + } + } + + + +/* old method before indirect buffer support was added protected void emitReturnVariableSetup(MethodBinding binding, PrintWriter writer) { writer.print(" "); JavaType returnType = binding.getJavaReturnType(); @@ -172,19 +258,68 @@ public class JavaMethodBindingImplEmitter extends JavaMethodBindingEmitter } } } +*/ + + + protected void emitReturnVariableSetupAndCall(MethodBinding binding, PrintWriter writer) { + + boolean returnFunction = false; - protected void emitCall(MethodBinding binding, PrintWriter writer) { + writer.print(" "); + JavaType returnType = binding.getJavaReturnType(); + if (!returnType.isVoid()) { + if (returnType.isCompoundTypeWrapper() || + returnType.isNIOByteBuffer()) { + writer.println("ByteBuffer _res;"); + writer.print(" _res = "); + } else if (returnType.isArrayOfCompoundTypeWrappers()) { + writer.println("ByteBuffer[] _res;"); + writer.print(" _res = "); + } else { + if(isGenerateIndirectBufferInterface()) + returnFunction = true; + else + writer.print("return "); + } + } + + + if(isGenerateIndirectBufferInterface()) { + //binding.setIndirectVariant(false); + //writer.println(" boolean direct = true;"); + writer.println(" if(direct) {"); + writer.print(" "); + }; + if(returnFunction) writer.print("return "); writer.print(getImplMethodName()); writer.print("("); - emitCallArguments(binding, writer); + emitCallArguments(binding, writer, false); writer.print(")"); + if(isGenerateIndirectBufferInterface()) { + writer.println(";"); + //binding.setIndirectVariant(true); + writer.println(" } else { "); + if(returnFunction) writer.print("return "); + // get the indirect Buffer implementation name + setIndirectBufferInterface(true); + writer.print(" " + getImplMethodName()); + writer.print("("); + setIndirectBufferInterface(false); + emitCallArguments(binding, writer, true); + writer.println(");"); + writer.println(" }"); + }; emitCallResultReturn(binding, writer); } - - protected int emitCallArguments(MethodBinding binding, PrintWriter writer) { + + + protected int emitCallArguments(MethodBinding binding, PrintWriter writer, boolean indirectCase) { boolean needComma = false; int numArgsEmitted = 0; int numBufferOffsetArgs = 0, numBufferOffsetArrayArgs = 0; + boolean generateDirectAndIndirect; + + generateDirectAndIndirect = isGenerateIndirectBufferInterface(); if (binding.hasContainingType()) { // Emit this pointer @@ -194,7 +329,7 @@ public class JavaMethodBindingImplEmitter extends JavaMethodBindingEmitter ++numArgsEmitted; numBufferOffsetArgs++; //writer.print(", " + byteOffsetConversionArgName(numBufferOffsetArgs)); - writer.print(", BufferFactory.getPositionByteOffset(getBuffer())"); + writer.print(", BufferFactory.getDirectBufferByteOffset(getBuffer())"); } for (int i = 0; i < binding.getNumArguments(); i++) { JavaType type = binding.getJavaArgumentType(i); @@ -217,14 +352,20 @@ public class JavaMethodBindingImplEmitter extends JavaMethodBindingEmitter if (type.isCompoundTypeWrapper()) { writer.print("(("); } - writer.print(binding.getArgumentName(i)); + + if(type.isNIOBuffer() && !type.isNIOBufferArray() && generateDirectAndIndirect && indirectCase) { + writer.print("BufferFactory.getArray(" + binding.getArgumentName(i) + ")"); + } else { + writer.print(binding.getArgumentName(i)); + } + if (type.isCompoundTypeWrapper()) { writer.print(" == null) ? null : "); writer.print(binding.getArgumentName(i)); writer.print(".getBuffer())"); numBufferOffsetArgs++; //writer.print(", " + byteOffsetConversionArgName(numBufferOffsetArgs)); - writer.print(", BufferFactory.getPositionByteOffset(((" + binding.getArgumentName(i)); + writer.print(", BufferFactory.getDirectBufferByteOffset(((" + binding.getArgumentName(i)); writer.print(" == null) ? null : " + binding.getArgumentName(i) + ".getBuffer()))"); } needComma = true; @@ -232,8 +373,18 @@ public class JavaMethodBindingImplEmitter extends JavaMethodBindingEmitter if(type.isNIOBuffer() || type.isNIOBufferArray()) { if(!type.isArray()) { numBufferOffsetArgs++; - writer.print - (", BufferFactory.getPositionByteOffset(" + binding.getArgumentName(i) + ")"); + if(generateDirectAndIndirect) { + if(!indirectCase) { + writer.print + (", BufferFactory.getDirectBufferByteOffset(" + binding.getArgumentName(i) + ")"); + } else { + writer.print + (", BufferFactory.getIndirectBufferByteOffset(" + binding.getArgumentName(i) + ")"); + } + } else { + writer.print + (", BufferFactory.getDirectBufferByteOffset(" + binding.getArgumentName(i) + ")"); + } } else { numBufferOffsetArrayArgs++; writer.print(", " + byteOffsetArrayConversionArgName(numBufferOffsetArrayArgs)); @@ -267,8 +418,12 @@ public class JavaMethodBindingImplEmitter extends JavaMethodBindingEmitter protected void emitCallResultReturn(MethodBinding binding, PrintWriter writer) { JavaType returnType = binding.getJavaReturnType(); + boolean indirect; + + indirect = isGenerateIndirectBufferInterface(); + if (returnType.isCompoundTypeWrapper()) { - writer.println(";"); + if(!indirect) writer.println(";"); String fmt = getReturnedArrayLengthExpression(); writer.println(" if (_res == null) return null;"); if (fmt == null) { @@ -304,20 +459,24 @@ public class JavaMethodBindingImplEmitter extends JavaMethodBindingEmitter writer.println(" }"); writer.print (" return _retarray"); } - } else if (returnType.isNIOBuffer()) { writer.println(";"); + } else if (returnType.isNIOBuffer()) { + if(!indirect) writer.println(";"); writer.println(" if (_res == null) return null;"); writer.print(" return _res.order(ByteOrder.nativeOrder())"); - } else if (returnType.isArrayOfCompoundTypeWrappers()) { writer.println(";"); + } else if (returnType.isArrayOfCompoundTypeWrappers()) { + if(!indirect) writer.println(";"); writer.println(" if (_res == null) return null;"); writer.println(" " + getReturnTypeString(false) + " _retarray = new " + getReturnTypeString(true) + "[_res.length];"); writer.println(" for (int _count = 0; _count < _res.length; _count++) {"); writer.println(" _retarray[_count] = new " + getReturnTypeString(true) + "(_res[_count]);"); writer.println(" }"); writer.print (" return _retarray"); + writer.println(";"); + } else { + if(!indirect) writer.println(";"); } - writer.println(";"); } } diff --git a/src/net/java/games/gluegen/opengl/CGLPAWrapperEmitter.java b/src/net/java/games/gluegen/opengl/CGLPAWrapperEmitter.java index 586641576..e233d7155 100644 --- a/src/net/java/games/gluegen/opengl/CGLPAWrapperEmitter.java +++ b/src/net/java/games/gluegen/opengl/CGLPAWrapperEmitter.java @@ -74,6 +74,8 @@ public class CGLPAWrapperEmitter extends CMethodBindingEmitter // if(binding.signatureUsesPrimitiveArrays()) // arrayImplRoutine = true; + indirectBufferInterface = methodToWrap.isIndirectBufferInterface(); + if (methodToWrap.getReturnValueCapacityExpression() != null) { setReturnValueCapacityExpression(methodToWrap.getReturnValueCapacityExpression()); } @@ -237,7 +239,9 @@ public class CGLPAWrapperEmitter extends CMethodBindingEmitter StringBuffer buf = new StringBuffer(); buf.append(jniMangle(binding.getName())); - if(binding.signatureUsesPrimitiveArrays()) + if( isIndirectBufferInterface() ) + buf.append("2"); + else if(binding.signatureUsesPrimitiveArrays()) buf.append("1"); buf.append("__"); diff --git a/src/net/java/games/gluegen/opengl/JavaGLPAWrapperEmitter.java b/src/net/java/games/gluegen/opengl/JavaGLPAWrapperEmitter.java index 951faf178..d0eafa8de 100644 --- a/src/net/java/games/gluegen/opengl/JavaGLPAWrapperEmitter.java +++ b/src/net/java/games/gluegen/opengl/JavaGLPAWrapperEmitter.java @@ -174,8 +174,8 @@ public class JavaGLPAWrapperEmitter extends JavaMethodBindingImplEmitter writer.println(" }"); } - protected int emitCallArguments(MethodBinding binding, PrintWriter writer) { - int numEmitted = super.emitCallArguments(binding, writer); + protected int emitCallArguments(MethodBinding binding, PrintWriter writer, boolean indirect) { + int numEmitted = super.emitCallArguments(binding, writer, indirect); if (numEmitted > 0) { writer.print(", "); } diff --git a/src/net/java/games/gluegen/runtime/BufferFactory.java b/src/net/java/games/gluegen/runtime/BufferFactory.java index 3e51aad9a..cae81b1b3 100644 --- a/src/net/java/games/gluegen/runtime/BufferFactory.java +++ b/src/net/java/games/gluegen/runtime/BufferFactory.java @@ -86,7 +86,7 @@ public class BufferFactory { account the Buffer position and the underlying type. This is the total offset for Direct Buffers. */ - public static int getPositionByteOffset(Buffer buf) { + public static int getDirectBufferByteOffset(Buffer buf) { if(buf == null) { return 0; } @@ -140,7 +140,7 @@ public class BufferFactory { object. The array offset also includes the position offset within the buffer, in addition to any array offset. */ - public static int getTotalByteOffset(Buffer buf) { + public static int getIndirectBufferByteOffset(Buffer buf) { if(buf == null) { return 0; } |