/* * %W% %E% * * Copyright (c) 2006 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 MIDROSYSTEMS, 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, licensed or intended * for use in the design, construction, operation or maintenance of any * nuclear facility. */ /* * %W% %E% * * Simple application to test if OGL rendering pipline is available. * * @author Rick Reynaga */ import java.awt.*; import java.awt.image.*; import java.lang.reflect.*; public class TestOGLConfiguration { private static boolean isOGLAvailable() { boolean oglStatus = false; // Get default GraphicsConfiguration GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration(); String gcString = gc.toString(); // Get os.name attribute String osName = System.getProperty("os.name"); // Check if using OGL GraphicsConfiguration if (osName.startsWith("Windows")) { if (gcString.startsWith("WGLGraphicsConfig")) { oglStatus = true; } } else if (osName.startsWith("Linux") || osName.startsWith("SunOS")) { if (gcString.startsWith("GLXGraphicsConfig")) { oglStatus = true; } } return oglStatus; } private static boolean isFBOAvailable() { // Get default GraphicsConfiguration GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration(); // Use reflection to see if the FBO codepath is in use try { Class oglgcKlass = Class.forName("sun.java2d.opengl.OGLGraphicsConfig"); Method m = oglgcKlass.getDeclaredMethod("isCapPresent", int.class); m.setAccessible(true); Class oglcKlass = Class.forName("sun.java2d.opengl.OGLContext"); Field f = oglcKlass.getDeclaredField("CAPS_EXT_FBOBJECT"); f.setAccessible(true); Boolean fbo = (Boolean)m.invoke(gc, f.get(null)); return fbo.booleanValue(); } catch (Exception e) { e.printStackTrace(); return false; } } public static void main(String[] args) { boolean checkfbo = (args.length == 1 && "-checkfbo".equals(args[0])); // Enable OGL pipeline if (checkfbo) { System.setProperty("sun.java2d.opengl", "true"); System.setProperty("sun.java2d.opengl.fbobject", "true"); } else { System.setProperty("sun.java2d.opengl", "True"); } // Require JDK 6 and above String javaVersion = System.getProperty("java.version"); int major = javaVersion.charAt(0); int minor = javaVersion.charAt(2); if (major == 1 && minor < 6) { System.out.println("TestOGLConfiguration: " + "Test suite requires JDK 6 or above"); System.exit(1); } if (isOGLAvailable()) { if (checkfbo) { if (isFBOAvailable()) { System.out.println("TestOGLConfiguration: " + "FBO codepath supported"); System.exit(0); } else { System.out.println("TestOGLConfiguration: " + "FBO codepath not supported"); System.exit(1); } } else { System.out.println("TestOGLConfiguration: " + "OpenGL supported configuration"); System.exit(0); } } else { System.out.println("TestOGLConfiguration: " + "OpenGL pipeline not supported "+ "on this configuration"); System.exit(1); } } }