/*
* 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 com.jogamp.common.util.*;
import com.jogamp.opengl.impl.Debug;
import com.jogamp.opengl.impl.GLJNILibLoader;
import com.jogamp.opengl.impl.GLDrawableFactoryImpl;
import com.jogamp.opengl.impl.egl.EGLDynamicLookupHelper;
import com.jogamp.opengl.impl.DesktopGLDynamicLookupHelper;
import com.jogamp.common.jvm.JVMUtil;
import java.util.HashMap;
import java.util.Iterator;
import java.security.*;
import javax.media.opengl.fixedfunc.GLPointerFunc;
import javax.media.nativewindow.NativeWindowFactory;
/**
* Specifies the the OpenGL profile.
*
* This class static singleton initialization queries the availability of all OpenGL Profiles
* and instantiates singleton GLProfile objects for each available profile.
*
* The platform default profile may be used, using {@link GLProfile#GetProfileDefault()},
* or more specialized versions using the other static GetProfile methods.
*/
public class GLProfile implements Cloneable {
public static final boolean DEBUG = Debug.debug("GLProfile");
//
// Query platform available OpenGL implementation
//
public static final boolean isGL4bcAvailable() { return null != mappedProfiles.get(GL4bc); }
public static final boolean isGL4Available() { return null != mappedProfiles.get(GL4); }
public static final boolean isGL3bcAvailable() { return null != mappedProfiles.get(GL3bc); }
public static final boolean isGL3Available() { return null != mappedProfiles.get(GL3); }
public static final boolean isGL2Available() { return null != mappedProfiles.get(GL2); }
public static final boolean isGLES2Available() { return null != mappedProfiles.get(GLES2); }
public static final boolean isGLES1Available() { return null != mappedProfiles.get(GLES1); }
public static final boolean isGL2ES1Available() { return null != mappedProfiles.get(GL2ES1); }
public static final boolean isGL2ES2Available() { return null != mappedProfiles.get(GL2ES2); }
private static final void glAvailabilityToString(StringBuffer sb, int major, int profile) {
String str = GLContext.getGLVersionAvailable(major, profile);
if(null==str) {
throw new GLException("Internal Error");
}
sb.append("[");
sb.append(str);
sb.append("]");
}
public static final String glAvailabilityToString() {
boolean avail;
String str;
StringBuffer sb = new StringBuffer();
sb.append("GLAvailability[Native[GL4bc ");
avail=isGL4bcAvailable();
sb.append(avail);
if(avail) {
glAvailabilityToString(sb, 4, GLContext.CTX_PROFILE_COMPAT);
}
sb.append(", GL4 ");
avail=isGL4Available();
sb.append(avail);
if(avail) {
glAvailabilityToString(sb, 4, GLContext.CTX_PROFILE_CORE);
}
sb.append(", GL3bc ");
avail=isGL3bcAvailable();
sb.append(avail);
if(avail) {
glAvailabilityToString(sb, 3, GLContext.CTX_PROFILE_COMPAT);
}
sb.append(", GL3 ");
avail=isGL3Available();
sb.append(avail);
if(avail) {
glAvailabilityToString(sb, 3, GLContext.CTX_PROFILE_CORE);
}
sb.append(", GL2 ");
avail=isGL2Available();
sb.append(avail);
if(avail) {
glAvailabilityToString(sb, 2, GLContext.CTX_PROFILE_COMPAT);
}
sb.append(", GL2ES1 ");
sb.append(isGL2ES1Available());
sb.append(", GLES1 ");
avail=isGLES1Available();
sb.append(avail);
if(avail) {
glAvailabilityToString(sb, 1, GLContext.CTX_PROFILE_ES);
}
sb.append(", GL2ES2 ");
sb.append(isGL2ES2Available());
sb.append(", GLES2 ");
avail=isGLES2Available();
sb.append(avail);
if(avail) {
glAvailabilityToString(sb, 2, GLContext.CTX_PROFILE_ES);
}
sb.append("], Profiles[");
for(Iterator i=mappedProfiles.values().iterator(); i.hasNext(); ) {
sb.append(((GLProfile)i.next()).toString());
sb.append(", ");
}
sb.append(", default ");
sb.append(defaultGLProfile);
sb.append("]]");
return sb.toString();
}
//
// Public (user-visible) profiles
//
/** The desktop OpenGL compatibility profile 4.x, with x >= 0, ie GL2 plus GL4.
bc
stands for backward compatibility. */
public static final String GL4bc = "GL4bc";
/** The desktop OpenGL core profile 4.x, with x >= 0 */
public static final String GL4 = "GL4";
/** The desktop OpenGL compatibility profile 3.x, with x >= 1, ie GL2 plus GL3.
bc
stands for backward compatibility. */
public static final String GL3bc = "GL3bc";
/** The desktop OpenGL core profile 3.x, with x >= 1 */
public static final String GL3 = "GL3";
/** The desktop OpenGL profile 1.x up to 3.0 */
public static final String GL2 = "GL2";
/** The embedded OpenGL profile ES 1.x, with x >= 0 */
public static final String GLES1 = "GLES1";
/** The embedded OpenGL profile ES 2.x, with x >= 0 */
public static final String GLES2 = "GLES2";
/** The intersection of the desktop GL2 and embedded ES1 profile */
public static final String GL2ES1 = "GL2ES1";
/** The intersection of the desktop GL3, GL2 and embedded ES2 profile */
public static final String GL2ES2 = "GL2ES2";
/** The intersection of the desktop GL3 and GL2 profile */
public static final String GL2GL3 = "GL2GL3";
/**
* All GL Profiles in the order of default detection.
* Desktop compatibility profiles (the one with fixed function pipeline) comes first.
*
* FIXME GL3GL4: Due to GL3 and GL4 implementation bugs, we still choose GL2 first, if available!
*
*
null
or GL
will result in
* the default profile.
*
* @throws GLException if no implementation for the given profile is found.
*/
public static final GLProfile get(String profile)
throws GLException
{
if(null==profile || profile.equals("GL")) return getDefault();
GLProfile glProfile = (GLProfile) mappedProfiles.get(profile);
if(null==glProfile) {
throw new GLException("No implementation for profile "+profile+" available");
}
return glProfile;
}
/**
* 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 get(String[] profiles)
throws GLException
{
for(int i=0; i