blob: 08063f312a6399a6564821cbf25560f0b4d250e7 [file] [log] [blame]
Jack Palevich412f38f22009-04-13 16:22:25 -07001
2import java.io.BufferedReader;
3import java.io.File;
4import java.io.FileOutputStream;
5import java.io.FileReader;
6import java.io.IOException;
7import java.io.PrintStream;
8
9public class GenerateGLES {
10
11 static void copy(String filename, PrintStream out) throws IOException {
12 BufferedReader br = new BufferedReader(new FileReader(filename));
13 String s;
14 while ((s = br.readLine()) != null) {
15 out.println(s);
16 }
17 }
18
19 private static void emit(GLESCodeEmitter emitter,
20 BufferedReader specReader,
21 PrintStream glStream,
22 PrintStream cStream) throws Exception {
23 String s = null;
24 while ((s = specReader.readLine()) != null) {
25 if (s.trim().startsWith("//")) {
26 continue;
27 }
28
29 CFunc cfunc = CFunc.parseCFunc(s);
30
31 String fname = cfunc.getName();
32 String stubRoot = "stubs/gles11/" + fname;
33 String javaPath = stubRoot + ".java";
34 File f = new File(javaPath);
35 if (f.exists()) {
36 System.out.println("Special-casing function " + fname);
37 copy(javaPath, glStream);
38 copy(stubRoot + ".cpp", cStream);
39
40 // Register native function names
41 // This should be improved to require fewer discrete files
42 String filename = stubRoot + ".nativeReg";
43 BufferedReader br =
44 new BufferedReader(new FileReader(filename));
45 String nfunc;
46 while ((nfunc = br.readLine()) != null) {
47 emitter.addNativeRegistration(nfunc);
48 }
49 } else {
50 emitter.emitCode(cfunc, s);
51 }
52 }
53 }
54
55 public static void main(String[] args) throws Exception {
56 int aidx = 0;
57 while ((aidx < args.length) && (args[aidx].charAt(0) == '-')) {
58 switch (args[aidx].charAt(1)) {
59 default:
60 System.err.println("Unknown flag: " + args[aidx]);
61 System.exit(1);
62 }
63
64 aidx++;
65 }
66
67 BufferedReader checksReader =
68 new BufferedReader(new FileReader("specs/gles11/checks.spec"));
69 ParameterChecker checker = new ParameterChecker(checksReader);
70
71 // Generate files
72 for(String suffix: new String[] {"GLES10", "GLES10Ext",
Jack Palevich50d0b142009-11-19 16:34:55 +080073 "GLES11", "GLES11Ext", "GLES20"})
Jack Palevich412f38f22009-04-13 16:22:25 -070074 {
75 BufferedReader spec11Reader =
76 new BufferedReader(new FileReader("specs/gles11/"
77 + suffix + ".spec"));
78 String gl11Filename = "android/opengl/" + suffix + ".java";
79 String gl11cFilename = "android_opengl_" + suffix + ".cpp";
80 PrintStream gl11Stream =
81 new PrintStream(new FileOutputStream("out/" + gl11Filename));
82 PrintStream gl11cStream =
83 new PrintStream(new FileOutputStream("out/" + gl11cFilename));
84 gl11Stream.println("/*");
85 gl11cStream.println("/*");
86 copy("stubs/gles11/" + suffix + "Header.java-if", gl11Stream);
87 copy("stubs/gles11/" + suffix + "cHeader.cpp", gl11cStream);
88 GLESCodeEmitter emitter = new GLESCodeEmitter(
89 "android/opengl/" + suffix,
90 checker, gl11Stream, gl11cStream);
91 emit(emitter, spec11Reader, gl11Stream, gl11cStream);
92 emitter.emitNativeRegistration("register_android_opengl_jni_"
93 + suffix);
94 gl11Stream.println("}");
95 gl11Stream.close();
96 gl11cStream.close();
97 }
98 }
99}