GLAutoGen updates

* Remove caps generation since it is no longer used by LWJGL renderer
 * Generate a separate interface GLExt for features only available in extensions to more easily detect their usage
 * Fix some extension references
experimental
shadowislord 10 years ago
parent ae70667104
commit d7b3cfe287
  1. 150
      jme3-gl-autogen/src/main/java/jme3tools/autogen/GLAutoGen.java

@ -11,26 +11,21 @@ import java.lang.reflect.Modifier;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.lwjgl.opengl.ARBDepthBufferFloat; import org.lwjgl.opengl.ARBDepthBufferFloat;
import org.lwjgl.opengl.ARBDrawInstanced; import org.lwjgl.opengl.ARBDrawInstanced;
import org.lwjgl.opengl.ARBGeometryShader4; import org.lwjgl.opengl.ARBES3Compatibility;
import org.lwjgl.opengl.ARBHalfFloatPixel; import org.lwjgl.opengl.ARBHalfFloatPixel;
import org.lwjgl.opengl.ARBInstancedArrays; import org.lwjgl.opengl.ARBInstancedArrays;
import org.lwjgl.opengl.ARBMultisample; import org.lwjgl.opengl.ARBMultisample;
import org.lwjgl.opengl.ARBTextureFloat; import org.lwjgl.opengl.ARBTextureFloat;
import org.lwjgl.opengl.ARBTextureMultisample; import org.lwjgl.opengl.ARBTextureMultisample;
import org.lwjgl.opengl.ARBVertexArrayObject; import org.lwjgl.opengl.ARBVertexArrayObject;
import org.lwjgl.opengl.ContextCapabilities;
import org.lwjgl.opengl.EXTFramebufferBlit; import org.lwjgl.opengl.EXTFramebufferBlit;
import org.lwjgl.opengl.EXTFramebufferMultisample; import org.lwjgl.opengl.EXTFramebufferMultisample;
import org.lwjgl.opengl.EXTFramebufferObject; import org.lwjgl.opengl.EXTFramebufferObject;
import org.lwjgl.opengl.EXTFramebufferSRGB; import org.lwjgl.opengl.EXTFramebufferSRGB;
import org.lwjgl.opengl.EXTGpuShader4;
import org.lwjgl.opengl.EXTPackedDepthStencil; import org.lwjgl.opengl.EXTPackedDepthStencil;
import org.lwjgl.opengl.EXTPackedFloat; import org.lwjgl.opengl.EXTPackedFloat;
import org.lwjgl.opengl.EXTTextureArray; import org.lwjgl.opengl.EXTTextureArray;
@ -45,6 +40,7 @@ import org.lwjgl.opengl.GL13;
import org.lwjgl.opengl.GL14; import org.lwjgl.opengl.GL14;
import org.lwjgl.opengl.GL15; import org.lwjgl.opengl.GL15;
import org.lwjgl.opengl.GL20; import org.lwjgl.opengl.GL20;
import org.lwjgl.opengl.GL30;
public class GLAutoGen { public class GLAutoGen {
@ -100,25 +96,8 @@ public class GLAutoGen {
private static final HashMap<String, List<MethodInfo>> methodMap private static final HashMap<String, List<MethodInfo>> methodMap
= new HashMap<String, List<MethodInfo>>(); = new HashMap<String, List<MethodInfo>>();
private static final HashSet<String> capsSet
= new HashSet<String>();
private static final TreeSet<String> usedConstants = new TreeSet<String>(); private static final TreeSet<String> usedConstants = new TreeSet<String>();
private static final TreeSet<String> usedMethods = new TreeSet<String>(); private static final TreeSet<String> usedMethods = new TreeSet<String>();
private static final TreeSet<String> usedCaps = new TreeSet<String>();
private static void scanCapsFromType(Class<?> clazz) {
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
if ((field.getModifiers() & (Modifier.STATIC | Modifier.PUBLIC)) != 0) {
String name = field.getName();
Class<?> type = field.getType();
if (type == boolean.class) {
capsSet.add(name);
}
}
}
}
private static void scanConstantsFromType(Class<?> clazz) { private static void scanConstantsFromType(Class<?> clazz) {
Field[] fields = clazz.getDeclaredFields(); Field[] fields = clazz.getDeclaredFields();
@ -181,8 +160,7 @@ public class GLAutoGen {
} }
private static String scanConstants(String line, private static String scanConstants(String line,
Collection<String> consts, Collection<String> consts) {
Collection<String> caps) {
String modifiedLine = line; String modifiedLine = line;
int next_gl = modifiedLine.indexOf("GL_"); int next_gl = modifiedLine.indexOf("GL_");
while (next_gl > 0) { while (next_gl > 0) {
@ -198,18 +176,23 @@ public class GLAutoGen {
for (int scan_idx = next_gl + 3; scan_idx < modifiedLine.length(); scan_idx++) { for (int scan_idx = next_gl + 3; scan_idx < modifiedLine.length(); scan_idx++) {
char chrCall = modifiedLine.charAt(scan_idx); char chrCall = modifiedLine.charAt(scan_idx);
if (Character.isLowerCase(chrCall)) { if (Character.isLowerCase(chrCall)) {
// GL constants cannot have lowercase letters.
// This is most likely capability type.
isCap = true; isCap = true;
} else if (!Character.isLetterOrDigit(chrCall) && chrCall != '_') { } else if (!Character.isLetterOrDigit(chrCall) && chrCall != '_') {
if (isCap) { if (!isCap) {
caps.add(modifiedLine.substring(next_gl, scan_idx)); String constant = modifiedLine.substring(next_gl, scan_idx);
} else {
consts.add(modifiedLine.substring(next_gl, scan_idx)); consts.add(constant);
ConstantInfo info = (ConstantInfo) constantMap.get(constant);
String className = "GL";
if (!info.declaringClazz.getSimpleName().startsWith("GL")) {
className = "EX";
}
// Also perform in-line injection. // Also perform in-line injection.
modifiedLine = modifiedLine.substring(0, next_gl) modifiedLine = modifiedLine.substring(0, next_gl)
+ "GL." + className + "."
+ modifiedLine.substring(next_gl); + modifiedLine.substring(next_gl);
} }
break; break;
@ -238,9 +221,16 @@ public class GLAutoGen {
String methodName = line.substring(next_gl, scan_idx); String methodName = line.substring(next_gl, scan_idx);
methods.add(methodName); methods.add(methodName);
MethodInfo info = (MethodInfo) methodMap.get(methodName).get(0);
String memberName = "gl";
if (!info.declaringClazz.getSimpleName().startsWith("GL")) {
memberName = "glext";
}
// Also perform in-line injection. // Also perform in-line injection.
modifiedLine = modifiedLine.substring(0, next_gl) + modifiedLine = modifiedLine.substring(0, next_gl) +
"gl." + memberName + "." +
modifiedLine.substring(next_gl); modifiedLine.substring(next_gl);
break; break;
@ -260,7 +250,6 @@ public class GLAutoGen {
FileReader reader = null; FileReader reader = null;
List<String> methods = new ArrayList<String>(); List<String> methods = new ArrayList<String>();
List<String> consts = new ArrayList<String>(); List<String> consts = new ArrayList<String>();
List<String> caps = new ArrayList<String>();
try { try {
reader = new FileReader(path); reader = new FileReader(path);
BufferedReader br = new BufferedReader(reader); BufferedReader br = new BufferedReader(reader);
@ -270,13 +259,12 @@ public class GLAutoGen {
break; break;
} }
line = scanMethods(line, methods); line = scanMethods(line, methods);
line = scanConstants(line, consts, caps); line = scanConstants(line, consts);
sb.append(line).append("\n"); sb.append(line).append("\n");
} }
usedMethods.addAll(methods); usedMethods.addAll(methods);
usedConstants.addAll(consts); usedConstants.addAll(consts);
usedCaps.addAll(caps);
return sb.toString(); return sb.toString();
} catch (IOException ex) { } catch (IOException ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
@ -290,32 +278,7 @@ public class GLAutoGen {
} }
} }
private static void addOpenGLCap(String glCap) { private static String exportGL(boolean forExt) {
usedCaps.add(glCap);
capsSet.add(glCap);
}
private static String exportGLCaps() {
StringBuilder sb = new StringBuilder();
sb.append("package jme3tools.autogen;\n");
sb.append("\n");
sb.append("public final class GLCaps {\n");
sb.append("\n");
sb.append("\tprivate GLCaps () { }\n");
sb.append("\n");
for (String cap : usedCaps) {
if (capsSet.contains(cap)) {
sb.append("\tpublic boolean ").append(cap).append(";\n");
} else {
throw new IllegalStateException("Cannot find required cap: " + cap);
}
}
sb.append("\n");
sb.append("}\n");
return sb.toString();
}
private static String exportGL() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("package jme3tools.autogen;\n"); sb.append("package jme3tools.autogen;\n");
sb.append("\n"); sb.append("\n");
@ -328,15 +291,21 @@ public class GLAutoGen {
sb.append("/**\n"); sb.append("/**\n");
sb.append(" * Auto-generated interface\n"); sb.append(" * Auto-generated interface\n");
sb.append(" */\n"); sb.append(" */\n");
sb.append("public interface GL {\n"); sb.append("public interface ").append(forExt ? "GLExt" : "GL").append(" {\n");
sb.append("\n"); sb.append("\n");
sb.append("// -- begin constants\n"); sb.append("// -- begin constants\n");
for (String constant : usedConstants) { for (String constant : usedConstants) {
ConstantInfo info = constantMap.get(constant); ConstantInfo info = constantMap.get(constant);
if (info == null) { if (info == null) {
throw new IllegalStateException("Cannot find required constant: " + constant); throw new IllegalStateException("Cannot find required constant: " + constant);
} }
boolean isExtConst = !info.declaringClazz.getSimpleName().startsWith("GL");
if (forExt != isExtConst) {
continue;
}
String typeStr = info.constantType.toString(); String typeStr = info.constantType.toString();
String valueStr = null; String valueStr = null;
@ -361,6 +330,11 @@ public class GLAutoGen {
} }
for (MethodInfo info : infos) { for (MethodInfo info : infos) {
boolean isExtConst = !info.declaringClazz.getSimpleName().startsWith("GL");
if (forExt != isExtConst) {
continue;
}
String retTypeStr = info.returnType.getSimpleName(); String retTypeStr = info.returnType.getSimpleName();
sb.append("\tpublic ").append(retTypeStr).append(" ").append(method).append("("); sb.append("\tpublic ").append(retTypeStr).append(" ").append(method).append("(");
for (int i = 0; i < info.paramTypes.length; i++) { for (int i = 0; i < info.paramTypes.length; i++) {
@ -374,9 +348,6 @@ public class GLAutoGen {
} }
sb.append("// -- end methods\n"); sb.append("// -- end methods\n");
sb.append("// -- begin custom methods\n");
sb.append("\tpublic GLCaps getGLCaps();\n");
sb.append("// -- end custom methods\n");
sb.append("\n"); sb.append("\n");
sb.append("}\n"); sb.append("}\n");
return sb.toString(); return sb.toString();
@ -406,52 +377,49 @@ public class GLAutoGen {
File rendererSrc = new File(rendererPath).getAbsoluteFile(); File rendererSrc = new File(rendererPath).getAbsoluteFile();
File textureUtilSrc = new File(textureUtilPath).getAbsoluteFile(); File textureUtilSrc = new File(textureUtilPath).getAbsoluteFile();
addOpenGLCap("OpenGL21");
addOpenGLCap("OpenGL30");
addOpenGLCap("OpenGL30");
addOpenGLCap("OpenGL31");
addOpenGLCap("OpenGL32");
addOpenGLCap("OpenGL33");
scanGLType(GL11.class); scanGLType(GL11.class);
scanGLType(GL14.class); scanGLType(GL14.class);
scanGLType(GL12.class); scanGLType(GL12.class);
scanGLType(GL13.class); scanGLType(GL13.class);
scanGLType(GL15.class); scanGLType(GL15.class);
scanGLType(GL20.class); scanGLType(GL20.class);
scanGLType(ARBGeometryShader4.class); scanGLType(GL30.class);
scanGLType(EXTFramebufferObject.class);
scanGLType(EXTFramebufferBlit.class); // Renderer extensions
scanGLType(EXTFramebufferMultisample.class);
scanGLType(ARBTextureMultisample.class);
scanGLType(ARBMultisample.class);
scanGLType(EXTTextureArray.class);
scanGLType(EXTTextureFilterAnisotropic.class);
scanGLType(ARBDrawInstanced.class); scanGLType(ARBDrawInstanced.class);
scanGLType(ARBInstancedArrays.class); scanGLType(ARBInstancedArrays.class);
scanGLType(ARBMultisample.class);
scanGLType(ARBTextureMultisample.class);
scanGLType(ARBVertexArrayObject.class); scanGLType(ARBVertexArrayObject.class);
scanGLType(EXTFramebufferBlit.class);
scanGLType(EXTFramebufferMultisample.class);
scanGLType(EXTFramebufferObject.class);
scanGLType(EXTFramebufferSRGB.class); scanGLType(EXTFramebufferSRGB.class);
scanGLType(EXTGpuShader4.class); scanGLType(EXTTextureArray.class);
scanGLType(EXTTextureCompressionLATC.class); scanGLType(EXTTextureFilterAnisotropic.class);
scanGLType(EXTTextureCompressionS3TC.class);
scanGLType(EXTTextureSRGB.class); // Texture extensions
scanGLType(EXTTextureSharedExponent.class);
scanGLType(ARBDepthBufferFloat.class); scanGLType(ARBDepthBufferFloat.class);
scanGLType(ARBES3Compatibility.class);
scanGLType(ARBHalfFloatPixel.class); scanGLType(ARBHalfFloatPixel.class);
scanGLType(ARBTextureFloat.class); scanGLType(ARBTextureFloat.class);
scanGLType(ARBTextureMultisample.class);
scanGLType(EXTPackedDepthStencil.class); scanGLType(EXTPackedDepthStencil.class);
scanGLType(EXTPackedFloat.class); scanGLType(EXTPackedFloat.class);
scanGLType(EXTTextureArray.class);
scanCapsFromType(ContextCapabilities.class); scanGLType(EXTTextureCompressionLATC.class);
scanGLType(EXTTextureCompressionS3TC.class);
scanGLType(EXTTextureSRGB.class);
scanGLType(EXTTextureSharedExponent.class);
String processedRenderer = scanFile(rendererSrc.toString()); String processedRenderer = scanFile(rendererSrc.toString());
String processedTextureUtil = scanFile(textureUtilSrc.toString()); String processedTextureUtil = scanFile(textureUtilSrc.toString());
String glCaps = exportGLCaps(); String gl = exportGL(false);
String gl = exportGL(); String glext = exportGL(true);
//writeFile("src/main/java/jme3tools/autogen/GLRenderer.java", processedRenderer); //writeFile("src/main/java/jme3tools/autogen/GLRenderer.java", processedRenderer);
//writeFile("src/main/java/jme3tools/autogen/TextureUtil.java", processedTextureUtil); //writeFile("src/main/java/jme3tools/autogen/TextureUtil.java", processedTextureUtil);
//writeFile("src/main/java/jme3tools/autogen/GL.java", gl); //writeFile("src/main/java/jme3tools/autogen/GL.java", gl);
//writeFile("src/main/java/jme3tools/autogen/GLCaps.java", glCaps); //writeFile("src/main/java/jme3tools/autogen/GLExt.java", glext);
} }
} }

Loading…
Cancel
Save