mirror of
https://github.com/shadowfacts/lwjgl2-arm64.git
synced 2026-04-08 07:54:05 +00:00
Added support for explicit length arguments in functions that map buffer objects.
Simplified CachedResult handling of functions that map buffer object ranges. Improved documentation of CachedResult functions.
This commit is contained in:
parent
f970b8ba42
commit
d97fc05a7b
13 changed files with 195 additions and 60 deletions
|
|
@ -71,6 +71,12 @@ class GLChecks {
|
|||
return scratch_buffer.get(0);
|
||||
}
|
||||
|
||||
static int getBufferObjectSizeATI(ContextCapabilities caps, int buffer) {
|
||||
IntBuffer scratch_buffer = caps.scratch_int_buffer;
|
||||
ATIVertexArrayObject.glGetObjectBufferATI(buffer, ATIVertexArrayObject.GL_OBJECT_BUFFER_SIZE_ATI, scratch_buffer);
|
||||
return scratch_buffer.get(0);
|
||||
}
|
||||
|
||||
static int getNamedBufferObjectSize(ContextCapabilities caps, int buffer) {
|
||||
IntBuffer scratch_buffer = caps.scratch_int_buffer;
|
||||
EXTDirectStateAccess.glGetNamedBufferParameterEXT(buffer, GL15.GL_BUFFER_SIZE, scratch_buffer);
|
||||
|
|
|
|||
|
|
@ -43,4 +43,5 @@ import java.lang.annotation.ElementType;
|
|||
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface CachedResult {
|
||||
boolean isRange() default false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,8 +91,12 @@ public class GeneratorVisitor extends SimpleDeclarationVisitor {
|
|||
}
|
||||
if (Utils.getResultParameter(method) != null && !method.getReturnType().equals(env.getTypeUtils().getVoidType()))
|
||||
throw new RuntimeException(method + " return type is not void but a parameter is annotated with Result");
|
||||
if (method.getAnnotation(CachedResult.class) != null && Utils.getNIOBufferType(Utils.getMethodReturnType(method)) == null)
|
||||
throw new RuntimeException(method + " return type is not a Buffer, but is annotated with CachedResult");
|
||||
if (method.getAnnotation(CachedResult.class) != null) {
|
||||
if (Utils.getNIOBufferType(Utils.getMethodReturnType(method)) == null)
|
||||
throw new RuntimeException(method + " return type is not a Buffer, but is annotated with CachedResult");
|
||||
if (method.getAnnotation(AutoResultSize.class) == null)
|
||||
throw new RuntimeException(method + " is annotated with CachedResult but misses an AutoResultSize annotation");
|
||||
}
|
||||
validateTypes(method, method.getAnnotationMirrors(), method.getReturnType());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -68,6 +68,9 @@ public class JavaMethodsGenerator {
|
|||
printMethodWithMultiType(env, type_map, writer, interface_decl, method, typeinfos_instance, Mode.NORMAL, generate_error_checks, context_specific);
|
||||
}
|
||||
}
|
||||
if ( method.getAnnotation(CachedResult.class) != null && !method.getAnnotation(CachedResult.class).isRange() ) {
|
||||
printMethodWithMultiType(env, type_map, writer, interface_decl, method, TypeInfo.getDefaultTypeInfoMap(method), Mode.CACHEDRESULT, generate_error_checks, context_specific);
|
||||
}
|
||||
printJavaNativeStub(writer, method, Mode.NORMAL, generate_error_checks, context_specific);
|
||||
if (Utils.hasMethodBufferObjectParameter(method)) {
|
||||
printMethodWithMultiType(env, type_map, writer, interface_decl, method, TypeInfo.getDefaultTypeInfoMap(method), Mode.BUFFEROBJECT, generate_error_checks, context_specific);
|
||||
|
|
@ -120,16 +123,23 @@ public class JavaMethodsGenerator {
|
|||
first_parameter = generateParameterJava(writer, param, type_info, native_stub, first_parameter, mode);
|
||||
}
|
||||
}
|
||||
CachedResult cached_result_annotation = method.getAnnotation(CachedResult.class);
|
||||
TypeMirror result_type = Utils.getMethodReturnType(method);
|
||||
if ((native_stub && Utils.getNIOBufferType(result_type) != null) || Utils.needResultSize(method)) {
|
||||
if (!first_parameter)
|
||||
writer.print(", ");
|
||||
first_parameter = false;
|
||||
writer.print("long " + Utils.RESULT_SIZE_NAME);
|
||||
if (cached_result_annotation == null || !cached_result_annotation.isRange()) {
|
||||
if (!first_parameter)
|
||||
writer.print(", ");
|
||||
first_parameter = false;
|
||||
writer.print("long " + Utils.RESULT_SIZE_NAME);
|
||||
}
|
||||
}
|
||||
if (method.getAnnotation(CachedResult.class) != null) {
|
||||
if (cached_result_annotation != null) {
|
||||
if (!first_parameter)
|
||||
writer.print(", ");
|
||||
|
||||
if ( mode == Mode.CACHEDRESULT )
|
||||
writer.print("long " + Utils.CACHED_BUFFER_LENGTH_NAME + ", ");
|
||||
|
||||
first_parameter = false;
|
||||
printResultType(writer, method, native_stub);
|
||||
writer.print(" " + Utils.CACHED_BUFFER_NAME);
|
||||
|
|
@ -403,16 +413,26 @@ public class JavaMethodsGenerator {
|
|||
first_parameter = printMethodCallArgument(writer, method, param, typeinfos_instance, mode, first_parameter);
|
||||
}
|
||||
if (Utils.getNIOBufferType(Utils.getMethodReturnType(method)) != null) {
|
||||
if (!first_parameter)
|
||||
writer.print(", ");
|
||||
first_parameter = false;
|
||||
AutoResultSize auto_result_size_annotation = method.getAnnotation(AutoResultSize.class);
|
||||
String result_size_expression;
|
||||
if (auto_result_size_annotation == null)
|
||||
result_size_expression = Utils.RESULT_SIZE_NAME;
|
||||
else
|
||||
result_size_expression = auto_result_size_annotation.value();
|
||||
Utils.printExtraCallArguments(writer, method, result_size_expression);
|
||||
if (method.getAnnotation(CachedResult.class) != null && method.getAnnotation(CachedResult.class).isRange()) {
|
||||
first_parameter = false;
|
||||
Utils.printExtraCallArguments(writer, method, "");
|
||||
} else {
|
||||
if (!first_parameter)
|
||||
writer.print(", ");
|
||||
first_parameter = false;
|
||||
|
||||
String result_size_expression;
|
||||
if ( mode == Mode.CACHEDRESULT )
|
||||
result_size_expression = Utils.CACHED_BUFFER_LENGTH_NAME;
|
||||
else {
|
||||
AutoResultSize auto_result_size_annotation = method.getAnnotation(AutoResultSize.class);
|
||||
if (auto_result_size_annotation == null)
|
||||
result_size_expression = Utils.RESULT_SIZE_NAME;
|
||||
else
|
||||
result_size_expression = auto_result_size_annotation.value();
|
||||
}
|
||||
Utils.printExtraCallArguments(writer, method, result_size_expression);
|
||||
}
|
||||
}
|
||||
return first_parameter;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,31 +1,31 @@
|
|||
/*
|
||||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
|
@ -34,5 +34,6 @@ package org.lwjgl.util.generator;
|
|||
public enum Mode {
|
||||
BUFFEROBJECT,
|
||||
AUTOS,
|
||||
CACHEDRESULT, // Used for generating a CachedResult method with an explicit length argument.
|
||||
NORMAL
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,8 +106,10 @@ public class NativeMethodStubsGenerator {
|
|||
writer.print("(JNIEnv *env, jclass clazz");
|
||||
generateParameters(writer, method.getParameters(), mode);
|
||||
if (Utils.getNIOBufferType(result_type) != null) {
|
||||
writer.print(", jlong " + Utils.RESULT_SIZE_NAME);
|
||||
if (method.getAnnotation(CachedResult.class) != null)
|
||||
CachedResult cached_result_annotation = method.getAnnotation(CachedResult.class);
|
||||
if (cached_result_annotation == null || !cached_result_annotation.isRange())
|
||||
writer.print(", jlong " + Utils.RESULT_SIZE_NAME);
|
||||
if (cached_result_annotation != null)
|
||||
writer.print(", jobject " + Utils.CACHED_BUFFER_NAME);
|
||||
}
|
||||
if (context_specific) {
|
||||
|
|
@ -160,7 +162,10 @@ public class NativeMethodStubsGenerator {
|
|||
writer.print(Utils.RESULT_VAR_NAME);
|
||||
if (Buffer.class.isAssignableFrom(java_result_type)) {
|
||||
writer.print(", ");
|
||||
Utils.printExtraCallArguments(writer, method, Utils.RESULT_SIZE_NAME);
|
||||
if (method.getAnnotation(CachedResult.class) != null && method.getAnnotation(CachedResult.class).isRange())
|
||||
Utils.printExtraCallArguments(writer, method, method.getAnnotation(AutoResultSize.class).value());
|
||||
else
|
||||
Utils.printExtraCallArguments(writer, method, Utils.RESULT_SIZE_NAME);
|
||||
}
|
||||
if (Buffer.class.isAssignableFrom(java_result_type) ||
|
||||
String.class.equals(java_result_type))
|
||||
|
|
|
|||
|
|
@ -58,13 +58,14 @@ public class Utils {
|
|||
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) {
|
||||
return method.getSimpleName() + TYPEDEF_POSTFIX;
|
||||
}
|
||||
|
||||
|
||||
public static String getFunctionAddressName(InterfaceDeclaration interface_decl, MethodDeclaration method) {
|
||||
return interface_decl.getSimpleName() + "_" + method.getSimpleName() + FUNCTION_POINTER_POSTFIX;
|
||||
}
|
||||
|
|
@ -201,7 +202,7 @@ public class Utils {
|
|||
public static boolean needResultSize(MethodDeclaration method) {
|
||||
return getNIOBufferType(getMethodReturnType(method)) != null && method.getAnnotation(AutoResultSize.class) == null;
|
||||
}
|
||||
|
||||
|
||||
public static void printExtraCallArguments(PrintWriter writer, MethodDeclaration method, String size_parameter_name) {
|
||||
writer.print(size_parameter_name);
|
||||
if (method.getAnnotation(CachedResult.class) != null) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue