aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/javax/media/opengl
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2009-08-01 05:37:29 -0700
committerSven Gothel <[email protected]>2009-08-01 05:37:29 -0700
commit4e0a5af0b359b98b26ea3e961d023c658650be6c (patch)
treeef7ca95b4c74dc5aedf7fcf11b6e4c3b07a6b95f /src/jogl/classes/javax/media/opengl
parenta9439fa3ecd366c419815959daedc030f4b8b4e1 (diff)
GL3 Related:
- Fix glGetStringi's return type to String - Fix ExtensionAvailabilityCache: GL3's glGetStringi for GL_EXTENSIONS Ensure to add GL_VERSION_2_0 in case version >= 3.0 Ensure to not exceed version 3.0 for non GL3.1 context. In case of GL 3.1, do not include GL_VERSIONS below 3.0, since this is a forward compatible context. - Add Prologue to glGetString, where the ExtensionCache is being used for GL_EXTENSIONS - if already initialized. This feature adds backward compatibility for GL3 context on GL_EXTENSION. +++ General: Add GLPipelineFactory, a convenient pipeline factory for Debug/Trace and custom ones .. Change 'void setGL(GL)' to 'GL setGL(GL)', and let it return the successful set GL, or null.
Diffstat (limited to 'src/jogl/classes/javax/media/opengl')
-rw-r--r--src/jogl/classes/javax/media/opengl/GLAutoDrawable.java5
-rw-r--r--src/jogl/classes/javax/media/opengl/GLContext.java4
-rw-r--r--src/jogl/classes/javax/media/opengl/GLPipelineFactory.java195
-rw-r--r--src/jogl/classes/javax/media/opengl/awt/GLCanvas.java4
-rw-r--r--src/jogl/classes/javax/media/opengl/awt/GLJPanel.java4
5 files changed, 207 insertions, 5 deletions
diff --git a/src/jogl/classes/javax/media/opengl/GLAutoDrawable.java b/src/jogl/classes/javax/media/opengl/GLAutoDrawable.java
index 43347c416..a94c14f33 100644
--- a/src/jogl/classes/javax/media/opengl/GLAutoDrawable.java
+++ b/src/jogl/classes/javax/media/opengl/GLAutoDrawable.java
@@ -208,6 +208,7 @@ public interface GLAutoDrawable extends GLDrawable {
This should only be called from within the GLEventListener's
callback methods, and usually only from within the init()
method, in order to install a composable pipeline. See the JOGL
- demos for examples. */
- public void setGL(GL gl);
+ demos for examples.
+ @return the set GL pipeline or null if not successful */
+ public GL setGL(GL gl);
}
diff --git a/src/jogl/classes/javax/media/opengl/GLContext.java b/src/jogl/classes/javax/media/opengl/GLContext.java
index a2bff729a..8ff52b6e9 100644
--- a/src/jogl/classes/javax/media/opengl/GLContext.java
+++ b/src/jogl/classes/javax/media/opengl/GLContext.java
@@ -205,8 +205,10 @@ public abstract class GLContext {
/**
* Sets the GL pipeline object for this GLContext.
+ *
+ * @return the set GL pipeline or null if not successful
*/
- public abstract void setGL(GL gl);
+ public abstract GL setGL(GL gl);
/**
* Returns the attached user object for the given name to this GLContext.
diff --git a/src/jogl/classes/javax/media/opengl/GLPipelineFactory.java b/src/jogl/classes/javax/media/opengl/GLPipelineFactory.java
new file mode 100644
index 000000000..bb9f86911
--- /dev/null
+++ b/src/jogl/classes/javax/media/opengl/GLPipelineFactory.java
@@ -0,0 +1,195 @@
+/*
+ * 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.
+ */
+
+package javax.media.opengl;
+
+import java.lang.reflect.*;
+import java.util.StringTokenizer;
+
+import com.sun.opengl.impl.*;
+
+/**
+ * Factory for pipelining GL instances
+ */
+public class GLPipelineFactory {
+ public static final boolean DEBUG = Debug.debug("GLPipelineFactory");
+
+ /**
+ * Creates a pipelined GL instance using the given downstream <code>downstream</code>
+ * and optional arguments <code>additionalArgs</code> for the constructor.<br>
+ *
+ * The upstream GL instance is determined as follows:
+ * <ul>
+ * <li> Use <code>pipelineClazzBaseName</code> as the class name's full basename, incl. package name</li>
+ * <li> For all <code>downstream</code> classes, do:</li>
+ * <ul>
+ * <li> For all <code>downstream</code> class interfaces, do:</li>
+ * <ul>
+ * <li> If <code>reqInterface</code> is not null and the interface is unequal, continue.</li>
+ * <li> If <code>downstream</code> is not instance of interface, continue.</li>
+ * <li> If <code>downstream</code> is not instance of interface, continue.</li>
+ * <li> If upstream class is available use it, end loop.</li>
+ * </ul>
+ * </ul>
+ * </ul><br>
+ *
+ * @arg pipelineClazzBaseName the basename of the pipline class name
+ * @arg reqInterface optional requested interface to be used, may be null, in which case the first matching one is used
+ * @arg downstream is always the 1st argument for the upstream constructor
+ * @arg additionalArgs additional arguments for the upstream constructor
+ */
+ public static final GL create(String pipelineClazzBaseName, Class reqInterface, GL downstream, Object[] additionalArgs) {
+ Class downstreamClazz = downstream.getClass();
+ Class upstreamClazz = null;
+ Class interfaceClazz = null;
+
+ if(DEBUG) {
+ System.out.println("GLPipelineFactory: Start "+downstreamClazz.getName()+", req. Interface: "+reqInterface+" -> "+pipelineClazzBaseName);
+ }
+
+ // For all classes: child -> parent
+ do {
+ // For all interfaces: right -> left == child -> parent
+ // It is important that this matches with the gluegen cfg file's 'Implements' clause !
+ Class[] clazzes = downstreamClazz.getInterfaces();
+ for(int i=clazzes.length-1; null==upstreamClazz && i>=0; i--) {
+ if(DEBUG) {
+ System.out.println("GLPipelineFactory: Try "+downstreamClazz.getName()+" Interface["+i+"]: "+clazzes[i].getName());
+ }
+ if( reqInterface != null && !reqInterface.getName().equals(clazzes[i].getName()) ) {
+ if(DEBUG) {
+ System.out.println("GLPipelineFactory: requested Interface "+reqInterface+" is _not_ "+ clazzes[i].getName());
+ }
+ continue; // not the requested one ..
+ }
+ if( ! clazzes[i].isInstance(downstream) ) {
+ if(DEBUG) {
+ System.out.println("GLPipelineFactory: "+downstream.getClass().getName() + " is _not_ instance of "+ clazzes[i].getName());
+ }
+ continue; // not a compatible one
+ } else {
+ if(DEBUG) {
+ System.out.println("GLPipelineFactory: "+downstream.getClass().getName() + " _is_ instance of "+ clazzes[i].getName());
+ }
+ }
+ upstreamClazz = getUpstreamClazz(clazzes[i], pipelineClazzBaseName);
+ if( null != upstreamClazz ) {
+ interfaceClazz = clazzes[i];
+ }
+ }
+
+ if(null==upstreamClazz) {
+ downstreamClazz = downstreamClazz.getSuperclass();
+ }
+ } while (null!=downstreamClazz && null==upstreamClazz);
+
+
+ if(null==upstreamClazz) {
+ throw new GLException("No pipeline ("+pipelineClazzBaseName+"*) available for :"+downstream.getClass().getName());
+ }
+
+ if(DEBUG) {
+ System.out.println("GLPipelineFactory: Got : "+ upstreamClazz.getName()+", base interface: "+interfaceClazz.getName());
+ }
+
+ Class[] cstrArgTypes = new Class[ 1 + ( ( null==additionalArgs ) ? 0 : additionalArgs.length ) ] ;
+ {
+ int i = 0;
+ cstrArgTypes[i++] = interfaceClazz;
+ for(int j=0; null!=additionalArgs && j<additionalArgs.length; j++) {
+ cstrArgTypes[i++] = additionalArgs[j].getClass();
+ }
+ }
+ Constructor cstr = null;
+ try {
+ cstr = upstreamClazz.getDeclaredConstructor( cstrArgTypes );
+ } catch(NoSuchMethodException nsme) {
+ throw new GLException("Couldn't find pipeline constructor: " + upstreamClazz.getName() +
+ " ( "+getArgsClassNameList(downstreamClazz, additionalArgs) +" )");
+ }
+ Object instance = null;
+ try {
+ Object[] cstrArgs = new Object[ 1 + ( ( null==additionalArgs ) ? 0 : additionalArgs.length ) ] ;
+ {
+ int i = 0;
+ cstrArgs[i++] = downstream;
+ for(int j=0; null!=additionalArgs && j<additionalArgs.length; j++) {
+ cstrArgs[i++] = additionalArgs[j];
+ }
+ }
+ instance = cstr.newInstance( cstrArgs ) ;
+ } catch (Throwable t) { t.printStackTrace(); }
+ if(null==instance) {
+ throw new GLException("Couldn't create instance of pipeline: "+upstreamClazz.getName()+
+ " ( "+getArgsClassNameList(downstreamClazz, additionalArgs) +" )");
+ }
+ if( ! (instance instanceof GL) ) {
+ throw new GLException(upstreamClazz.getName()+" not an instance of GL");
+ }
+ return (GL) instance;
+ }
+
+ private static final String getArgsClassNameList(Class arg0, Object[] args) {
+ StringBuffer sb = new StringBuffer();
+ sb.append(arg0.getName());
+ if(args!=null) {
+ for(int j=0; j<args.length; j++) {
+ sb.append(", ");
+ sb.append(args[j].getClass().getName());
+ }
+ }
+ return sb.toString();
+ }
+
+ private static final Class getUpstreamClazz(Class downstreamClazz, String pipelineClazzBaseName) {
+ String downstreamClazzName = downstreamClazz.getName();
+
+ StringTokenizer st = new StringTokenizer(downstreamClazzName, ".");
+ String downstreamClazzBaseName = downstreamClazzName;
+ while(st.hasMoreTokens()) {
+ downstreamClazzBaseName = st.nextToken();
+ }
+ String upstreamClazzName = pipelineClazzBaseName+downstreamClazzBaseName;
+
+ Class upstreamClazz = null;
+ try {
+ upstreamClazz = Class.forName(upstreamClazzName, true, GLPipelineFactory.class.getClassLoader());
+ } catch (Throwable e) { e.printStackTrace(); }
+
+ return upstreamClazz;
+ }
+}
+
diff --git a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java
index 4282e9985..038d6d280 100644
--- a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java
+++ b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java
@@ -486,11 +486,13 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable {
return (context == null) ? null : context.getGL();
}
- public void setGL(GL gl) {
+ public GL setGL(GL gl) {
GLContext context = getContext();
if (context != null) {
context.setGL(gl);
+ return gl;
}
+ return null;
}
diff --git a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java
index 7b942b358..fe55b2dbd 100644
--- a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java
+++ b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java
@@ -404,11 +404,13 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable {
return (context == null) ? null : context.getGL();
}
- public void setGL(GL gl) {
+ public GL setGL(GL gl) {
GLContext context = getContext();
if (context != null) {
context.setGL(gl);
+ return gl;
}
+ return null;
}
public void setAutoSwapBufferMode(boolean onOrOff) {