41package com.jogamp.gluegen.opengl;
43import java.io.BufferedReader;
44import java.io.BufferedWriter;
46import java.io.FileReader;
47import java.io.FileWriter;
48import java.io.IOException;
49import java.io.PrintWriter;
50import java.util.ArrayList;
51import java.util.Collections;
52import java.util.HashMap;
53import java.util.HashSet;
54import java.util.Iterator;
58import java.util.regex.Matcher;
59import java.util.regex.Pattern;
111 Pattern.compile(
"^(GLAPI|GL_API|GL_APICALL|EGLAPI|extern)?(\\s*)((unsigned|const)\\s+)?(\\w+)(\\s+\\*\\s*|\\s*\\*\\s+|\\s+)?(GLAPIENTRY|GL_APIENTRY|APIENTRY|EGLAPIENTRY|WINAPI)?(\\s*)([ew]?gl\\w+)\\s?(\\(.*)");
114 Pattern.compile(
"\\#ifndef ([CEW]?GL[XU]?_[A-Za-z0-9_]+)(.*)");
117 Pattern.compile(
"\\#if(.*)");
119 Pattern.compile(
"\\#(elif|else)(.*)");
121 Pattern.compile(
"\\#endif(.*)");
125 Pattern.compile(
"\\#define ([CEW]?GL[XU]?_[A-Za-z0-9_]+)\\s*([A-Za-z0-9_]+)(.*)");
141 public static void main(
final String[] args)
throws IOException {
142 if (args.length > 0 && args[0].equals(
"-test")) {
145 final String[] newArgs =
new String[args.length - 1];
146 System.arraycopy(args, 1, newArgs, 0, args.length - 1);
147 builder.
parse(newArgs);
152 final String packageName = args[0];
153 final String packageDir = args[1];
155 final String[] cHeaderFilePaths =
new String[args.length - 2];
156 System.arraycopy(args, 2, cHeaderFilePaths, 0, cHeaderFilePaths.length);
160 builder.
parse(cHeaderFilePaths);
162 final File file =
new File(packageDir + File.separatorChar +
"StaticGLInfo.java");
163 final String parentDir = file.getParent();
164 if (parentDir !=
null) {
165 final File pDirFile =
new File(parentDir);
169 final PrintWriter writer =
new PrintWriter(
new BufferedWriter(
new FileWriter(file)));
174 }
catch (
final Exception e) {
175 final StringBuilder buf =
new StringBuilder(
"{ ");
176 for (
int i = 0; i < cHeaderFilePaths.length; ++i) {
177 buf.append(cHeaderFilePaths[i]);
181 throw new RuntimeException(
182 "Error building StaticGLInfo.java from " + buf.toString(), e);
192 public void parse(
final String[] cHeaderFilePaths)
throws IOException {
193 for (
int i = 0; i < cHeaderFilePaths.length; i++) {
194 parse(cHeaderFilePaths[i]);
200 public void parse(
final String cHeaderFilePath)
throws IOException {
201 final BufferedReader reader =
new BufferedReader(
new FileReader(cHeaderFilePath));
202 String line, activeAssociation =
null;
205 while ((line = reader.readLine()) !=
null) {
208 String identifier =
null;
218 if ( identifier !=
null &&
219 activeAssociation !=
null &&
220 !identifier.equals(activeAssociation)
225 System.err.println(
"<"+block+
"> ADDING ASSOCIATION: <" + identifier +
"> <" + activeAssociation +
"> ; type " + type);
228 if ((m =
ifPattern.matcher(line)).matches()) {
229 final String comment = m.group(1).trim();
232 System.err.println(
"<"+block+
"> BEGIN IF BLOCK: <" + comment +
">");
234 }
else if ((m =
elsePattern.matcher(line)).matches()) {
235 final String comment = m.group(1).trim();
237 System.err.println(
"<"+block+
"> ELSE BLOCK: <" + comment +
">");
239 }
else if ((m =
endifPattern.matcher(line)).matches()) {
240 final String comment = m.group(1).trim();
244 System.err.println(
"<"+block+
"> END ASSOCIATION BLOCK: <" + activeAssociation +
" <-> " + comment +
">");
246 activeAssociation =
null;
249 System.err.println(
"<"+block+
"> END IF BLOCK: <" + comment +
">");
256 activeAssociation = m.group(1).trim();
259 System.err.println(
"<"+block+
"> BEGIN ASSOCIATION BLOCK: <" + activeAssociation +
">");
267 System.err.println(
"BuildStaticGLInfo.dump():");
270 System.err.println(
"<" + name +
"> :");
271 final List<String> l =
new ArrayList<String>();
274 for (
final String str : l) {
275 System.err.println(
" <" + str +
">");
292 public void emitJavaCode(
final PrintWriter output,
final String packageName) {
293 output.println(
"package " + packageName +
";");
295 output.println(
"import java.util.*;");
297 output.println(
"public final class StaticGLInfo");
300 output.println(
" // maps function names to the extension string or OpenGL");
301 output.println(
" // specification version string to which they correspond.");
302 output.println(
" private static HashMap funcToAssocMap;");
305 output.println(
" /**");
306 output.println(
" * Returns the OpenGL extension string or GL_VERSION string with which the");
307 output.println(
" * given function is associated. <P>");
308 output.println(
" *");
309 output.println(
" * If the");
310 output.println(
" * function is part of the OpenGL core, the returned value will be");
311 output.println(
" * GL_VERSION_XXX where XXX represents the OpenGL version of which the");
312 output.println(
" * function is a member (XXX will be of the form \"A\" or \"A_B\" or \"A_B_C\";");
313 output.println(
" * e.g., GL_VERSION_1_2_1 for OpenGL version 1.2.1).");
314 output.println(
" *");
315 output.println(
" * If the function is an extension function, the returned value will the");
316 output.println(
" * OpenGL extension string for the extension to which the function");
317 output.println(
" * corresponds. For example, if glLoadTransposeMatrixfARB is the argument,");
318 output.println(
" * GL_ARB_transpose_matrix will be the value returned.");
319 output.println(
" * Please see http://oss.sgi.com/projects/ogl-sample/registry/index.html for");
320 output.println(
" * a list of extension names and the functions they expose.");
321 output.println(
" *");
322 output.println(
" * If the function specified is not part of any known OpenGL core version or");
323 output.println(
" * extension, then NULL will be returned.");
324 output.println(
" */");
325 output.println(
" public static String getFunctionAssociation(String glFunctionName)");
326 output.println(
" {");
327 output.println(
" String mappedName = null;");
328 output.println(
" int funcNamePermNum = com.jogamp.gluegen.runtime.opengl.GLNameResolver.getFuncNamePermutationNumber(glFunctionName);");
329 output.println(
" for(int i = 0; null==mappedName && i < funcNamePermNum; i++) {");
330 output.println(
" String tmp = com.jogamp.gluegen.runtime.opengl.GLNameResolver.getFuncNamePermutation(glFunctionName, i);");
331 output.println(
" try {");
332 output.println(
" mappedName = (String)funcToAssocMap.get(tmp);");
333 output.println(
" } catch (Exception e) { }");
334 output.println(
" }");
335 output.println(
" return mappedName;");
336 output.println(
" }");
339 output.println(
" static");
340 output.println(
" {");
345 if (!name.startsWith(
"GL")) {
350 output.println(
" funcToAssocMap = new HashMap(" + maxCapacity +
"); // approximate max capacity");
351 output.println(
" String group;");
353 Collections.sort(sets);
354 for (
final String groupName : sets) {
356 final List<String> l =
new ArrayList<String>();
359 final Iterator<String> funcIter = l.iterator();
360 boolean printedHeader =
false;
361 while (funcIter.hasNext()) {
362 final String funcName = funcIter.next();
363 if (!funcName.startsWith(
"GL")) {
364 if (!printedHeader) {
366 output.println(
" //----------------------------------------------------------------");
367 output.println(
" // " + groupName);
368 output.println(
" //----------------------------------------------------------------");
369 output.println(
" group = \"" + groupName +
"\";");
370 printedHeader =
true;
373 output.println(
" funcToAssocMap.put(\"" + funcName +
"\", group);");
377 output.println(
" }");
378 output.println(
"} // end class StaticGLInfo");
384 protected void addAssociation(
final String identifier,
final String association) {
386 if(
null == extensions) {
387 extensions =
new HashSet<String>();
390 extensions.add(association);
393 if (identifiers ==
null) {
394 identifiers =
new HashSet<String>();
397 identifiers.add(identifier);
Builds the StaticGLInfo class from the OpenGL header files (i.e., gl.h and glext.h) whose paths were ...
static final Pattern endifPattern
Map< String, Set< String > > declarationToExtensionMap
Set< String > getExtensions()
static final int defineIdentifierGroup
static final Pattern ifPattern
void parse(final String[] cHeaderFilePaths)
Parses the supplied C header files and adds the function associations contained therein to the intern...
void emitJavaCode(final PrintWriter output, final String packageName)
static final Pattern associationPattern
Map< String, Set< String > > extensionToDeclarationMap
static final Pattern elsePattern
Set< String > getDeclarations(final String extension)
static final Pattern definePattern
static final int funcIdentifierGroup
void parse(final String cHeaderFilePath)
Parses the supplied C header file and adds the function associations contained therein to the interna...
static final Pattern funcPattern
static void main(final String[] args)
The first argument is the package to which the StaticGLInfo class belongs, the second is the path to ...
Set< String > getExtension(final String identifier)
void addAssociation(final String identifier, final String association)
void setDebug(final boolean v)