mirror of
https://github.com/shadowfacts/lwjgl2-arm64.git
synced 2026-04-05 06:25:46 +00:00
Converted GL APIUtil to a per ContextCapabilities instance.
This commit is contained in:
parent
5d624b86bf
commit
a9a7067461
41 changed files with 186 additions and 167 deletions
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* Copyright (c) 2002-2011 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
@ -37,35 +37,33 @@ import org.lwjgl.MemoryUtil;
|
|||
|
||||
import java.nio.*;
|
||||
|
||||
/** @author spasi */
|
||||
/**
|
||||
* Utility class for OpenGL API calls. Instances of APIUtil are created in ContextCapabilities,
|
||||
* so we have an instance per OpenGL context.
|
||||
*
|
||||
* @author spasi
|
||||
*/
|
||||
final class APIUtil {
|
||||
|
||||
private static final int INITIAL_BUFFER_SIZE = 256;
|
||||
private static final int INITIAL_BUFFER_SIZE = 256;
|
||||
private static final int INITIAL_LENGTHS_SIZE = 4;
|
||||
|
||||
private static final int BUFFERS_SIZE = 32;
|
||||
|
||||
private static final ThreadLocal<char[]> arrayTL = new ThreadLocal<char[]>() {
|
||||
protected char[] initialValue() { return new char[INITIAL_BUFFER_SIZE]; }
|
||||
};
|
||||
private char[] arrayTL;
|
||||
private ByteBuffer bufferTL;
|
||||
private IntBuffer lengthsTL;
|
||||
private final Buffers buffersTL;
|
||||
|
||||
private static final ThreadLocal<ByteBuffer> bufferTL = new ThreadLocal<ByteBuffer>() {
|
||||
protected ByteBuffer initialValue() { return BufferUtils.createByteBuffer(INITIAL_BUFFER_SIZE); }
|
||||
};
|
||||
|
||||
private static final ThreadLocal<IntBuffer> lengthsTL = new ThreadLocal<IntBuffer>() {
|
||||
protected IntBuffer initialValue() { return BufferUtils.createIntBuffer(INITIAL_LENGTHS_SIZE); }
|
||||
};
|
||||
|
||||
private static final ThreadLocal<Buffers> buffersTL = new ThreadLocal<Buffers>() {
|
||||
protected Buffers initialValue() { return new Buffers(); }
|
||||
};
|
||||
|
||||
private APIUtil() {
|
||||
APIUtil() {
|
||||
arrayTL = new char[INITIAL_BUFFER_SIZE];
|
||||
bufferTL = BufferUtils.createByteBuffer(INITIAL_BUFFER_SIZE);
|
||||
lengthsTL = BufferUtils.createIntBuffer(INITIAL_LENGTHS_SIZE);
|
||||
buffersTL = new Buffers();
|
||||
}
|
||||
|
||||
private static char[] getArray(final int size) {
|
||||
char[] array = arrayTL.get();
|
||||
private static char[] getArray(final ContextCapabilities caps, final int size) {
|
||||
char[] array = caps.util.arrayTL;
|
||||
|
||||
if ( array.length < size ) {
|
||||
int sizeNew = array.length << 1;
|
||||
|
|
@ -73,14 +71,14 @@ final class APIUtil {
|
|||
sizeNew <<= 1;
|
||||
|
||||
array = new char[size];
|
||||
arrayTL.set(array);
|
||||
caps.util.arrayTL = array;
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
static ByteBuffer getBufferByte(final int size) {
|
||||
ByteBuffer buffer = bufferTL.get();
|
||||
static ByteBuffer getBufferByte(final ContextCapabilities caps, final int size) {
|
||||
ByteBuffer buffer = caps.util.bufferTL;
|
||||
|
||||
if ( buffer.capacity() < size ) {
|
||||
int sizeNew = buffer.capacity() << 1;
|
||||
|
|
@ -88,15 +86,15 @@ final class APIUtil {
|
|||
sizeNew <<= 1;
|
||||
|
||||
buffer = BufferUtils.createByteBuffer(size);
|
||||
bufferTL.set(buffer);
|
||||
caps.util.bufferTL = buffer;
|
||||
} else
|
||||
buffer.clear();
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
private static ByteBuffer getBufferByteOffset(final int size) {
|
||||
ByteBuffer buffer = bufferTL.get();
|
||||
private static ByteBuffer getBufferByteOffset(final ContextCapabilities caps, final int size) {
|
||||
ByteBuffer buffer = caps.util.bufferTL;
|
||||
|
||||
if ( buffer.capacity() < size ) {
|
||||
int sizeNew = buffer.capacity() << 1;
|
||||
|
|
@ -105,7 +103,7 @@ final class APIUtil {
|
|||
|
||||
final ByteBuffer bufferNew = BufferUtils.createByteBuffer(size);
|
||||
bufferNew.put(buffer);
|
||||
bufferTL.set(buffer = bufferNew);
|
||||
caps.util.bufferTL = (buffer = bufferNew);
|
||||
} else {
|
||||
buffer.position(buffer.limit());
|
||||
buffer.limit(buffer.capacity());
|
||||
|
|
@ -114,22 +112,22 @@ final class APIUtil {
|
|||
return buffer;
|
||||
}
|
||||
|
||||
static ShortBuffer getBufferShort() { return buffersTL.get().shorts; }
|
||||
static ShortBuffer getBufferShort(final ContextCapabilities caps) { return caps.util.buffersTL.shorts; }
|
||||
|
||||
static IntBuffer getBufferInt() { return buffersTL.get().ints; }
|
||||
static IntBuffer getBufferInt(final ContextCapabilities caps) { return caps.util.buffersTL.ints; }
|
||||
|
||||
static LongBuffer getBufferLong() { return buffersTL.get().longs; }
|
||||
static LongBuffer getBufferLong(final ContextCapabilities caps) { return caps.util.buffersTL.longs; }
|
||||
|
||||
static FloatBuffer getBufferFloat() { return buffersTL.get().floats; }
|
||||
static FloatBuffer getBufferFloat(final ContextCapabilities caps) { return caps.util.buffersTL.floats; }
|
||||
|
||||
static DoubleBuffer getBufferDouble() { return buffersTL.get().doubles; }
|
||||
static DoubleBuffer getBufferDouble(final ContextCapabilities caps) { return caps.util.buffersTL.doubles; }
|
||||
|
||||
static IntBuffer getLengths() {
|
||||
return getLengths(1);
|
||||
static IntBuffer getLengths(final ContextCapabilities caps) {
|
||||
return getLengths(caps, 1);
|
||||
}
|
||||
|
||||
static IntBuffer getLengths(final int size) {
|
||||
IntBuffer lengths = lengthsTL.get();
|
||||
static IntBuffer getLengths(final ContextCapabilities caps, final int size) {
|
||||
IntBuffer lengths = caps.util.lengthsTL;
|
||||
|
||||
if ( lengths.capacity() < size ) {
|
||||
int sizeNew = lengths.capacity();
|
||||
|
|
@ -137,7 +135,7 @@ final class APIUtil {
|
|||
sizeNew <<= 1;
|
||||
|
||||
lengths = BufferUtils.createIntBuffer(size);
|
||||
lengthsTL.set(lengths);
|
||||
caps.util.lengthsTL = lengths;
|
||||
} else
|
||||
lengths.clear();
|
||||
|
||||
|
|
@ -169,9 +167,9 @@ final class APIUtil {
|
|||
*
|
||||
* @return the buffer as a String.
|
||||
*/
|
||||
static String getString(final ByteBuffer buffer) {
|
||||
static String getString(final ContextCapabilities caps, final ByteBuffer buffer) {
|
||||
final int length = buffer.remaining();
|
||||
final char[] charArray = getArray(length);
|
||||
final char[] charArray = getArray(caps, length);
|
||||
|
||||
for ( int i = buffer.position(); i < buffer.limit(); i++ )
|
||||
charArray[i - buffer.position()] = (char)buffer.get(i);
|
||||
|
|
@ -186,8 +184,8 @@ final class APIUtil {
|
|||
*
|
||||
* @return the String as a ByteBuffer
|
||||
*/
|
||||
static long getBuffer(final CharSequence string) {
|
||||
final ByteBuffer buffer = encode(getBufferByte(string.length()), string);
|
||||
static long getBuffer(final ContextCapabilities caps, final CharSequence string) {
|
||||
final ByteBuffer buffer = encode(getBufferByte(caps, string.length()), string);
|
||||
buffer.flip();
|
||||
return MemoryUtil.getAddress0(buffer);
|
||||
}
|
||||
|
|
@ -199,8 +197,8 @@ final class APIUtil {
|
|||
*
|
||||
* @return the String as a ByteBuffer
|
||||
*/
|
||||
static long getBuffer(final CharSequence string, final int offset) {
|
||||
final ByteBuffer buffer = encode(getBufferByteOffset(offset + string.length()), string);
|
||||
static long getBuffer(final ContextCapabilities caps, final CharSequence string, final int offset) {
|
||||
final ByteBuffer buffer = encode(getBufferByteOffset(caps, offset + string.length()), string);
|
||||
buffer.flip();
|
||||
return MemoryUtil.getAddress(buffer);
|
||||
}
|
||||
|
|
@ -212,8 +210,8 @@ final class APIUtil {
|
|||
*
|
||||
* @return the String as a ByteBuffer
|
||||
*/
|
||||
static long getBufferNT(final CharSequence string) {
|
||||
final ByteBuffer buffer = encode(getBufferByte(string.length() + 1), string);
|
||||
static long getBufferNT(final ContextCapabilities caps, final CharSequence string) {
|
||||
final ByteBuffer buffer = encode(getBufferByte(caps, string.length() + 1), string);
|
||||
buffer.put((byte)0);
|
||||
buffer.flip();
|
||||
return MemoryUtil.getAddress0(buffer);
|
||||
|
|
@ -234,8 +232,8 @@ final class APIUtil {
|
|||
*
|
||||
* @return the Strings as a ByteBuffer
|
||||
*/
|
||||
static long getBuffer(final CharSequence[] strings) {
|
||||
final ByteBuffer buffer = getBufferByte(getTotalLength(strings));
|
||||
static long getBuffer(final ContextCapabilities caps, final CharSequence[] strings) {
|
||||
final ByteBuffer buffer = getBufferByte(caps, getTotalLength(strings));
|
||||
|
||||
for ( CharSequence string : strings )
|
||||
encode(buffer, string);
|
||||
|
|
@ -251,8 +249,8 @@ final class APIUtil {
|
|||
*
|
||||
* @return the Strings as a ByteBuffer
|
||||
*/
|
||||
static long getBufferNT(final CharSequence[] strings) {
|
||||
final ByteBuffer buffer = getBufferByte(getTotalLength(strings) + strings.length);
|
||||
static long getBufferNT(final ContextCapabilities caps, final CharSequence[] strings) {
|
||||
final ByteBuffer buffer = getBufferByte(caps, getTotalLength(strings) + strings.length);
|
||||
|
||||
for ( CharSequence string : strings ) {
|
||||
encode(buffer, string);
|
||||
|
|
@ -270,8 +268,8 @@ final class APIUtil {
|
|||
*
|
||||
* @return the String lengths in an IntBuffer
|
||||
*/
|
||||
static long getLengths(final CharSequence[] strings) {
|
||||
IntBuffer buffer = getLengths(strings.length);
|
||||
static long getLengths(final ContextCapabilities caps, final CharSequence[] strings) {
|
||||
IntBuffer buffer = getLengths(caps, strings.length);
|
||||
|
||||
for ( CharSequence string : strings )
|
||||
buffer.put(string.length());
|
||||
|
|
@ -280,21 +278,21 @@ final class APIUtil {
|
|||
return MemoryUtil.getAddress0(buffer);
|
||||
}
|
||||
|
||||
static long getInt(final int value) {
|
||||
return MemoryUtil.getAddress0(getBufferInt().put(0, value));
|
||||
static long getInt(final ContextCapabilities caps, final int value) {
|
||||
return MemoryUtil.getAddress0(getBufferInt(caps).put(0, value));
|
||||
}
|
||||
|
||||
static long getBufferByte0() {
|
||||
return MemoryUtil.getAddress0(getBufferByte(0));
|
||||
static long getBufferByte0(final ContextCapabilities caps) {
|
||||
return MemoryUtil.getAddress0(getBufferByte(caps, 0));
|
||||
}
|
||||
|
||||
private static class Buffers {
|
||||
|
||||
final ShortBuffer shorts;
|
||||
final IntBuffer ints;
|
||||
final LongBuffer longs;
|
||||
final IntBuffer ints;
|
||||
final LongBuffer longs;
|
||||
|
||||
final FloatBuffer floats;
|
||||
final FloatBuffer floats;
|
||||
final DoubleBuffer doubles;
|
||||
|
||||
Buffers() {
|
||||
|
|
|
|||
|
|
@ -301,13 +301,13 @@ public class JavaMethodsGenerator {
|
|||
}
|
||||
} else if ( method.getAnnotation(GLreturn.class) != null ) {
|
||||
has_result = true;
|
||||
Utils.printGLReturnPre(writer, method, method.getAnnotation(GLreturn.class));
|
||||
Utils.printGLReturnPre(writer, method, method.getAnnotation(GLreturn.class), type_map);
|
||||
}
|
||||
writer.print(Utils.getSimpleNativeMethodName(method, generate_error_checks, context_specific));
|
||||
if (mode == Mode.BUFFEROBJECT)
|
||||
writer.print(Utils.BUFFER_OBJECT_METHOD_POSTFIX);
|
||||
writer.print("(");
|
||||
boolean first_parameter = printMethodCallArguments(writer, method, typeinfos_instance, mode);
|
||||
boolean first_parameter = printMethodCallArguments(writer, method, typeinfos_instance, mode, type_map);
|
||||
if (context_specific) {
|
||||
if (!first_parameter)
|
||||
writer.print(", ");
|
||||
|
|
@ -335,7 +335,7 @@ public class JavaMethodsGenerator {
|
|||
else
|
||||
writer.println(tabs + "return " + Utils.RESULT_VAR_NAME + ";");
|
||||
} else
|
||||
Utils.printGLReturnPost(writer, method, method.getAnnotation(GLreturn.class));
|
||||
Utils.printGLReturnPost(writer, method, method.getAnnotation(GLreturn.class), type_map);
|
||||
}
|
||||
|
||||
if ( code_annotation != null && code_annotation.tryBlock() ) {
|
||||
|
|
@ -439,7 +439,7 @@ public class JavaMethodsGenerator {
|
|||
throw new RuntimeException(c + " is not allowed");
|
||||
}
|
||||
|
||||
private static boolean printMethodCallArgument(PrintWriter writer, MethodDeclaration method, ParameterDeclaration param, Map<ParameterDeclaration, TypeInfo> typeinfos_instance, Mode mode, boolean first_parameter) {
|
||||
private static boolean printMethodCallArgument(PrintWriter writer, MethodDeclaration method, ParameterDeclaration param, Map<ParameterDeclaration, TypeInfo> typeinfos_instance, Mode mode, boolean first_parameter, TypeMap type_map) {
|
||||
if (!first_parameter)
|
||||
writer.print(", ");
|
||||
|
||||
|
|
@ -496,7 +496,9 @@ public class JavaMethodsGenerator {
|
|||
writer.print("APIUtil.getBuffer");
|
||||
if ( param.getAnnotation(NullTerminated.class) != null )
|
||||
writer.print("NT");
|
||||
writer.print("(" + param.getSimpleName());
|
||||
writer.print('(');
|
||||
writer.print(type_map.getAPIUtilParam(true));
|
||||
writer.print(param.getSimpleName());
|
||||
if ( offset != null )
|
||||
writer.print(", " + offset);
|
||||
writer.print(")");
|
||||
|
|
@ -531,7 +533,7 @@ public class JavaMethodsGenerator {
|
|||
return false;
|
||||
}
|
||||
|
||||
private static boolean printMethodCallArguments(PrintWriter writer, MethodDeclaration method, Map<ParameterDeclaration, TypeInfo> typeinfos_instance, Mode mode) {
|
||||
private static boolean printMethodCallArguments(PrintWriter writer, MethodDeclaration method, Map<ParameterDeclaration, TypeInfo> typeinfos_instance, Mode mode, TypeMap type_map) {
|
||||
boolean first_parameter = true;
|
||||
for ( ParameterDeclaration param : method.getParameters() ) {
|
||||
if ( param.getAnnotation(Result.class) != null || (param.getAnnotation(Helper.class) != null && !param.getAnnotation(Helper.class).passToNative()) )
|
||||
|
|
@ -539,7 +541,7 @@ public class JavaMethodsGenerator {
|
|||
|
||||
final Constant constant_annotation = param.getAnnotation(Constant.class);
|
||||
if ( constant_annotation== null || !constant_annotation.isNative() )
|
||||
first_parameter = printMethodCallArgument(writer, method, param, typeinfos_instance, mode, first_parameter);
|
||||
first_parameter = printMethodCallArgument(writer, method, param, typeinfos_instance, mode, first_parameter, type_map);
|
||||
}
|
||||
if (Utils.getNIOBufferType(Utils.getMethodReturnType(method)) != null) {
|
||||
if (method.getAnnotation(CachedResult.class) != null && method.getAnnotation(CachedResult.class).isRange()) {
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ import java.lang.annotation.Annotation;
|
|||
public interface TypeMap {
|
||||
void printCapabilitiesInit(PrintWriter writer);
|
||||
String getCapabilities();
|
||||
String getAPIUtilParam(boolean comma);
|
||||
void printErrorCheckMethod(PrintWriter writer, MethodDeclaration method, String tabs);
|
||||
String getRegisterNativesFunctionName();
|
||||
PrimitiveType.Kind getPrimitiveTypeFromNativeType(Class<? extends Annotation> native_type);
|
||||
|
|
|
|||
|
|
@ -57,19 +57,19 @@ import com.sun.mirror.type.TypeMirror;
|
|||
|
||||
public class Utils {
|
||||
|
||||
public static final String TYPEDEF_POSTFIX = "PROC";
|
||||
public static final String FUNCTION_POINTER_VAR_NAME = "function_pointer";
|
||||
public static final String FUNCTION_POINTER_POSTFIX = "_pointer";
|
||||
public static final String CHECKS_CLASS_NAME = "GLChecks";
|
||||
public static final String CONTEXT_CAPS_CLASS_NAME = "ContextCapabilities";
|
||||
public static final String STUB_INITIALIZER_NAME = "initNativeStubs";
|
||||
public static final String BUFFER_OBJECT_METHOD_POSTFIX = "BO";
|
||||
public static final String BUFFER_OBJECT_PARAMETER_POSTFIX = "_buffer_offset";
|
||||
public static final String RESULT_SIZE_NAME = "result_size";
|
||||
public static final String RESULT_VAR_NAME = "__result";
|
||||
public static final String CACHED_BUFFER_LENGTH_NAME = "length";
|
||||
public static final String CACHED_BUFFER_NAME = "old_buffer";
|
||||
private static final String OVERLOADED_METHOD_PREFIX = "n";
|
||||
public static final String TYPEDEF_POSTFIX = "PROC";
|
||||
public static final String FUNCTION_POINTER_VAR_NAME = "function_pointer";
|
||||
public static final String FUNCTION_POINTER_POSTFIX = "_pointer";
|
||||
public static final String CHECKS_CLASS_NAME = "GLChecks";
|
||||
public static final String CONTEXT_CAPS_CLASS_NAME = "ContextCapabilities";
|
||||
public static final String STUB_INITIALIZER_NAME = "initNativeStubs";
|
||||
public static final String BUFFER_OBJECT_METHOD_POSTFIX = "BO";
|
||||
public static final String BUFFER_OBJECT_PARAMETER_POSTFIX = "_buffer_offset";
|
||||
public static final String RESULT_SIZE_NAME = "result_size";
|
||||
public static final String RESULT_VAR_NAME = "__result";
|
||||
public static final String CACHED_BUFFER_LENGTH_NAME = "length";
|
||||
public static final String CACHED_BUFFER_NAME = "old_buffer";
|
||||
private static final String OVERLOADED_METHOD_PREFIX = "n";
|
||||
|
||||
public static String getTypedefName(MethodDeclaration method) {
|
||||
Alternate alt_annotation = method.getAnnotation(Alternate.class);
|
||||
|
|
@ -102,6 +102,7 @@ public class Utils {
|
|||
}
|
||||
|
||||
private static class AnnotationMirrorComparator implements Comparator<AnnotationMirror> {
|
||||
|
||||
public int compare(AnnotationMirror a1, AnnotationMirror a2) {
|
||||
String n1 = a1.getAnnotationType().getDeclaration().getQualifiedName();
|
||||
String n2 = a2.getAnnotationType().getDeclaration().getQualifiedName();
|
||||
|
|
@ -148,22 +149,22 @@ public class Utils {
|
|||
|
||||
private static boolean hasParameterMultipleTypes(ParameterDeclaration param) {
|
||||
int num_native_annotations = 0;
|
||||
for (AnnotationMirror annotation : param.getAnnotationMirrors())
|
||||
if (NativeTypeTranslator.getAnnotation(annotation, NativeType.class) != null)
|
||||
for ( AnnotationMirror annotation : param.getAnnotationMirrors() )
|
||||
if ( NativeTypeTranslator.getAnnotation(annotation, NativeType.class) != null )
|
||||
num_native_annotations++;
|
||||
return num_native_annotations > 1;
|
||||
}
|
||||
|
||||
public static boolean isParameterMultiTyped(ParameterDeclaration param) {
|
||||
boolean result = Buffer.class.equals(Utils.getJavaType(param.getType()));
|
||||
if (!result && hasParameterMultipleTypes(param))
|
||||
if ( !result && hasParameterMultipleTypes(param) )
|
||||
throw new RuntimeException(param + " not defined as java.nio.Buffer but has multiple types");
|
||||
return result;
|
||||
}
|
||||
|
||||
public static ParameterDeclaration findParameter(MethodDeclaration method, String name) {
|
||||
for (ParameterDeclaration param : method.getParameters())
|
||||
if (param.getSimpleName().equals(name))
|
||||
for ( ParameterDeclaration param : method.getParameters() )
|
||||
if ( param.getSimpleName().equals(name) )
|
||||
return param;
|
||||
throw new RuntimeException("Parameter " + name + " not found");
|
||||
}
|
||||
|
|
@ -176,7 +177,7 @@ public class Utils {
|
|||
overloadsComment = null;
|
||||
|
||||
String doc_comment = decl.getDocComment();
|
||||
if (doc_comment != null) {
|
||||
if ( doc_comment != null ) {
|
||||
final String tab = decl instanceof InterfaceDeclaration ? "" : "\t";
|
||||
writer.println(tab + "/**");
|
||||
|
||||
|
|
@ -187,7 +188,7 @@ public class Utils {
|
|||
|
||||
final StringTokenizer doc_lines = new StringTokenizer(doc_comment, "\n", true);
|
||||
boolean lastWasNL = false;
|
||||
while (doc_lines.hasMoreTokens()) {
|
||||
while ( doc_lines.hasMoreTokens() ) {
|
||||
final String t = doc_lines.nextToken();
|
||||
if ( "\n".equals(t) ) {
|
||||
if ( lastWasNL )
|
||||
|
|
@ -205,8 +206,8 @@ public class Utils {
|
|||
}
|
||||
|
||||
public static AnnotationMirror getParameterAutoAnnotation(ParameterDeclaration param) {
|
||||
for (AnnotationMirror annotation : param.getAnnotationMirrors())
|
||||
if (NativeTypeTranslator.getAnnotation(annotation, Auto.class) != null)
|
||||
for ( AnnotationMirror annotation : param.getAnnotationMirrors() )
|
||||
if ( NativeTypeTranslator.getAnnotation(annotation, Auto.class) != null )
|
||||
return annotation;
|
||||
return null;
|
||||
}
|
||||
|
|
@ -242,9 +243,9 @@ public class Utils {
|
|||
|
||||
public static ParameterDeclaration getResultParameter(MethodDeclaration method) {
|
||||
ParameterDeclaration result_param = null;
|
||||
for (ParameterDeclaration param : method.getParameters()) {
|
||||
if (param.getAnnotation(Result.class) != null) {
|
||||
if (result_param != null)
|
||||
for ( ParameterDeclaration param : method.getParameters() ) {
|
||||
if ( param.getAnnotation(Result.class) != null ) {
|
||||
if ( result_param != null )
|
||||
throw new RuntimeException("Multiple parameters annotated with Result in method " + method);
|
||||
result_param = param;
|
||||
}
|
||||
|
|
@ -255,7 +256,7 @@ public class Utils {
|
|||
public static TypeMirror getMethodReturnType(MethodDeclaration method) {
|
||||
TypeMirror result_type;
|
||||
ParameterDeclaration result_param = getResultParameter(method);
|
||||
if (result_param != null) {
|
||||
if ( result_param != null ) {
|
||||
result_type = result_param.getType();
|
||||
} else
|
||||
result_type = method.getReturnType();
|
||||
|
|
@ -291,20 +292,20 @@ public class Utils {
|
|||
|
||||
public static void printExtraCallArguments(PrintWriter writer, MethodDeclaration method, String size_parameter_name) {
|
||||
writer.print(size_parameter_name);
|
||||
if (method.getAnnotation(CachedResult.class) != null) {
|
||||
if ( method.getAnnotation(CachedResult.class) != null ) {
|
||||
writer.print(", " + CACHED_BUFFER_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
private static String getClassName(InterfaceDeclaration interface_decl, String opengl_name) {
|
||||
Extension extension_annotation = interface_decl.getAnnotation(Extension.class);
|
||||
if (extension_annotation != null && !"".equals(extension_annotation.className())) {
|
||||
if ( extension_annotation != null && !"".equals(extension_annotation.className()) ) {
|
||||
return extension_annotation.className();
|
||||
}
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (int i = 0; i < opengl_name.length(); i++) {
|
||||
for ( int i = 0; i < opengl_name.length(); i++ ) {
|
||||
int ch = opengl_name.codePointAt(i);
|
||||
if (ch == '_') {
|
||||
if ( ch == '_' ) {
|
||||
i++;
|
||||
result.appendCodePoint(Character.toUpperCase(opengl_name.codePointAt(i)));
|
||||
} else
|
||||
|
|
@ -314,8 +315,8 @@ public class Utils {
|
|||
}
|
||||
|
||||
public static boolean hasMethodBufferObjectParameter(MethodDeclaration method) {
|
||||
for (ParameterDeclaration param : method.getParameters()) {
|
||||
if (param.getAnnotation(BufferObject.class) != null) {
|
||||
for ( ParameterDeclaration param : method.getParameters() ) {
|
||||
if ( param.getAnnotation(BufferObject.class) != null ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -332,7 +333,7 @@ public class Utils {
|
|||
|
||||
public static Class<?> getNIOBufferType(TypeMirror t) {
|
||||
Class<?> param_type = getJavaType(t);
|
||||
if (Buffer.class.isAssignableFrom(param_type))
|
||||
if ( Buffer.class.isAssignableFrom(param_type) )
|
||||
return param_type;
|
||||
else if ( param_type == CharSequence.class || param_type == CharSequence[].class || param_type == PointerBuffer.class )
|
||||
return ByteBuffer.class;
|
||||
|
|
@ -344,7 +345,7 @@ public class Utils {
|
|||
String method_name;
|
||||
Alternate alt_annotation = method.getAnnotation(Alternate.class);
|
||||
method_name = alt_annotation == null || alt_annotation.nativeAlt() ? method.getSimpleName() : alt_annotation.value();
|
||||
if (isMethodIndirect(generate_error_checks, context_specific, method))
|
||||
if ( isMethodIndirect(generate_error_checks, context_specific, method) )
|
||||
method_name = OVERLOADED_METHOD_PREFIX + method_name;
|
||||
return method_name;
|
||||
}
|
||||
|
|
@ -392,15 +393,15 @@ public class Utils {
|
|||
return offset;
|
||||
}
|
||||
|
||||
static void printGLReturnPre(PrintWriter writer, MethodDeclaration method, GLreturn return_annotation) {
|
||||
static void printGLReturnPre(PrintWriter writer, MethodDeclaration method, GLreturn return_annotation, TypeMap type_map) {
|
||||
final String return_type = getMethodReturnType(method, return_annotation, true);
|
||||
|
||||
if ( "String".equals(return_type) ) {
|
||||
if ( !return_annotation.forceMaxLength() ) {
|
||||
writer.println("IntBuffer " + return_annotation.value() + "_length = APIUtil.getLengths();");
|
||||
writer.println("IntBuffer " + return_annotation.value() + "_length = APIUtil.getLengths(" + type_map.getAPIUtilParam(false) + ");");
|
||||
writer.print("\t\t");
|
||||
}
|
||||
writer.print("ByteBuffer " + return_annotation.value() + " = APIUtil.getBufferByte(" + return_annotation.maxLength());
|
||||
writer.print("ByteBuffer " + return_annotation.value() + " = APIUtil.getBufferByte(" + type_map.getAPIUtilParam(true) + return_annotation.maxLength());
|
||||
/*
|
||||
Params that use the return buffer will advance its position while filling it. When we return, the position will be
|
||||
at the right spot for grabbing the returned string bytes. We only have to make sure that the original buffer was
|
||||
|
|
@ -412,9 +413,9 @@ public class Utils {
|
|||
writer.println(");");
|
||||
} else {
|
||||
final String buffer_type = "Boolean".equals(return_type) ? "Byte" : return_type;
|
||||
writer.print(buffer_type + "Buffer " + return_annotation.value() + " = APIUtil.getBuffer" + buffer_type + "(");
|
||||
writer.print(buffer_type + "Buffer " + return_annotation.value() + " = APIUtil.getBuffer" + buffer_type + "(" + type_map.getAPIUtilParam(false));
|
||||
if ( "Byte".equals(buffer_type) )
|
||||
writer.print('1');
|
||||
writer.print((type_map.getAPIUtilParam(false).length() > 0 ? ", " : "") + "1");
|
||||
writer.println(");");
|
||||
}
|
||||
|
||||
|
|
@ -426,20 +427,20 @@ public class Utils {
|
|||
writer.print("\t\t");
|
||||
}
|
||||
|
||||
static void printGLReturnPost(PrintWriter writer, MethodDeclaration method, GLreturn return_annotation) {
|
||||
static void printGLReturnPost(PrintWriter writer, MethodDeclaration method, GLreturn return_annotation, TypeMap type_map) {
|
||||
final String return_type = getMethodReturnType(method, return_annotation, true);
|
||||
|
||||
if ( "String".equals(return_type) ) {
|
||||
writer.print("\t\t" + return_annotation.value() + ".limit(");
|
||||
final String offset = getStringOffset(method, null);
|
||||
if ( offset != null)
|
||||
if ( offset != null )
|
||||
writer.print(offset + " + ");
|
||||
if ( return_annotation.forceMaxLength() )
|
||||
writer.print(return_annotation.maxLength());
|
||||
else
|
||||
writer.print(return_annotation.value() + "_length.get(0)");
|
||||
writer.println(");");
|
||||
writer.println("\t\treturn APIUtil.getString(" + return_annotation.value() + ");");
|
||||
writer.println("\t\treturn APIUtil.getString(" + type_map.getAPIUtilParam(true) + return_annotation.value() + ");");
|
||||
} else {
|
||||
writer.print("\t\treturn " + return_annotation.value() + ".get(0)");
|
||||
if ( "Boolean".equals(return_type) )
|
||||
|
|
|
|||
|
|
@ -178,6 +178,10 @@ public class ALTypeMap implements TypeMap {
|
|||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public String getAPIUtilParam(boolean comma) {
|
||||
return "";
|
||||
}
|
||||
|
||||
public void printErrorCheckMethod(final PrintWriter writer, final MethodDeclaration method, final String tabs) {
|
||||
writer.println(tabs + "Util.checkALError();");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,6 +89,10 @@ public class CLTypeMap implements TypeMap {
|
|||
return "CLCapabilities";
|
||||
}
|
||||
|
||||
public String getAPIUtilParam(boolean comma) {
|
||||
return "";
|
||||
}
|
||||
|
||||
public void printErrorCheckMethod(final PrintWriter writer, final MethodDeclaration method, final String tabs) {
|
||||
final Check check = method.getAnnotation(Check.class);
|
||||
if ( check != null ) // Get the error code from an IntBuffer output parameter
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ public class GLCapabilitiesGenerator {
|
|||
public static void generateClassPrologue(PrintWriter writer, boolean context_specific, boolean generate_error_checks) {
|
||||
writer.println("public class " + Utils.CONTEXT_CAPS_CLASS_NAME + " {");
|
||||
writer.println("\tstatic final boolean DEBUG = " + Boolean.toString(generate_error_checks) + ";");
|
||||
writer.println("\tfinal APIUtil util = new APIUtil();");
|
||||
writer.println("\tfinal StateTracker tracker = new StateTracker();");
|
||||
writer.println();
|
||||
if ( !context_specific ) {
|
||||
|
|
|
|||
|
|
@ -97,6 +97,10 @@ public class GLESTypeMap implements TypeMap {
|
|||
return "caps";
|
||||
}
|
||||
|
||||
public String getAPIUtilParam(boolean comma) {
|
||||
return "";
|
||||
}
|
||||
|
||||
public void printErrorCheckMethod(final PrintWriter writer, final MethodDeclaration method, final String tabs) {
|
||||
writer.println(tabs + "Util.checkGLError();");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,6 +106,10 @@ public class GLTypeMap implements TypeMap {
|
|||
return "caps";
|
||||
}
|
||||
|
||||
public String getAPIUtilParam(boolean comma) {
|
||||
return comma ? "caps, " : "caps";
|
||||
}
|
||||
|
||||
public void printErrorCheckMethod(final PrintWriter writer, final MethodDeclaration method, final String tabs) {
|
||||
writer.println(tabs + "Util.checkGLError();");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue