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;
44import jogamp.nativewindow.jawt.JAWTUtil;
46import org.junit.Assert;
47import org.junit.BeforeClass;
49import org.junit.FixMethodOrder;
50import org.junit.runners.MethodSorters;
52import com.jogamp.junit.util.JunitTracer;
53import com.jogamp.newt.Window;
54import com.jogamp.newt.awt.NewtCanvasAWT;
55import com.jogamp.newt.opengl.GLWindow;
56import com.jogamp.newt.opengl.util.NEWTDemoListener;
57import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
58import com.jogamp.opengl.test.junit.newt.parenting.NewtAWTReparentingKeyAdapter;
59import com.jogamp.opengl.test.junit.newt.parenting.NewtReparentingKeyAdapter;
60import com.jogamp.opengl.test.junit.util.NewtTestUtil;
61import com.jogamp.opengl.test.junit.util.MiscUtils;
62import com.jogamp.opengl.test.junit.util.UITestCase;
63import com.jogamp.opengl.util.Animator;
73@FixMethodOrder(MethodSorters.NAME_ASCENDING)
75 static boolean singleBuffer =
false;
76 static boolean useMSAA =
false;
77 static boolean addComp =
true;
78 static int swapInterval = 1;
79 static boolean shallUseOffscreenPBufferLayer =
false;
80 static boolean noAnimation =
false;
84 static long durationPerTest = 1000;
85 static boolean waitForKey =
false;
94 private void setupFrameAndShow(
final Frame f,
final java.awt.Component comp)
throws InterruptedException, InvocationTargetException {
95 final Container c =
new Container();
96 c.setLayout(
new BorderLayout());
97 c.add(
new Button(
"north"), BorderLayout.NORTH);
98 c.add(
new Button(
"south"), BorderLayout.SOUTH);
99 c.add(
new Button(
"east"), BorderLayout.EAST);
100 c.add(
new Button(
"west"), BorderLayout.WEST);
101 c.add(comp, BorderLayout.CENTER);
103 f.setLayout(
new BorderLayout());
104 f.add(
new Button(
"NORTH"), BorderLayout.NORTH);
105 f.add(
new Button(
"SOUTH"), BorderLayout.SOUTH);
106 f.add(
new Button(
"EAST"), BorderLayout.EAST);
107 f.add(
new Button(
"WEST"), BorderLayout.WEST);
108 f.add(c, BorderLayout.CENTER);
110 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
118 private void end(
final GLAnimatorControl actrl,
final Frame f,
final Window w)
throws InterruptedException, InvocationTargetException {
120 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
131 testOffscreenLayerNewtCanvas_Impl(
null);
135 public void test02_GL3() throws InterruptedException, InvocationTargetException {
137 System.err.println(
"GL3 n/a");
143 private void testOffscreenLayerNewtCanvas_Impl(
final GLProfile glp)
throws InterruptedException, InvocationTargetException {
144 if(!JAWTUtil.isOffscreenLayerSupported()) {
145 System.err.println(
"offscreen layer n/a");
148 final Frame frame1 =
new Frame(
"AWT Parent Frame");
158 if(shallUseOffscreenPBufferLayer) {
162 final GLWindow glWindow1 = GLWindow.create(caps);
164 final NewtCanvasAWT newtCanvasAWT1 =
new NewtCanvasAWT(glWindow1);
165 newtCanvasAWT1.setShallUseOffscreenLayer(
true);
166 newtCanvasAWT1.setPreferredSize(preferredGLSize);
167 newtCanvasAWT1.setMinimumSize(preferredGLSize);
168 newtCanvasAWT1.setSize(preferredGLSize);
170 final GearsES2 demo1 =
new GearsES2(swapInterval);
172 demo1.setDoRotation(
false);
174 setDemoFields(demo1, glWindow1,
false);
175 glWindow1.addGLEventListener(demo1);
176 glWindow1.addKeyListener(
new NewtAWTReparentingKeyAdapter(frame1, newtCanvasAWT1, glWindow1));
178 frame1.setSize(frameSize0);
179 setupFrameAndShow(frame1, newtCanvasAWT1);
180 Assert.assertEquals(
true, NewtTestUtil.waitForRealized(glWindow1,
true,
null));
181 Assert.assertEquals(
true, NewtTestUtil.waitForVisible(glWindow1,
true,
null));
182 Assert.assertEquals(newtCanvasAWT1.getNativeWindow(),glWindow1.getParent());
183 Assert.assertEquals(
true, newtCanvasAWT1.isOffscreenLayerSurfaceEnabled());
185 final GLAnimatorControl animator1 =
new Animator(glWindow1);
189 animator1.setUpdateFPSFrames(60, System.err);
191 Thread.sleep(durationPerTest/2);
192 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
194 frame1.setSize(frameSize1);
199 Thread.sleep(durationPerTest/2);
201 end(animator1, frame1, glWindow1);
203 JunitTracer.waitForKey(
"Continue");
208 Assert.assertNotNull(demo);
209 Assert.assertNotNull(glWindow);
220 static int atoi(
final String a) {
223 i = Integer.parseInt(a);
224 }
catch (
final Exception ex) { ex.printStackTrace(); }
228 public static void main(
final String args[])
throws IOException {
229 for(
int i=0; i<args.length; i++) {
230 if(args[i].equals(
"-time")) {
231 durationPerTest = atoi(args[++i]);
232 }
else if(args[i].equals(
"-vsync")) {
235 }
else if(args[i].equals(
"-layeredPBuffer")) {
236 shallUseOffscreenPBufferLayer =
true;
237 }
else if(args[i].equals(
"-msaa")) {
239 }
else if(args[i].equals(
"-single")) {
241 }
else if(args[i].equals(
"-still")) {
243 }
else if(args[i].equals(
"-wait")) {
248 JunitTracer.waitForKey(
"Start");
263 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 setDemoFields(final GLEventListener demo, final GLWindow glWindow, final boolean debug)
static void main(final String args[])
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.