From 4e0a5af0b359b98b26ea3e961d023c658650be6c Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sat, 1 Aug 2009 05:37:29 -0700 Subject: 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. --- .../classes/javax/media/opengl/GLAutoDrawable.java | 5 +- src/jogl/classes/javax/media/opengl/GLContext.java | 4 +- .../javax/media/opengl/GLPipelineFactory.java | 195 +++++++++++++++++++++ .../classes/javax/media/opengl/awt/GLCanvas.java | 4 +- .../classes/javax/media/opengl/awt/GLJPanel.java | 4 +- 5 files changed, 207 insertions(+), 5 deletions(-) create mode 100644 src/jogl/classes/javax/media/opengl/GLPipelineFactory.java (limited to 'src/jogl/classes/javax/media/opengl') 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 downstream + * and optional arguments additionalArgs for the constructor.
+ * + * The upstream GL instance is determined as follows: + *
+ * + * @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