/*
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Copyright (c) 2010 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistribution of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Neither the name of Sun Microsystems, Inc. or the names of
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
* MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
* ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
* DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
* DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for use
* in the design, construction, operation or maintenance of any nuclear
* facility.
*
* Sun gratefully acknowledges that this software was originally authored
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
package com.jogamp.gluegen.opengl;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Builds the StaticGLInfo class from the OpenGL header files (i.e., gl.h
* and glext.h) whose paths were passed as arguments to {@link
* #main(String[])}.
*
* It relies upon the assumption that a function's membership is scoped by
* preprocessor blocks in the header files that match the following pattern:
*
*
*
* * #ifndef GL_XXXX * GLAPI* * For example, if it parses the following data: * *glFuncName( ) * #endif GL_XXXX * *
* * #ifndef GL_VERSION_1_3 * GLAPI void APIENTRY glActiveTexture (GLenum); * GLAPI void APIENTRY glMultiTexCoord1dv (GLenum, const GLdouble *); * GLAPI void* * It will associate *glFuncName( ) * #endif GL_VERSION_1_3 * * #ifndef GL_ARB_texture_compression * GLAPI void APIENTRY glCompressedTexImage3DARB (GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLint, GLsizei, const GLvoid *); * GLAPI void APIENTRY glCompressedTexImage2DARB (GLenum, GLint, GLenum, GLsizei, GLsizei, GLint, GLsizei, const GLvoid *); * #endif * *
glActiveTexture
and
* glMultiTexCoord1dv
* with the symbol
* GL_VERSION_1_3
,
* and associate
* glCompressedTexImage2DARB
and
* glCompressedTexImage3DARB
* with the symbol
* GL_ARB_texture_compression
.
* */
public class BuildStaticGLInfo {
// Handles function pointer
protected static final int funcIdentifierGroup = 9;
protected static Pattern funcPattern =
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?(\\(.*)");
protected static Pattern associationPattern =
Pattern.compile("\\#ifndef ([CEW]?GL[XU]?_[A-Za-z0-9_]+)(.*)");
protected static Pattern ifPattern =
Pattern.compile("\\#if(.*)");
protected static Pattern elsePattern =
Pattern.compile("\\#(elif|else)(.*)");
protected static Pattern endifPattern =
Pattern.compile("\\#endif(.*)");
protected static final int defineIdentifierGroup = 1;
protected static Pattern definePattern =
Pattern.compile("\\#define ([CEW]?GL[XU]?_[A-Za-z0-9_]+)\\s*([A-Za-z0-9_]+)(.*)");
// Maps function / #define names to Set of names of the extensions they're declared in
protected Map");
output.println(" *");
output.println(" * If the");
output.println(" * function is part of the OpenGL core, the returned value will be");
output.println(" * GL_VERSION_XXX where XXX represents the OpenGL version of which the");
output.println(" * function is a member (XXX will be of the form \"A\" or \"A_B\" or \"A_B_C\";");
output.println(" * e.g., GL_VERSION_1_2_1 for OpenGL version 1.2.1).");
output.println(" *");
output.println(" * If the function is an extension function, the returned value will the");
output.println(" * OpenGL extension string for the extension to which the function");
output.println(" * corresponds. For example, if glLoadTransposeMatrixfARB is the argument,");
output.println(" * GL_ARB_transpose_matrix will be the value returned.");
output.println(" * Please see http://oss.sgi.com/projects/ogl-sample/registry/index.html for");
output.println(" * a list of extension names and the functions they expose.");
output.println(" *");
output.println(" * If the function specified is not part of any known OpenGL core version or");
output.println(" * extension, then NULL will be returned.");
output.println(" */");
output.println(" public static String getFunctionAssociation(String glFunctionName)");
output.println(" {");
output.println(" String mappedName = null;");
output.println(" int funcNamePermNum = com.jogamp.gluegen.runtime.opengl.GLNameResolver.getFuncNamePermutationNumber(glFunctionName);");
output.println(" for(int i = 0; null==mappedName && i < funcNamePermNum; i++) {");
output.println(" String tmp = com.jogamp.gluegen.runtime.opengl.GLNameResolver.getFuncNamePermutation(glFunctionName, i);");
output.println(" try {");
output.println(" mappedName = (String)funcToAssocMap.get(tmp);");
output.println(" } catch (Exception e) { }");
output.println(" }");
output.println(" return mappedName;");
output.println(" }");
output.println();
output.println(" static");
output.println(" {");
// Compute max capacity
int maxCapacity = 0;
for (String name : declarationToExtensionMap.keySet()) {
if (!name.startsWith("GL")) {
++maxCapacity;
}
}
output.println(" funcToAssocMap = new HashMap(" + maxCapacity + "); // approximate max capacity");
output.println(" String group;");
ArrayList