diff options
Diffstat (limited to 'opengl/tools/glgen/src')
-rw-r--r-- | opengl/tools/glgen/src/CType.java | 3 | ||||
-rw-r--r-- | opengl/tools/glgen/src/GenerateEGL.java | 42 | ||||
-rw-r--r-- | opengl/tools/glgen/src/GenerateGLES.java | 6 | ||||
-rw-r--r-- | opengl/tools/glgen/src/JType.java | 10 | ||||
-rw-r--r-- | opengl/tools/glgen/src/JniCodeEmitter.java | 73 | ||||
-rw-r--r-- | opengl/tools/glgen/src/ParameterChecker.java | 17 |
6 files changed, 92 insertions, 59 deletions
diff --git a/opengl/tools/glgen/src/CType.java b/opengl/tools/glgen/src/CType.java index 92950ea..aba98af 100644 --- a/opengl/tools/glgen/src/CType.java +++ b/opengl/tools/glgen/src/CType.java @@ -70,7 +70,8 @@ public class CType { } public boolean isConstCharPointer() { - return isConst && isPointer && baseType.equals("char"); + return isConst && isPointer && + (baseType.equals("char") || baseType.equals("GLchar")); } public boolean isTypedPointer() { diff --git a/opengl/tools/glgen/src/GenerateEGL.java b/opengl/tools/glgen/src/GenerateEGL.java index aaa748c..2ef3970 100644 --- a/opengl/tools/glgen/src/GenerateEGL.java +++ b/opengl/tools/glgen/src/GenerateEGL.java @@ -84,26 +84,26 @@ public class GenerateEGL { ParameterChecker checker = new ParameterChecker(checksReader); - BufferedReader specReader = - new BufferedReader(new FileReader("specs/egl/EGL14.spec")); - - String egljFilename = "android/opengl/EGL14.java"; - String eglcFilename = "android_opengl_EGL14.cpp"; - PrintStream egljStream = - new PrintStream(new FileOutputStream("out/" + egljFilename)); - PrintStream eglcStream = - new PrintStream(new FileOutputStream("out/" + eglcFilename)); - egljStream.println("/*"); - eglcStream.println("/*"); - copy("stubs/egl/EGL14Header.java-if", egljStream); - copy("stubs/egl/EGL14cHeader.cpp", eglcStream); - EGLCodeEmitter emitter = new EGLCodeEmitter( - "android/opengl/EGL14", - checker, egljStream, eglcStream); - emit(emitter, specReader, egljStream, eglcStream); - emitter.emitNativeRegistration("register_android_opengl_jni_EGL14"); - egljStream.println("}"); - egljStream.close(); - eglcStream.close(); + for(String suffix: new String[] {"EGL14", "EGLExt"}) { + BufferedReader specReader = new BufferedReader(new FileReader( + "specs/egl/" + suffix + ".spec")); + String egljFilename = "android/opengl/" + suffix + ".java"; + String eglcFilename = "android_opengl_" + suffix + ".cpp"; + PrintStream egljStream = + new PrintStream(new FileOutputStream("out/" + egljFilename)); + PrintStream eglcStream = + new PrintStream(new FileOutputStream("out/" + eglcFilename)); + copy("stubs/egl/" + suffix + "Header.java-if", egljStream); + copy("stubs/egl/" + suffix + "cHeader.cpp", eglcStream); + EGLCodeEmitter emitter = new EGLCodeEmitter( + "android/opengl/" + suffix, + checker, egljStream, eglcStream); + emit(emitter, specReader, egljStream, eglcStream); + emitter.emitNativeRegistration( + "register_android_opengl_jni_" + suffix); + egljStream.println("}"); + egljStream.close(); + eglcStream.close(); + } } } diff --git a/opengl/tools/glgen/src/GenerateGLES.java b/opengl/tools/glgen/src/GenerateGLES.java index 6468957..c99c45d 100644 --- a/opengl/tools/glgen/src/GenerateGLES.java +++ b/opengl/tools/glgen/src/GenerateGLES.java @@ -42,7 +42,6 @@ public class GenerateGLES { } CFunc cfunc = CFunc.parseCFunc(s); - String fname = cfunc.getName(); String stubRoot = "stubs/gles11/" + fname; String javaPath = stubRoot + ".java"; @@ -85,7 +84,7 @@ public class GenerateGLES { // Generate files for(String suffix: new String[] {"GLES10", "GLES10Ext", - "GLES11", "GLES11Ext", "GLES20"}) + "GLES11", "GLES11Ext", "GLES20", "GLES30"}) { BufferedReader spec11Reader = new BufferedReader(new FileReader("specs/gles11/" @@ -96,10 +95,9 @@ public class GenerateGLES { new PrintStream(new FileOutputStream("out/" + gl11Filename)); PrintStream gl11cStream = new PrintStream(new FileOutputStream("out/" + gl11cFilename)); - gl11Stream.println("/*"); - gl11cStream.println("/*"); copy("stubs/gles11/" + suffix + "Header.java-if", gl11Stream); copy("stubs/gles11/" + suffix + "cHeader.cpp", gl11cStream); + copy("stubs/gles11/common.cpp", gl11cStream); GLESCodeEmitter emitter = new GLESCodeEmitter( "android/opengl/" + suffix, checker, gl11Stream, gl11cStream); diff --git a/opengl/tools/glgen/src/JType.java b/opengl/tools/glgen/src/JType.java index 3f7cb73..b10e7e2 100644 --- a/opengl/tools/glgen/src/JType.java +++ b/opengl/tools/glgen/src/JType.java @@ -46,7 +46,10 @@ public class JType { typeMapping.put(new CType("GLubyte", true, true), new JType("String", false, false)); typeMapping.put(new CType("char", false, true), new JType("byte")); typeMapping.put(new CType("char", true, true), new JType("String", false, false)); + typeMapping.put(new CType("GLchar", true, true), new JType("String", false, false)); typeMapping.put(new CType("int"), new JType("int")); + typeMapping.put(new CType("GLuint64"), new JType("long")); + typeMapping.put(new CType("GLsync"), new JType("long")); // EGL primitive types typeMapping.put(new CType("EGLint"), new JType("int")); @@ -56,6 +59,7 @@ public class JType { typeMapping.put(new CType("EGLNativeWindowType"), new JType("int")); typeMapping.put(new CType("EGLNativeDisplayType"), new JType("int")); typeMapping.put(new CType("EGLClientBuffer"), new JType("int")); + typeMapping.put(new CType("EGLnsecsANDROID"), new JType("long")); // EGL nonprimitive types typeMapping.put(new CType("EGLConfig"), new JType("EGLConfig", true, false)); @@ -79,6 +83,8 @@ public class JType { new JType("java.nio.IntBuffer", true, false)); typeMapping.put(new CType("GLenum", false, true), new JType("java.nio.IntBuffer", true, false)); + typeMapping.put(new CType("GLenum", true, true), + new JType("java.nio.IntBuffer", true, false)); typeMapping.put(new CType("GLfixed", false, true), new JType("java.nio.IntBuffer", true, false)); typeMapping.put(new CType("GLfixed", true, true), @@ -99,6 +105,8 @@ public class JType { new JType("java.nio.IntBuffer", true, false)); typeMapping.put(new CType("GLshort", true, true), new JType("java.nio.ShortBuffer", true, false)); + typeMapping.put(new CType("GLint64", false, true), + new JType("java.nio.LongBuffer", true, false)); // Typed pointers map to arrays + offsets arrayTypeMapping.put(new CType("char", false, true), @@ -106,6 +114,7 @@ public class JType { arrayTypeMapping.put(new CType("GLboolean", false, true), new JType("boolean", false, true)); arrayTypeMapping.put(new CType("GLenum", false, true), new JType("int", false, true)); + arrayTypeMapping.put(new CType("GLenum", true, true), new JType("int", false, true)); arrayTypeMapping.put(new CType("GLfixed", true, true), new JType("int", false, true)); arrayTypeMapping.put(new CType("GLfixed", false, true), new JType("int", false, true)); arrayTypeMapping.put(new CType("GLfloat", false, true), new JType("float", false, true)); @@ -119,6 +128,7 @@ public class JType { arrayTypeMapping.put(new CType("GLuint", true, true), new JType("int", false, true)); arrayTypeMapping.put(new CType("GLintptr"), new JType("int", false, true)); arrayTypeMapping.put(new CType("GLsizeiptr"), new JType("int", false, true)); + arrayTypeMapping.put(new CType("GLint64", false, true), new JType("long", false, true)); //EGL typed pointers map to arrays + offsets arrayTypeMapping.put(new CType("EGLint", false, true), new JType("int", false, true)); diff --git a/opengl/tools/glgen/src/JniCodeEmitter.java b/opengl/tools/glgen/src/JniCodeEmitter.java index 774f40c..d5e2d34 100644 --- a/opengl/tools/glgen/src/JniCodeEmitter.java +++ b/opengl/tools/glgen/src/JniCodeEmitter.java @@ -54,7 +54,7 @@ public class JniCodeEmitter { } else if (baseType.equals("short")) { jniName += "S"; } else if (baseType.equals("long")) { - jniName += "L"; + jniName += "J"; } else if (baseType.equals("byte")) { jniName += "B"; } else if (baseType.equals("String")) { @@ -197,30 +197,30 @@ public class JniCodeEmitter { void printIfcheckPostamble(PrintStream out, boolean isBuffer, boolean emitExceptionCheck, String iii) { - printIfcheckPostamble(out, isBuffer, emitExceptionCheck, - "offset", "_remaining", iii); - } + printIfcheckPostamble(out, isBuffer, emitExceptionCheck, + "offset", "_remaining", iii); + } void printIfcheckPostamble(PrintStream out, boolean isBuffer, boolean emitExceptionCheck, String offset, String remaining, String iii) { - out.println(iii + " default:"); - out.println(iii + " _needed = 0;"); - out.println(iii + " break;"); - out.println(iii + "}"); - - out.println(iii + "if (" + remaining + " < _needed) {"); - out.println(iii + indent + "_exception = 1;"); - out.println(iii + indent + - "_exceptionType = \"java/lang/IllegalArgumentException\";"); - out.println(iii + indent + - "_exceptionMessage = \"" + - (isBuffer ? "remaining()" : "length - " + offset) + - " < needed\";"); - out.println(iii + indent + "goto exit;"); - out.println(iii + "}"); - - needsExit = true; - } + out.println(iii + " default:"); + out.println(iii + " _needed = 1;"); + out.println(iii + " break;"); + out.println(iii + "}"); + + out.println(iii + "if (" + remaining + " < _needed) {"); + out.println(iii + indent + "_exception = 1;"); + out.println(iii + indent + + "_exceptionType = \"java/lang/IllegalArgumentException\";"); + out.println(iii + indent + + "_exceptionMessage = \"" + + (isBuffer ? "remaining()" : "length - " + offset) + + " < needed\";"); + out.println(iii + indent + "goto exit;"); + out.println(iii + "}"); + + needsExit = true; + } boolean isNullAllowed(CFunc cfunc) { String[] checks = mChecker.getChecks(cfunc.getName()); @@ -749,10 +749,20 @@ public class JniCodeEmitter { String outName = "android_" + jfunc.getName(); boolean isPointerFunc = isPointerFunc(jfunc); - boolean isVBOPointerFunc = (outName.endsWith("Pointer") || - outName.endsWith("PointerOES") || - outName.endsWith("DrawElements") || outName.endsWith("VertexAttribPointer")) && - !jfunc.getCFunc().hasPointerArg(); + boolean isPointerOffsetFunc = + (outName.endsWith("Pointer") || outName.endsWith("PointerOES") || + outName.endsWith("glDrawElements") || + outName.endsWith("glDrawRangeElements") || + outName.endsWith("glTexImage2D") || + outName.endsWith("glTexSubImage2D") || + outName.endsWith("glCompressedTexImage2D") || + outName.endsWith("glCompressedTexSubImage2D") || + outName.endsWith("glTexImage3D") || + outName.endsWith("glTexSubImage3D") || + outName.endsWith("glCompressedTexImage3D") || + outName.endsWith("glCompressedTexSubImage3D") || + outName.endsWith("glReadPixels")) + && !jfunc.getCFunc().hasPointerArg(); if (isPointerFunc) { outName += "Bounds"; } @@ -932,8 +942,8 @@ public class JniCodeEmitter { // Emit an _exeption variable if there will be error checks if (emitExceptionCheck) { out.println(indent + "jint _exception = 0;"); - out.println(indent + "const char * _exceptionType;"); - out.println(indent + "const char * _exceptionMessage;"); + out.println(indent + "const char * _exceptionType = NULL;"); + out.println(indent + "const char * _exceptionMessage = NULL;"); } // Emit a single _array or multiple _XXXArray variables @@ -1271,8 +1281,8 @@ public class JniCodeEmitter { } for (int i = 0; i < numArgs; i++) { String typecast; - if (i == numArgs - 1 && isVBOPointerFunc) { - typecast = "(const GLvoid *)"; + if (i == numArgs - 1 && isPointerOffsetFunc) { + typecast = "(GLvoid *)"; } else { typecast = "(" + cfunc.getArgType(i).getDeclaration() + ")"; } @@ -1421,7 +1431,8 @@ public class JniCodeEmitter { "return toEGLHandle(_env, " + baseType + "Class, " + baseType + "Constructor, _returnValue);"); } else { - out.println(indent + "return _returnValue;"); + out.println(indent + "return (" + + getJniType(jfunc.getType()) + ")_returnValue;"); } } diff --git a/opengl/tools/glgen/src/ParameterChecker.java b/opengl/tools/glgen/src/ParameterChecker.java index bff6d86..fbc47fb 100644 --- a/opengl/tools/glgen/src/ParameterChecker.java +++ b/opengl/tools/glgen/src/ParameterChecker.java @@ -22,8 +22,21 @@ public class ParameterChecker { HashMap<String,String[]> map = new HashMap<String,String[]>(); public ParameterChecker(BufferedReader reader) throws Exception { - String s; - while ((s = reader.readLine()) != null) { + String line; + while ((line = reader.readLine()) != null) { + String s = line.trim(); + + // skip empty lines + if (s.isEmpty()) { + continue; + } + + // skip single-line comments + if (s.startsWith("//") || + s.startsWith("#")) { + continue; + } + String[] tokens = s.split("\\s"); map.put(tokens[0], tokens); } |