1 /* 2 * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. 3 * Copyright (c) 2010 JogAmp Community. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: 8 * 9 * - Redistribution of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * - Redistribution in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * Neither the name of Sun Microsystems, Inc. or the names of 17 * contributors may be used to endorse or promote products derived from 18 * this software without specific prior written permission. 19 * 20 * This software is provided "AS IS," without a warranty of any kind. ALL 21 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, 22 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A 23 * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN 24 * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR 25 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR 26 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR 27 * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR 28 * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE 29 * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, 30 * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF 31 * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 32 * 33 * You acknowledge that this software is not designed or intended for use 34 * in the design, construction, operation or maintenance of any nuclear 35 * facility. 36 * 37 * Sun gratefully acknowledges that this software was originally authored 38 * and developed by Kenneth Bradley Russell and Christopher John Kline. 39 */ 40 41 package com.jogamp.opengl.test.junit.jogl.caps; 42 43 import com.jogamp.opengl.GLAutoDrawable; 44 import com.jogamp.opengl.GLCapabilities; 45 import com.jogamp.opengl.GLCapabilitiesChooser; 46 import com.jogamp.opengl.GLEventListener; 47 import com.jogamp.opengl.GLProfile; 48 49 import org.junit.Test; 50 import org.junit.FixMethodOrder; 51 import org.junit.runners.MethodSorters; 52 53 import com.jogamp.newt.opengl.GLWindow; 54 import com.jogamp.opengl.test.junit.jogl.demos.es2.MultisampleDemoES2; 55 import com.jogamp.opengl.test.junit.util.MiscUtils; 56 import com.jogamp.opengl.test.junit.util.UITestCase; 57 import com.jogamp.opengl.util.GLReadBufferUtil; 58 import com.jogamp.opengl.util.texture.TextureIO; 59 60 @FixMethodOrder(MethodSorters.NAME_ASCENDING) 61 public class TestMultisampleES2NEWT extends UITestCase { 62 static long durationPerTest = 60; // ms 63 main(final String[] args)64 public static void main(final String[] args) { 65 for(int i=0; i<args.length; i++) { 66 if(args[i].equals("-time")) { 67 durationPerTest = MiscUtils.atoi(args[++i], 500); 68 } 69 } 70 System.out.println("durationPerTest: "+durationPerTest); 71 final String tstname = TestMultisampleES2NEWT.class.getName(); 72 org.junit.runner.JUnitCore.main(tstname); 73 } 74 75 @Test testOnscreenMultiSampleAA0()76 public void testOnscreenMultiSampleAA0() throws InterruptedException { 77 testMultiSampleAAImpl(false, false, 0); 78 } 79 80 @Test testOnscreenMultiSampleAA8()81 public void testOnscreenMultiSampleAA8() throws InterruptedException { 82 testMultiSampleAAImpl(false, false, 8); 83 } 84 85 @Test testOffscreenPBufferMultiSampleAA0()86 public void testOffscreenPBufferMultiSampleAA0() throws InterruptedException { 87 testMultiSampleAAImpl(false, true, 0); 88 } 89 90 @Test(timeout = 10000) testOffsreenPBufferMultiSampleAA8()91 public void testOffsreenPBufferMultiSampleAA8() throws InterruptedException { 92 testMultiSampleAAImpl(false, true, 8); 93 } 94 95 @Test(timeout = 10000) testOffscreenFBOMultiSampleAA0()96 public void testOffscreenFBOMultiSampleAA0() throws InterruptedException { 97 testMultiSampleAAImpl(true, false, 0); 98 } 99 100 @Test(timeout = 10000) testOffsreenFBOMultiSampleAA8()101 public void testOffsreenFBOMultiSampleAA8() throws InterruptedException { 102 testMultiSampleAAImpl(true, false, 8); 103 } 104 testMultiSampleAAImpl(final boolean useFBO, final boolean usePBuffer, final int reqSamples)105 private void testMultiSampleAAImpl(final boolean useFBO, final boolean usePBuffer, final int reqSamples) throws InterruptedException { 106 final GLReadBufferUtil screenshot = new GLReadBufferUtil(true, false); 107 final GLProfile glp = GLProfile.getGL2ES2(); 108 final GLCapabilities caps = new GLCapabilities(glp); 109 final GLCapabilitiesChooser chooser = new MultisampleChooser01(); 110 111 caps.setAlphaBits(1); 112 caps.setFBO(useFBO); 113 caps.setPBuffer(usePBuffer); 114 115 if(reqSamples>0) { 116 caps.setSampleBuffers(true); 117 caps.setNumSamples(reqSamples); 118 } 119 120 final GLWindow window = GLWindow.create(caps); 121 window.setCapabilitiesChooser(chooser); 122 window.addGLEventListener(new MultisampleDemoES2(reqSamples>0?true:false)); 123 window.addGLEventListener(new GLEventListener() { 124 int displayCount = 0; 125 public void init(final GLAutoDrawable drawable) {} 126 public void dispose(final GLAutoDrawable drawable) {} 127 public void display(final GLAutoDrawable drawable) { 128 snapshot(displayCount++, null, drawable.getGL(), screenshot, TextureIO.PNG, null); 129 } 130 public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { } 131 }); 132 window.setSize(512, 512); 133 window.setVisible(true); 134 window.requestFocus(); 135 136 Thread.sleep(durationPerTest); 137 138 window.destroy(); 139 } 140 141 } 142