JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestMultisampleES2NEWT.java
Go to the documentation of this file.
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
41package com.jogamp.opengl.test.junit.jogl.caps;
42
43import com.jogamp.opengl.GLAutoDrawable;
44import com.jogamp.opengl.GLCapabilities;
45import com.jogamp.opengl.GLCapabilitiesChooser;
46import com.jogamp.opengl.GLEventListener;
47import com.jogamp.opengl.GLProfile;
48
49import org.junit.Test;
50import org.junit.FixMethodOrder;
51import org.junit.runners.MethodSorters;
52
53import com.jogamp.newt.opengl.GLWindow;
54import com.jogamp.opengl.test.junit.jogl.demos.es2.MultisampleDemoES2;
55import com.jogamp.opengl.test.junit.util.MiscUtils;
56import com.jogamp.opengl.test.junit.util.UITestCase;
57import com.jogamp.opengl.util.GLReadBufferUtil;
58import com.jogamp.opengl.util.texture.TextureIO;
59
60@FixMethodOrder(MethodSorters.NAME_ASCENDING)
61public class TestMultisampleES2NEWT extends UITestCase {
62 static long durationPerTest = 60; // ms
63
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
76 public void testOnscreenMultiSampleAA0() throws InterruptedException {
77 testMultiSampleAAImpl(false, false, 0);
78 }
79
80 @Test
81 public void testOnscreenMultiSampleAA8() throws InterruptedException {
82 testMultiSampleAAImpl(false, false, 8);
83 }
84
85 @Test
86 public void testOffscreenPBufferMultiSampleAA0() throws InterruptedException {
87 testMultiSampleAAImpl(false, true, 0);
88 }
89
90 @Test(timeout = 10000)
91 public void testOffsreenPBufferMultiSampleAA8() throws InterruptedException {
92 testMultiSampleAAImpl(false, true, 8);
93 }
94
95 @Test(timeout = 10000)
96 public void testOffscreenFBOMultiSampleAA0() throws InterruptedException {
97 testMultiSampleAAImpl(true, false, 0);
98 }
99
100 @Test(timeout = 10000)
101 public void testOffsreenFBOMultiSampleAA8() throws InterruptedException {
102 testMultiSampleAAImpl(true, false, 8);
103 }
104
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}
void setAlphaBits(final int alphaBits)
Sets the number of bits requested for the color buffer's alpha component.
Specifies a set of OpenGL capabilities.
void setPBuffer(final boolean enable)
Requesting offscreen pbuffer mode.
void setFBO(final boolean enable)
Requesting offscreen FBO mode.
void setNumSamples(final int numSamples)
If sample buffers are enabled, indicates the number of buffers to be allocated.
void setSampleBuffers(final boolean enable)
Defaults to false.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
Definition: GLProfile.java:913
static int atoi(final String str, final int def)
Definition: MiscUtils.java:57
Utility to read out the current FB to TextureData, optionally writing the data back to a texture obje...
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
Provides a mechanism by which applications can customize the window type selection for a given GLCapa...
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.