diff options
author | Sven Gothel <[email protected]> | 2009-06-03 19:57:05 +0000 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2009-06-03 19:57:05 +0000 |
commit | af23607f257b01777d52c93f8908912d1ae8c8bb (patch) | |
tree | a25f002e6ad9cc827981d6fe33ed15627edc7fdf /src/jogl/classes/javax | |
parent | 522e3b3ed592d80881938cc3176d5fba5289a79f (diff) |
Tested:
- Linux / X11 / GL3 / GL2 / ES1 / ES2
- Using etc/profile.jogl JOGL_ALL
. ./setenv-jogl.x86.sh JOGL_ALL
- Java2D/GLJPanel: demos.jrefract.JRefract
- GLCanvas: demos.gears.Gears
- Newt/Nativewindow (demos.GLInfo, demos.es2.RedSquare, demos.es2.RedSquare)
- with multiple instances of different GL profiles, ie
java demos.es1.RedSquare -GLES2 -GLES1
java demos.GLInfo -GLES2 -GL2
- GL 3.1 test with demos.GLInfo
java demos.GLInfo -GL3
java demos.GLInfo -GL3 -GL2
with NVIDIA 180.37.05
JOGL
Enable parallel GLProfiles:
- GL holds it's GLProfile
- GL / GLBase added:
hasGLSL()
getGLProfile()
- Removed all hardcoded GLProfile checks
- Make GLProfile an instance of GLCapabilities
- GLCapabilities needs GLProfile in constructor,
or null for the default GLProfile
- All GLProfiles are singelton mapped objects,
setup and verified at static init.
- All GLDrawableFactories in GLDrawableFactory are singelton objects,
setup at static init.
- GLDrawableFactories.getFactory() needs an argument,
which leads to GLProfile, ie
NativeWindow, AbstractGraphicsConfiguration, GLCapabilities or GLProfile.
- EGLDrawableFactory takes GLProfile as an argument,
being able to take the singleton role as ES1 or ES2
- EGLDrawableFactory loads ES & EGL libraries _local_,
otherwise the symbols produce a collision (Unix/PC-Emulation).
TODO: Check on Windows/WinCE !
- Fixing etc/profile.jogl JOGL_ALL
EGLGraphicsConfigurationFactory
- Added eglGetConfigs -> GLCapabilities -> eglChooseConfig,
in case the simple eglChooseConfig fails.
- Using given chooser, is null, use DefaultGLCapabilitiesChooser
Moved FixedFuncUtil.class -> jogl.util.jar,
otherwise the FixedFuncUtil pipeline cannot be used without emulation.
GLDrawable
Rename getChosenGLCapabilities() -> getGLCapabilities(),
since all GLCapabilities access functions return the current state.
Add getGLProfile()
NativeLibLoader[Base]
Added 'addLoaded' and 'isLoaded', so all LoadAction implementation
can use it and circumvent double library loading.
GlueGen
Split openLibrary -> openLibraryLocal / Global,
utilizing as an optional flag (global), which is true per default.
TODO: How to do this on Windows ?
TODO: Verify Windows and MacOSX !!
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JOGL_2_SANDBOX@1922 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/jogl/classes/javax')
8 files changed, 660 insertions, 306 deletions
diff --git a/src/jogl/classes/javax/media/opengl/GLBase.java b/src/jogl/classes/javax/media/opengl/GLBase.java index dcbd3e4cf..efd2eedd1 100644 --- a/src/jogl/classes/javax/media/opengl/GLBase.java +++ b/src/jogl/classes/javax/media/opengl/GLBase.java @@ -63,6 +63,9 @@ public interface GLBase { */ public boolean isGL2ES2(); + /** Indicates whether this GL object supports GLSL. */ + public boolean hasGLSL(); + /** * Casts this object to the GL interface. * @return this object cast to the GL interface @@ -117,4 +120,10 @@ public interface GLBase { * @return the GLContext with which this GL object is associated */ public GLContext getContext(); + + /** + * Returns the GLProfile with which this GL object is associated. + * @return the GLProfile with which this GL object is associated + */ + public GLProfile getGLProfile(); } diff --git a/src/jogl/classes/javax/media/opengl/GLCapabilities.java b/src/jogl/classes/javax/media/opengl/GLCapabilities.java index 0a73856c0..bc49bbde1 100644 --- a/src/jogl/classes/javax/media/opengl/GLCapabilities.java +++ b/src/jogl/classes/javax/media/opengl/GLCapabilities.java @@ -47,6 +47,7 @@ import javax.media.nativewindow.Capabilities; configuration on all supported window systems. */ public class GLCapabilities extends Capabilities implements Cloneable { + private GLProfile glProfile = null; private boolean doubleBuffered = true; private boolean stereo = false; private boolean hardwareAccelerated = true; @@ -72,10 +73,18 @@ public class GLCapabilities extends Capabilities implements Cloneable { private boolean pbufferRenderToTexture; private boolean pbufferRenderToTextureRectangle; - /** Creates a GLCapabilities object. All attributes are in a default - state. + /** Creates a GLCapabilities object. All attributes are in a default state. + * @param glp GLProfile, or null for the default GLProfile */ - public GLCapabilities() {} + public GLCapabilities(GLProfile glp) { + glProfile = (null!=glp)?glp:GLProfile.GetProfileDefault(); + if(glProfile.usesNativeGLES()) { + setRedBits(5); + setGreenBits(6); + setBlueBits(5); + setDepthBits(16); + } + } public Object clone() { try { @@ -85,6 +94,16 @@ public class GLCapabilities extends Capabilities implements Cloneable { } } + /** Returns the GL profile you desire or used by the drawable. */ + public GLProfile getGLProfile() { + return glProfile; + } + + /** Sets the GL profile you desire */ + public void setGLProfile(GLProfile profile) { + glProfile=profile; + } + /** Indicates whether double-buffering is enabled. */ public boolean getDoubleBuffered() { return doubleBuffered; @@ -290,6 +309,7 @@ public class GLCapabilities extends Capabilities implements Cloneable { public String toString() { return getClass().toString()+"[" + super.toString()+ + ", GL profile: " + glProfile + ", DoubleBuffered: " + doubleBuffered + ", Stereo: " + stereo + ", HardwareAccelerated: " + hardwareAccelerated + diff --git a/src/jogl/classes/javax/media/opengl/GLContext.java b/src/jogl/classes/javax/media/opengl/GLContext.java index c7e5899a7..ce4bc14d1 100644 --- a/src/jogl/classes/javax/media/opengl/GLContext.java +++ b/src/jogl/classes/javax/media/opengl/GLContext.java @@ -149,8 +149,23 @@ public abstract class GLContext { public abstract void copy(GLContext source, int mask) throws GLException; /** - * Returns the context which is current on the current thread. If no - * context is current, returns null. + * Returns the GL object bound to this thread current context. + * If no context is current, throw an GLException + * + * @return the current context's GL object on this thread + * @thows GLException if no context is current + */ + public static GL getCurrentGL() throws GLException { + GLContext glc = getCurrent(); + if(null==glc) { + throw new GLException("No OpenGL context current on this thread"); + } + return glc.getGL(); + } + + /** + * Returns this thread current context. + * If no context is current, returns null. * * @return the context current on this thread, or null if no context * is current. diff --git a/src/jogl/classes/javax/media/opengl/GLDrawable.java b/src/jogl/classes/javax/media/opengl/GLDrawable.java index 746c8e728..f85147a79 100644 --- a/src/jogl/classes/javax/media/opengl/GLDrawable.java +++ b/src/jogl/classes/javax/media/opengl/GLDrawable.java @@ -144,16 +144,18 @@ public interface GLDrawable { public void swapBuffers() throws GLException; /** Fetches the {@link GLCapabilities} corresponding to the chosen - OpenGL capabilities (pixel format / visual) for this drawable. - Some drawables, in particular on-screen drawables, may be - created lazily; null is returned if the drawable is not - currently created or if its pixel format has not been set yet. + OpenGL capabilities (pixel format / visual / GLProfile) for this drawable. On some platforms, the pixel format is not directly associated with the drawable; a best attempt is made to return a reasonable value in this case. - Returns a copy of the passed object. + Returns a copy of the queried object. */ - public GLCapabilities getChosenGLCapabilities(); + public GLCapabilities getGLCapabilities(); + + /** Fetches the {@link GLProfile} for this drawable. + Returns the GLProfile object, no copy. + */ + public GLProfile getGLProfile(); public NativeWindow getNativeWindow(); diff --git a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java index e9208f49e..6cfe66dff 100644 --- a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java +++ b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java @@ -80,68 +80,140 @@ import com.sun.nativewindow.impl.NWReflection; */ public abstract class GLDrawableFactory { - private static GLDrawableFactory factory; - /** Creates a new GLDrawableFactory instance. End users do not need to call this method. */ protected GLDrawableFactory() { } - /** Returns the sole GLDrawableFactory instance. The {@link - GLProfile GLProfile} must be configured before calling this - method. */ - public static GLDrawableFactory getFactory() throws GLException { - if (null == factory) { - if (null == GLProfile.getProfile()) { - GLProfile.setProfileGLAny(); // do it now .. last resort - } + private static final GLDrawableFactory eglES1Factory; + private static final GLDrawableFactory eglES2Factory; + private static final GLDrawableFactory nativeOSFactory; + private static final String nativeOSType; - // See if the user is requesting one of the embedded profiles, - // and if so, try to instantiate the EGLDrawableFactory - if ( GLProfile.usesNativeGLES() ) { - try { - factory = (GLDrawableFactory) NWReflection.createInstance("com.sun.opengl.impl.egl.EGLDrawableFactory"); - } catch (Exception e) { - e.printStackTrace(); + /** + * Instantiate singleton factories if available, EGLES1, EGLES2 and the OS native ones. + */ + static { + GLDrawableFactory tmp = null; + try { + tmp = (GLDrawableFactory) NWReflection.createInstance("com.sun.opengl.impl.egl.EGLDrawableFactory", new Object[] { GLProfile.GLES1 }); + } catch (Throwable t) { + if (GLProfile.DEBUG) { + System.err.println("GLDrawableFactory.static - EGLDrawableFactory GLES1 - not available"); + t.printStackTrace(); } - } else if ( !GLProfile.isGL2ES1() && !GLProfile.isGL2ES2() ) { - // We require that the user passes in one of the known profiles - throw new GLException("Unknown or unsupported profile \"" + GLProfile.getProfile() + "\""); - } + } + eglES1Factory = tmp; + + tmp = null; + try { + tmp = (GLDrawableFactory) NWReflection.createInstance("com.sun.opengl.impl.egl.EGLDrawableFactory", new Object[] { GLProfile.GLES2 }); + } catch (Throwable t) { + if (GLProfile.DEBUG) { + System.err.println("GLDrawableFactory.static - EGLDrawableFactory GLES2 - not available"); + t.printStackTrace(); + } + } + eglES2Factory = tmp; - if (null == factory) { - // Use the desktop OpenGL as the fallback always - try { - String factoryClassName = + nativeOSType = NativeWindowFactory.getNativeWindowType(false); + + String factoryClassName = null; + tmp = null; + try { + factoryClassName = (String) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { return System.getProperty("opengl.factory.class.name"); } }); - String osName = System.getProperty("os.name"); - String osNameLowerCase = osName.toLowerCase(); - if (factoryClassName == null) { - if (osNameLowerCase.startsWith("windows")) { + if (null == factoryClassName) { + if ( nativeOSType.equals(NativeWindowFactory.TYPE_EGL) ) { + // use egl*Factory .. + } else if ( nativeOSType.equals(NativeWindowFactory.TYPE_X11) ) { + factoryClassName = "com.sun.opengl.impl.x11.glx.X11GLXDrawableFactory"; + } else if ( nativeOSType.equals(NativeWindowFactory.TYPE_WINDOWS) ) { factoryClassName = "com.sun.opengl.impl.windows.wgl.WindowsWGLDrawableFactory"; - } else if (osNameLowerCase.startsWith("mac os x") || - osNameLowerCase.startsWith("darwin")) { + } else if ( nativeOSType.equals(NativeWindowFactory.TYPE_MACOSX) ) { // FIXME: remove this residual dependence on the AWT factoryClassName = "com.sun.opengl.impl.macosx.cgl.awt.MacOSXAWTCGLDrawableFactory"; } else { - // Assume Linux, Solaris, etc. Should probably test for these explicitly. - factoryClassName = "com.sun.opengl.impl.x11.glx.X11GLXDrawableFactory"; + throw new GLException("Unsupported NativeWindow type: "+nativeOSType); } - } - - factory = (GLDrawableFactory) NWReflection.createInstance(factoryClassName); - } catch (Exception e) { - throw new GLException(e); } + if (null != factoryClassName) { + tmp = (GLDrawableFactory) NWReflection.createInstance(factoryClassName); + } + } catch (Throwable t) { + if (GLProfile.DEBUG) { + System.err.println("GLDrawableFactory.static - Native Platform: "+nativeOSType+" - not available: "+factoryClassName); + t.printStackTrace(); + } + } + nativeOSFactory = tmp; + } + + /** + * Returns the sole GLDrawableFactory instance. + * + * @arg nw NativeWindow object to query the ES GLProfile type, + * which itself helps to determine the EGL factory type. + */ + public static GLDrawableFactory getFactory(NativeWindow nw) throws GLException { + return getFactory(nw.getGraphicsConfiguration().getNativeGraphicsConfiguration()); + } + + /** + * Returns the sole GLDrawableFactory instance. + * + * @arg agc AbstractGraphicsConfiguration object to query the ES GLProfile type, + * which itself helps to determine the EGL factory type. + */ + public static GLDrawableFactory getFactory(AbstractGraphicsConfiguration agc) throws GLException { + if(null==agc) { + throw new GLException("Null AbstractGraphicsConfiguration"); + } + if( !(agc.getCapabilities() instanceof GLCapabilities) ) { + throw new GLException("Unsupported AbstractGraphicsConfiguration for OpenGL: "+agc); } + return getFactory((GLCapabilities)agc.getCapabilities()); + } + + /** + * Returns the sole GLDrawableFactory instance. + * + * @arg esCaps GLCapabilities object to query the ES GLProfile type, + * which itself helps to determine the EGL factory type. + */ + public static GLDrawableFactory getFactory(GLCapabilities esCaps) throws GLException { + return getFactory(esCaps.getGLProfile()); + } + + /** + * Returns the sole GLDrawableFactory instance. + * + * @arg esProfile GLProfile to determine the EGL factory type. + */ + public static GLDrawableFactory getFactory(GLProfile esProfile) throws GLException { + return getFactory(esProfile.getImplName()); + } + + protected static GLDrawableFactory getFactory(String profileImpl) throws GLException { + if ( GLProfile.UsesNativeGLES1(profileImpl) ) { + if(null==eglES1Factory) throw new GLException("GLDrawableFactory unavailable for EGL/ES1: "+profileImpl); + return eglES1Factory; + } else if ( GLProfile.UsesNativeGLES2(profileImpl) ) { + if(null==eglES2Factory) throw new GLException("GLDrawableFactory unavailable for EGL/ES2: "+profileImpl); + return eglES2Factory; } - return factory; + return getNativeOSFactory(); + } + + protected static GLDrawableFactory getNativeOSFactory() { + if(null==nativeOSFactory) throw new GLException("GLDrawableFactory unavailable for Native Platform "+nativeOSType); + return nativeOSFactory; } /** Shuts down this GLDrawableFactory, releasing resources diff --git a/src/jogl/classes/javax/media/opengl/GLProfile.java b/src/jogl/classes/javax/media/opengl/GLProfile.java index bf0f5bbb5..1d92fbb18 100644 --- a/src/jogl/classes/javax/media/opengl/GLProfile.java +++ b/src/jogl/classes/javax/media/opengl/GLProfile.java @@ -38,298 +38,262 @@ package javax.media.opengl; import javax.media.opengl.fixedfunc.*; import java.lang.reflect.*; +import java.util.HashMap; import java.security.*; import com.sun.opengl.impl.*; import com.sun.nativewindow.impl.NWReflection; -public class GLProfile { +/** + * Manages all available OpenGL Profiles. + * Each GLProfile is a singleton instance queried at static initialization time. + * All returned GLProfile objects are references to such singletons. + */ +public class GLProfile implements Cloneable { public static final boolean DEBUG = Debug.debug("GLProfile"); // // Public (user-visible) profiles // - /** The desktop (OpenGL 3.1) profile */ + /** The desktop OpenGL >= 3.1 profile */ public static final String GL3 = "GL3"; - /** The desktop (OpenGL 2.0) profile */ + /** The desktop OpenGL [1.5 .. 3.0] profile */ public static final String GL2 = "GL2"; - /** The OpenGL ES 1 (really, 1.1) profile */ + /** The embedded OpenGL ES >= 1.0 profile */ public static final String GLES1 = "GLES1"; - /** The OpenGL ES 2 (really, 2.0) profile */ + /** The embedded OpenGL ES >= 2.0 profile */ public static final String GLES2 = "GLES2"; - /** The intersection of the desktop (OpenGL 2.0) and OpenGL ES 1.x profiles */ + /** The intersection of the desktop GL2 and embedded ES1 profiles */ public static final String GL2ES1 = "GL2ES1"; - /** The intersection of the desktop (OpenGL 2.0) and OpenGL ES 2.x profiles */ + /** The intersection of the desktop GL2 and embedded ES2 profiles */ public static final String GL2ES2 = "GL2ES2"; - // - // Profiles which are implementation details - // - - // The intersection between desktop OpenGL and the union of the OpenGL ES profiles - // This is here only to avoid having separate GL2ES1Impl and GL2ES2Impl classes - private static final String GL2ES12 = "GL2ES12"; - - /** The JVM/process wide chosen GL profile **/ - private static String profile = null; + /** + * All GL Profiles in the order of default detection. + * Order: GL2, GL2ES2, GL2ES1, GL3, GLES2, GLES1 + */ + public static final String[] GL_PROFILE_LIST = new String[] { GL2, GL2ES2, GL2ES1, GL3, GLES2, GLES1 }; - /** The "real" profile implementing the chosen profile; for example, - both GL2ES1 and GL2ES2 currently map to GL2ES12 */ - private static String realProfile = null; + /** + * All GL2ES2 Profiles in the order of default detection + * Order: GL2ES2, GL2, GL3, GLES2 + */ + public static final String[] GL2ES2_PROFILE_LIST = new String[] { GL2ES2, GL2, GL3, GLES2 }; - private static final Throwable tryLibrary() - { - String clazzName = getGLImplBaseClassName() + "Impl" ; - try { - Class clazz = Class.forName(clazzName); - if(GL3.equals(realProfile) || GL2.equals(realProfile)) { - // See DRIHack.java for an explanation of why this is necessary - DRIHack.begin(); - NativeLibLoader.loadGLDesktop(); - DRIHack.end(); - } if(GL2ES12.equals(realProfile)) { - // See DRIHack.java for an explanation of why this is necessary - DRIHack.begin(); - NativeLibLoader.loadGL2ES12(); - DRIHack.end(); - } else if(usesNativeGLES()) { - Object eGLDrawableFactory = NWReflection.createInstance("com.sun.opengl.impl.egl.EGLDrawableFactory"); - if(null==eGLDrawableFactory) { - throw new GLException("com.sun.opengl.impl.egl.EGLDrawableFactory not available"); - } - } - System.out.println("Successfully loaded profile " + profile + " ("+realProfile+"/"+clazzName+")"); - return null; - } catch (Throwable e) { - if (DEBUG) { - System.err.println("GLProfile.tryLibrary: failed: " + profile + " ("+realProfile+"/"+clazzName+")"); - e.printStackTrace(); - } - profile=null; - realProfile = null; - return e; + /** + * All GL2ES1 Profiles in the order of default detection + * Order: GL2ES1, GL2, GLES1 + */ + public static final String[] GL2ES1_PROFILE_LIST = new String[] { GL2ES1, GL2, GLES1 }; + + /** Returns a default GLProfile object, reflecting the best for the running platform. + * It selects the first of the set {@link GLProfile#GL_PROFILE_LIST} + */ + public static final GLProfile GetProfileDefault() { + if(null==defaultGLProfile) { + throw new GLException("No default profile available"); // should never be reached } + return defaultGLProfile; } - private static boolean hasGL2ES12Impl = null!=NWReflection.getClass("com.sun.opengl.impl.gl2es12.GL2ES12Impl"); - private static boolean hasGL2Impl = null!=NWReflection.getClass("com.sun.opengl.impl.gl2.GL2Impl"); - - private static String computeRealProfile() { - if (GL2ES1.equals(profile) || - GL2ES2.equals(profile)) { - if(hasGL2Impl) { - realProfile = GL2; - return realProfile; - } else if(hasGL2ES12Impl) { - realProfile = GL2ES12; - return realProfile; - } + /** Returns a GLProfile object. + * Verfifies the given profile and chooses an apropriate implementation. + * + * @throws GLException if no implementation for the given profile is found. + */ + public static final GLProfile GetProfile(String profile) + throws GLException + { + if(null==profile) return GetProfileDefault(); + GLProfile glProfile = (GLProfile) mappedProfiles.get(profile); + if(null==glProfile) { + throw new GLException("No implementation for profile "+profile+" available"); } - realProfile = profile; - return realProfile; + return glProfile; } - private static final void initStatics() { - GLDrawableFactory.getFactory(); + /** + * Returns a profile, implementing the interface GL2ES1. + * It selects the first of the set: {@link GLProfile#GL2ES1_PROFILE_LIST} + * + * @throws GLException if no implementation for the given profile is found. + */ + public static final GLProfile GetProfileGL2ES1() + throws GLException + { + return GetProfile(GL2ES1_PROFILE_LIST); } - public static synchronized final void setProfile(String profile) + /** + * Returns a profile, implementing the interface GL2ES2. + * It selects the first of the set: {@link GLProfile#GL2ES2_PROFILE_LIST} + * + * @throws GLException if no implementation for the given profile is found. + */ + public static final GLProfile GetProfileGL2ES2() throws GLException { - if(null==GLProfile.profile) { - GLProfile.profile = profile; - String rp = computeRealProfile(); - Throwable t = tryLibrary(); - if (GLProfile.profile == null) { - throw new GLException("Profile " + profile + " ("+rp+") not available", t); - } - initStatics(); - } else { - if(!GLProfile.profile.equals(profile)) { - throw new GLException("Requested profile ("+profile+") doesn't match already chosen one: "+GLProfile.profile); - } - } + return GetProfile(GL2ES2_PROFILE_LIST); } - public static synchronized final void setProfile(String[] profiles) + /** + * Returns the first profile from the given list, + * where an implementation is available. + * + * @throws GLException if no implementation for the given profile is found. + */ + public static final GLProfile GetProfile(String[] profiles) throws GLException { - Throwable t = null; - for(int i=0; profile==null && i<profiles.length; i++) { - profile = profiles[i]; - computeRealProfile(); - if (t == null) { - t = tryLibrary(); - } else { - tryLibrary(); + for(int i=0; i<profiles.length; i++) { + String profile = profiles[i]; + GLProfile glProfile = (GLProfile) mappedProfiles.get(profile); + if(null!=glProfile) { + return glProfile; } } - if(null==profile) { - StringBuffer msg = new StringBuffer(); - msg.append("["); - for (int i = 0; i < profiles.length; i++) { - if (i > 0) - msg.append(", "); - msg.append(profiles[i]); - } - msg.append("]"); - throw new GLException("Profiles "+msg.toString()+" not available", t); - } - initStatics(); + throw new GLException("Profiles "+list2String(profiles)+" not available"); } - /** - * Selects a profile, implementing the interface GL2ES1. - * Order: GL2ES1, GL2, GLES1 + /** Indicates whether the native OpenGL ES1 profile is in use. + * This requires an EGL interface. */ - public static synchronized final void setProfileGL2ES1() { - setProfile(new String[] { GL2ES1, GL2, GLES1 }); + public static final boolean UsesNativeGLES1(String profileImpl) { + return GLES1.equals(profileImpl) || GL2ES1.equals(profileImpl) ; } - /** - * Selects a profile, implementing the interface GL2ES2. - * Order: GL2ES2, GL2, GL3, GLES2 + /** Indicates whether the native OpenGL ES2 profile is in use. + * This requires an EGL interface. */ - public static synchronized final void setProfileGL2ES2() { - setProfile(new String[] { GL2ES2, GL2, /*GL3,*/ GLES2 }); + public static final boolean UsesNativeGLES2(String profileImpl) { + return GLES2.equals(profileImpl) || GL2ES2.equals(profileImpl) ; + } + + /** Indicates whether either of the native OpenGL ES profiles are in use. */ + public static final boolean UsesNativeGLES(String profileImpl) { + return UsesNativeGLES2(profileImpl) || UsesNativeGLES1(profileImpl); + } + + public static final String GetGLImplBaseClassName(String profileImpl) { + if(GL3.equals(profileImpl)) { + return "com.sun.opengl.impl.gl3.GL3"; + } else if(GL2.equals(profileImpl)) { + return "com.sun.opengl.impl.gl2.GL2"; + } else if(GL2ES12.equals(profileImpl)) { + return "com.sun.opengl.impl.gl2es12.GL2ES12"; + } else if(GLES1.equals(profileImpl) || GL2ES1.equals(profileImpl)) { + return "com.sun.opengl.impl.es1.GLES1"; + } else if(GLES2.equals(profileImpl) || GL2ES2.equals(profileImpl)) { + return "com.sun.opengl.impl.es2.GLES2"; + } else { + throw new GLException("unsupported profile \"" + profileImpl + "\""); + } + } + + public final String getGLImplBaseClassName() { + return GetGLImplBaseClassName(profileImpl); + } + + public Object clone() { + try { + return super.clone(); + } catch (Exception e) { + throw new GLException(e); + } } /** - * Selects a profile, implementing the interface GL - * Order: GL2, GL2ES2, GL2ES1, GL3, GLES2, GLES1 + * @param o GLProfile object to compare with + * @return true if given Object is a GLProfile and + * if both, profile and profileImpl is equal with this. + */ + public final boolean equals(Object o) { + if(o instanceof GLProfile) { + GLProfile glp = (GLProfile)o; + return profile.equals(glp.getName()) && + profileImpl.equals(glp.getImplName()) ; + } + return false; + } + + /** + * @param glp GLProfile to compare with + * @throws GLException if given GLProfile and this aren't equal */ - public static synchronized final void setProfileGLAny() { - setProfile(new String[] { GL2, GL2ES2, GL2ES1, /*GL3,*/ GLES2, GLES1 }); + public final void verifyEquality(GLProfile glp) + throws GLException + { + if(!this.equals(glp)) throw new GLException("GLProfiles are not equal: "+this+" != "+glp); } - public static final String getProfile() { + public final String getName() { return profile; } - - public static final boolean isGL3() { + + public final String getImplName() { + return profileImpl; + } + + /** Indicates whether this profile is capable os GL3. */ + public final boolean isGL3() { return GL3.equals(profile); } - public static final boolean isGL2() { + /** Indicates whether this profile is capable os GL2. */ + public final boolean isGL2() { return GL2.equals(profile); } - public static final boolean isGLES1() { + /** Indicates whether this profile is capable os GLES1. */ + public final boolean isGLES1() { return GLES1.equals(profile); } - public static final boolean isGLES2() { + /** Indicates whether this profile is capable os GLES2. */ + public final boolean isGLES2() { return GLES2.equals(profile); } - /* Indicates whether a GL2ES1 capable profile is in use, ie GL2ES1, GL2, GLES1 */ - public static final boolean isGL2ES1() { + /** Indicates whether this profile is capable os GL2ES1. */ + public final boolean isGL2ES1() { return GL2ES1.equals(profile) || isGL2() || isGLES1() ; } - /* Indicates whether a GL2ES2 capable profile is in use, ie GL2ES2, GL2, GLES2 */ - public static final boolean isGL2ES2() { + /** Indicates whether this profile is capable os GL2ES2. */ + public final boolean isGL2ES2() { return GL2ES2.equals(profile) || isGL2() || isGL3() || isGLES2() ; } - /** Indicates whether the native OpenGL ES1 profile is in use. - * This requires an EGL interface. - */ - public static final boolean usesNativeGLES1() { - return GLES1.equals(realProfile) || GL2ES1.equals(realProfile) ; + /** Indicates whether this profile uses the native OpenGL ES1 implementations. */ + public final boolean usesNativeGLES1() { + return GLES1.equals(profileImpl) || GL2ES1.equals(profileImpl) ; } - /** Indicates whether the native OpenGL ES2 profile is in use. - * This requires an EGL interface. - */ - public static final boolean usesNativeGLES2() { - return GLES2.equals(realProfile) || GL2ES2.equals(realProfile) ; + /** Indicates whether this profile uses the native OpenGL ES2 implementations. */ + public final boolean usesNativeGLES2() { + return GLES2.equals(profileImpl) || GL2ES2.equals(profileImpl) ; } - /** Indicates whether either of the native OpenGL ES profiles are in use. */ - public static final boolean usesNativeGLES() { + /** Indicates whether this profile uses either of the native OpenGL ES implementations. */ + public final boolean usesNativeGLES() { return usesNativeGLES2() || usesNativeGLES1(); } - /** Indicates whether a GLSL capable profiles is in use. */ - public static final boolean hasGLSL() { + /** Indicates whether this profile supports GLSL. */ + public final boolean hasGLSL() { return isGL2ES2() ; } - public static final boolean matches(String test_profile) { - return (null==test_profile)?false:test_profile.equals(profile); - } - - public static final String getGLImplBaseClassName() { - if(GL3.equals(realProfile)) { - return "com.sun.opengl.impl.gl3.GL3"; - } else if(GL2.equals(realProfile)) { - return "com.sun.opengl.impl.gl2.GL2"; - } else if(GL2ES12.equals(realProfile)) { - return "com.sun.opengl.impl.gl2es12.GL2ES12"; - } else if(GLES1.equals(realProfile) || GL2ES1.equals(realProfile)) { - return "com.sun.opengl.impl.es1.GLES1"; - } else if(GLES2.equals(realProfile) || GL2ES2.equals(realProfile)) { - return "com.sun.opengl.impl.es2.GLES2"; - } else { - throw new GLException("unsupported profile \"" + profile + "\""); - } - } - - private static String getGLTypeName(int type) { - switch (type) { - case GL.GL_UNSIGNED_BYTE: - return "GL_UNSIGNED_BYTE"; - case GL.GL_BYTE: - return "GL_BYTE"; - case GL.GL_UNSIGNED_SHORT: - return "GL_UNSIGNED_SHORT"; - case GL.GL_SHORT: - return "GL_SHORT"; - case GL.GL_FLOAT: - return "GL_FLOAT"; - case GL.GL_FIXED: - return "GL_FIXED"; - case javax.media.opengl.GL2ES2.GL_INT: - return "GL_INT"; - case javax.media.opengl.GL2ES2.GL_UNSIGNED_INT: - return "GL_UNSIGNED_INT"; - case javax.media.opengl.GL2.GL_DOUBLE: - return "GL_DOUBLE"; - case javax.media.opengl.GL2.GL_2_BYTES: - return "GL_2_BYTES"; - case javax.media.opengl.GL2.GL_3_BYTES: - return "GL_3_BYTES"; - case javax.media.opengl.GL2.GL_4_BYTES: - return "GL_4_BYTES"; - } - return null; - } - - private static String getGLArrayName(int array) { - switch(array) { - case GLPointerFunc.GL_VERTEX_ARRAY: - return "GL_VERTEX_ARRAY"; - case GLPointerFunc.GL_NORMAL_ARRAY: - return "GL_NORMAL_ARRAY"; - case GLPointerFunc.GL_COLOR_ARRAY: - return "GL_COLOR_ARRAY"; - case GLPointerFunc.GL_TEXTURE_COORD_ARRAY: - return "GL_TEXTURE_COORD_ARRAY"; - } - return null; - } - /** * General validation if type is a valid GL data type * for the current profile */ - public static boolean isValidDataType(int type, boolean throwException) { + public boolean isValidDataType(int type, boolean throwException) { switch(type) { case GL.GL_UNSIGNED_BYTE: case GL.GL_BYTE: @@ -355,15 +319,15 @@ public class GLProfile { } } if(throwException) { - throw new GLException("Illegal data type on profile "+GLProfile.getProfile()+": "+type); + throw new GLException("Illegal data type on profile "+this+": "+type); } return false; } - public static boolean isValidArrayDataType(int index, int comps, int type, - boolean isVertexAttribPointer, boolean throwException) { - String arrayName = getGLArrayName(index); - if(GLProfile.isGLES1()) { + public boolean isValidArrayDataType(int index, int comps, int type, + boolean isVertexAttribPointer, boolean throwException) { + String arrayName = GetGLArrayName(index); + if(isGLES1()) { if(isVertexAttribPointer) { if(throwException) { throw new GLException("Illegal array type for "+arrayName+" on profile GLES1: VertexAttribPointer"); @@ -446,7 +410,7 @@ public class GLProfile { } break; } - } else if(GLProfile.isGLES2()) { + } else if(isGLES2()) { // simply ignore !isVertexAttribPointer case, since it is simulated anyway .. switch(type) { @@ -476,7 +440,7 @@ public class GLProfile { } return false; } - } else if( GLProfile.isGL2ES2() ) { + } else if( isGL2ES2() ) { if(isVertexAttribPointer) { switch(type) { case GL.GL_UNSIGNED_BYTE: @@ -621,4 +585,239 @@ public class GLProfile { } return true; } + + public String toString() { + return "GLProfile[" + profile + "/" + profileImpl + "]"; + } + + // The intersection between desktop OpenGL and the union of the OpenGL ES profiles + // This is here only to avoid having separate GL2ES1Impl and GL2ES2Impl classes + private static final String GL2ES12 = "GL2ES12"; + + private static final boolean hasGL3Impl; + private static final boolean hasGL2Impl; + private static final boolean hasGL2ES12Impl; + private static final boolean hasGLES2Impl; + private static final boolean hasGLES1Impl; + + /** The JVM/process wide default GL profile **/ + private static GLProfile defaultGLProfile; + + /** All GLProfiles */ + private static final HashMap/*<String, GLProfile>*/ mappedProfiles; + + /** + * Tries the profiles implementation and native libraries. + * Throws an GLException if no profile could be found at all. + */ + static { + boolean hasDesktopGL = false; + try { + // See DRIHack.java for an explanation of why this is necessary + DRIHack.begin(); + NativeLibLoader.loadGLDesktop(); + DRIHack.end(); + hasDesktopGL = true; + } catch (Throwable t) { + if (DEBUG) { + System.err.println("GLProfile.static Desktop GL Library not available"); + t.printStackTrace(); + } + } + boolean hasDesktopGLES12 = false; + try { + // See DRIHack.java for an explanation of why this is necessary + DRIHack.begin(); + NativeLibLoader.loadGLDesktopES12(); + DRIHack.end(); + hasDesktopGLES12 = true; + } catch (Throwable t) { + if (DEBUG) { + System.err.println("GLProfile.static Desktop GL ES12 Library not available"); + t.printStackTrace(); + } + } + + boolean hasNativeOSFactory = false; + if(hasDesktopGL||hasDesktopGLES12) { + try { + hasNativeOSFactory = null!=GLDrawableFactory.getNativeOSFactory(); + } catch (Throwable t) { + if (DEBUG) { + System.err.println("GLProfile.static - Native platform GLDrawable factory not available"); + t.printStackTrace(); + } + } + } + if(!hasNativeOSFactory) { + hasDesktopGLES12=false; + hasDesktopGL=false; + } + + // FIXME: check for real GL3 availability .. ? + hasGL3Impl = hasDesktopGL && null!=NWReflection.getClass("com.sun.opengl.impl.gl3.GL3Impl"); + hasGL2Impl = hasDesktopGL && null!=NWReflection.getClass("com.sun.opengl.impl.gl2.GL2Impl"); + + hasGL2ES12Impl = hasDesktopGLES12 && null!=NWReflection.getClass("com.sun.opengl.impl.gl2es12.GL2ES12Impl"); + + boolean btest = false; + try { + btest = null!=GLDrawableFactory.getFactory(GLES2) && null!=NWReflection.getClass("com.sun.opengl.impl.es2.GLES2Impl"); + } catch (Throwable t) { + if (DEBUG) { + System.err.println("GLProfile.static - GL ES2 Factory/Library not available"); + t.printStackTrace(); + } + } + hasGLES2Impl = btest; + + btest = false; + try { + btest = null!=GLDrawableFactory.getFactory(GLES1) && null!=NWReflection.getClass("com.sun.opengl.impl.es1.GLES1Impl"); + } catch (Throwable t) { + if (DEBUG) { + System.err.println("GLProfile.static - GL ES1 Factory/Library not available"); + t.printStackTrace(); + } + } + hasGLES1Impl = btest; + + if (DEBUG) { + System.err.println("GLProfile.static hasNativeOSFactory "+hasNativeOSFactory); + System.err.println("GLProfile.static hasDesktopGLES12 "+hasDesktopGLES12); + System.err.println("GLProfile.static hasDesktopGL "+hasDesktopGL); + System.err.println("GLProfile.static hasGL3Impl "+hasGL3Impl); + System.err.println("GLProfile.static hasGL2Impl "+hasGL2Impl); + System.err.println("GLProfile.static hasGL2ES12Impl "+hasGL2ES12Impl); + System.err.println("GLProfile.static hasGLES2Impl "+hasGLES2Impl); + System.err.println("GLProfile.static hasGLES1Impl "+hasGLES1Impl); + } + + HashMap/*<String, GLProfile>*/ _mappedProfiles = new HashMap(GL_PROFILE_LIST.length); + for(int i=0; i<GL_PROFILE_LIST.length; i++) { + String profile = GL_PROFILE_LIST[i]; + String profileImpl = ComputeProfileImpl(profile); + if(null!=profileImpl) { + GLProfile glProfile = new GLProfile(profile, profileImpl); + _mappedProfiles.put(profile, glProfile); + if (DEBUG) { + System.err.println("GLProfile.static map "+glProfile); + } + if(null==defaultGLProfile) { + defaultGLProfile=glProfile; + if (DEBUG) { + System.err.println("GLProfile.static default "+glProfile); + } + } + } else { + if (DEBUG) { + System.err.println("GLProfile.static map *** no mapping for "+profile); + } + } + } + mappedProfiles = _mappedProfiles; // final .. + if(null==defaultGLProfile) { + throw new GLException("No profile available: "+list2String(GL_PROFILE_LIST)); + } + } + + private static final String list2String(String[] list) { + StringBuffer msg = new StringBuffer(); + msg.append("["); + for (int i = 0; i < list.length; i++) { + if (i > 0) + msg.append(", "); + msg.append(list[i]); + } + msg.append("]"); + return msg.toString(); + } + + + /** + * Returns the profile implementation + */ + private static String ComputeProfileImpl(String profile) { + if (GL2ES1.equals(profile)) { + if(hasGL2Impl) { + return GL2; + } else if(hasGL2ES12Impl) { + return GL2ES12; + } else if(hasGLES1Impl) { + return GLES1; + } + } else if (GL2ES2.equals(profile)) { + if(hasGL2ES12Impl) { + return GL2ES12; + } else if(hasGL2Impl) { + return GL2; + } else if(hasGL3Impl) { + return GL3; + } else if(hasGLES2Impl) { + return GLES2; + } + } else if(GL3.equals(profile) && hasGL3Impl) { + return GL3; + } else if(GL2.equals(profile) && hasGL2Impl) { + return GL2; + } else if(GLES2.equals(profile) && hasGLES2Impl) { + return GLES2; + } else if(GLES1.equals(profile) && hasGLES1Impl) { + return GLES1; + } + return null; + } + + public static String GetGLTypeName(int type) { + switch (type) { + case GL.GL_UNSIGNED_BYTE: + return "GL_UNSIGNED_BYTE"; + case GL.GL_BYTE: + return "GL_BYTE"; + case GL.GL_UNSIGNED_SHORT: + return "GL_UNSIGNED_SHORT"; + case GL.GL_SHORT: + return "GL_SHORT"; + case GL.GL_FLOAT: + return "GL_FLOAT"; + case GL.GL_FIXED: + return "GL_FIXED"; + case javax.media.opengl.GL2ES2.GL_INT: + return "GL_INT"; + case javax.media.opengl.GL2ES2.GL_UNSIGNED_INT: + return "GL_UNSIGNED_INT"; + case javax.media.opengl.GL2.GL_DOUBLE: + return "GL_DOUBLE"; + case javax.media.opengl.GL2.GL_2_BYTES: + return "GL_2_BYTES"; + case javax.media.opengl.GL2.GL_3_BYTES: + return "GL_3_BYTES"; + case javax.media.opengl.GL2.GL_4_BYTES: + return "GL_4_BYTES"; + } + return null; + } + + public static String GetGLArrayName(int array) { + switch(array) { + case GLPointerFunc.GL_VERTEX_ARRAY: + return "GL_VERTEX_ARRAY"; + case GLPointerFunc.GL_NORMAL_ARRAY: + return "GL_NORMAL_ARRAY"; + case GLPointerFunc.GL_COLOR_ARRAY: + return "GL_COLOR_ARRAY"; + case GLPointerFunc.GL_TEXTURE_COORD_ARRAY: + return "GL_TEXTURE_COORD_ARRAY"; + } + return null; + } + + private GLProfile(String profile, String profileImpl) { + this.profile = profile; + this.profileImpl = profileImpl; + } + + private String profileImpl = null; + private String profile = null; + } diff --git a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java index 727d06b61..7ed6d3c3c 100644 --- a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java +++ b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java @@ -76,6 +76,8 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable { private static final boolean DEBUG = Debug.debug("GLCanvas"); + static private GLProfile glProfileDefault = GLProfile.GetProfileDefault(); + private GLProfile glProfile; private GLDrawableHelper drawableHelper = new GLDrawableHelper(); private GLDrawable drawable; private GLContextImpl context; @@ -83,16 +85,9 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable { private boolean sendReshape = false; private GraphicsConfiguration chosen; - private GLCapabilities glCaps; + private AWTGraphicsConfiguration awtConfig; private GLCapabilitiesChooser glCapChooser; - static { - // Default to the GL2 profile, which is the default on the desktop - if (GLProfile.getProfile() == null) { - GLProfile.setProfile(GLProfile.GL2); - } - } - /** Creates a new GLCanvas component with a default set of OpenGL capabilities, using the default OpenGL capabilities selection mechanism, on the default screen device. */ @@ -133,17 +128,23 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable { * below. */ super(); + + if(null==capabilities) { + capabilities = new GLCapabilities(glProfileDefault); + } + glProfile = capabilities.getGLProfile(); + /* * Save the chosen capabilities for use in getGraphicsConfiguration(). */ - AWTGraphicsConfiguration config = chooseGraphicsConfiguration(capabilities, chooser, device); + awtConfig = chooseGraphicsConfiguration(capabilities, chooser, device); if(DEBUG) { - Exception e = new Exception("Created Config: "+config); + Exception e = new Exception("Created Config: "+awtConfig); e.printStackTrace(); } - if(null!=config) { + if(null!=awtConfig) { // update .. - chosen = config.getGraphicsConfiguration(); + chosen = awtConfig.getGraphicsConfiguration(); /* * If we are running on a platform that @@ -151,13 +152,12 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable { * save these for later use in getGraphicsConfiguration(). */ this.glCapChooser = chooser; - this.glCaps = (GLCapabilities)config.getCapabilities(); } if (!Beans.isDesignTime()) { - if(null==config) { + if(null==awtConfig) { throw new GLException("Error: AWTGraphicsConfiguration is null"); } - drawable = GLDrawableFactory.getFactory().createGLDrawable(NativeWindowFactory.getNativeWindow(this, config)); + drawable = GLDrawableFactory.getFactory(awtConfig).createGLDrawable(NativeWindowFactory.getNativeWindow(this, awtConfig)); context = (GLContextImpl) drawable.createContext(shareWith); context.setSynchronized(true); } @@ -245,7 +245,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable { * block, both devices should have the same visual list, and the * same configuration should be selected here. */ - AWTGraphicsConfiguration config = chooseGraphicsConfiguration(glCaps, glCapChooser, gc.getDevice()); + AWTGraphicsConfiguration config = chooseGraphicsConfiguration((GLCapabilities)awtConfig.getCapabilities(), glCapChooser, gc.getDevice()); final GraphicsConfiguration compatible = (null!=config)?config.getGraphicsConfiguration():null; if (compatible != null) { @@ -254,6 +254,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable { * any outside callers of this method. */ chosen = compatible; + awtConfig = config; // FIXME: ?? } } @@ -448,16 +449,18 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable { if (Beans.isDesignTime()) { return null; } - - return getContext().getGL(); + GLContext context = getContext(); + return (context == null) ? null : context.getGL(); } public void setGL(GL gl) { - if (!Beans.isDesignTime()) { - getContext().setGL(gl); + GLContext context = getContext(); + if (context != null) { + context.setGL(gl); } } + public void setAutoSwapBufferMode(boolean onOrOff) { drawableHelper.setAutoSwapBufferMode(onOrOff); } @@ -470,11 +473,16 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable { maybeDoSingleThreadedWorkaround(swapBuffersOnEventDispatchThreadAction, swapBuffersAction); } - public GLCapabilities getChosenGLCapabilities() { - if (drawable == null) - return null; + public GLProfile getGLProfile() { + return getGLCapabilities().getGLProfile(); + } + + public GLCapabilities getGLCapabilities() { + if (awtConfig == null) { + throw new GLException("No AWTGraphicsConfiguration: "+this); + } - return drawable.getChosenGLCapabilities(); + return (GLCapabilities)awtConfig.getCapabilities(); } public NativeWindow getNativeWindow() { @@ -486,7 +494,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable { } public String toString() { - return "AWT-GLCanvas[ "+((null!=drawable)?drawable.getClass().getName():"null-drawable")+", "+drawableHelper+"]"; + return "AWT-GLCanvas[ "+awtConfig+", "+((null!=drawable)?drawable.getClass().getName():"null-drawable")+", "+drawableHelper+"]"; } //---------------------------------------------------------------------- diff --git a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java index bf4176a08..eff9b8f3f 100644 --- a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java +++ b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java @@ -93,6 +93,8 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable { // Data used for either pbuffers or pixmap-based offscreen surfaces private GLCapabilities offscreenCaps; + private GLProfile glProfile; + private GLDrawableFactoryImpl factory; private GLCapabilitiesChooser chooser; private GLContext shareWith; // Width of the actual GLJPanel @@ -102,8 +104,6 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable { private boolean handleReshape = false; private boolean sendReshape = true; - private static GLDrawableFactoryImpl factory; - // The backend in use private Backend backend; @@ -145,8 +145,6 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable { getLocalGraphicsEnvironment(). getDefaultScreenDevice()); } - GLProfile.setProfile(GLProfile.GL2); - factory = GLDrawableFactoryImpl.getFactoryImpl(); } /** Creates a new GLJPanel component with a default set of OpenGL @@ -182,9 +180,11 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable { if (capabilities != null) { offscreenCaps = (GLCapabilities) capabilities.clone(); } else { - offscreenCaps = new GLCapabilities(); + offscreenCaps = new GLCapabilities(null); } offscreenCaps.setDoubleBuffered(false); + this.glProfile = offscreenCaps.getGLProfile(); + this.factory = GLDrawableFactoryImpl.getFactoryImpl(glProfile); this.chooser = ((chooser != null) ? chooser : new DefaultGLCapabilitiesChooser()); this.shareWith = shareWith; } @@ -352,6 +352,9 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable { } public GL getGL() { + if (Beans.isDesignTime()) { + return null; + } GLContext context = getContext(); return (context == null) ? null : context.getGL(); } @@ -404,15 +407,19 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable { return oglPipelineEnabled; } - public GLCapabilities getChosenGLCapabilities() { - return backend.getChosenGLCapabilities(); + public GLCapabilities getGLCapabilities() { + return backend.getGLCapabilities(); + } + + public final GLProfile getGLProfile() { + return glProfile; } public NativeWindow getNativeWindow() { throw new GLException("FIXME"); } - public GLDrawableFactory getFactory() { + public final GLDrawableFactory getFactory() { return factory; } @@ -620,8 +627,11 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable { // Called to get the current backend's GLDrawable public GLDrawable getDrawable(); - // Called to fetch the "real" chosen GLCapabilities for the backend - public GLCapabilities getChosenGLCapabilities(); + // Called to fetch the "real" GLCapabilities for the backend + public GLCapabilities getGLCapabilities(); + + // Called to fetch the "real" GLProfile for the backend + public GLProfile getGLProfile(); // Called to handle a reshape event. When this is called, the // OpenGL context associated with the backend is not current, to @@ -861,11 +871,18 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable { return offscreenDrawable; } - public GLCapabilities getChosenGLCapabilities() { + public GLCapabilities getGLCapabilities() { + if (offscreenDrawable == null) { + return null; + } + return offscreenDrawable.getGLCapabilities(); + } + + public GLProfile getGLProfile() { if (offscreenDrawable == null) { return null; } - return offscreenDrawable.getChosenGLCapabilities(); + return offscreenDrawable.getGLProfile(); } public void handleReshape() { @@ -952,11 +969,18 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable { return pbuffer; } - public GLCapabilities getChosenGLCapabilities() { + public GLCapabilities getGLCapabilities() { + if (pbuffer == null) { + return null; + } + return pbuffer.getGLCapabilities(); + } + + public GLProfile getGLProfile() { if (pbuffer == null) { return null; } - return pbuffer.getChosenGLCapabilities(); + return pbuffer.getGLProfile(); } public void handleReshape() { @@ -1123,9 +1147,14 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable { return joglDrawable; } - public GLCapabilities getChosenGLCapabilities() { + public GLCapabilities getGLCapabilities() { + // FIXME: should do better than this; is it possible to using only platform-independent code? + return new GLCapabilities(null); + } + + public GLProfile getGLProfile() { // FIXME: should do better than this; is it possible to using only platform-independent code? - return new GLCapabilities(); + return GLProfile.GetProfileDefault(); } public void handleReshape() { @@ -1388,9 +1417,9 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable { if (factory.canCreateExternalGLDrawable()) { joglDrawable = factory.createExternalGLDrawable(); joglContext = joglDrawable.createContext(shareWith); - } else if (((GLDrawableFactoryImpl) factory).canCreateContextOnJava2DSurface()) { + } else if (factory.canCreateContextOnJava2DSurface()) { // Mac OS X code path - joglContext = ((GLDrawableFactoryImpl) factory).createContextOnJava2DSurface(g, shareWith); + joglContext = factory.createContextOnJava2DSurface(g, shareWith); } if (DEBUG) { joglContext.setGL(new DebugGL2(joglContext.getGL().getGL2())); |