blob: cbca682bcb87cc9375ee733c9f742c6ab6a1605e [file] [log] [blame]
Kenny Rootbd393b72010-03-11 18:20:12 -08001/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Jack Palevich412f38f22009-04-13 16:22:25 -070016
17import java.io.BufferedReader;
18import java.io.File;
19import java.io.FileOutputStream;
20import java.io.FileReader;
21import java.io.IOException;
22import java.io.PrintStream;
23
24public class GenerateGLES {
25
26 static void copy(String filename, PrintStream out) throws IOException {
27 BufferedReader br = new BufferedReader(new FileReader(filename));
28 String s;
29 while ((s = br.readLine()) != null) {
30 out.println(s);
31 }
32 }
33
34 private static void emit(GLESCodeEmitter emitter,
35 BufferedReader specReader,
36 PrintStream glStream,
37 PrintStream cStream) throws Exception {
38 String s = null;
39 while ((s = specReader.readLine()) != null) {
40 if (s.trim().startsWith("//")) {
41 continue;
42 }
43
44 CFunc cfunc = CFunc.parseCFunc(s);
Jack Palevich412f38f22009-04-13 16:22:25 -070045 String fname = cfunc.getName();
46 String stubRoot = "stubs/gles11/" + fname;
47 String javaPath = stubRoot + ".java";
48 File f = new File(javaPath);
49 if (f.exists()) {
50 System.out.println("Special-casing function " + fname);
51 copy(javaPath, glStream);
52 copy(stubRoot + ".cpp", cStream);
53
54 // Register native function names
55 // This should be improved to require fewer discrete files
56 String filename = stubRoot + ".nativeReg";
57 BufferedReader br =
58 new BufferedReader(new FileReader(filename));
59 String nfunc;
60 while ((nfunc = br.readLine()) != null) {
61 emitter.addNativeRegistration(nfunc);
62 }
63 } else {
64 emitter.emitCode(cfunc, s);
65 }
66 }
67 }
68
69 public static void main(String[] args) throws Exception {
70 int aidx = 0;
71 while ((aidx < args.length) && (args[aidx].charAt(0) == '-')) {
72 switch (args[aidx].charAt(1)) {
73 default:
74 System.err.println("Unknown flag: " + args[aidx]);
75 System.exit(1);
76 }
77
78 aidx++;
79 }
80
81 BufferedReader checksReader =
82 new BufferedReader(new FileReader("specs/gles11/checks.spec"));
83 ParameterChecker checker = new ParameterChecker(checksReader);
84
85 // Generate files
86 for(String suffix: new String[] {"GLES10", "GLES10Ext",
Jesse Hall16f03922014-05-19 15:12:22 -070087 "GLES11", "GLES11Ext", "GLES20",
Pablo Ceballos8a59ca72015-10-30 10:31:22 -070088 "GLES30", "GLES31", "GLES31Ext", "GLES32"})
Jack Palevich412f38f22009-04-13 16:22:25 -070089 {
90 BufferedReader spec11Reader =
91 new BufferedReader(new FileReader("specs/gles11/"
92 + suffix + ".spec"));
93 String gl11Filename = "android/opengl/" + suffix + ".java";
94 String gl11cFilename = "android_opengl_" + suffix + ".cpp";
95 PrintStream gl11Stream =
96 new PrintStream(new FileOutputStream("out/" + gl11Filename));
97 PrintStream gl11cStream =
98 new PrintStream(new FileOutputStream("out/" + gl11cFilename));
Jack Palevich412f38f22009-04-13 16:22:25 -070099 copy("stubs/gles11/" + suffix + "Header.java-if", gl11Stream);
100 copy("stubs/gles11/" + suffix + "cHeader.cpp", gl11cStream);
Mathias Agopianbf13ba52013-02-22 19:34:06 -0800101 copy("stubs/gles11/common.cpp", gl11cStream);
Jack Palevich412f38f22009-04-13 16:22:25 -0700102 GLESCodeEmitter emitter = new GLESCodeEmitter(
103 "android/opengl/" + suffix,
104 checker, gl11Stream, gl11cStream);
105 emit(emitter, spec11Reader, gl11Stream, gl11cStream);
106 emitter.emitNativeRegistration("register_android_opengl_jni_"
107 + suffix);
108 gl11Stream.println("}");
109 gl11Stream.close();
110 gl11cStream.close();
111 }
112 }
113}