aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/games/gluegen/CMethodBindingEmitter.java
diff options
context:
space:
mode:
authorTravis Bryson <[email protected]>2005-06-24 20:28:37 +0000
committerTravis Bryson <[email protected]>2005-06-24 20:28:37 +0000
commit0969a98f2007d76e38f8819eedfead5b840f6364 (patch)
tree82aff6a7fb922f45fc7853e5c5442af0d978768f /src/net/java/games/gluegen/CMethodBindingEmitter.java
parented85f53f73d69a44c6b98b3824354be3fbb7bf58 (diff)
This putback adds array offsets to the public JOGL API. The offsets are
respected and used properly in all of the public and private functions. The changes are in gluegen, so that the code is generated properly. And also throughout the parts of the jogl code that are not gluegen-generated. For the internally generated implementation methods, a "1" is added to the method names. So as to not overload the public API. This is similar to what is already done with Buffer APIs, which have a "0" added internally. I used a "1" instead of a "0" to avoid any collisions of the signatures, which could happen if a null object was sent down for the Array (e.g., the wrong method would get called). This should be a suitable foundation for the implementation to add the ability to wrap arrays in Buffers, which we plan to add to the implementation soon. These changes will cause all existing JOGL programs to break, although adapting them is pretty easy. We will later be putting back changed examples and utilities that incorporate these new APIs. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JSR-231@313 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/net/java/games/gluegen/CMethodBindingEmitter.java')
-rw-r--r--src/net/java/games/gluegen/CMethodBindingEmitter.java45
1 files changed, 38 insertions, 7 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());