40package com.jogamp.gluegen.opengl;
42import static java.util.logging.Level.INFO;
44import com.jogamp.gluegen.GlueEmitterControls;
45import com.jogamp.gluegen.GlueGen;
46import com.jogamp.gluegen.MethodBinding;
47import com.jogamp.gluegen.cgram.types.AliasedSymbol;
48import com.jogamp.gluegen.procaddress.ProcAddressConfiguration;
49import com.jogamp.gluegen.runtime.opengl.GLNameResolver;
52import java.io.IOException;
53import java.util.ArrayList;
54import java.util.HashMap;
55import java.util.HashSet;
56import java.util.Iterator;
59import java.util.NoSuchElementException;
61import java.util.StringTokenizer;
66 private final List<String> glSemHeaders =
new ArrayList<String>();
67 private final Set<String> ignoredExtensions =
new HashSet<String>();
68 private final Set<String> forcedExtensions =
new HashSet<String>();
69 private final Set<String> renameExtensionsIntoCore =
new HashSet<String>();
73 boolean dropDocInfo =
false;
74 private final List<String> glDocHeaders =
new ArrayList<String>();
77 private final Map<String, String> javaDocSymbolRenames =
new HashMap<String, String>();
78 private final Map<String, Set<String>> javaDocRenamedSymbols =
new HashMap<String, Set<String>>();
82 private final Set<String> bufferObjectOnly =
new HashSet<String>();
84 private final Set<String> dropUniqVendorExtensions =
new HashSet<String>();
89 private boolean autoUnifyExtensions =
false;
90 private boolean allowNonGLExtensions =
false;
94 this.emitter = emitter;
96 setProcAddressNameExpr(
"PFN $UPPERCASE({0}) PROC");
97 }
catch (
final NoSuchElementException e) {
98 throw new RuntimeException(
"Error configuring ProcAddressNameExpr", e);
103 protected void dispatch(
final String cmd,
final StringTokenizer tok,
final File file,
final String filename,
final int lineNo)
throws IOException {
104 if (cmd.equalsIgnoreCase(
"IgnoreExtension")) {
105 final String sym = readString(
"IgnoreExtension", tok, filename, lineNo);
106 ignoredExtensions.add(sym);
107 }
else if (cmd.equalsIgnoreCase(
"ForceExtension")) {
108 final String sym = readString(
"ForceExtension", tok, filename, lineNo);
109 forcedExtensions.add(sym);
110 }
else if (cmd.equalsIgnoreCase(
"RenameExtensionIntoCore")) {
111 final String sym = readString(
"RenameExtensionIntoCore", tok, filename, lineNo);
112 renameExtensionsIntoCore.add(sym);
113 }
else if (cmd.equalsIgnoreCase(
"AllowNonGLExtensions")) {
114 allowNonGLExtensions = readBoolean(
"AllowNonGLExtensions", tok, filename, lineNo).booleanValue();
115 }
else if (cmd.equalsIgnoreCase(
"AutoUnifyExtensions")) {
116 autoUnifyExtensions = readBoolean(
"AutoUnifyExtensions", tok, filename, lineNo).booleanValue();
117 }
else if (cmd.equalsIgnoreCase(
"GLSemHeader")) {
118 final String sym = readString(
"GLSemHeader", tok, filename, lineNo);
119 if( !glSemHeaders.contains(sym) ) {
120 glSemHeaders.add(sym);
122 if( !dropDocInfo && !glDocHeaders.contains(sym) ) {
123 glDocHeaders.add(sym);
125 }
else if (cmd.equalsIgnoreCase(
"GLDocHeader")) {
126 final String sym = readString(
"GLDocHeader", tok, filename, lineNo);
127 if( !dropDocInfo && !glDocHeaders.contains(sym) ) {
128 glDocHeaders.add(sym);
130 }
else if (cmd.equalsIgnoreCase(
"DropAllGLDocHeader")) {
131 dropDocInfo = readBoolean(
"DropAllGLDocHeader", tok, filename, lineNo).booleanValue();
132 }
else if (cmd.equalsIgnoreCase(
"BufferObjectKind")) {
134 }
else if (cmd.equalsIgnoreCase(
"BufferObjectOnly")) {
135 final String sym = readString(
"BufferObjectOnly", tok, filename, lineNo);
136 bufferObjectOnly.add(sym);
137 }
else if (cmd.equalsIgnoreCase(
"DropUniqVendorExtensions")) {
138 final String sym = readString(
"DropUniqVendorExtensions", tok, filename, lineNo);
139 dropUniqVendorExtensions.add(sym);
141 super.dispatch(cmd, tok, file, filename, lineNo);
147 final String kindString = tok.nextToken();
148 GLEmitter.BufferObjectKind kind =
null;
149 final String target = tok.nextToken();
150 if (kindString.equalsIgnoreCase(
"UnpackPixel")) {
152 }
else if (kindString.equalsIgnoreCase(
"PackPixel")) {
154 }
else if (kindString.equalsIgnoreCase(
"Array")) {
156 }
else if (kindString.equalsIgnoreCase(
"Element")) {
158 }
else if (kindString.equalsIgnoreCase(
"Indirect")) {
161 throw new RuntimeException(
"Error parsing \"BufferObjectKind\" command at line " + lineNo
162 +
" in file \"" + filename +
"\": illegal BufferObjectKind \""
163 + kindString +
"\", expected one of UnpackPixel, PackPixel, Array, Element or Indirect");
166 bufferObjectKinds.put(target, kind);
167 }
catch (
final NoSuchElementException e) {
168 throw new RuntimeException(
"Error parsing \"BufferObjectKind\" command at line " + lineNo
169 +
" in file \"" + filename +
"\"", e);
177 public List<String>
javaPrologueForMethod(
final MethodBinding binding,
final boolean forImplementingMethodCall,
final boolean eraseBufferAndArrayTypes) {
179 List<String> res = super.javaPrologueForMethod(binding, forImplementingMethodCall, eraseBufferAndArrayTypes);
180 final GLEmitter.BufferObjectKind kind = getBufferObjectKind(binding.getCSymbol());
188 final ArrayList<String> res2 =
new ArrayList<String>();
194 String prologue =
"check";
197 prologue = prologue +
"UnpackPBO";
199 prologue = prologue +
"PackPBO";
201 prologue = prologue +
"ArrayVBO";
203 prologue = prologue +
"ElementVBO";
205 prologue = prologue +
"IndirectVBO";
207 throw new RuntimeException(
"Unknown BufferObjectKind " + kind);
211 prologue = prologue +
"Bound";
213 prologue = prologue +
"Unbound";
216 prologue = prologue +
"(true);";
218 res.add(0, prologue);
223 for (
final Iterator<String> iter = res.iterator(); iter.hasNext();) {
224 final String line = iter.next();
225 if (line.indexOf(
"Buffers.rangeCheck") >= 0) {
237 LOG.log(INFO,
"GL Ignored extensions: {0}", ignoredExtensions.size());
238 for (
final String str : ignoredExtensions) {
239 LOG.log(INFO,
"\t{0}", str);
241 LOG.log(INFO,
"GL Forced extensions: {0}", forcedExtensions.size());
242 for (
final String str : forcedExtensions) {
243 LOG.log(INFO,
"\t{0}", str);
250 LOG.log(INFO,
"GL Renamed extensions into core: {0}", renameExtensionsIntoCore.size());
251 for (
final String str : renameExtensionsIntoCore) {
252 LOG.log(INFO,
"\t{0}", str);
258 if( ignoredExtensions.contains(extensionName) ) {
259 return !forcedExtensions.contains(extensionName);
266 final Set<String> symExtensionNames;
269 final Set<String> s = glSemInfo.
getExtension(symbol.getName());
271 symExtensionNames = s;
273 symExtensionNames =
new HashSet<String>();
277 if( symbol.hasAliases() ) {
278 final Set<String> aliases = symbol.getAliasedNames();
279 for(
final String alias : aliases) {
281 if(
null != s && s.size() > 0 ) {
282 symExtensionNames.addAll(s);
286 boolean ignoreExtension = symExtensionNames.size() > 0 &&
287 ignoredExtensions.containsAll(symExtensionNames);
289 if( LOG.isLoggable(INFO) ) {
290 final Set<String> ignoredSymExtensionNames =
new HashSet<String>();
291 final Set<String> notIgnoredSymExtensionNames =
new HashSet<String>();
292 for(
final Iterator<String> i=symExtensionNames.iterator(); i.hasNext(); ) {
293 final String extensionName = i.next();
294 if (
null != extensionName && ignoredExtensions.contains(extensionName) ) {
295 ignoredSymExtensionNames.add(extensionName);
297 notIgnoredSymExtensionNames.add(extensionName);
300 if( ignoreExtension ) {
301 LOG.log(INFO, getASTLocusTag(symbol),
"Ignored symbol {0} of all extensions <{1}>", symbol, symExtensionNames);
302 }
else if( ignoredSymExtensionNames.size() > 0 ) {
303 LOG.log(INFO, getASTLocusTag(symbol),
"Not ignored symbol {0}; Ignored in <{1}>, but active in <{2}>",
304 symbol, ignoredSymExtensionNames, notIgnoredSymExtensionNames);
307 if( !ignoreExtension ) {
309 final String name = symbol.getName();
312 String extSuffix =
null;
313 if (isGLFunc || isGLEnum) {
317 LOG.log(INFO, getASTLocusTag(symbol),
"Ignore UniqVendorEXT: {0}, vendor {1}, isGLFunc {2}, isGLEnum {3}",
318 symbol, extSuffix, isGLFunc, isGLEnum);
319 ignoreExtension =
true;
323 if (!ignoreExtension) {
324 LOG.log(INFO, getASTLocusTag(symbol),
"Not ignored UniqVendorEXT: {0}, vendor {1}, isGLFunc {2}, isGLEnum {3}",
325 symbol, extSuffix, isGLFunc, isGLEnum);
328 if( ignoreExtension ) {
331 return ignoreExtension;
334 for(
final Iterator<String> i=symExtensionNames.iterator(); i.hasNext(); ) {
335 final String extensionName = i.next();
336 if ( extensionName !=
null && forcedExtensions.contains(extensionName) ) {
337 LOG.log(INFO, getASTLocusTag(symbol),
"Not ignored symbol {0} of extension <{1}>", symbol, extensionName);
376 return autoUnifyExtensions;
382 return allowNonGLExtensions;
387 return dropUniqVendorExtensions.contains(extName);
392 GLEmitter.BufferObjectKind getBufferObjectKind(
final AliasedSymbol symbol) {
393 final String name = symbol.getName();
394 final Set<String> aliases = symbol.getAliasedNames();
395 GLEmitter.BufferObjectKind res = bufferObjectKinds.get( name );
397 res = oneInMap(bufferObjectKinds, aliases);
403 return null != getBufferObjectKind(symbol);
407 return bufferObjectOnly.contains(name);
419 glSemInfo.
setDebug(GlueGen.debug());
420 if (!glSemHeaders.isEmpty()) {
421 for (
final String file : glSemHeaders) {
422 final String fullPath = controls.findHeaderFile(file);
423 if (fullPath ==
null) {
424 throw new IOException(
"Unable to locate header file \"" + file +
"\"");
426 glSemInfo.
parse(fullPath);
451 glDocInfo.
setDebug(GlueGen.debug());
452 if (!glDocHeaders.isEmpty()) {
453 for (
final String file : glDocHeaders) {
454 final String fullPath = controls.findHeaderFile(file);
455 if (fullPath ==
null) {
456 throw new IOException(
"Unable to locate header file \"" + file +
"\"");
458 glDocInfo.
parse(fullPath);
484 return javaDocRenamedSymbols.get(aliasedName);
495 super.addJavaSymbolRename(origName, newName);
505 LOG.log(INFO,
"\tDoc Rename {0} -> {1}", origName, newName);
506 final String prevValue = javaDocSymbolRenames.put(origName, newName);
507 if(
null != prevValue && !prevValue.equals(newName)) {
508 throw new RuntimeException(
"Doc-Rename-Override Attampt: "+origName+
" -> "+newName+
509 ", but "+origName+
" -> "+prevValue+
" already exist. Run in 'debug' mode to analyze!");
512 Set<String> origNames = javaDocRenamedSymbols.get(newName);
513 if(
null == origNames) {
514 origNames =
new HashSet<String>();
515 javaDocRenamedSymbols.put(newName, origNames);
517 origNames.add(origName);
525 return renameExtensionsIntoCore;
Builds the StaticGLInfo class from the OpenGL header files (i.e., gl.h and glext.h) whose paths were ...
void parse(final String[] cHeaderFilePaths)
Parses the supplied C header files and adds the function associations contained therein to the intern...
Set< String > getExtension(final String identifier)
void setDebug(final boolean v)
void parseGLDocHeaders(final GlueEmitterControls controls)
Parses any GL headers specified in the configuration file for the purpose of being able to ignore an ...
List< String > javaPrologueForMethod(final MethodBinding binding, final boolean forImplementingMethodCall, final boolean eraseBufferAndArrayTypes)
Overrides javaPrologueForMethod in superclass and automatically generates prologue code for functions...
BuildStaticGLInfo getGLDocInfo()
Returns the information about the association between #defines, function symbols and the OpenGL exten...
GLConfiguration(final GLEmitter emitter)
boolean isIgnoredExtension(final String extensionName)
boolean shouldIgnoreInImpl(final AliasedSymbol symbol)
void readBufferObjectKind(final StringTokenizer tok, final String filename, final int lineNo)
boolean shouldForceExtension(final AliasedSymbol symbol, final Set< String > symExtensionNames)
void parseGLSemHeaders(final GlueEmitterControls controls)
Parses any GL headers specified in the configuration file for the purpose of being able to ignore an ...
Set< String > getAliasedDocNames(final AliasedSymbol symbol)
void dispatch(final String cmd, final StringTokenizer tok, final File file, final String filename, final int lineNo)
Set< String > getRenamedJavaDocSymbols(final String aliasedName)
Returns a set of replaced javadoc names to the given aliasedName.
boolean getAutoUnifyExtensions()
Should we automatically ignore extensions that have already been fully subsumed into the OpenGL core ...
boolean isBufferObjectFunction(final AliasedSymbol symbol)
boolean isBufferObjectOnly(final String name)
void addJavaSymbolRename(final String origName, final String newName)
boolean shouldIgnoreExtension(final AliasedSymbol symbol)
boolean shouldIgnoreInInterface(final AliasedSymbol symbol)
void addJavaDocSymbolRename(final String origName, final String newName)
Adds a javadoc rename directive for the given symbol.
boolean getDropUniqVendorExtensions(final String extName)
shall the non unified (uniq) vendor extensions be dropped ?
Set< String > getExtensionsRenamedIntoCore()
Returns the OpenGL extensions that should have all of their constant definitions and functions rename...
boolean getAllowNonGLExtensions()
If true, accept all non encapsulated defines and functions, as it is mandatory for GL declarations.
BuildStaticGLInfo getGLSemInfo()
Returns the information about the association between #defines, function symbols and the OpenGL exten...
A subclass of ProcAddressEmitter with special OpenGL-specific configuration abilities.
boolean isBufferObjectMethodBinding(final MethodBinding binding)
Runtime utility identify and resolve extension names, which may be subsumed to core.
static final boolean isExtensionVEN(final String str, final boolean isGLFunc)
static final String getExtensionSuffix(final String str, final boolean isGLFunc)
static final boolean isGLFunction(final String str)
static final boolean isGLEnumeration(final String str)