29package com.jogamp.opengl.test.junit.jogl.awt;
31import com.jogamp.opengl.*;
33import com.jogamp.opengl.util.Animator;
35import com.jogamp.opengl.awt.GLCanvas;
36import javax.swing.BoundedRangeModel;
37import javax.swing.BoxLayout;
38import javax.swing.JFrame;
39import javax.swing.JScrollBar;
40import javax.swing.JScrollPane;
41import javax.swing.JSplitPane;
42import javax.swing.ScrollPaneConstants;
44import com.jogamp.common.util.awt.AWTEDTExecutor;
45import com.jogamp.newt.event.awt.AWTWindowAdapter;
46import com.jogamp.newt.event.TraceWindowAdapter;
47import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
48import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2;
49import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
50import com.jogamp.opengl.test.junit.util.MiscUtils;
51import com.jogamp.opengl.test.junit.util.UITestCase;
52import com.jogamp.opengl.test.junit.util.QuitAdapter;
54import java.awt.BorderLayout;
55import java.awt.Button;
56import java.awt.Component;
57import java.awt.Container;
58import java.awt.Dimension;
59import java.awt.FlowLayout;
61import java.awt.GridLayout;
62import java.lang.reflect.InvocationTargetException;
64import org.junit.Assert;
65import org.junit.Assume;
67import org.junit.FixMethodOrder;
68import org.junit.runners.MethodSorters;
76@FixMethodOrder(MethodSorters.NAME_ASCENDING)
78 public enum FrameLayout { None, Flow, DoubleBorderCenterSurrounded,
Box, Split };
80 static long duration = 1600;
81 static final int width = 640, height = 480;
83 static boolean forceES2 =
false;
84 static boolean forceGL3 =
false;
85 static int swapInterval = 1;
86 static java.awt.Dimension rwsize =
new Dimension(800, 600);
88 static void setComponentSize(
final Frame frame,
final Component comp1,
final java.awt.Dimension new_sz1,
final Component comp2,
final java.awt.Dimension new_sz2) {
90 AWTEDTExecutor.singleton.invoke(
true ,
new Runnable() {
92 comp1.setMinimumSize(new_sz1);
93 comp1.setPreferredSize(new_sz1);
94 comp1.setSize(new_sz1);
96 comp2.setMinimumSize(new_sz2);
97 comp2.setPreferredSize(new_sz2);
98 comp2.setSize(new_sz2);
100 if(
null != frame ) {
104 }
catch(
final Throwable throwable ) {
105 throwable.printStackTrace();
106 Assume.assumeNoException( throwable );
109 static void setFrameSize(
final Frame frame,
final boolean frameLayout,
final java.awt.Dimension new_sz) {
111 AWTEDTExecutor.singleton.invoke(
true ,
new Runnable() {
113 frame.setSize(new_sz);
118 }
catch(
final Throwable throwable ) {
119 throwable.printStackTrace();
120 Assume.assumeNoException( throwable );
124 protected void runTestGL(
final GLCapabilities caps,
final FrameLayout frameLayout,
final boolean twoCanvas,
final boolean resizeByComp)
throws InterruptedException, InvocationTargetException {
125 final JFrame frame =
new JFrame(
"Bug816: "+this.getTestMethodName());
126 Assert.assertNotNull(frame);
127 final Container framePane = frame.getContentPane();
130 Assert.assertNotNull(glCanvas1);
134 Assert.assertNotNull(glCanvas2);
139 final Dimension glcDim =
new Dimension(width/2, height);
140 final Dimension frameDim =
new Dimension(twoCanvas ? width + 64: width/2 + 64, height + 64);
142 setComponentSize(
null, glCanvas1, glcDim, glCanvas2, glcDim);
144 switch( frameLayout) {
146 framePane.add(glCanvas1);
150 final Container c =
new Container();
151 c.setLayout(
new FlowLayout(FlowLayout.LEFT, 0, 0));
159 case DoubleBorderCenterSurrounded: {
160 final Container c =
new Container();
161 c.setLayout(
new BorderLayout());
162 c.add(
new Button(
"north"), BorderLayout.NORTH);
163 c.add(
new Button(
"south"), BorderLayout.SOUTH);
164 c.add(
new Button(
"east"), BorderLayout.EAST);
165 c.add(
new Button(
"west"), BorderLayout.WEST);
167 final Container c2 =
new Container();
168 c2.setLayout(
new GridLayout(1, 2));
171 c.add(c2, BorderLayout.CENTER);
173 c.add(glCanvas1, BorderLayout.CENTER);
175 framePane.setLayout(
new BorderLayout());
176 framePane.add(
new Button(
"NORTH"), BorderLayout.NORTH);
177 framePane.add(
new Button(
"SOUTH"), BorderLayout.SOUTH);
178 framePane.add(
new Button(
"EAST"), BorderLayout.EAST);
179 framePane.add(
new Button(
"WEST"), BorderLayout.WEST);
180 framePane.add(c, BorderLayout.CENTER);
184 final Container c =
new Container();
185 c.setLayout(
new BoxLayout(c, BoxLayout.X_AXIS));
194 final Dimension sbDim =
new Dimension(16, 16);
195 final JScrollPane vsp =
new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
197 final JScrollBar vsb = vsp.getVerticalScrollBar();
198 vsb.setPreferredSize(sbDim);
199 final BoundedRangeModel model = vsb.getModel();
201 model.setMaximum(100);
204 vsb.setEnabled(
true);
206 final JScrollPane hsp =
new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
208 final JScrollBar hsb = hsp.getHorizontalScrollBar();
209 hsb.setPreferredSize(sbDim);
210 final BoundedRangeModel model = hsb.getModel();
212 model.setMaximum(100);
215 hsb.setEnabled(
true);
217 final JSplitPane horizontalSplitPane =
new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
true,
218 twoCanvas ? glCanvas2 : vsp, glCanvas1 );
219 horizontalSplitPane.setResizeWeight(0.5);
220 final JSplitPane verticalSplitPane =
new JSplitPane(JSplitPane.VERTICAL_SPLIT,
221 true, horizontalSplitPane, hsp);
222 verticalSplitPane.setResizeWeight(0.5);
223 framePane.add(verticalSplitPane);
235 animator.
add(glCanvas1);
237 animator.
add(glCanvas2);
242 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
247 setFrameSize(frame,
true, frameDim);
249 frame.setVisible(
true);
259 Assert.assertTrue(animator.isAnimating());
266 Thread.sleep(Math.max(1000, duration/2));
267 if(
null != rwsize ) {
268 final Dimension compRSizeHalf =
new Dimension(rwsize.width/2, rwsize.height);
269 final Dimension frameRSizeHalf =
new Dimension(twoCanvas ? rwsize.width + 64: rwsize.width/2 + 64, rwsize.height + 64);
271 setComponentSize(frame, glCanvas1, compRSizeHalf, glCanvas2, compRSizeHalf);
273 setFrameSize(frame,
true, frameRSizeHalf);
281 final long t0 = System.currentTimeMillis();
283 while(!quitAdapter.shouldQuit() && t1 - t0 < duration) {
285 t1 = System.currentTimeMillis();
288 Assert.assertNotNull(frame);
289 Assert.assertNotNull(glCanvas1);
291 Assert.assertNotNull(glCanvas2);
293 Assert.assertNull(glCanvas2);
296 Assert.assertNotNull(animator);
298 Assert.assertFalse(animator.isAnimating());
299 Assert.assertFalse(animator.
isStarted());
301 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
303 frame.setVisible(
false);
305 Assert.assertEquals(
false, frame.isVisible());
306 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
308 frame.remove(glCanvas1);
310 frame.remove(glCanvas2);
322 if( testNum != -1 && testNum != 0 ) { return ; }
329 if( testNum != -1 && testNum != 1 ) { return ; }
336 if( testNum != -1 && testNum != 2 ) { return ; }
343 if( testNum != -1 && testNum != 3 ) { return ; }
350 if( testNum != -1 && testNum != 4 ) { return ; }
357 if( testNum != -1 && testNum != 5 ) { return ; }
364 if( testNum != -1 && testNum != 6 ) { return ; }
371 if( testNum != -1 && testNum != 7 ) { return ; }
378 if( testNum != -1 && testNum != 8 ) { return ; }
385 if( testNum != -1 && testNum != 10 ) { return ; }
392 if( testNum != -1 && testNum != 11 ) { return ; }
399 if( testNum != -1 && testNum != 12 ) { return ; }
406 if( testNum != -1 && testNum != 13 ) { return ; }
413 if( testNum != -1 && testNum != 14) { return ; }
420 if( testNum != -1 && testNum != 15 ) { return ; }
427 if( testNum != -1 && testNum != 16 ) { return ; }
434 if( testNum != -1 && testNum != 17 ) { return ; }
441 if( testNum != -1 && testNum != 18 ) { return ; }
446 static int testNum = -1;
448 public static void main(
final String args[]) {
449 for(
int i=0; i<args.length; i++) {
450 if(args[i].equals(
"-time")) {
453 }
else if(args[i].equals(
"-test")) {
456 }
else if(args[i].equals(
"-noresize")) {
458 }
else if(args[i].equals(
"-es2")) {
460 }
else if(args[i].equals(
"-gl3")) {
462 }
else if(args[i].equals(
"-vsync")) {
468 System.err.println(
"resize "+rwsize);
469 System.err.println(
"forceES2 "+forceES2);
470 System.err.println(
"forceGL3 "+forceGL3);
471 System.err.println(
"swapInterval "+swapInterval);
synchronized AWTAdapter addTo(final java.awt.Component awtComponent)
Due to the fact that some NEWT com.jogamp.newt.event.NEWTEventListener are mapped to more than one ja...
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
static GLProfile getMaxProgrammableCore(final AbstractGraphicsDevice device, final boolean favorHardwareRasterizer)
Returns the highest profile, implementing the programmable shader core pipeline only.
A heavyweight AWT component which provides OpenGL rendering support.
int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Bug 816: OSX CALayer Positioning Bug.
void runTestGL(final GLCapabilities caps, final FrameLayout frameLayout, final boolean twoCanvas, final boolean resizeByComp)
void test11_Frame_Flow_One()
void test02_Compo_DblBrd_One()
void test05_Compo_Flow_Two()
void test04_Compo_Split_One()
void test00_Compo_None_One()
void test07_Compo_Box_Two()
void test08_Compo_Split_Two()
void test01_Compo_Flow_One()
void test06_Compo_DblBrd_Two()
void test10_Frame_None_One()
static void main(final String args[])
void test12_Frame_DblBrd_One()
void test16_Frame_DblBrd_Two()
void test03_Compo_Box_One()
void test18_Frame_Split_Two()
void test13_Frame_Box_One()
void test15_Frame_Flow_Two()
void test17_Frame_Box_Two()
void test14_Frame_Split_One()
static boolean waitForRealized(final java.awt.Component comp, final boolean realized, final Runnable waitAction)
static boolean waitForVisible(final java.awt.Component comp, final boolean visible, final Runnable waitAction)
static int atoi(final String str, final int def)
static long atol(final String str, final long def)
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
synchronized boolean isStarted()
Indicates whether this animator has been started.
final synchronized boolean start()
Starts this animator, if not running.
final synchronized boolean stop()
Stops this animator.
DoubleBorderCenterSurrounded