29package com.jogamp.opengl.test.junit.jogl.awt;
31import com.jogamp.opengl.GLProfile;
32import com.jogamp.opengl.awt.GLCanvas;
34import com.jogamp.opengl.util.Animator;
35import com.jogamp.opengl.test.junit.util.UITestCase;
36import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
37import com.jogamp.opengl.test.junit.util.MiscUtils;
39import java.awt.Dimension;
43import jogamp.nativewindow.SurfaceScaleUtils;
45import org.junit.Assert;
46import org.junit.Assume;
47import org.junit.Before;
48import org.junit.BeforeClass;
49import org.junit.After;
51import org.junit.FixMethodOrder;
52import org.junit.runners.MethodSorters;
55@FixMethodOrder(MethodSorters.NAME_ASCENDING)
57 static long durationPerTest = 500;
59 final static int sizeEps = 64;
60 final static Dimension size1 =
new Dimension(512, 512-sizeEps-1);
61 final static Dimension size2 =
new Dimension(512+sizeEps+1+256, 512+256);
62 final static Dimension size3 =
new Dimension(512-256, 512-sizeEps-1-256);
81 Assert.assertNotNull(glComp);
87 label1 =
new Label(
"L1 - No GLCanvas");
88 label1.setMinimumSize(size1);
89 label1.setPreferredSize(size1);
90 frame1 =
new Frame(
"Frame 1");
91 Assert.assertNotNull(frame1);
93 frame1.setLocation(0, 0);
95 label2 =
new Label(
"L2 - No GLCanvas");
96 label2.setMinimumSize(size2);
97 label2.setPreferredSize(size2);
98 frame2 =
new Frame(
"Frame 2");
99 Assert.assertNotNull(frame2);
101 frame2.setLocation(size1.width + size1.width/2, 0);
103 label3 =
new Label(
"L3 - No GLCanvas");
104 label3.setMinimumSize(size3);
105 label3.setPreferredSize(size3);
106 frame3 =
new Frame(
"Frame 3");
107 Assert.assertNotNull(frame3);
109 frame3.setLocation(0, size1.height + size1.height/2);
114 Assert.assertNotNull(frame1);
115 Assert.assertNotNull(frame2);
116 Assert.assertNotNull(glComp);
118 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
125 }
catch (
final Throwable t) {
127 Assume.assumeNoException(t);
138 private void addCanvas(
final Frame frame,
final Label label,
final Dimension size) {
140 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
143 glComp.setPreferredSize(size);
144 glComp.setMinimumSize(size);
148 }
catch (
final Throwable t) {
150 Assume.assumeNoException(t);
154 private void removeCanvas(
final Frame frame,
final Label label) {
156 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
158 frame.remove(glComp);
163 }
catch (
final Throwable t) {
165 Assume.assumeNoException(t);
169 private void setVisible(
final Frame frame,
final boolean v) {
171 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
176 }
catch (
final Throwable t) {
178 Assume.assumeNoException(t);
182 private void assertSize(
final Dimension expSize) {
183 final float[] scale = { 1f, 1f };
186 final Dimension hasSize = glComp.getSize(
null);
188 Assert.assertTrue(
"AWT Size.width mismatch: expected "+expSize+
", has "+hasSize,
189 Math.abs(expSize.width-hasSize.width) <= sizeEps);
190 Assert.assertTrue(
"AWT Size.height mismatch: expected "+expSize+
", has "+hasSize,
191 Math.abs(expSize.height-hasSize.height) <= sizeEps);
193 final int expSurfWidth = SurfaceScaleUtils.scale(expSize.width, scale[0]);
194 final int expSurfHeight = SurfaceScaleUtils.scale(expSize.height, scale[0]);
198 Assert.assertTrue(
"GL Size.width mismatch: expected "+expSurfWidth+
", has "+hasSurfWidth,
199 Math.abs(expSurfWidth-hasSurfWidth) <= sizeEps);
200 Assert.assertTrue(
"GL Size.height mismatch: expected "+expSurfHeight+
", has "+hasSurfHeight,
201 Math.abs(expSurfHeight-hasSurfHeight) <= sizeEps);
206 setVisible(frame1,
true);
207 setVisible(frame2,
true);
208 setVisible(frame3,
true);
211 addCanvas(frame1, label1, size1);
212 Thread.sleep(durationPerTest);
216 removeCanvas(frame1, label1);
217 addCanvas(frame2, label2, size2);
218 Thread.sleep(durationPerTest);
222 removeCanvas(frame2, label2);
223 addCanvas(frame3, label3, size3);
224 Thread.sleep(durationPerTest);
228 removeCanvas(frame3, label3);
229 addCanvas(frame1, label1, size1);
230 Thread.sleep(durationPerTest);
234 public static void main(
final String args[]) {
235 for(
int i=0; i<args.length; i++) {
236 if(args[i].equals(
"-time")) {
237 durationPerTest =
MiscUtils.
atoi(args[++i], (
int)durationPerTest);
Specifies the the OpenGL profile.
static String glAvailabilityToString(final AbstractGraphicsDevice device)
A heavyweight AWT component which provides OpenGL rendering support.
void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext....
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.
float[] getMaximumSurfaceScale(final float[] result)
Returns the maximum pixel scale of the associated NativeSurface.The maximum pixel scale maybe used to...
static void main(final String args[])
void testAddRemove3Times()
static int atoi(final String str, final int def)
final synchronized boolean start()
Starts this animator, if not running.
final synchronized boolean stop()
Stops this animator.