Beispiel #1
0
 private static Class[] getValidPrimitiveTypes(Class type) {
   if (type.equals(long.class))
     return new Class[] {
       GLintptrARB.class,
       GLuint.class,
       GLintptr.class,
       GLsizeiptrARB.class,
       GLsizeiptr.class,
       GLint64EXT.class,
       GLuint64EXT.class
     };
   else if (type.equals(int.class))
     return new Class[] {
       GLbitfield.class, GLenum.class, GLhandleARB.class, GLint.class, GLuint.class, GLsizei.class
     };
   else if (type.equals(double.class)) return new Class[] {GLclampd.class, GLdouble.class};
   else if (type.equals(float.class)) return new Class[] {GLclampf.class, GLfloat.class};
   else if (type.equals(short.class))
     return new Class[] {GLhalf.class, GLshort.class, GLushort.class};
   else if (type.equals(byte.class))
     return new Class[] {GLbyte.class, GLcharARB.class, GLchar.class, GLubyte.class};
   else if (type.equals(boolean.class)) return new Class[] {GLboolean.class};
   else if (type.equals(void.class)) return new Class[] {GLvoid.class};
   else return new Class[] {};
 }
Beispiel #2
0
 public String getAutoTypeFromAnnotation(AnnotationMirror annotation) {
   Class annotation_class = NativeTypeTranslator.getClassFromType(annotation.getAnnotationType());
   if (annotation_class.equals(GLint.class)) return "GL11.GL_INT";
   else if (annotation_class.equals(GLbyte.class)) return "GL11.GL_BYTE";
   else if (annotation_class.equals(GLshort.class)) return "GL11.GL_SHORT";
   if (annotation_class.equals(GLuint.class)) return "GL11.GL_UNSIGNED_INT";
   else if (annotation_class.equals(GLubyte.class)) return "GL11.GL_UNSIGNED_BYTE";
   else if (annotation_class.equals(GLushort.class)) return "GL11.GL_UNSIGNED_SHORT";
   else if (annotation_class.equals(GLfloat.class)) return "GL11.GL_FLOAT";
   else if (annotation_class.equals(GLdouble.class)) return "GL11.GL_DOUBLE";
   else return null;
 }
Beispiel #3
0
 private static Class[] getValidBufferTypes(Class type) {
   if (type.equals(IntBuffer.class))
     return new Class[] {
       GLbitfield.class, GLenum.class, GLhandleARB.class, GLint.class, GLsizei.class, GLuint.class
     };
   else if (type.equals(FloatBuffer.class)) return new Class[] {GLclampf.class, GLfloat.class};
   else if (type.equals(ByteBuffer.class))
     return new Class[] {
       GLboolean.class, GLbyte.class, GLcharARB.class, GLchar.class, GLubyte.class, GLvoid.class
     };
   else if (type.equals(ShortBuffer.class))
     return new Class[] {GLhalf.class, GLshort.class, GLushort.class};
   else if (type.equals(DoubleBuffer.class)) return new Class[] {GLclampd.class, GLdouble.class};
   else if (type.equals(LongBuffer.class))
     return new Class[] {GLint64EXT.class, GLuint64EXT.class};
   else return new Class[] {};
 }
  private static boolean generateBufferParameterAddress(
      TypeMap type_map,
      PrintWriter writer,
      MethodDeclaration method,
      ParameterDeclaration param,
      Mode mode,
      boolean loopDeclared) {
    NativeTypeTranslator translator = new NativeTypeTranslator(type_map, param);
    param.getType().accept(translator);
    writer.print("\t" + translator.getSignature() + param.getSimpleName());
    writer.print(BUFFER_ADDRESS_POSTFIX + " = ((");
    writer.print(translator.getSignature());
    Check check_annotation = param.getAnnotation(Check.class);
    writer.print(")");
    if (mode == Mode.BUFFEROBJECT && param.getAnnotation(BufferObject.class) != null) {
      writer.print(
          "offsetToPointer("
              + param.getSimpleName()
              + Utils.BUFFER_OBJECT_PARAMETER_POSTFIX
              + "))");
    } else {
      Class java_type = Utils.getJavaType(param.getType());
      if (Buffer.class.isAssignableFrom(java_type)
          || java_type.equals(CharSequence.class)
          || java_type.equals(CharSequence[].class)) {
        boolean explicitly_byte_sized =
            java_type.equals(Buffer.class)
                || translator.getAnnotationType().equals(type_map.getVoidType());
        if (explicitly_byte_sized) writer.print("(((char *)");
        if (method.getAnnotation(GenerateAutos.class) != null
            || (check_annotation != null && check_annotation.canBeNull())) {
          writer.print("safeGetBufferAddress(env, " + param.getSimpleName());
        } else {
          writer.print("(*env)->GetDirectBufferAddress(env, " + param.getSimpleName());
        }
        writer.print("))");
        writer.print(" + " + param.getSimpleName() + BUFFER_POSITION_POSTFIX);
        if (explicitly_byte_sized) writer.print("))");
      } else if (java_type.equals(String.class)) {
        writer.print("GetStringNativeChars(env, " + param.getSimpleName() + "))");
      } else throw new RuntimeException("Illegal type " + java_type);
    }
    writer.println(";");

    if (param.getAnnotation(StringList.class) != null) {
      if (Utils.getJavaType(param.getType()) != CharSequence[].class
          && (param.getAnnotation(GLchar.class) == null
              || param.getAnnotation(NullTerminated.class) == null
              || param.getAnnotation(NullTerminated.class).value().length() == 0))
        throw new RuntimeException(
            "StringList annotation can only be applied on null-terminated GLchar buffers.");

      if ("_str".equals(param.getSimpleName()))
        throw new RuntimeException(
            "The name '_str' is not valid for arguments annotated with StringList");

      // Declare loop counters and allocate string array
      if (!loopDeclared) {
        writer.println("\tunsigned int _str_i;");
        writer.println("\tGLchar *_str_address;");
        loopDeclared = true;
      }
      writer.println(
          "\tGLchar **"
              + param.getSimpleName()
              + STRING_LIST_POSTFIX
              + " = (GLchar **) malloc("
              + param.getAnnotation(StringList.class).value()
              + "*sizeof(GLchar*));");
    }
    return loopDeclared;
  }
Beispiel #5
0
 public String translateAnnotation(Class annotation_type) {
   if (annotation_type.equals(GLuint.class)) return "i";
   else if (annotation_type.equals(GLint.class)) return "i";
   else if (annotation_type.equals(GLushort.class)) return "s";
   else if (annotation_type.equals(GLshort.class)) return "s";
   else if (annotation_type.equals(GLubyte.class)) return "b";
   else if (annotation_type.equals(GLbyte.class)) return "b";
   else if (annotation_type.equals(GLfloat.class)) return "f";
   else if (annotation_type.equals(GLdouble.class)) return "d";
   else if (annotation_type.equals(GLhalf.class)) return "h";
   else if (annotation_type.equals(GLuint64EXT.class)) return "i64";
   else if (annotation_type.equals(GLint64EXT.class)) return "i64";
   else if (annotation_type.equals(GLboolean.class) || annotation_type.equals(GLvoid.class))
     return "";
   else throw new RuntimeException(annotation_type + " is not allowed");
 }