29package com.jogamp.opengl.test.junit.jogl.acore;
33import com.jogamp.newt.opengl.GLWindow;
35import com.jogamp.nativewindow.util.InsetsImmutable;
36import com.jogamp.opengl.GLCapabilities;
37import com.jogamp.opengl.GLContext;
38import com.jogamp.opengl.GLProfile;
40import com.jogamp.opengl.util.Animator;
41import com.jogamp.opengl.test.junit.util.GLTestUtil;
42import com.jogamp.opengl.test.junit.util.MiscUtils;
43import com.jogamp.opengl.test.junit.util.NewtTestUtil;
44import com.jogamp.opengl.test.junit.util.UITestCase;
45import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
47import org.junit.Assert;
48import org.junit.BeforeClass;
50import org.junit.FixMethodOrder;
51import org.junit.runners.MethodSorters;
65@FixMethodOrder(MethodSorters.NAME_ASCENDING)
69 static int width, height;
75 Assert.assertNotNull(glp);
77 Assert.assertNotNull(caps);
81 setTestSupported(
false);
87 Assert.assertNotNull(glWindow);
89 glWindow.
setTitle(
"Shared Gears NEWT Test: "+x+
"/"+y+
" shared true");
90 glWindow.
setSize(width, height);
98 syncedOneAnimator(
true,
false);
102 syncedOneAnimator(
true,
true);
107 syncedOneAnimator(
false,
false);
111 syncedOneAnimator(
false,
true);
114 public void syncedOneAnimator(
final boolean destroyCleanOrder,
final boolean useMappedBuffers)
throws InterruptedException {
121 final GLWindow f1 = createGLWindow(0, 0, g1);
129 f2.setSharedAutoDrawable(f1);
146 Assert.assertTrue(
"Gears1 not initialized", g1.
waitForInit(
true));
151 Assert.assertTrue(
"Gears2 not initialized", g2.
waitForInit(
true));
157 f3.setSharedAutoDrawable(f1);
164 Assert.assertTrue(
"Gears3 not initialized", g3.
waitForInit(
true));
177 Assert.assertTrue(
"Ctx1 is not shared", ctx1.
isShared());
178 Assert.assertTrue(
"Ctx2 is not shared", ctx2.
isShared());
179 Assert.assertTrue(
"Ctx3 is not shared", ctx3.
isShared());
180 Assert.assertEquals(
"Ctx1 has unexpected number of created shares", 2, ctx1Shares.size());
181 Assert.assertEquals(
"Ctx2 has unexpected number of created shares", 2, ctx2Shares.size());
182 Assert.assertEquals(
"Ctx3 has unexpected number of created shares", 2, ctx3Shares.size());
183 Assert.assertEquals(
"Ctx1 Master Context is different", ctx1, ctx1.
getSharedMaster());
184 Assert.assertEquals(
"Ctx2 Master Context is different", ctx1, ctx2.
getSharedMaster());
185 Assert.assertEquals(
"Ctx3 Master Context is different", ctx1, ctx3.
getSharedMaster());
188 Assert.assertTrue(
"Gears1 is shared", !g1.usesSharedGears());
189 Assert.assertTrue(
"Gears2 is not shared", g2.usesSharedGears());
190 Assert.assertTrue(
"Gears3 is not shared", g3.usesSharedGears());
193 Thread.sleep(duration);
194 }
catch(
final Exception e) {
198 if( destroyCleanOrder ) {
199 System.err.println(
"XXX Destroy in clean order NOW");
201 try { Thread.sleep(durationPostDestroy); }
catch(
final Exception e) { e.printStackTrace(); }
203 try { Thread.sleep(durationPostDestroy); }
catch(
final Exception e) { e.printStackTrace(); }
205 try { Thread.sleep(durationPostDestroy); }
catch(
final Exception e) { e.printStackTrace(); }
207 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.");
211 try { Thread.sleep(durationPostDestroy); }
catch(
final Exception e) { e.printStackTrace(); }
216 try { Thread.sleep(durationPostDestroy); }
catch(
final Exception e) { e.printStackTrace(); }
219 try { Thread.sleep(durationPostDestroy); }
catch(
final Exception e) { e.printStackTrace(); }
237 Assert.assertTrue(
"Ctx1 is shared", !ctx1.
isShared());
238 Assert.assertTrue(
"Ctx2 is shared", !ctx2.
isShared());
239 Assert.assertTrue(
"Ctx3 is shared", !ctx3.
isShared());
240 Assert.assertEquals(
"Ctx1 has unexpected number of created shares", 0, ctx1Shares.size());
241 Assert.assertEquals(
"Ctx2 has unexpected number of created shares", 0, ctx2Shares.size());
242 Assert.assertEquals(
"Ctx3 has unexpected number of created shares", 0, ctx3Shares.size());
243 Assert.assertEquals(
"Ctx1 Master Context is set",
null, ctx1.
getSharedMaster());
244 Assert.assertEquals(
"Ctx2 Master Context is set",
null, ctx2.
getSharedMaster());
245 Assert.assertEquals(
"Ctx3 Master Context is set",
null, ctx3.
getSharedMaster());
251 asyncEachAnimator(
true,
false);
255 asyncEachAnimator(
true,
true);
260 asyncEachAnimator(
false,
false);
264 asyncEachAnimator(
false,
true);
267 public void asyncEachAnimator(
final boolean destroyCleanOrder,
final boolean useMappedBuffers)
throws InterruptedException {
273 final GLWindow f1 = createGLWindow(0, 0, g1);
284 f2.setSharedAutoDrawable(f1);
302 Assert.assertTrue(
"Gears1 not initialized", g1.
waitForInit(
true));
307 Assert.assertTrue(
"Gears2 not initialized", g2.
waitForInit(
true));
314 f3.setSharedAutoDrawable(f1);
322 Assert.assertTrue(
"Gears3 not initialized", g3.
waitForInit(
true));
335 Assert.assertTrue(
"Ctx1 is not shared", ctx1.
isShared());
336 Assert.assertTrue(
"Ctx2 is not shared", ctx2.
isShared());
337 Assert.assertTrue(
"Ctx3 is not shared", ctx3.
isShared());
338 Assert.assertEquals(
"Ctx1 has unexpected number of created shares", 2, ctx1Shares.size());
339 Assert.assertEquals(
"Ctx2 has unexpected number of created shares", 2, ctx2Shares.size());
340 Assert.assertEquals(
"Ctx3 has unexpected number of created shares", 2, ctx3Shares.size());
341 Assert.assertEquals(
"Ctx1 Master Context is different", ctx1, ctx1.
getSharedMaster());
342 Assert.assertEquals(
"Ctx2 Master Context is different", ctx1, ctx2.
getSharedMaster());
343 Assert.assertEquals(
"Ctx3 Master Context is different", ctx1, ctx3.
getSharedMaster());
346 Assert.assertTrue(
"Gears1 is shared", !g1.usesSharedGears());
347 Assert.assertTrue(
"Gears2 is not shared", g2.usesSharedGears());
348 Assert.assertTrue(
"Gears3 is not shared", g3.usesSharedGears());
351 Thread.sleep(duration);
352 }
catch(
final Exception e) {
356 if( destroyCleanOrder ) {
357 System.err.println(
"XXX Destroy in clean order NOW");
360 try { Thread.sleep(durationPostDestroy); }
catch(
final Exception e) { e.printStackTrace(); }
363 try { Thread.sleep(durationPostDestroy); }
catch(
final Exception e) { e.printStackTrace(); }
366 try { Thread.sleep(durationPostDestroy); }
catch(
final Exception e) { e.printStackTrace(); }
368 System.err.println(
"XXX Destroy in creation order NOW - Driver Impl. May trigger driver Bug i.e. not postponing GL ctx destruction after releasing all refs.");
375 try { Thread.sleep(durationPostDestroy); }
catch(
final Exception e) { e.printStackTrace(); }
381 try { Thread.sleep(durationPostDestroy); }
catch(
final Exception e) { e.printStackTrace(); }
385 try { Thread.sleep(durationPostDestroy); }
catch(
final Exception e) { e.printStackTrace(); }
395 static long duration = 1000;
396 static long durationPostDestroy = 170;
397 static boolean mainRun =
false;
399 public static void main(
final String args[]) {
401 for(
int i=0; i<args.length; i++) {
402 if(args[i].equals(
"-time")) {
405 duration = Integer.parseInt(args[i]);
406 }
catch (
final Exception ex) { ex.printStackTrace(); }
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final void setPosition(final int x, final int y)
Sets the location of the window's client area excluding insets (window decorations) in window units.
final void setTitle(final String title)
final int getX()
Returns the current x position of this window, relative to it's parent.
final int getY()
Returns the current y position of the top-left corner of the client area relative to it's parent in w...
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
final InsetsImmutable getInsets()
Returns the insets defined as the width and height of the window decoration on the left,...
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
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 GLContext getSharedMaster()
Returns the shared master GLContext of this GLContext if shared, otherwise return null.
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.
Sharing the VBO of 3 GearsES2 instances, each in their own GLWindow.
void test11ASyncEachAnimatorCleanDtorOrderCopyBuffer()
void test01SyncedOneAnimatorCleanDtorOrderCopyBuffer()
GLWindow createGLWindow(final int x, final int y, final GearsES2 gears)
void test13AsyncEachAnimatorDirtyDtorOrderCopyBuffers()
static void main(final String args[])
void test14AsyncEachAnimatorDirtyDtorOrderMapBuffers()
void test03SyncedOneAnimatorDirtyDtorOrderCopyBuffer()
void test04SyncedOneAnimatorDirtyDtorOrderMapBuffer()
void asyncEachAnimator(final boolean destroyCleanOrder, final boolean useMappedBuffers)
void test12ASyncEachAnimatorCleanDtorOrderMapBuffer()
void test02SyncedOneAnimatorCleanDtorOrderMapBuffer()
void syncedOneAnimator(final boolean destroyCleanOrder, final boolean useMappedBuffers)
void setValidateBuffers(final boolean v)
void setSharedGears(final GearsES2 shared)
boolean waitForInit(final boolean initialized)
void setSyncObjects(final Object sync)
void setUseMappedBuffers(final boolean v)
static boolean waitForContextCreated(final GLAutoDrawable autoDrawable, final boolean created, final Runnable waitAction)
static void dumpSharedGLContext(final String prefix, final GLContext self)
static boolean waitForRealized(final Screen screen, final boolean realized, final Runnable waitAction)
static boolean waitForVisible(final Window win, final boolean visible, final Runnable waitAction)
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
final synchronized boolean pause()
Pauses this animator.
final synchronized boolean resume()
Resumes animation if paused.
final synchronized boolean start()
Starts this animator, if not running.
final synchronized boolean stop()
Stops this animator.
Immutable insets representing rectangular window decoration insets on all four edges in window units.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
GLContext getContext()
Returns the context associated with this drawable.