diff options
author | Sven Gothel <[email protected]> | 2009-08-05 07:31:49 -0700 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2009-08-05 07:31:49 -0700 |
commit | ae26bd0aac4a98c26aceb95584988defae970dde (patch) | |
tree | c25739c22fb1774722737982aea0bed66ba11167 /src | |
parent | 48465d43cf58d98758639f4064cc5eb3ee86bee8 (diff) |
Cleanup for a better OpenGL 3.2 integration,
for subsuming extensions:
- Allow RenameExtensionIntoCore generate duplicate names,
ie those will not be generated.
- Add proper comment showing the extension of the symbol.
- Fail if no 'GLHeader' is specified, but we are processing a GL/ProcAddress config
- Fail if a GL function is not part of an extension
MethodBinding, ConstantDefinition cleanup:
- getName() returns the renamed name
- getOrigName() returns the original
- getAliasedNames() returns the aliased ones
MethodBinding:
- Change: equals() operates on renamed name
- Add: hashCode() function - same criteria as equals()
Impact:
- All config options etc shall trigger with the renamed name,
but ignore, rename etc.
- Generated Java impl. uses the renamed base name as well
Change: emitDefine() uses the ConstantDefinition
Add: JavaConfiguration: dumpRenames()
Change JavaConfiguration.shouldIgnoreInInterface/Impl():
- respect the renamed symbol name as well
Change JavaEmitter.emitFunctions():
- only emit a generated MethodBinding once,
therefor store emitted method bindings in a HashSet
Fix BuildStaticGLInfo:
- Allow white space at the end of #ifndef and #define
- Trim strings
- Allow 'const' qualifier in function pattern
Fix GLEmitter:
- Fail if no 'GLHeader' is specified, but a RenameIntoCore option ..
- Don't emit marker defines, marking an extension (ie not part of an extension)
Fix GLJavaMethodBindingEmitter:
- Fail if a GL function is not part of an extension
Fix PCPP:
- Pass constant type qualifiers for hex-constants: 'l' 'L' ...
Fix ProcAddressEmitter:
- Operate on the aliased/renamed name for querying ProcAddress usage
and generating code.
Diffstat (limited to 'src')
4 files changed, 110 insertions, 52 deletions
diff --git a/src/java/com/sun/gluegen/opengl/BuildStaticGLInfo.java b/src/java/com/sun/gluegen/opengl/BuildStaticGLInfo.java index 4226f4612..f5193dcdf 100644 --- a/src/java/com/sun/gluegen/opengl/BuildStaticGLInfo.java +++ b/src/java/com/sun/gluegen/opengl/BuildStaticGLInfo.java @@ -91,17 +91,23 @@ import java.util.regex.*; public class BuildStaticGLInfo { // Handles function pointer + protected static int funcIdentifierGroup = 9; protected static Pattern funcPattern = - Pattern.compile("^(GLAPI|GL_API|GL_APICALL|EGLAPI|extern)?(\\s*)(\\w+)(\\*)?(\\s+)(GLAPIENTRY|GL_APIENTRY|APIENTRY|EGLAPIENTRY|WINAPI)?(\\s*)([ew]?gl\\w+)\\s?(\\(.*)"); + Pattern.compile("^(GLAPI|GL_API|GL_APICALL|EGLAPI|extern)?(\\s*)(const\\s+)?(\\w+)(\\s*\\*)?(\\s+)(GLAPIENTRY|GL_APIENTRY|APIENTRY|EGLAPIENTRY|WINAPI)?(\\s*)([ew]?gl\\w+)\\s?(\\(.*)"); + protected static Pattern associationPattern = - Pattern.compile("\\#ifndef ([EW]?GL[X]?_[A-Za-z0-9_]+)"); + Pattern.compile("\\#ifndef ([EW]?GL[X]?_[A-Za-z0-9_]+)\\s*"); + + protected static int defineIdentifierGroup = 1; protected static Pattern definePattern = - Pattern.compile("\\#define ([EW]?GL[X]?_[A-Za-z0-9_]+)\\s*([A-Za-z0-9_]+)"); + Pattern.compile("\\#define ([EW]?GL[X]?_[A-Za-z0-9_]+)\\s*([A-Za-z0-9_]+)\\s*"); + // Maps function / #define names to the names of the extensions they're declared in protected Map declarationToExtensionMap = new HashMap(); // Maps extension names to Set of identifiers (both #defines and // function names) this extension declares protected Map/*<String, Set<String>*/ extensionToDeclarationMap = new HashMap(); + protected boolean debug = false; /** * The first argument is the package to which the StaticGLInfo class @@ -113,6 +119,7 @@ public class BuildStaticGLInfo { if (args.length > 0 && args[0].equals("-test")) { BuildStaticGLInfo builder = new BuildStaticGLInfo(); + builder.setDebug(true); String[] newArgs = new String[args.length - 1]; System.arraycopy(args, 1, newArgs, 0, args.length - 1); builder.parse(newArgs); @@ -157,6 +164,9 @@ public class BuildStaticGLInfo } } + public void setDebug(boolean v) { + debug = v; + } /** Parses the supplied C header files and adds the function associations contained therein to the internal map. */ @@ -173,14 +183,20 @@ public class BuildStaticGLInfo String line, activeAssociation = null; Matcher m = null; while ((line = reader.readLine()) != null) { + int type = 0; // 1-define, 2-function // see if we're inside a #ifndef GL_XXX block and matching a function if (activeAssociation != null) { String identifier = null; if ((m = funcPattern.matcher(line)).matches()) { - identifier = m.group(8); + identifier = m.group(funcIdentifierGroup).trim(); + type =2; } else if ((m = definePattern.matcher(line)).matches()) { - identifier = m.group(1); + identifier = m.group(defineIdentifierGroup).trim(); + type =1; } else if (line.startsWith("#endif")) { + if(debug) { + System.err.println("END ASSOCIATION BLOCK: <" + activeAssociation + ">"); + } activeAssociation = null; } if ((identifier != null) && @@ -188,13 +204,17 @@ public class BuildStaticGLInfo // Handles #ifndef GL_... #define GL_... !identifier.equals(activeAssociation)) { addAssociation(identifier, activeAssociation); - // System.err.println(" ADDING ASSOCIATION: " + identifier + " " + activeAssociation); + if(debug) { + System.err.println(" ADDING ASSOCIATION: <" + identifier + "> <" + activeAssociation + "> ; type "+type); + } } } else if ((m = associationPattern.matcher(line)).matches()) { // found a new #ifndef GL_XXX block - activeAssociation = m.group(1); + activeAssociation = m.group(1).trim(); - // System.err.println("FOUND NEW ASSOCIATION BLOCK: " + activeAssociation); + if(debug) { + System.err.println("BEGIN ASSOCIATION BLOCK: <" + activeAssociation + ">"); + } } } reader.close(); @@ -204,12 +224,12 @@ public class BuildStaticGLInfo for (Iterator i1 = extensionToDeclarationMap.keySet().iterator(); i1.hasNext(); ) { String name = (String) i1.next(); Set decls = (Set) extensionToDeclarationMap.get(name); - System.out.println(name + ":"); + System.out.println("<"+name+"> :"); List l = new ArrayList(); l.addAll(decls); Collections.sort(l); for (Iterator i2 = l.iterator(); i2.hasNext(); ) { - System.out.println(" " + (String) i2.next()); + System.out.println(" <" + (String) i2.next() + ">"); } } } diff --git a/src/java/com/sun/gluegen/opengl/GLConfiguration.java b/src/java/com/sun/gluegen/opengl/GLConfiguration.java index 923dcf52d..4e8c0c369 100755 --- a/src/java/com/sun/gluegen/opengl/GLConfiguration.java +++ b/src/java/com/sun/gluegen/opengl/GLConfiguration.java @@ -202,13 +202,6 @@ public class GLConfiguration extends ProcAddressConfiguration { super.dumpIgnores(); } - protected String getExtension(String symbol) { - if (glInfo != null) { - return glInfo.getExtension(symbol); - } - return null; - } - protected boolean shouldIgnoreExtension(String symbol, boolean criteria) { if (criteria && glInfo != null) { String extension = glInfo.getExtension(symbol); @@ -216,14 +209,14 @@ public class GLConfiguration extends ProcAddressConfiguration { ignoredExtensions.contains(extension)) { return true; } - boolean isGLFunc = GLExtensionNames.isGLFunction(symbol); boolean isGLEnum = GLExtensionNames.isGLEnumeration(symbol); + boolean isGLFunc = GLExtensionNames.isGLFunction(symbol); if(isGLFunc || isGLEnum) { if(GLExtensionNames.isExtensionVEN(symbol, isGLFunc)) { String extSuffix = GLExtensionNames.getExtensionSuffix(symbol, isGLFunc); if( getDropUniqVendorExtensions(extSuffix) ) { if(DEBUG_IGNORES) { - System.err.println("Ignore UniqVendorEXT: "+symbol); + System.err.println("Ignore UniqVendorEXT: "+symbol+", vendor "+extSuffix); } return true; } diff --git a/src/java/com/sun/gluegen/opengl/GLEmitter.java b/src/java/com/sun/gluegen/opengl/GLEmitter.java index 83e688eec..9e3202658 100644 --- a/src/java/com/sun/gluegen/opengl/GLEmitter.java +++ b/src/java/com/sun/gluegen/opengl/GLEmitter.java @@ -85,9 +85,15 @@ public class GLEmitter extends ProcAddressEmitter // renaming mechanisms that are built elsewhere. GLConfiguration config = getGLConfig(); + Set extensionsRenamedIntoCore = config.getExtensionsRenamedIntoCore(); BuildStaticGLInfo glInfo = config.getGLInfo(); - for (Iterator iter = config.getExtensionsRenamedIntoCore().iterator(); - iter.hasNext(); ) { + if(null==glInfo) { + if(extensionsRenamedIntoCore.size()>0) { + throw new RuntimeException("ExtensionRenamedIntoCore (num: "+extensionsRenamedIntoCore.size()+"), but no GLHeader"); + } + return; + } + for (Iterator iter = extensionsRenamedIntoCore.iterator(); iter.hasNext(); ) { String extension = (String) iter.next(); Set/*<String>*/ declarations = glInfo.getDeclarations(extension); if (declarations != null) { @@ -305,19 +311,68 @@ public class GLEmitter extends ProcAddressEmitter return bufferObjectMethodBindings.containsKey(binding); } - public void emitDefine(String name, String value, String optionalComment) throws Exception { - String extensionName = getGLConfig().getExtension(name); + public void emitDefine(ConstantDefinition def, String optionalComment) throws Exception { + BuildStaticGLInfo glInfo = getGLConfig().getGLInfo(); + if(null==glInfo) { + throw new Exception("No GLInfo for: "+def); + } + String symbolRenamed = def.getName(); StringBuffer newComment = new StringBuffer(); - if(null!=extensionName) { - newComment.append("Part of <code>"+extensionName+"</code>"); - } else { - newComment.append("Part of <code>unknown extension</code>"); + newComment.append("Part of <code>"); + if(0==addExtensionsOfSymbols2Buffer(newComment, ", ", symbolRenamed, def.getAliasedNames())) { + // Note: All GL enums must be contained within an extension marker ! + // #ifndef GL_EXT_lala + // #define GL_EXT_lala 1 + // ... + // #endif + if(JavaConfiguration.DEBUG_IGNORES) { + StringBuffer sb = new StringBuffer(); + JavaEmitter.addStrings2Buffer(sb, ", ", symbolRenamed, def.getAliasedNames()); + System.err.println("Dropping marker: "+sb.toString()); + } + return; } + newComment.append("</code>"); + if(null!=optionalComment) { newComment.append(" "); newComment.append(optionalComment); } - super.emitDefine(name, value, newComment.toString()); + + super.emitDefine(def, newComment.toString()); + } + + public int addExtensionsOfSymbols2Buffer(StringBuffer buf, String sep, String first, Collection col) { + BuildStaticGLInfo glInfo = getGLConfig().getGLInfo(); + if(null==glInfo) { + throw new RuntimeException("No GLInfo for: "+first); + } + int num = 0; + if(null==buf) buf=new StringBuffer(); + String extensionName; + + Iterator iter=col.iterator(); + if(null!=first) { + extensionName = glInfo.getExtension(first); + if(null!=extensionName) { + buf.append(extensionName); + if( iter.hasNext() ) { + buf.append(sep); + } + num++; + } + } + while( iter.hasNext() ) { + extensionName = glInfo.getExtension((String)iter.next()); + if(null!=extensionName) { + buf.append(extensionName); + if( iter.hasNext() ) { + buf.append(sep); + } + num++; + } + } + return num; } //---------------------------------------------------------------------- @@ -399,23 +454,4 @@ public class GLEmitter extends ProcAddressEmitter w.flush(); w.close(); } - - protected void emitProcAddressTableEntryForSymbol(FunctionSymbol cFunc) - { - emitProcAddressTableEntryForString(cFunc.getName()); - } - - protected void emitProcAddressTableEntryForString(String str) - { - // Deal gracefully with forced proc address generation in the face - // of having the function pointer typedef in the header file too - if (emittedTableEntries.contains(str)) - return; - emittedTableEntries.add(str); - tableWriter.print(" public long "); - tableWriter.print(PROCADDRESS_VAR_PREFIX); - tableWriter.print(str); - tableWriter.println(";"); - } - } diff --git a/src/java/com/sun/gluegen/opengl/GLJavaMethodBindingEmitter.java b/src/java/com/sun/gluegen/opengl/GLJavaMethodBindingEmitter.java index b952272f3..5e8bada0d 100755 --- a/src/java/com/sun/gluegen/opengl/GLJavaMethodBindingEmitter.java +++ b/src/java/com/sun/gluegen/opengl/GLJavaMethodBindingEmitter.java @@ -109,12 +109,21 @@ public class GLJavaMethodBindingEmitter extends ProcAddressJavaMethodBindingEmit { protected void emitBindingCSignature(MethodBinding binding, PrintWriter writer) { super.emitBindingCSignature(binding, writer); - String extensionName = glEmitter.getGLConfig().getExtension(binding.getCSymbol().getName()); - if(null!=extensionName) { - writer.print("<br>Part of <code>"+extensionName+"</code>"); - } else { - writer.print("<br>Part of <code>unknown extension</code>"); + + String symbolRenamed = binding.getName(); + StringBuffer newComment = new StringBuffer(); + newComment.append("Part of <code>"); + if(0==glEmitter.addExtensionsOfSymbols2Buffer(newComment, ", ", symbolRenamed, binding.getAliasedNames())) { + StringBuffer sb = new StringBuffer(); + JavaEmitter.addStrings2Buffer(sb, ", ", symbolRenamed, binding.getAliasedNames()); + RuntimeException ex = new RuntimeException("Couldn't find extension to: "+binding+" ; "+sb.toString()); + ex.printStackTrace(); + glEmitter.getGLConfig().getGLInfo().dump(); + // glEmitter.getGLConfig().dumpRenames(); + throw ex; } + newComment.append("</code>"); + writer.print(newComment.toString()); } } } |