29package com.jogamp.opengl.test.junit.jogl.acore;
32import java.lang.reflect.InvocationTargetException;
35import com.jogamp.opengl.GLCapabilities;
36import com.jogamp.opengl.GLContext;
37import com.jogamp.opengl.GLProfile;
38import com.jogamp.opengl.awt.GLCanvas;
40import com.jogamp.opengl.util.Animator;
41import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
42import com.jogamp.opengl.test.junit.util.GLTestUtil;
43import com.jogamp.opengl.test.junit.util.MiscUtils;
44import com.jogamp.opengl.test.junit.util.NewtTestUtil;
45import com.jogamp.opengl.test.junit.util.UITestCase;
46import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
48import org.junit.Assert;
49import org.junit.BeforeClass;
51import org.junit.FixMethodOrder;
52import org.junit.runners.MethodSorters;
66@FixMethodOrder(MethodSorters.NAME_ASCENDING)
70 static int width, height;
76 Assert.assertNotNull(glp);
78 Assert.assertNotNull(caps);
82 setTestSupported(
false);
88 Assert.assertNotNull(glCanvas);
91 frame.setLocation(x, y);
92 frame.setSize(width, height);
93 frame.setTitle(
"AWT GLCanvas Shared Gears Test: "+x+
"/"+y+
" shared true");
99 syncedOneAnimator(
true);
104 syncedOneAnimator(
false);
107 public void syncedOneAnimator(
final boolean destroyCleanOrder)
throws InterruptedException, InvocationTargetException {
108 final Frame f1 =
new Frame();
113 final GLCanvas c1 = createGLCanvas(f1, 0, 0, g1);
116 final Frame f2 =
new Frame();
119 final GLCanvas c2 = createGLCanvas(f2, f1.getX()+width,
124 final Frame f3 =
new Frame();
127 final GLCanvas c3 = createGLCanvas(f3, f1.getX()+0,
128 f1.getY()+height, g3);
132 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
140 Thread.sleep(1000/60*10);
145 Assert.assertTrue(
"Gears1 not initialized", g1.
waitForInit(
true));
150 Assert.assertTrue(
"Gears2 not initialized", g2.
waitForInit(
true));
155 Assert.assertTrue(
"Gears3 not initialized", g3.
waitForInit(
true));
168 Assert.assertTrue(
"Ctx1 is not shared", ctx1.
isShared());
169 Assert.assertTrue(
"Ctx2 is not shared", ctx2.
isShared());
170 Assert.assertTrue(
"Ctx3 is not shared", ctx3.
isShared());
171 Assert.assertEquals(
"Ctx1 has unexpected number of created shares", 2, ctx1Shares.size());
172 Assert.assertEquals(
"Ctx2 has unexpected number of created shares", 2, ctx2Shares.size());
173 Assert.assertEquals(
"Ctx3 has unexpected number of created shares", 2, ctx3Shares.size());
176 Assert.assertTrue(
"Gears1 is shared", !g1.usesSharedGears());
177 Assert.assertTrue(
"Gears2 is not shared", g2.usesSharedGears());
178 Assert.assertTrue(
"Gears3 is not shared", g3.usesSharedGears());
181 Thread.sleep(duration);
182 }
catch(
final Exception e) {
188 Assert.assertEquals(
false, animator.isAnimating());
190 if( destroyCleanOrder ) {
191 System.err.println(
"XXX Destroy in clean order NOW");
193 System.err.println(
"XXX Destroy in creation order NOW - Driver Impl. Ma trigger driver Bug i.e. not postponing GL ctx destruction after releasing all refs.");
195 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
198 if( destroyCleanOrder ) {
203 }
catch (
final Throwable t) {
204 throw new RuntimeException(t);
208 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
212 }
catch (
final Throwable t) {
213 throw new RuntimeException(t);
217 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
220 if( destroyCleanOrder ) {
225 }
catch (
final Throwable t) {
226 throw new RuntimeException(t);
237 syncedOneAnimator(
true);
242 asyncEachOneAnimator(
false);
245 public void asyncEachOneAnimator(
final boolean destroyCleanOrder)
throws InterruptedException, InvocationTargetException {
246 final Frame f1 =
new Frame();
252 final GLCanvas c1 = createGLCanvas(f1, 0, 0, g1);
257 final Frame f2 =
new Frame();
261 final GLCanvas c2 = createGLCanvas(f2, f1.getX()+width, f1.getY()+0, g2);
265 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
272 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
277 final Frame f3 =
new Frame();
281 final GLCanvas c3 = createGLCanvas(f3, f1.getX()+0, f1.getY()+height, g3);
285 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
290 Thread.sleep(1000/60*10);
295 Assert.assertTrue(
"Gears1 not initialized", g1.
waitForInit(
true));
300 Assert.assertTrue(
"Gears2 not initialized", g2.
waitForInit(
true));
305 Assert.assertTrue(
"Gears3 not initialized", g3.
waitForInit(
true));
318 Assert.assertTrue(
"Ctx1 is not shared", ctx1.
isShared());
319 Assert.assertTrue(
"Ctx2 is not shared", ctx2.
isShared());
320 Assert.assertTrue(
"Ctx3 is not shared", ctx3.
isShared());
321 Assert.assertEquals(
"Ctx1 has unexpected number of created shares", 2, ctx1Shares.size());
322 Assert.assertEquals(
"Ctx2 has unexpected number of created shares", 2, ctx2Shares.size());
323 Assert.assertEquals(
"Ctx3 has unexpected number of created shares", 2, ctx3Shares.size());
326 Assert.assertTrue(
"Gears1 is shared", !g1.usesSharedGears());
327 Assert.assertTrue(
"Gears2 is not shared", g2.usesSharedGears());
328 Assert.assertTrue(
"Gears3 is not shared", g3.usesSharedGears());
331 Thread.sleep(duration);
332 }
catch(
final Exception e) {
338 Assert.assertEquals(
false, a1.isAnimating());
340 Assert.assertEquals(
false, a2.isAnimating());
342 Assert.assertEquals(
false, a3.isAnimating());
344 if( destroyCleanOrder ) {
345 System.err.println(
"XXX Destroy in clean order NOW");
347 System.err.println(
"XXX Destroy in creation order NOW - Driver Impl. Ma trigger driver Bug i.e. not postponing GL ctx destruction after releasing all refs.");
349 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
352 if( destroyCleanOrder ) {
357 }
catch (
final Throwable t) {
358 throw new RuntimeException(t);
362 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
366 }
catch (
final Throwable t) {
367 throw new RuntimeException(t);
371 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
374 if( destroyCleanOrder ) {
379 }
catch (
final Throwable t) {
380 throw new RuntimeException(t);
389 static long duration = 1000;
391 public static void main(
final String args[]) {
392 for(
int i=0; i<args.length; i++) {
393 if(args[i].equals(
"-time")) {
396 duration = Integer.parseInt(args[i]);
397 }
catch (
final Exception ex) { ex.printStackTrace(); }
Specifies a set of OpenGL capabilities.
Abstraction for an OpenGL rendering context.
final boolean isShared()
Returns true if this GLContext is shared, otherwise false.
final List< GLContext > getCreatedShares()
Returns a new list of created GLContext shared with this GLContext.
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 GL2ES2
The intersection of the desktop GL3, GL2 and embedded ES2 profile.
static GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
A heavyweight AWT component which provides OpenGL rendering support.
final void setSharedAutoDrawable(final GLAutoDrawable sharedAutoDrawable)
Specifies an GLAutoDrawable, which OpenGL context shall be shared by this GLAutoDrawable's GLContext.
GLContext getContext()
Returns the context associated with this drawable.
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Sharing the VBO of 3 GearsES2 instances, each in their own AWT GLCanvas.
static void main(final String args[])
void test01SyncedOneAnimatorCleanDtorOrder()
GLCanvas createGLCanvas(final Frame frame, final int x, final int y, final GearsES2 gears)
void test11AsyncEachAnimatorCleanDtorOrder()
void syncedOneAnimator(final boolean destroyCleanOrder)
void asyncEachOneAnimator(final boolean destroyCleanOrder)
void test12AsyncEachAnimatorDirtyDtorOrder()
void test02SyncedOneAnimatorDirtyDtorOrder()
void setValidateBuffers(final boolean v)
void setSharedGears(final GearsES2 shared)
boolean waitForInit(final boolean initialized)
void setSyncObjects(final Object sync)
static boolean waitForVisible(final java.awt.Component comp, final boolean visible, final Runnable waitAction)
static boolean waitForRealized(final GLAutoDrawable glad, final boolean realized, final Runnable waitAction)
static boolean waitForContextCreated(final GLAutoDrawable autoDrawable, final boolean created, final Runnable waitAction)
static void dumpSharedGLContext(final String prefix, final GLContext self)
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
final synchronized boolean start()
Starts this animator, if not running.
final synchronized boolean stop()
Stops this animator.