2 * Copyright (C) 2009 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 import java.io.BufferedReader;
19 import java.io.FileOutputStream;
20 import java.io.FileReader;
21 import java.io.IOException;
22 import java.io.PrintStream;
24 public class GenerateGLES {
26 static void copy(String filename, PrintStream out) throws IOException {
27 BufferedReader br = new BufferedReader(new FileReader(filename));
29 while ((s = br.readLine()) != null) {
34 private static void emit(GLESCodeEmitter emitter,
35 BufferedReader specReader,
37 PrintStream cStream) throws Exception {
39 while ((s = specReader.readLine()) != null) {
40 if (s.trim().startsWith("//")) {
44 CFunc cfunc = CFunc.parseCFunc(s);
45 String fname = cfunc.getName();
46 String stubRoot = "stubs/gles11/" + fname;
47 String javaPath = stubRoot + ".java";
48 File f = new File(javaPath);
50 System.out.println("Special-casing function " + fname);
51 copy(javaPath, glStream);
52 copy(stubRoot + ".cpp", cStream);
54 // Register native function names
55 // This should be improved to require fewer discrete files
56 String filename = stubRoot + ".nativeReg";
58 new BufferedReader(new FileReader(filename));
60 while ((nfunc = br.readLine()) != null) {
61 emitter.addNativeRegistration(nfunc);
64 emitter.emitCode(cfunc, s);
69 public static void main(String[] args) throws Exception {
71 while ((aidx < args.length) && (args[aidx].charAt(0) == '-')) {
72 switch (args[aidx].charAt(1)) {
74 System.err.println("Unknown flag: " + args[aidx]);
81 BufferedReader checksReader =
82 new BufferedReader(new FileReader("specs/gles11/checks.spec"));
83 ParameterChecker checker = new ParameterChecker(checksReader);
86 for(String suffix: new String[] {"GLES10", "GLES10Ext",
87 "GLES11", "GLES11Ext", "GLES20", "GLES30"})
89 BufferedReader spec11Reader =
90 new BufferedReader(new FileReader("specs/gles11/"
92 String gl11Filename = "android/opengl/" + suffix + ".java";
93 String gl11cFilename = "android_opengl_" + suffix + ".cpp";
94 PrintStream gl11Stream =
95 new PrintStream(new FileOutputStream("out/" + gl11Filename));
96 PrintStream gl11cStream =
97 new PrintStream(new FileOutputStream("out/" + gl11cFilename));
98 copy("stubs/gles11/" + suffix + "Header.java-if", gl11Stream);
99 copy("stubs/gles11/" + suffix + "cHeader.cpp", gl11cStream);
100 copy("stubs/gles11/common.cpp", gl11cStream);
101 GLESCodeEmitter emitter = new GLESCodeEmitter(
102 "android/opengl/" + suffix,
103 checker, gl11Stream, gl11cStream);
104 emit(emitter, spec11Reader, gl11Stream, gl11cStream);
105 emitter.emitNativeRegistration("register_android_opengl_jni_"
107 gl11Stream.println("}");