29package com.jogamp.opengl.test.junit.jogl.acore;
33import com.jogamp.opengl.GLCapabilities;
34import com.jogamp.opengl.GLContext;
35import com.jogamp.opengl.GLProfile;
37import com.jogamp.nativewindow.swt.SWTAccessor;
38import com.jogamp.opengl.util.Animator;
39import com.jogamp.opengl.swt.GLCanvas;
40import com.jogamp.opengl.test.junit.util.GLTestUtil;
41import com.jogamp.opengl.test.junit.util.MiscUtils;
42import com.jogamp.opengl.test.junit.util.SWTTestUtil;
43import com.jogamp.opengl.test.junit.util.UITestCase;
44import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
46import org.eclipse.swt.SWT;
47import org.eclipse.swt.layout.FillLayout;
48import org.eclipse.swt.widgets.Composite;
49import org.eclipse.swt.widgets.Display;
50import org.eclipse.swt.widgets.Shell;
51import org.junit.After;
52import org.junit.Assert;
53import org.junit.Assume;
54import org.junit.Before;
55import org.junit.BeforeClass;
57import org.junit.FixMethodOrder;
58import org.junit.runners.MethodSorters;
97@FixMethodOrder(MethodSorters.NAME_ASCENDING)
101 static int width, height;
107 Assert.assertNotNull(glp);
109 Assert.assertNotNull(caps);
113 setTestSupported(
false);
119 Composite composite1 =
null;
121 Composite composite2 =
null;
123 Composite composite3 =
null;
131 Assert.assertNotNull( display );
133 display.syncExec(
new Runnable() {
136 shell1 =
new Shell( display );
137 shell1.setLayout(
new FillLayout() );
138 composite1 =
new Composite( shell1, SWT.NO_BACKGROUND );
139 composite1.setLayout(
new FillLayout() );
141 shell2 =
new Shell( display );
142 shell2.setLayout(
new FillLayout() );
143 composite2 =
new Composite( shell2, SWT.NO_BACKGROUND );
144 composite2.setLayout(
new FillLayout() );
146 shell3 =
new Shell( display );
147 shell3.setLayout(
new FillLayout() );
148 composite3 =
new Composite( shell3, SWT.NO_BACKGROUND );
149 composite3.setLayout(
new FillLayout() );
155 Assert.assertNotNull( display );
156 Assert.assertNotNull( shell1 );
157 Assert.assertNotNull( composite1 );
158 Assert.assertNotNull( shell2 );
159 Assert.assertNotNull( composite2 );
160 Assert.assertNotNull( shell3 );
161 Assert.assertNotNull( composite3 );
163 display.syncExec(
new Runnable() {
166 composite3.dispose();
168 composite2.dispose();
170 composite1.dispose();
179 catch(
final Throwable throwable ) {
180 throwable.printStackTrace();
181 Assume.assumeNoException( throwable );
194 Assert.assertNotNull( glCanvas );
196 display.syncExec(
new Runnable() {
199 shell.setText(
"SWT GLCanvas Shared Gears Test");
200 shell.setSize( width, height);
201 shell.setLocation(x, y);
212 final GLCanvas c1 = createGLCanvas(shell1, composite1, 0, 0, g1);
217 final GLCanvas c2 = createGLCanvas(shell2, composite2, 0+width, 0+0, g2);
223 final GLCanvas c3 = createGLCanvas(shell3, composite3, 0, height, g3);
227 display.syncExec(
new Runnable() {
234 final long t0 = System.currentTimeMillis();
240 Assert.assertTrue(
"Gears1 not initialized", g1.
waitForInit(
true));
244 Assert.assertTrue(
"Gears2 not initialized", g2.
waitForInit(
true));
248 Assert.assertTrue(
"Gears3 not initialized", g3.
waitForInit(
true));
261 Assert.assertTrue(
"Ctx1 is not shared", ctx1.
isShared());
262 Assert.assertTrue(
"Ctx2 is not shared", ctx2.
isShared());
263 Assert.assertTrue(
"Ctx3 is not shared", ctx3.
isShared());
264 Assert.assertEquals(
"Ctx1 has unexpected number of created shares", 2, ctx1Shares.size());
265 Assert.assertEquals(
"Ctx2 has unexpected number of created shares", 2, ctx2Shares.size());
266 Assert.assertEquals(
"Ctx3 has unexpected number of created shares", 2, ctx3Shares.size());
269 Assert.assertTrue(
"Gears1 is shared", !g1.usesSharedGears());
270 Assert.assertTrue(
"Gears2 is not shared", g2.usesSharedGears());
271 Assert.assertTrue(
"Gears3 is not shared", g3.usesSharedGears());
273 while(animator.isAnimating() && System.currentTimeMillis()-t0<duration) {
280 Assert.assertEquals(
false, animator.isAnimating());
282 display.syncExec(
new Runnable() {
298 System.err.println(
"TestSharedContextVBOES2SWT3.test02AsyncEachAnimator: 0.0");
299 final GLCanvas c1 = createGLCanvas(shell1, composite1, 0, 0, g1);
301 display.syncExec(
new Runnable() {
308 System.err.println(
"TestSharedContextVBOES2SWT3.test02AsyncEachAnimator: 1.0");
311 System.err.println(
"TestSharedContextVBOES2SWT3.test02AsyncEachAnimator: 1.1");
313 System.err.println(
"TestSharedContextVBOES2SWT3.test02AsyncEachAnimator: 1.2");
314 Assert.assertTrue(
"Gears1 not initialized", g1.
waitForInit(
true));
316 System.err.println(
"TestSharedContextVBOES2SWT3.test02AsyncEachAnimator: 2.0");
320 final GLCanvas c2 = createGLCanvas(shell2, composite2, width, 0, g2);
323 display.syncExec(
new Runnable() {
330 System.err.println(
"TestSharedContextVBOES2SWT3.test02AsyncEachAnimator: 3.0");
334 final GLCanvas c3 = createGLCanvas(shell3, composite3, 0, height, g3);
337 display.syncExec(
new Runnable() {
344 System.err.println(
"TestSharedContextVBOES2SWT3.test02AsyncEachAnimator: 4.0");
346 System.err.println(
"TestSharedContextVBOES2SWT3.test02AsyncEachAnimator: 4.1: Exception "+(
null != waitAction.getException(
true)));
348 System.err.println(
"TestSharedContextVBOES2SWT3.test02AsyncEachAnimator: 4.2: Exception "+(
null != waitAction.getException(
true)));
349 Assert.assertTrue(
"Gears2 not initialized", g2.
waitForInit(
true));
351 System.err.println(
"TestSharedContextVBOES2SWT3.test02AsyncEachAnimator: 5.0: Exception "+(
null != waitAction.getException(
true)));
353 System.err.println(
"TestSharedContextVBOES2SWT3.test02AsyncEachAnimator: 5.1: Exception "+(
null != waitAction.getException(
true)));
355 System.err.println(
"TestSharedContextVBOES2SWT3.test02AsyncEachAnimator: 5.2: Exception "+(
null != waitAction.getException(
true)));
356 Assert.assertTrue(
"Gears3 not initialized", g3.
waitForInit(
true));
358 System.err.println(
"TestSharedContextVBOES2SWT3.test02AsyncEachAnimator: 6.0: Exception "+(
null != waitAction.getException(
true)));
359 final long t0 = System.currentTimeMillis();
372 Assert.assertTrue(
"Ctx1 is not shared", ctx1.
isShared());
373 Assert.assertTrue(
"Ctx2 is not shared", ctx2.
isShared());
374 Assert.assertTrue(
"Ctx3 is not shared", ctx3.
isShared());
375 Assert.assertEquals(
"Ctx1 has unexpected number of created shares", 2, ctx1Shares.size());
376 Assert.assertEquals(
"Ctx2 has unexpected number of created shares", 2, ctx2Shares.size());
377 Assert.assertEquals(
"Ctx3 has unexpected number of created shares", 2, ctx3Shares.size());
380 Assert.assertTrue(
"Gears1 is shared", !g1.usesSharedGears());
381 Assert.assertTrue(
"Gears2 is not shared", g2.usesSharedGears());
382 Assert.assertTrue(
"Gears3 is not shared", g3.usesSharedGears());
384 while(System.currentTimeMillis()-t0<duration) {
387 System.err.println(
"TestSharedContextVBOES2SWT3.test02AsyncEachAnimator: 8.0: Exception "+(
null != waitAction.getException(
true)));
391 Assert.assertEquals(
false, a1.isAnimating());
393 Assert.assertEquals(
false, a2.isAnimating());
395 Assert.assertEquals(
false, a3.isAnimating());
397 display.syncExec(
new Runnable() {
406 static long duration = 2000;
408 public static void main(
final String args[]) {
409 for(
int i=0; i<args.length; i++) {
410 if(args[i].equals(
"-time")) {
413 duration = Integer.parseInt(args[i]);
414 }
catch (
final Exception ex) { ex.printStackTrace(); }
static void invokeOnOSTKThread(final boolean blocking, final Runnable runnable)
Runs the specified action in an SWT compatible OS toolkit thread, which is:
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 SWT GLCanvas.
static void main(final String args[])
GLCanvas createGLCanvas(final Shell shell, final Composite composite, final int x, final int y, final GearsES2 gears)
void test01SyncedOneAnimator()
void test02AsyncEachAnimator()
void setValidateBuffers(final boolean v)
void setSharedGears(final GearsES2 shared)
boolean waitForInit(final boolean initialized)
void setSyncObjects(final Object sync)
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.