JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestMultisampleES1AWT.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 java.lang.reflect.InvocationTargetException;
44import java.awt.BorderLayout;
45import java.awt.Frame;
46
47import com.jogamp.opengl.GLAutoDrawable;
48import com.jogamp.opengl.GLCapabilities;
49import com.jogamp.opengl.GLCapabilitiesChooser;
50import com.jogamp.opengl.GLEventListener;
51import com.jogamp.opengl.GLProfile;
52import com.jogamp.opengl.awt.GLCanvas;
53
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
60import org.junit.Test;
61import org.junit.FixMethodOrder;
62import org.junit.runners.MethodSorters;
63
64
65@FixMethodOrder(MethodSorters.NAME_ASCENDING)
66public class TestMultisampleES1AWT extends UITestCase {
67 static long durationPerTest = 60; // ms
68 private GLCanvas canvas;
69
70 public static void main(final String[] args) {
71 for(int i=0; i<args.length; i++) {
72 if(args[i].equals("-time")) {
73 durationPerTest = MiscUtils.atoi(args[++i], 500);
74 }
75 }
76 System.out.println("durationPerTest: "+durationPerTest);
77 final String tstname = TestMultisampleES1AWT.class.getName();
78 org.junit.runner.JUnitCore.main(tstname);
79 }
80
81 @Test
82 public void testOnscreenMultiSampleAA0() throws InterruptedException, InvocationTargetException {
83 testMultiSampleAAImpl(0);
84 }
85
86 @Test
87 public void testOnscreenMultiSampleAA4() throws InterruptedException, InvocationTargetException {
88 testMultiSampleAAImpl(4);
89 }
90
91 @Test
92 public void testOnscreenMultiSampleAA8() throws InterruptedException, InvocationTargetException {
93 testMultiSampleAAImpl(8);
94 }
95
96 private void testMultiSampleAAImpl(final int reqSamples) throws InterruptedException, InvocationTargetException {
97 final GLReadBufferUtil screenshot = new GLReadBufferUtil(true, false);
98 final GLProfile glp = GLProfile.getMaxFixedFunc(true);
99 final GLCapabilities caps = new GLCapabilities(glp);
100 final GLCapabilitiesChooser chooser = new MultisampleChooser01();
101
102 if(reqSamples>0) {
103 caps.setSampleBuffers(true);
104 caps.setNumSamples(reqSamples);
105 }
106
107 canvas = new GLCanvas(caps, chooser, null);
108 canvas.addGLEventListener(new MultisampleDemoES1(reqSamples>0?true:false));
110 int displayCount = 0;
111 public void init(final GLAutoDrawable drawable) {}
112 public void dispose(final GLAutoDrawable drawable) {}
113 public void display(final GLAutoDrawable drawable) {
114 snapshot(displayCount++, null, drawable.getGL(), screenshot, TextureIO.PNG, null);
115 }
116 public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { }
117 });
118
119 final Frame frame = new Frame("Multi Samples "+reqSamples);
120 frame.setLayout(new BorderLayout());
121 canvas.setSize(512, 512);
122
123 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
124 public void run() {
125 frame.add(canvas, BorderLayout.CENTER);
126 frame.pack();
127 frame.setVisible(true);
128 canvas.requestFocus();
129 canvas.display();
130 }});
131
132 Thread.sleep(durationPerTest);
133
134 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
135 public void run() {
136 frame.setVisible(false);
137 frame.remove(canvas);
138 frame.dispose();
139 }});
140
141 }
142}
Specifies a set of OpenGL capabilities.
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
A heavyweight AWT component which provides OpenGL rendering support.
Definition: GLCanvas.java:170
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Definition: GLCanvas.java:1065
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.
void setSize(int width, int height)
Requests a new width and height for this AWTGLAutoDrawable.