aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/java/com/sun/gluegen/opengl/BuildComposablePipeline.java567
-rw-r--r--src/java/com/sun/gluegen/opengl/BuildStaticGLInfo.java320
-rwxr-xr-xsrc/java/com/sun/gluegen/opengl/GLConfiguration.java198
-rw-r--r--src/java/com/sun/gluegen/opengl/GLEmitter.java179
-rwxr-xr-xsrc/java/com/sun/gluegen/opengl/GLJavaMethodBindingEmitter.java95
5 files changed, 1359 insertions, 0 deletions
diff --git a/src/java/com/sun/gluegen/opengl/BuildComposablePipeline.java b/src/java/com/sun/gluegen/opengl/BuildComposablePipeline.java
new file mode 100644
index 000000000..5235631be
--- /dev/null
+++ b/src/java/com/sun/gluegen/opengl/BuildComposablePipeline.java
@@ -0,0 +1,567 @@
+/*
+ * Copyright (c) 2003 Sun Microsystems, Inc. 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.sun.gluegen.opengl;
+
+import com.sun.gluegen.*;
+
+import java.lang.reflect.*;
+import java.io.*;
+import java.util.*;
+import java.util.regex.*;
+
+public class BuildComposablePipeline
+{
+ private String outputDirectory;
+ private Class classToComposeAround;
+
+ public static void main(String[] args)
+ {
+ String nameOfClassToComposeAround = args[0];
+ Class classToComposeAround;
+ try {
+ classToComposeAround = Class.forName(nameOfClassToComposeAround);
+ } catch (Exception e) {
+ throw new RuntimeException(
+ "Could not find class \"" + nameOfClassToComposeAround + "\"", e);
+ }
+
+ String outputDir = args[1];
+
+ BuildComposablePipeline composer =
+ new BuildComposablePipeline(classToComposeAround, outputDir);
+
+ try
+ {
+ composer.emit();
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(
+ "Error generating composable pipeline source files", e);
+ }
+ }
+
+ protected BuildComposablePipeline(Class classToComposeAround, String outputDirectory)
+ {
+ this.outputDirectory = outputDirectory;
+ this.classToComposeAround = classToComposeAround;
+
+ if (! classToComposeAround.isInterface())
+ {
+ throw new IllegalArgumentException(
+ classToComposeAround.getName() + " is not an interface class");
+ }
+ }
+
+ /**
+ * Emit the java source code for the classes that comprise the composable
+ * pipeline.
+ */
+ public void emit() throws IOException
+ {
+ String pDir = outputDirectory;
+ String pInterface = classToComposeAround.getName();
+ List/*<Method>*/ publicMethods = Arrays.asList(classToComposeAround.getMethods());
+
+ (new DebugPipeline(pDir, pInterface)).emit(publicMethods);
+ (new TracePipeline(pDir, pInterface)).emit(publicMethods);
+ }
+
+ //-------------------------------------------------------
+
+ /**
+ * Emits a Java source file that represents one element of the composable
+ * pipeline.
+ */
+ protected static abstract class PipelineEmitter
+ {
+ private File file;
+ private String basePackage;
+ private String baseName; // does not include package!
+ private String outputDir;
+
+ /**
+ * @param outputDir the directory into which the pipeline classes will be
+ * generated.
+ * @param baseInterfaceClassName the full class name (including package,
+ * e.g. "java.lang.String") of the interface that the pipeline wraps
+ * @exception IllegalArgumentException if classToComposeAround is not an
+ * interface.
+ */
+ public PipelineEmitter(String outputDir, String baseInterfaceClassName)
+ {
+ int lastDot = baseInterfaceClassName.lastIndexOf('.');
+ if (lastDot == -1)
+ {
+ // no package, class is at root level
+ this.baseName = baseInterfaceClassName;
+ this.basePackage = null;
+ }
+ else
+ {
+ this.baseName = baseInterfaceClassName.substring(lastDot+1);
+ this.basePackage = baseInterfaceClassName.substring(0, lastDot);
+ }
+
+ this.outputDir = outputDir;
+ }
+
+ public void emit(List/*<Method>*/ methodsToWrap) throws IOException
+ {
+ String pipelineClassName = getPipelineName();
+ this.file = new File(outputDir + File.separatorChar + pipelineClassName + ".java");
+ String parentDir = file.getParent();
+ if (parentDir != null)
+ {
+ File pDirFile = new File(parentDir);
+ pDirFile.mkdirs();
+ }
+
+ PrintWriter output = new PrintWriter(new BufferedWriter(new FileWriter(file)));
+
+ CodeGenUtils.emitJavaHeaders(output,
+ basePackage,
+ pipelineClassName,
+ true,
+ new String[] { "java.io.*" },
+ new String[] { "public" },
+ new String[] { baseName },
+ null,
+ new CodeGenUtils.EmissionCallback() {
+ public void emit(PrintWriter w) { emitClassDocComment(w); }
+ }
+ );
+
+ preMethodEmissionHook(output);
+
+ constructorHook(output);
+
+ for (int i = 0; i < methodsToWrap.size(); ++i)
+ {
+ Method m = (Method)methodsToWrap.get(i);
+ emitMethodDocComment(output, m);
+ emitSignature(output, m);
+ emitBody(output, m);
+ }
+
+ postMethodEmissionHook(output);
+
+ output.println();
+ output.print(" private " + baseName + " " + getDownstreamObjectName() + ";");
+
+ // end the class
+ output.println();
+ output.print("} // end class ");
+ output.println(pipelineClassName);
+
+ output.flush();
+ output.close();
+ }
+
+ /** Get the name of the object through which API calls should be routed. */
+ protected String getDownstreamObjectName()
+ {
+ return "downstream" + baseName;
+ }
+
+ protected void emitMethodDocComment(PrintWriter output, Method m)
+ {
+ }
+
+ protected void emitSignature(PrintWriter output, Method m)
+ {
+ output.print(" public ");
+ output.print(' ');
+ output.print(JavaType.createForClass(m.getReturnType()).getName());
+ output.print(' ');
+ output.print(m.getName());
+ output.print('(');
+ output.print(getArgListAsString(m, true, true));
+ output.println(")");
+ }
+
+ protected void emitBody(PrintWriter output, Method m)
+ {
+ output.println(" {");
+ output.print(" ");
+ Class retType = m.getReturnType();
+
+ preDownstreamCallHook(output, m);
+
+ if (retType != Void.TYPE)
+ {
+ output.print(JavaType.createForClass(retType).getName());
+ output.print(" _res = ");
+ }
+ output.print(getDownstreamObjectName());
+ output.print('.');
+ output.print(m.getName());
+ output.print('(');
+ output.print(getArgListAsString(m, false, true));
+ output.println(");");
+
+ postDownstreamCallHook(output, m);
+
+ if (retType != Void.TYPE)
+ {
+ output.println(" return _res;");
+ }
+ output.println(" }");
+
+ }
+
+ private String getArgListAsString(Method m, boolean includeArgTypes, boolean includeArgNames)
+ {
+ StringBuffer buf = new StringBuffer(256);
+ if (!includeArgNames && !includeArgTypes)
+ {
+ throw new IllegalArgumentException(
+ "Cannot generate arglist without both arg types and arg names");
+ }
+
+ Class[] argTypes = m.getParameterTypes();
+ for (int i = 0; i < argTypes.length; ++i)
+ {
+ if (includeArgTypes)
+ {
+ buf.append(JavaType.createForClass(argTypes[i]).getName());
+ buf.append(' ');
+ }
+
+ if (includeArgNames)
+ {
+ buf.append("arg");
+ buf.append(i);
+ }
+ if (i < argTypes.length-1) { buf.append(','); }
+ }
+
+ return buf.toString();
+ }
+
+ /** The name of the class around which this pipeline is being
+ * composed. E.g., if this pipeline was constructed with
+ * "java.util.Set" as the baseInterfaceClassName, then this method will
+ * return "Set".
+ */
+ protected String getBaseInterfaceName()
+ {
+ return baseName;
+ }
+
+ /** Get the name for this pipeline class. */
+ protected abstract String getPipelineName();
+
+ /**
+ * Called after the class headers have been generated, but before any
+ * method wrappers have been generated.
+ */
+ protected abstract void preMethodEmissionHook(PrintWriter output);
+
+ /**
+ * Emits the constructor for the pipeline; called after the preMethodEmissionHook.
+ */
+ protected void constructorHook(PrintWriter output) {
+ output.print( " public " + getPipelineName() + "(" + baseName + " ");
+ output.println(getDownstreamObjectName() + ")");
+ output.println(" {");
+ output.println(" if (" + getDownstreamObjectName() + " == null) {");
+ output.println(" throw new IllegalArgumentException(\"null " + getDownstreamObjectName() + "\");");
+ output.println(" }");
+ output.print( " this." + getDownstreamObjectName());
+ output.println(" = " + getDownstreamObjectName() + ";");
+ output.println(" }");
+ output.println();
+ }
+
+ /**
+ * Called after the method wrappers have been generated, but before the
+ * closing parenthesis of the class is emitted.
+ */
+ protected abstract void postMethodEmissionHook(PrintWriter output);
+
+ /**
+ * Called before the pipeline routes the call to the downstream object.
+ */
+ protected abstract void preDownstreamCallHook(PrintWriter output, Method m);
+
+ /**
+ * Called after the pipeline has routed the call to the downstream object,
+ * but before the calling function exits or returns a value.
+ */
+ protected abstract void postDownstreamCallHook(PrintWriter output, Method m);
+
+ /** Emit a Javadoc comment for this pipeline class. */
+ protected abstract void emitClassDocComment(PrintWriter output);
+
+ } // end class PipelineEmitter
+
+ //-------------------------------------------------------
+
+ protected class DebugPipeline extends PipelineEmitter
+ {
+ String className;
+ String baseInterfaceClassName;
+ public DebugPipeline(String outputDir, String baseInterfaceClassName)
+ {
+ super(outputDir, baseInterfaceClassName);
+ className = "Debug" + getBaseInterfaceName();
+ }
+
+ protected String getPipelineName()
+ {
+ return className;
+ }
+
+ protected void preMethodEmissionHook(PrintWriter output)
+ {
+ }
+
+ protected void postMethodEmissionHook(PrintWriter output)
+ {
+ output.println(" private void checkGLGetError(String caller)");
+ output.println(" {");
+ output.println(" if (insideBeginEndPair) {");
+ output.println(" return;");
+ output.println(" }");
+ output.println();
+ output.println(" // Debug code to make sure the pipeline is working; leave commented out unless testing this class");
+ output.println(" //System.err.println(\"Checking for GL errors " +
+ "after call to \" + caller + \"()\");");
+ output.println();
+ output.println(" int err = " +
+ getDownstreamObjectName() +
+ ".glGetError();");
+ output.println(" if (err == GL_NO_ERROR) { return; }");
+ output.println();
+ output.println(" StringBuffer buf = new StringBuffer(");
+ output.println(" \"glGetError() returned the following error codes " +
+ "after a call to \" + caller + \"(): \");");
+ output.println();
+ output.println(" // Loop repeatedly to allow for distributed GL implementations,");
+ output.println(" // as detailed in the glGetError() specification");
+ output.println(" int recursionDepth = 10;");
+ output.println(" do {");
+ output.println(" switch (err) {");
+ output.println(" case GL_INVALID_ENUM: buf.append(\"GL_INVALID_ENUM \"); break;");
+ output.println(" case GL_INVALID_VALUE: buf.append(\"GL_INVALID_VALUE \"); break;");
+ output.println(" case GL_INVALID_OPERATION: buf.append(\"GL_INVALID_OPERATION \"); break;");
+ output.println(" case GL_STACK_OVERFLOW: buf.append(\"GL_STACK_OVERFLOW \"); break;");
+ output.println(" case GL_STACK_UNDERFLOW: buf.append(\"GL_STACK_UNDERFLOW \"); break;");
+ output.println(" case GL_OUT_OF_MEMORY: buf.append(\"GL_OUT_OF_MEMORY \"); break;");
+ output.println(" case GL_NO_ERROR: throw new InternalError(\"Should not be treating GL_NO_ERROR as error\");");
+ output.println(" default: throw new InternalError(\"Unknown glGetError() return value: \" + err);");
+ output.println(" }");
+ output.println(" } while ((--recursionDepth >= 0) && (err = " +
+ getDownstreamObjectName() +
+ ".glGetError()) != GL_NO_ERROR);");
+ output.println(" throw new GLException(buf.toString());");
+ output.println(" }");
+
+ output.println(" /** True if the pipeline is inside a glBegin/glEnd pair.*/");
+ output.println(" private boolean insideBeginEndPair = false;");
+ output.println();
+
+ }
+ protected void emitClassDocComment(PrintWriter output)
+ {
+ output.println("/** <P> Composable pipline which wraps an underlying {@link GL} implementation,");
+ output.println(" providing error checking after each OpenGL method call. If an error occurs,");
+ output.println(" causes a {@link GLException} to be thrown at exactly the point of failure.");
+ output.println(" Sample code which installs this pipeline: </P>");
+ output.println();
+ output.println("<PRE>");
+ output.println(" drawable.setGL(new DebugGL(drawable.getGL()));");
+ output.println("</PRE>");
+ output.println("*/");
+ }
+
+ protected void preDownstreamCallHook(PrintWriter output, Method m)
+ {
+ }
+
+ protected void postDownstreamCallHook(PrintWriter output, Method m)
+ {
+ if (m.getName().equals("glBegin"))
+ {
+ output.println(" insideBeginEndPair = true;");
+ output.println(" // NOTE: can't check glGetError(); it's not allowed inside glBegin/glEnd pair");
+ }
+ else
+ {
+ if (m.getName().equals("glEnd"))
+ {
+ output.println(" insideBeginEndPair = false;");
+ }
+
+ // calls to glGetError() are only allowed outside of glBegin/glEnd pairs
+ output.println(" checkGLGetError(\"" + m.getName() + "\");");
+ }
+ }
+
+ } // end class DebugPipeline
+
+ //-------------------------------------------------------
+
+ protected class TracePipeline extends PipelineEmitter
+ {
+ String className;
+ String baseInterfaceClassName;
+ public TracePipeline(String outputDir, String baseInterfaceClassName)
+ {
+ super(outputDir, baseInterfaceClassName);
+ className = "Trace" + getBaseInterfaceName();
+ }
+
+ protected String getPipelineName()
+ {
+ return className;
+ }
+
+ protected void preMethodEmissionHook(PrintWriter output)
+ {
+ }
+
+ protected void constructorHook(PrintWriter output) {
+ output.print( " public " + getPipelineName() + "(" + getBaseInterfaceName() + " ");
+ output.println(getDownstreamObjectName() + ", PrintStream " + getOutputStreamName() + ")");
+ output.println(" {");
+ output.println(" if (" + getDownstreamObjectName() + " == null) {");
+ output.println(" throw new IllegalArgumentException(\"null " + getDownstreamObjectName() + "\");");
+ output.println(" }");
+ output.print( " this." + getDownstreamObjectName());
+ output.println(" = " + getDownstreamObjectName() + ";");
+ output.print( " this." + getOutputStreamName());
+ output.println(" = " + getOutputStreamName() + ";");
+ output.println(" }");
+ output.println();
+ }
+
+ protected void postMethodEmissionHook(PrintWriter output)
+ {
+ output.println("private PrintStream " + getOutputStreamName() + ";");
+ output.println("private int indent = 0;");
+ output.println("protected String dumpArray(Object obj)");
+ output.println("{");
+ output.println(" if (obj == null) return \"[null]\";");
+ output.println(" StringBuffer sb = new StringBuffer(\"[\");");
+ output.println(" int len = java.lang.reflect.Array.getLength(obj);");
+ output.println(" int count = Math.min(len,16);");
+ output.println(" for ( int i =0; i < count; i++ ) {");
+ output.println(" sb.append(java.lang.reflect.Array.get(obj,i));");
+ output.println(" if (i < count-1)");
+ output.println(" sb.append(',');");
+ output.println(" }");
+ output.println(" if ( len > 16 )");
+ output.println(" sb.append(\"...\").append(len);");
+ output.println(" sb.append(']');");
+ output.println(" return sb.toString();");
+ output.println("}");
+ output.println("protected void print(String str)");
+ output.println("{");
+ output.println(" "+getOutputStreamName()+".print(str);");
+ output.println("}");
+ output.println("protected void println(String str)");
+ output.println("{");
+ output.println(" "+getOutputStreamName()+".println(str);");
+ output.println("}");
+ output.println("protected void printIndent()");
+ output.println("{");
+ output.println(" for( int i =0; i < indent; i++) {"+getOutputStreamName()+".print(' ');}");
+ output.println("}");
+ }
+ protected void emitClassDocComment(PrintWriter output)
+ {
+ output.println("/** <P> Composable pipline which wraps an underlying {@link GL} implementation,");
+ output.println(" providing tracing information to a user-specified {@link java.io.PrintStream}");
+ output.println(" before and after each OpenGL method call. Sample code which installs this pipeline: </P>");
+ output.println();
+ output.println("<PRE>");
+ output.println(" drawable.setGL(new TraceGL(drawable.getGL(), System.err));");
+ output.println("</PRE>");
+ output.println("*/");
+ }
+
+ protected void preDownstreamCallHook(PrintWriter output, Method m)
+ {
+ Class[] params = m.getParameterTypes();
+ if ( m.getName().equals("glEnd") || m.getName().equals("glEndList"))
+ {
+ output.println("indent-=2;");
+ output.println(" printIndent();");
+ }
+ else
+ {
+ output.println("printIndent();");
+ }
+
+ output.print(" print(\"" + m.getName() + "(\"");
+ for ( int i =0; i < params.length; i++ )
+ {
+ if ( params[i].isArray() )
+ output.print("+dumpArray(arg"+i+")");
+ else
+ output.print("+arg"+i);
+ if ( i < params.length-1)
+ output.print("+\",\"");
+ }
+ output.println("+\")\");");
+ output.print(" ");
+ }
+
+ protected void postDownstreamCallHook(PrintWriter output, Method m)
+ {
+ Class ret = m.getReturnType();
+ if ( ret != Void.TYPE )
+ {
+ output.println(" println(\" = \"+_res);");
+ }
+ else
+ {
+ output.println(" println(\"\");");
+ }
+ }
+
+ private String getOutputStreamName() {
+ return "stream";
+ }
+
+ } // end class TracePipeline
+}
diff --git a/src/java/com/sun/gluegen/opengl/BuildStaticGLInfo.java b/src/java/com/sun/gluegen/opengl/BuildStaticGLInfo.java
new file mode 100644
index 000000000..52b9fde51
--- /dev/null
+++ b/src/java/com/sun/gluegen/opengl/BuildStaticGLInfo.java
@@ -0,0 +1,320 @@
+/*
+ * Copyright (c) 2003 Sun Microsystems, Inc. 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.sun.gluegen.opengl;
+
+import java.io.*;
+import java.util.*;
+import java.util.regex.*;
+
+ /**
+ * 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:
+ * <br>
+ *
+ * <pre>
+ *
+ * #ifndef GL_XXXX
+ * GLAPI <returnType> <APIENTRY|GLAPIENTRY> glFuncName(<params>)
+ * #endif GL_XXXX
+ *
+ * </pre>
+ *
+ * For example, if it parses the following data:
+ *
+ * <pre>
+ *
+ * #ifndef GL_VERSION_1_3
+ * GLAPI void APIENTRY glActiveTexture (GLenum);
+ * GLAPI void APIENTRY glMultiTexCoord1dv (GLenum, const GLdouble *);
+ * GLAPI void <APIENTRY|GLAPIENTRY> glFuncName(<params>)
+ * #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
+ *
+ * </pre>
+ *
+ * It will associate
+ * <code> glActiveTexture </code> and
+ * <code> glMultiTexCoord1dv </code>
+ * with the symbol
+ * <code> GL_VERSION_1_3 </code>,
+ * and associate
+ * <code> glCompressedTexImage2DARB </code> and
+ * <code> glCompressedTexImage3DARB </code>
+ * with the symbol
+ * <code> GL_ARB_texture_compression </code>.
+ * */
+public class BuildStaticGLInfo
+{
+ // Handles function pointer
+ protected static Pattern funcPattern =
+ Pattern.compile("^(GLAPI|extern)?(\\s*)(\\w+)(\\*)?(\\s+)(GLAPIENTRY|APIENTRY|WINAPI)?(\\s*)([w]?gl\\w+)\\s?(\\(.*)");
+ protected static Pattern associationPattern =
+ Pattern.compile("\\#ifndef ([W]?GL[X]?_[A-Za-z0-9_]+)");
+ protected static Pattern definePattern =
+ Pattern.compile("\\#define ([W]?GL[X]?_[A-Za-z0-9_]+)\\s*([A-Za-z0-9_]+)");
+ // 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();
+
+ /**
+ * The first argument is the package to which the StaticGLInfo class
+ * belongs, the second is the path to the directory in which that package's
+ * classes reside, and the remaining arguments are paths to the C header
+ * files that should be parsed
+ */
+ public static void main(String[] args) throws IOException
+ {
+ if (args.length > 0 && args[0].equals("-test")) {
+ BuildStaticGLInfo builder = new BuildStaticGLInfo();
+ String[] newArgs = new String[args.length - 1];
+ System.arraycopy(args, 1, newArgs, 0, args.length - 1);
+ builder.parse(newArgs);
+ builder.dump();
+ System.exit(0);
+ }
+
+ String packageName = args[0];
+ String packageDir = args[1];
+
+ String[] cHeaderFilePaths = new String[args.length-2];
+ System.arraycopy(args, 2, cHeaderFilePaths, 0, cHeaderFilePaths.length);
+
+ BuildStaticGLInfo builder = new BuildStaticGLInfo();
+ try {
+ builder.parse(cHeaderFilePaths);
+
+ File file = new File(packageDir + File.separatorChar + "StaticGLInfo.java");
+ String parentDir = file.getParent();
+ if (parentDir != null) {
+ File pDirFile = new File(parentDir);
+ pDirFile.mkdirs();
+ }
+
+ PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(file)));
+ builder.emitJavaCode(writer, packageName);
+
+ writer.flush();
+ writer.close();
+ }
+ catch (Exception e)
+ {
+ StringBuffer buf = new StringBuffer("{ ");
+ for (int i = 0; i < cHeaderFilePaths.length; ++i)
+ {
+ buf.append(cHeaderFilePaths[i]);
+ buf.append(" ");
+ }
+ buf.append('}');
+ throw new RuntimeException(
+ "Error building StaticGLInfo.java from " + buf.toString(), e);
+ }
+ }
+
+
+ /** Parses the supplied C header files and adds the function
+ associations contained therein to the internal map. */
+ public void parse(String[] cHeaderFilePaths) throws IOException {
+ for (int i = 0; i < cHeaderFilePaths.length; i++) {
+ parse(cHeaderFilePaths[i]);
+ }
+ }
+
+ /** Parses the supplied C header file and adds the function
+ associations contained therein to the internal map. */
+ public void parse(String cHeaderFilePath) throws IOException {
+ BufferedReader reader = new BufferedReader(new FileReader(cHeaderFilePath));
+ String line, activeAssociation = null;
+ Matcher m = null;
+ while ((line = reader.readLine()) != null) {
+ // 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);
+ } else if ((m = definePattern.matcher(line)).matches()) {
+ identifier = m.group(1);
+ } else if (line.startsWith("#endif")) {
+ activeAssociation = null;
+ }
+ if ((identifier != null) &&
+ (activeAssociation != null) &&
+ // Handles #ifndef GL_... #define GL_...
+ !identifier.equals(activeAssociation)) {
+ addAssociation(identifier, activeAssociation);
+ }
+ } else if ((m = associationPattern.matcher(line)).matches()) {
+ // found a new #ifndef GL_XXX block
+ activeAssociation = m.group(1);
+
+ //System.err.println("FOUND NEW ASSOCIATION BLOCK: " + activeAssociation);
+ }
+ }
+ reader.close();
+ }
+
+ public void dump() {
+ for (Iterator i1 = extensionToDeclarationMap.keySet().iterator(); i1.hasNext(); ) {
+ String name = (String) i1.next();
+ Set decls = (Set) extensionToDeclarationMap.get(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());
+ }
+ }
+ }
+
+ public String getExtension(String identifier) {
+ return (String) declarationToExtensionMap.get(identifier);
+ }
+
+ public Set getDeclarations(String extension) {
+ return (Set) extensionToDeclarationMap.get(extension);
+ }
+
+ public void emitJavaCode(PrintWriter output, String packageName) {
+ output.println("package " + packageName + ";");
+ output.println();
+ output.println("import java.util.*;");
+ output.println();
+ output.println("public final class StaticGLInfo");
+ output.println("{");
+
+ output.println(" // maps function names to the extension string or OpenGL");
+ output.println(" // specification version string to which they correspond.");
+ output.println(" private static HashMap funcToAssocMap;");
+ output.println();
+
+ output.println(" /**");
+ output.println(" * Returns the OpenGL extension string or GL_VERSION string with which the");
+ output.println(" * given function is associated. <P>");
+ 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(" return (String)funcToAssocMap.get(glFunctionName);");
+ output.println(" }");
+ output.println();
+
+ output.println(" static");
+ output.println(" {");
+
+ // Compute max capacity
+ int maxCapacity = 0;
+ for (Iterator iter = declarationToExtensionMap.keySet().iterator(); iter.hasNext(); ) {
+ String name = (String) iter.next();
+ if (!name.startsWith("GL")) {
+ ++maxCapacity;
+ }
+ }
+
+ output.println(" funcToAssocMap = new HashMap(" + maxCapacity + "); // approximate max capacity");
+ output.println(" String group;");
+ ArrayList sets = new ArrayList(extensionToDeclarationMap.keySet());
+ Collections.sort(sets);
+ for (Iterator iter = sets.iterator(); iter.hasNext(); ) {
+ String groupName = (String) iter.next();
+ Set funcs = (Set) extensionToDeclarationMap.get(groupName);
+ List l = new ArrayList();
+ l.addAll(funcs);
+ Collections.sort(l);
+ Iterator funcIter = l.iterator();
+ boolean printedHeader = false;
+ while (funcIter.hasNext()) {
+ String funcName = (String)funcIter.next();
+ if (!funcName.startsWith("GL")) {
+ if (!printedHeader) {
+ output.println();
+ output.println(" //----------------------------------------------------------------");
+ output.println(" // " + groupName);
+ output.println(" //----------------------------------------------------------------");
+ output.println(" group = \"" + groupName + "\";");
+ printedHeader = true;
+ }
+
+ output.println(" funcToAssocMap.put(\"" + funcName + "\", group);");
+ }
+ }
+ }
+ output.println(" }");
+ output.println("} // end class StaticGLInfo");
+ }
+
+ //----------------------------------------------------------------------
+ // Internals only below this point
+ //
+
+ protected void addAssociation(String identifier, String association) {
+ declarationToExtensionMap.put(identifier, association);
+ Set/*<String>*/ identifiers = (Set) extensionToDeclarationMap.get(association);
+ if (identifiers == null) {
+ identifiers = new HashSet/*<String>*/();
+ extensionToDeclarationMap.put(association, identifiers);
+ }
+ identifiers.add(identifier);
+ }
+}
diff --git a/src/java/com/sun/gluegen/opengl/GLConfiguration.java b/src/java/com/sun/gluegen/opengl/GLConfiguration.java
new file mode 100755
index 000000000..a44f3fe9f
--- /dev/null
+++ b/src/java/com/sun/gluegen/opengl/GLConfiguration.java
@@ -0,0 +1,198 @@
+/*
+ * Copyright (c) 2003-2005 Sun Microsystems, Inc. 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.sun.gluegen.opengl;
+
+import java.io.*;
+import java.util.*;
+
+import com.sun.gluegen.*;
+import com.sun.gluegen.procaddress.*;
+
+public class GLConfiguration extends ProcAddressConfiguration {
+ // The following data members support ignoring an entire extension at a time
+ private List/*<String>*/ glHeaders = new ArrayList();
+ private Set/*<String>*/ ignoredExtensions = new HashSet();
+ private BuildStaticGLInfo glInfo;
+ // Maps function names to the kind of buffer object it deals with
+ private Map/*<String,GLEmitter.BufferObjectKind>*/ bufferObjectKinds = new HashMap();
+ private GLEmitter emitter;
+
+ public GLConfiguration(GLEmitter emitter) {
+ super();
+ this.emitter = emitter;
+ try {
+ setProcAddressNameExpr("PFN $UPPERCASE({0}) PROC");
+ } catch (NoSuchElementException e) {
+ throw new RuntimeException("Error configuring ProcAddressNameExpr", e);
+ }
+ }
+
+ protected void dispatch(String cmd, StringTokenizer tok, File file, String filename, int lineNo) throws IOException {
+ if (cmd.equalsIgnoreCase("IgnoreExtension"))
+ {
+ String sym = readString("IgnoreExtension", tok, filename, lineNo);
+ ignoredExtensions.add(sym);
+ }
+ else if (cmd.equalsIgnoreCase("GLHeader"))
+ {
+ String sym = readString("GLHeader", tok, filename, lineNo);
+ glHeaders.add(sym);
+ }
+ else if (cmd.equalsIgnoreCase("BufferObjectKind"))
+ {
+ readBufferObjectKind(tok, filename, lineNo);
+ }
+ else
+ {
+ super.dispatch(cmd,tok,file,filename,lineNo);
+ }
+ }
+
+ protected void readBufferObjectKind(StringTokenizer tok, String filename, int lineNo) {
+ try {
+ String kindString = tok.nextToken();
+ GLEmitter.BufferObjectKind kind = null;
+ String target = tok.nextToken();
+ if (kindString.equalsIgnoreCase("UnpackPixel")) {
+ kind = GLEmitter.BufferObjectKind.UNPACK_PIXEL;
+ } else if (kindString.equalsIgnoreCase("PackPixel")) {
+ kind = GLEmitter.BufferObjectKind.PACK_PIXEL;
+ } else if (kindString.equalsIgnoreCase("Array")) {
+ kind = GLEmitter.BufferObjectKind.ARRAY;
+ } else if (kindString.equalsIgnoreCase("Element")) {
+ kind = GLEmitter.BufferObjectKind.ELEMENT;
+ } else {
+ throw new RuntimeException("Error parsing \"BufferObjectKind\" command at line " + lineNo +
+ " in file \"" + filename + "\": illegal BufferObjectKind \"" +
+ kindString + "\", expected one of UnpackPixel, PackPixel, Array, or Element");
+ }
+
+ bufferObjectKinds.put(target, kind);
+ } catch (NoSuchElementException e) {
+ throw new RuntimeException("Error parsing \"BufferObjectKind\" command at line " + lineNo +
+ " in file \"" + filename + "\"", e);
+ }
+ }
+
+ /** Overrides javaPrologueForMethod in superclass and
+ automatically generates prologue code for functions associated
+ with buffer objects. */
+ public List/*<String>*/ javaPrologueForMethod(MethodBinding binding,
+ boolean forImplementingMethodCall,
+ boolean eraseBufferAndArrayTypes) {
+ List/*<String>*/ res = super.javaPrologueForMethod(binding,
+ forImplementingMethodCall,
+ eraseBufferAndArrayTypes);
+ GLEmitter.BufferObjectKind kind = getBufferObjectKind(binding.getName());
+ if (kind != null) {
+ // Need to generate appropriate prologue based on both buffer
+ // object kind and whether this variant of the MethodBinding
+ // is the one accepting a "long" as argument
+ if (res == null) {
+ res = new ArrayList();
+ }
+
+ String prologue = "check";
+
+ if (kind == GLEmitter.BufferObjectKind.UNPACK_PIXEL) {
+ prologue = prologue + "UnpackPBO";
+ } else if (kind == GLEmitter.BufferObjectKind.PACK_PIXEL) {
+ prologue = prologue + "PackPBO";
+ } else if (kind == GLEmitter.BufferObjectKind.ARRAY) {
+ prologue = prologue + "ArrayVBO";
+ } else if (kind == GLEmitter.BufferObjectKind.ELEMENT) {
+ prologue = prologue + "ElementVBO";
+ } else {
+ throw new RuntimeException("Unknown BufferObjectKind " + kind);
+ }
+
+ if (emitter.isBufferObjectMethodBinding(binding)) {
+ prologue = prologue + "Enabled";
+ } else {
+ prologue = prologue + "Disabled";
+ }
+
+ prologue = prologue + "();";
+
+ res.add(0, prologue);
+ }
+
+ return res;
+ }
+
+ public boolean shouldIgnore(String symbol) {
+ // Check ignored extensions based on our knowledge of the static GL info
+ if (glInfo != null) {
+ String extension = glInfo.getExtension(symbol);
+ if (extension != null &&
+ ignoredExtensions.contains(extension)) {
+ return true;
+ }
+ }
+
+ return super.shouldIgnore(symbol);
+ }
+
+ /** Returns the kind of buffer object this function deals with, or
+ null if none. */
+ public GLEmitter.BufferObjectKind getBufferObjectKind(String name) {
+ return (GLEmitter.BufferObjectKind) bufferObjectKinds.get(name);
+ }
+
+ public boolean isBufferObjectFunction(String name) {
+ return (getBufferObjectKind(name) != null);
+ }
+
+ /** Parses any GL headers specified in the configuration file for
+ the purpose of being able to ignore an extension at a time. */
+ public void parseGLHeaders(GlueEmitterControls controls) throws IOException {
+ if (!glHeaders.isEmpty()) {
+ glInfo = new BuildStaticGLInfo();
+ for (Iterator iter = glHeaders.iterator(); iter.hasNext(); ) {
+ String file = (String) iter.next();
+ String fullPath = controls.findHeaderFile(file);
+ if (fullPath == null) {
+ throw new IOException("Unable to locate header file \"" + file + "\"");
+ }
+ glInfo.parse(fullPath);
+ }
+ }
+ }
+}
diff --git a/src/java/com/sun/gluegen/opengl/GLEmitter.java b/src/java/com/sun/gluegen/opengl/GLEmitter.java
new file mode 100644
index 000000000..8e7484a73
--- /dev/null
+++ b/src/java/com/sun/gluegen/opengl/GLEmitter.java
@@ -0,0 +1,179 @@
+/*
+ * Copyright (c) 2003-2005 Sun Microsystems, Inc. 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.sun.gluegen.opengl;
+
+import java.io.*;
+import java.text.MessageFormat;
+import java.util.*;
+import com.sun.gluegen.*;
+import com.sun.gluegen.cgram.types.*;
+import com.sun.gluegen.procaddress.*;
+import com.sun.gluegen.runtime.*;
+
+/**
+ * A subclass of ProcAddressEmitter with special OpenGL-specific
+ * configuration abilities.
+ */
+public class GLEmitter extends ProcAddressEmitter
+{
+ // Keeps track of which MethodBindings were created for handling
+ // Buffer Object variants. Used as a Set rather than a Map.
+ private Map/*<MethodBinding>*/ bufferObjectMethodBindings = new IdentityHashMap();
+
+ static class BufferObjectKind {
+ private BufferObjectKind() {}
+
+ static final BufferObjectKind UNPACK_PIXEL = new BufferObjectKind();
+ static final BufferObjectKind PACK_PIXEL = new BufferObjectKind();
+ static final BufferObjectKind ARRAY = new BufferObjectKind();
+ static final BufferObjectKind ELEMENT = new BufferObjectKind();
+ }
+
+ public void beginEmission(GlueEmitterControls controls) throws IOException
+ {
+ getGLConfig().parseGLHeaders(controls);
+ super.beginEmission(controls);
+ }
+
+ protected JavaConfiguration createConfig() {
+ return new GLConfiguration(this);
+ }
+
+ /** In order to implement Buffer Object variants of certain
+ functions we generate another MethodBinding which maps the void*
+ argument to a Java long. The generation of emitters then takes
+ place as usual. We do however need to keep track of the modified
+ MethodBinding object so that we can also modify the emitters
+ later to inform them that their argument has changed. We might
+ want to push this functionality down into the MethodBinding
+ (i.e., mutators for argument names). We also would need to
+ inform the CMethodBindingEmitter that it is overloaded in this
+ case (though we default to true currently). */
+ protected List/*<MethodBinding>*/ expandMethodBinding(MethodBinding binding) {
+ List/*<MethodBinding>*/ bindings = super.expandMethodBinding(binding);
+
+ if (!getGLConfig().isBufferObjectFunction(binding.getName())) {
+ return bindings;
+ }
+
+ List/*<MethodBinding>*/ newBindings = new ArrayList();
+ newBindings.addAll(bindings);
+
+ // Need to expand each one of the generated bindings to take a
+ // Java long instead of a Buffer for each void* argument
+ for (Iterator iter = bindings.iterator(); iter.hasNext(); ) {
+ MethodBinding cur = (MethodBinding) iter.next();
+
+ // Some of these routines (glBitmap) take strongly-typed
+ // primitive pointers as arguments which are expanded into
+ // non-void* arguments
+ // This test (rather than !signatureUsesNIO) is used to catch
+ // more unexpected situations
+ if (cur.signatureUsesJavaPrimitiveArrays()) {
+ continue;
+ }
+
+ MethodBinding result = cur;
+ for (int i = 0; i < cur.getNumArguments(); i++) {
+ if (cur.getJavaArgumentType(i).isNIOBuffer()) {
+ result = result.replaceJavaArgumentType(i, JavaType.createForClass(Long.TYPE));
+ }
+ }
+
+ if (result == cur) {
+ throw new RuntimeException("Error: didn't find any void* arguments for BufferObject function " +
+ binding.getName());
+ }
+
+ newBindings.add(result);
+ // Now need to flag this MethodBinding so that we generate the
+ // correct flags in the emitters later
+ bufferObjectMethodBindings.put(result, result);
+ }
+
+ return newBindings;
+ }
+
+ protected boolean needsModifiedEmitters(FunctionSymbol sym) {
+ if ((!needsProcAddressWrapper(sym) && !needsBufferObjectVariant(sym)) ||
+ getConfig().isUnimplemented(sym.getName())) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public boolean isBufferObjectMethodBinding(MethodBinding binding) {
+ return bufferObjectMethodBindings.containsKey(binding);
+ }
+
+ //----------------------------------------------------------------------
+ // Internals only below this point
+ //
+
+ protected void generateModifiedEmitters(JavaMethodBindingEmitter baseJavaEmitter, List emitters) {
+ List superEmitters = new ArrayList();
+ super.generateModifiedEmitters(baseJavaEmitter, superEmitters);
+
+ // See whether this is one of the Buffer Object variants
+ boolean bufferObjectVariant = bufferObjectMethodBindings.containsKey(baseJavaEmitter.getBinding());
+
+ if (bufferObjectVariant) {
+ for (Iterator iter = superEmitters.iterator(); iter.hasNext(); ) {
+ JavaMethodBindingEmitter emitter = (JavaMethodBindingEmitter) iter.next();
+ if (emitter instanceof ProcAddressJavaMethodBindingEmitter) {
+ emitters.add(new GLJavaMethodBindingEmitter((ProcAddressJavaMethodBindingEmitter) emitter, bufferObjectVariant));
+ } else {
+ emitters.add(emitter);
+ }
+ }
+ } else {
+ emitters.addAll(superEmitters);
+ }
+ }
+
+ protected boolean needsBufferObjectVariant(FunctionSymbol sym) {
+ return getGLConfig().isBufferObjectFunction(sym.getName());
+ }
+
+ protected GLConfiguration getGLConfig() {
+ return (GLConfiguration) getConfig();
+ }
+}
diff --git a/src/java/com/sun/gluegen/opengl/GLJavaMethodBindingEmitter.java b/src/java/com/sun/gluegen/opengl/GLJavaMethodBindingEmitter.java
new file mode 100755
index 000000000..ce7f3110e
--- /dev/null
+++ b/src/java/com/sun/gluegen/opengl/GLJavaMethodBindingEmitter.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2003-2005 Sun Microsystems, Inc. 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.sun.gluegen.opengl;
+
+import java.io.*;
+import java.util.*;
+import com.sun.gluegen.*;
+import com.sun.gluegen.cgram.types.*;
+import com.sun.gluegen.procaddress.*;
+
+/** A specialization of the proc address emitter which knows how to
+ change argument names to take into account Vertex Buffer Object /
+ Pixel Buffer Object variants. */
+
+public class GLJavaMethodBindingEmitter extends ProcAddressJavaMethodBindingEmitter {
+ private boolean bufferObjectVariant;
+
+ public GLJavaMethodBindingEmitter(JavaMethodBindingEmitter methodToWrap,
+ boolean callThroughProcAddress,
+ String getProcAddressTableExpr,
+ boolean changeNameAndArguments,
+ boolean bufferObjectVariant,
+ GLEmitter emitter) {
+ super(methodToWrap,
+ callThroughProcAddress,
+ getProcAddressTableExpr,
+ changeNameAndArguments,
+ emitter);
+ this.bufferObjectVariant = bufferObjectVariant;
+ }
+
+ public GLJavaMethodBindingEmitter(ProcAddressJavaMethodBindingEmitter methodToWrap,
+ boolean bufferObjectVariant) {
+ super(methodToWrap);
+ this.bufferObjectVariant = bufferObjectVariant;
+ }
+
+ protected String getArgumentName(int i) {
+ String name = super.getArgumentName(i);
+
+ if (!bufferObjectVariant) {
+ return name;
+ }
+
+ // Emitters for VBO/PBO-related routines change the outgoing
+ // argument name for the buffer
+ if (binding.getJavaArgumentType(i).isLong()) {
+ Type cType = binding.getCArgumentType(i);
+ if (cType.isPointer() &&
+ (cType.asPointer().getTargetType().isVoid() ||
+ cType.asPointer().getTargetType().isPrimitive())) {
+ return name + "_buffer_offset";
+ }
+ }
+
+ return name;
+ }
+}