JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestMultisampleES1NEWT.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.es1.MultisampleDemoES1;
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 TestMultisampleES1NEWT extends UITestCase {
62 static long durationPerTest = 60; // ms
63 private GLWindow window;
64
65 public static void main(final String[] args) {
66 for(int i=0; i<args.length; i++) {
67 if(args[i].equals("-time")) {
68 durationPerTest = MiscUtils.atoi(args[++i], 500);
69 }
70 }
71 System.out.println("durationPerTest: "+durationPerTest);
72 final String tstname = TestMultisampleES1NEWT.class.getName();
73 org.junit.runner.JUnitCore.main(tstname);
74 }
75
76 @Test
77 public void testOnscreenMultiSampleAA0() throws InterruptedException {
78 testMultiSampleAAImpl(false, false, 0);
79 }
80
81 @Test
82 public void testOnscreenMultiSampleAA2() throws InterruptedException {
83 testMultiSampleAAImpl(false, false, 2);
84 }
85
86 @Test
87 public void testOnscreenMultiSampleAA4() throws InterruptedException {
88 testMultiSampleAAImpl(false, false, 4);
89 }
90
91 @Test
92 public void testOnscreenMultiSampleAA8() throws InterruptedException {
93 testMultiSampleAAImpl(false, false, 8);
94 }
95
96 @Test
97 public void testOffscreenPBufferMultiSampleAA0() throws InterruptedException {
98 testMultiSampleAAImpl(false, true, 0);
99 }
100
101 @Test
102 public void testOffsreenPBufferMultiSampleAA8() throws InterruptedException {
103 testMultiSampleAAImpl(false, true, 8);
104 }
105
106 @Test
107 public void testOffscreenFBOMultiSampleAA0() throws InterruptedException {
108 testMultiSampleAAImpl(true, false, 0);
109 }
110
111 @Test
112 public void testOffsreenFBOMultiSampleAA8() throws InterruptedException {
113 testMultiSampleAAImpl(true, false, 8);
114 }
115
116 private void testMultiSampleAAImpl(final boolean useFBO, final boolean usePBuffer, final int reqSamples) throws InterruptedException {
117 final GLReadBufferUtil screenshot = new GLReadBufferUtil(true, false);
118 final GLProfile glp = GLProfile.getMaxFixedFunc(true);
119 final GLCapabilities caps = new GLCapabilities(glp);
120 final GLCapabilitiesChooser chooser = new MultisampleChooser01();
121
122 caps.setAlphaBits(1);
123 caps.setFBO(useFBO);
124 caps.setPBuffer(usePBuffer);
125
126 if(reqSamples>0) {
127 caps.setSampleBuffers(true);
128 caps.setNumSamples(reqSamples);
129 }
130
131 window = GLWindow.create(caps);
132 window.setCapabilitiesChooser(chooser);
133 window.addGLEventListener(new MultisampleDemoES1(reqSamples>0?true:false));
135 int displayCount = 0;
136 public void init(final GLAutoDrawable drawable) {}
137 public void dispose(final GLAutoDrawable drawable) {}
138 public void display(final GLAutoDrawable drawable) {
139 snapshot(displayCount++, null, drawable.getGL(), screenshot, TextureIO.PNG, null);
140 }
141 public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { }
142 });
143 window.setSize(512, 512);
144 window.setVisible(true);
145 window.requestFocus();
146
147 Thread.sleep(durationPerTest);
148
149 window.destroy();
150 }
151
152}
void setAlphaBits(final int alphaBits)
Sets the number of bits requested for the color buffer's alpha component.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
Definition: GLWindow.java:625
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
Definition: GLWindow.java:615
CapabilitiesChooser setCapabilitiesChooser(final CapabilitiesChooser chooser)
Set the CapabilitiesChooser to help determine the native visual type.
Definition: GLWindow.java:261
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
Definition: GLWindow.java:605
final void requestFocus()
Request focus for this native window.
Definition: GLWindow.java:416
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Definition: GLWindow.java:169
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 getMaxFixedFunc(final AbstractGraphicsDevice device, final boolean favorHardwareRasterizer)
Returns the highest profile, implementing the fixed function pipeline.
Definition: GLProfile.java:808
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.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
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.