29package com.jogamp.opengl.test.junit.jogl.acore;
33import com.jogamp.newt.opengl.GLWindow;
35import com.jogamp.nativewindow.util.InsetsImmutable;
36import com.jogamp.opengl.GLAutoDrawable;
37import com.jogamp.opengl.GLCapabilities;
38import com.jogamp.opengl.GLContext;
39import com.jogamp.opengl.GLProfile;
41import com.jogamp.opengl.util.Animator;
42import com.jogamp.opengl.test.junit.util.NewtTestUtil;
43import com.jogamp.opengl.test.junit.util.GLTestUtil;
44import com.jogamp.opengl.test.junit.util.MiscUtils;
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;
61@FixMethodOrder(MethodSorters.NAME_ASCENDING)
65 static int width, height;
71 Assert.assertNotNull(glp);
73 Assert.assertNotNull(caps);
77 setTestSupported(
false);
82 final boolean useShared =
null != sharedDrawable;
84 Assert.assertNotNull(glWindow);
86 glWindow.
setTitle(
"Shared Gears NEWT Test: "+x+
"/"+y+
" shared "+useShared);
88 glWindow.setSharedAutoDrawable(sharedDrawable);
90 glWindow.
setSize(width, height);
93 animator.add(glWindow);
99 Assert.assertTrue(
"Gears not initialized", gears.waitForInit(
true));
106 testCommonAnimatorSharedImpl(
false);
110 testCommonAnimatorSharedImpl(
true);
112 private void testCommonAnimatorSharedImpl(
final boolean useMappedBuffers)
throws InterruptedException {
121 final GLWindow f1 = runTestGL(animator, 0, 0, g1,
null);
123 Assert.assertTrue(
"Ctx is shared before shared creation", !ctx1.
isShared());
134 f1.
getY()+0, g2, f1);
136 Assert.assertTrue(
"Ctx1 is not shared", ctx1.
isShared());
137 Assert.assertTrue(
"Ctx2 is not shared", ctx2.
isShared());
145 Assert.assertEquals(
"Ctx1 has unexpected number of created shares", 1, ctx1Shares.size());
146 Assert.assertEquals(
"Ctx2 has unexpected number of created shares", 1, ctx2Shares.size());
152 final GearsES2 g3 =
new GearsES2(0);
153 g3.setSharedGears(g1);
154 final GLWindow f3 = runTestGL(animator, f1.
getX()+0,
158 Assert.assertTrue(
"Ctx1 is not shared", ctx1.
isShared());
159 Assert.assertTrue(
"Ctx2 is not shared", ctx2.
isShared());
160 Assert.assertTrue(
"Ctx3 is not shared", ctx3.
isShared());
166 MiscUtils.dumpSharedGLContext(
"XXX-C-3.1", ctx1);
167 MiscUtils.dumpSharedGLContext(
"XXX-C-3.2", ctx2);
168 MiscUtils.dumpSharedGLContext(
"XXX-C-3.3", ctx3);
170 Assert.assertEquals(
"Ctx1 has unexpected number of created shares", 2, ctx1Shares.size());
171 Assert.assertEquals(
"Ctx2 has unexpected number of created shares", 2, ctx2Shares.size());
172 Assert.assertEquals(
"Ctx3 has unexpected number of created shares", 2, ctx3Shares.size());
175 Assert.assertTrue(
"Gears1 is shared", !g1.usesSharedGears());
176 Assert.assertTrue(
"Gears2 is not shared", g2.usesSharedGears());
177 Assert.assertTrue(
"Gears3 is not shared", g3.usesSharedGears());
182 Thread.sleep(duration);
183 }
catch(
final Exception e) {
188 Assert.assertTrue(NewtTestUtil.waitForVisible(f3,
false,
null));
189 Assert.assertTrue(NewtTestUtil.waitForRealized(f3,
false,
null));
190 Assert.assertTrue(GLTestUtil.waitForContextCreated(f3,
false,
null));
195 MiscUtils.dumpSharedGLContext(
"XXX-D-0.1", ctx1);
196 MiscUtils.dumpSharedGLContext(
"XXX-D-0.2", ctx2);
197 MiscUtils.dumpSharedGLContext(
"XXX-D-0.3", ctx3);
199 Assert.assertTrue(
"Ctx1 is shared", ctx1.
isShared());
200 Assert.assertTrue(
"Ctx2 is shared", ctx2.
isShared());
201 Assert.assertTrue(
"Ctx3 is shared", ctx3.
isShared());
202 Assert.assertEquals(
"Ctx1 has unexpected number of created shares", 1, ctx1Shares.size());
203 Assert.assertEquals(
"Ctx2 has unexpected number of created shares", 1, ctx2Shares.size());
204 Assert.assertEquals(
"Ctx3 has unexpected number of created shares", 2, ctx3Shares.size());
206 try { Thread.sleep(durationPostDestroy); }
catch(
final Exception e) { e.printStackTrace(); }
209 Assert.assertTrue(NewtTestUtil.waitForVisible(f2,
false,
null));
210 Assert.assertTrue(NewtTestUtil.waitForRealized(f2,
false,
null));
211 Assert.assertTrue(GLTestUtil.waitForContextCreated(f2,
false,
null));
216 MiscUtils.dumpSharedGLContext(
"XXX-D-1.1", ctx1);
217 MiscUtils.dumpSharedGLContext(
"XXX-D-1.2", ctx2);
218 MiscUtils.dumpSharedGLContext(
"XXX-D-1.3", ctx3);
220 Assert.assertTrue(
"Ctx1 is not shared", ctx1.
isShared());
221 Assert.assertTrue(
"Ctx2 is not shared", ctx2.
isShared());
222 Assert.assertTrue(
"Ctx3 is not shared", ctx3.
isShared());
223 Assert.assertEquals(
"Ctx1 has unexpected number of created shares", 0, ctx1Shares.size());
224 Assert.assertEquals(
"Ctx2 has unexpected number of created shares", 1, ctx2Shares.size());
225 Assert.assertEquals(
"Ctx3 has unexpected number of created shares", 1, ctx3Shares.size());
227 try { Thread.sleep(durationPostDestroy); }
catch(
final Exception e) { e.printStackTrace(); }
230 Assert.assertTrue(NewtTestUtil.waitForVisible(f1,
false,
null));
231 Assert.assertTrue(NewtTestUtil.waitForRealized(f1,
false,
null));
232 Assert.assertTrue(GLTestUtil.waitForContextCreated(f1,
false,
null));
237 MiscUtils.dumpSharedGLContext(
"XXX-D-2.1", ctx1);
238 MiscUtils.dumpSharedGLContext(
"XXX-D-2.2", ctx2);
239 MiscUtils.dumpSharedGLContext(
"XXX-D-2.3", ctx3);
241 Assert.assertTrue(
"Ctx1 is not shared", !ctx1.
isShared());
242 Assert.assertTrue(
"Ctx2 is not shared", !ctx2.
isShared());
243 Assert.assertTrue(
"Ctx3 is not shared", !ctx3.
isShared());
244 Assert.assertEquals(
"Ctx1 has unexpected number of created shares", 0, ctx1Shares.size());
245 Assert.assertEquals(
"Ctx2 has unexpected number of created shares", 0, ctx2Shares.size());
246 Assert.assertEquals(
"Ctx3 has unexpected number of created shares", 0, ctx3Shares.size());
248 try { Thread.sleep(durationPostDestroy); }
catch(
final Exception e) { e.printStackTrace(); }
251 Assert.assertEquals(
false, animator.isAnimating());
254 static long duration = 1000;
255 static long durationPostDestroy = 1000;
257 public static void main(
final String args[]) {
258 for(
int i=0; i<args.length; i++) {
259 if(args[i].equals(
"-time")) {
262 duration = Integer.parseInt(args[i]);
263 }
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 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 test02CommonAnimatorMapBuffer()
static void main(final String args[])
void test01CommonAnimatorSharedCopyBuffer()
GLWindow runTestGL(final Animator animator, final int x, final int y, final GearsES2 gears, final GLAutoDrawable sharedDrawable)
void setValidateBuffers(final boolean v)
void setSharedGears(final GearsES2 shared)
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 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.
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
GLContext getContext()
Returns the context associated with this drawable.