29package com.jogamp.opengl.test.junit.jogl.acore;
31import java.awt.BorderLayout;
32import java.awt.Button;
33import java.awt.Container;
34import java.awt.Dimension;
36import java.io.IOException;
37import java.lang.reflect.InvocationTargetException;
39import com.jogamp.opengl.GLAnimatorControl;
40import com.jogamp.opengl.GLCapabilities;
41import com.jogamp.opengl.GLEventListener;
42import com.jogamp.opengl.GLProfile;
43import com.jogamp.opengl.awt.GLCanvas;
45import jogamp.nativewindow.jawt.JAWTUtil;
47import org.junit.Assert;
48import org.junit.BeforeClass;
50import org.junit.FixMethodOrder;
51import org.junit.runners.MethodSorters;
53import com.jogamp.common.os.Platform;
54import com.jogamp.newt.Window;
55import com.jogamp.newt.opengl.GLWindow;
56import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
57import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
58import com.jogamp.opengl.test.junit.util.MiscUtils;
59import com.jogamp.opengl.test.junit.util.UITestCase;
60import com.jogamp.opengl.util.Animator;
62@FixMethodOrder(MethodSorters.NAME_ASCENDING)
64 static boolean singleBuffer =
false;
65 static boolean useMSAA =
false;
66 static boolean addComp =
true;
67 static int swapInterval = 1;
68 static boolean shallUseOffscreenPBufferLayer =
false;
69 static boolean noAnimation =
false;
73 static long durationPerTest = 1000;
74 static boolean waitForKey =
false;
83 private void setupFrameAndShow(
final Frame f,
final java.awt.Component comp)
throws InterruptedException, InvocationTargetException {
85 final Container c =
new Container();
86 c.setLayout(
new BorderLayout());
87 c.add(
new Button(
"north"), BorderLayout.NORTH);
88 c.add(
new Button(
"south"), BorderLayout.SOUTH);
89 c.add(
new Button(
"east"), BorderLayout.EAST);
90 c.add(
new Button(
"west"), BorderLayout.WEST);
91 c.add(comp, BorderLayout.CENTER);
93 f.setLayout(
new BorderLayout());
94 f.add(
new Button(
"NORTH"), BorderLayout.NORTH);
95 f.add(
new Button(
"SOUTH"), BorderLayout.SOUTH);
96 f.add(
new Button(
"EAST"), BorderLayout.EAST);
97 f.add(
new Button(
"WEST"), BorderLayout.WEST);
98 f.add(c, BorderLayout.CENTER);
100 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
108 private void end(
final GLAnimatorControl actrl,
final Frame f,
final Window w)
throws InterruptedException, InvocationTargetException {
110 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
120 public void testInfo00() throws InterruptedException, InvocationTargetException {
121 System.err.println(
"Java Version: "+Platform.getJavaVersionNumber());
122 System.err.println(
"OS Version: "+Platform.getOSVersionNumber());
123 System.err.println(
"JAWTUtil.isOffscreenLayerRequired(): "+JAWTUtil.isOffscreenLayerRequired());
124 System.err.println(
"JAWTUtil.isOffscreenLayerSupported(): "+JAWTUtil.isOffscreenLayerSupported());
129 testOffscreenLayerGLCanvas_Impl(
null);
133 public void test01_GL3() throws InterruptedException, InvocationTargetException {
135 System.err.println(
"GL3 n/a");
141 private void testOffscreenLayerGLCanvas_Impl(
final GLProfile glp)
throws InterruptedException, InvocationTargetException {
142 if(!JAWTUtil.isOffscreenLayerSupported()) {
143 System.err.println(
"offscreen layer n/a");
146 final Frame frame1 =
new Frame(
"AWT Parent Frame");
156 if(shallUseOffscreenPBufferLayer) {
160 final GLCanvas glc =
new GLCanvas(caps);
161 glc.setShallUseOffscreenLayer(
true);
162 glc.setPreferredSize(preferredGLSize);
163 glc.setMinimumSize(preferredGLSize);
164 glc.setSize(preferredGLSize);
166 final GearsES2 demo1 =
new GearsES2(swapInterval);
168 demo1.setDoRotation(
false);
170 glc.addGLEventListener(demo1);
172 frame1.setSize(frameSize0);
173 setupFrameAndShow(frame1, glc);
174 Assert.assertEquals(
true, AWTRobotUtil.waitForRealized(glc,
true,
null));
175 Assert.assertEquals(
true, AWTRobotUtil.waitForVisible(glc,
true,
null));
176 Assert.assertEquals(
true, glc.isOffscreenLayerSurfaceEnabled());
178 final GLAnimatorControl animator1 =
new Animator(glc);
182 animator1.setUpdateFPSFrames(60, System.err);
184 Thread.sleep(durationPerTest/2);
185 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
187 frame1.setSize(frameSize1);
192 Thread.sleep(durationPerTest/2);
194 end(animator1, frame1,
null);
196 UITestCase.waitForKey(
"Continue");
201 Assert.assertNotNull(demo);
202 Assert.assertNotNull(glWindow);
213 static int atoi(
final String a) {
216 i = Integer.parseInt(a);
217 }
catch (
final Exception ex) { ex.printStackTrace(); }
221 public static void main(
final String args[])
throws IOException {
222 for(
int i=0; i<args.length; i++) {
223 if(args[i].equals(
"-time")) {
224 durationPerTest = atoi(args[++i]);
225 }
else if(args[i].equals(
"-vsync")) {
228 }
else if(args[i].equals(
"-layeredPBuffer")) {
229 shallUseOffscreenPBufferLayer =
true;
230 }
else if(args[i].equals(
"-msaa")) {
232 }
else if(args[i].equals(
"-single")) {
234 }
else if(args[i].equals(
"-still")) {
236 }
else if(args[i].equals(
"-wait")) {
256 org.junit.runner.JUnitCore.
main(tstname);
void setOnscreen(final boolean onscreen)
Sets whether the surface shall be on- or offscreen.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final Window getDelegatedWindow()
If the implementation uses delegation, return the delegated Window instance, otherwise return this in...
Specifies a set of OpenGL capabilities.
void setPBuffer(final boolean enable)
Requesting offscreen pbuffer mode.
void setDoubleBuffered(final boolean enable)
Enables or disables double buffering.
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.
static boolean isAvailable(final AbstractGraphicsDevice device, final String profile)
Returns the availability of a profile on a device.
static final String GL3
The desktop OpenGL core profile 3.x, with x >= 1.
static GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
static void main(final String args[])
static void setDemoFields(final GLEventListener demo, final GLWindow glWindow, final boolean debug)
static boolean setFieldIfExists(final Object instance, final String fieldName, final Object value)
static int atoi(final String str, final int def)
Specifying NEWT's Window functionality:
An animator control interface, which implementation may drive a com.jogamp.opengl....
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.