29package com.jogamp.opengl.test.junit.jogl.acore;
31import java.util.ArrayList;
33import java.util.concurrent.atomic.AtomicInteger;
35import com.jogamp.newt.opengl.GLWindow;
36import com.jogamp.opengl.test.junit.util.MiscUtils;
37import com.jogamp.opengl.test.junit.util.UITestCase;
38import com.jogamp.opengl.util.Animator;
39import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
41import com.jogamp.opengl.GLAnimatorControl;
42import com.jogamp.opengl.GLAutoDrawable;
43import com.jogamp.opengl.GLCapabilities;
44import com.jogamp.opengl.GLEventListener;
45import com.jogamp.opengl.GLProfile;
46import com.jogamp.opengl.GLRunnable;
48import org.junit.Assert;
49import org.junit.BeforeClass;
51import org.junit.FixMethodOrder;
52import org.junit.runners.MethodSorters;
54@FixMethodOrder(MethodSorters.NAME_ASCENDING)
57 static int width, height;
59 @SuppressWarnings(
"serial")
60 static class AnimException
extends RuntimeException {
67 this.animator = animator;
68 this.drawable = drawable;
75 Assert.assertNotNull(glp);
81 System.err.println(
"User caught exception "+t.getClass().getSimpleName()+
": "+t.getMessage()+
" on thread "+Thread.currentThread().getName());
86 final boolean throwInInit,
final boolean throwInDisplay,
87 final boolean throwInReshape,
final boolean throwInInvoke,
88 final boolean throwInDispose)
throws InterruptedException {
90 Assert.assertNotNull(glWindow);
91 glWindow.
setTitle(getTestMethodName());
95 final AtomicInteger cleanInitCount =
new AtomicInteger();
96 final AtomicInteger cleanDisposeCount =
new AtomicInteger();
97 final AtomicInteger cleanDisplayCount =
new AtomicInteger();
98 final AtomicInteger cleanReshapeCount =
new AtomicInteger();
99 final AtomicInteger cleanInvokeCount =
new AtomicInteger();
100 final AtomicInteger allInitCount =
new AtomicInteger();
101 final AtomicInteger allDisposeCount =
new AtomicInteger();
102 final AtomicInteger allDisplayCount =
new AtomicInteger();
103 final AtomicInteger allReshapeCount =
new AtomicInteger();
104 final AtomicInteger allInvokeCount =
new AtomicInteger();
105 final AtomicInteger exceptionSent =
new AtomicInteger();
111 exceptionSent.incrementAndGet();
112 throw new RuntimeException(
"<Injected GLEventListener exception in init: #"+exceptionSent.get()+
" on thread "+Thread.currentThread().getName()+
">");
117 if( throwInDispose ) {
118 exceptionSent.incrementAndGet();
119 throw new RuntimeException(
"<Injected GLEventListener exception in dispose: #"+exceptionSent.get()+
" on thread "+Thread.currentThread().getName()+
">");
124 if( throwInDisplay ) {
125 exceptionSent.incrementAndGet();
126 throw new RuntimeException(
"<Injected GLEventListener exception in display: #"+exceptionSent.get()+
" on thread "+Thread.currentThread().getName()+
">");
130 public void reshape(
final GLAutoDrawable drawable,
final int x,
final int y,
final int width,
final int height) {
131 if( throwInReshape ) {
132 exceptionSent.incrementAndGet();
133 throw new RuntimeException(
"<Injected GLEventListener exception in reshape: #"+exceptionSent.get()+
" on thread "+Thread.currentThread().getName()+
">");
140 if( throwInInvoke ) {
141 exceptionSent.incrementAndGet();
142 throw new RuntimeException(
"<Injected GLEventListener exception in invoke: #"+exceptionSent.get()+
" on thread "+Thread.currentThread().getName()+
">");
150 if( 0 == exceptionSent.get() ) {
151 cleanInvokeCount.incrementAndGet();
153 allInvokeCount.incrementAndGet();
161 if( 0 == exceptionSent.get() ) {
162 cleanInitCount.incrementAndGet();
164 allInitCount.incrementAndGet();
168 if( 0 == exceptionSent.get() ) {
169 cleanDisposeCount.incrementAndGet();
171 allDisposeCount.incrementAndGet();
175 if( 0 == exceptionSent.get() ) {
176 cleanDisplayCount.incrementAndGet();
178 allDisplayCount.incrementAndGet();
181 public void reshape(
final GLAutoDrawable drawable,
final int x,
final int y,
final int width,
final int height) {
182 if( 0 == exceptionSent.get() ) {
183 cleanReshapeCount.incrementAndGet();
185 allReshapeCount.incrementAndGet();
189 RuntimeException exceptionAtInitReshapeDisplay =
null;
190 RuntimeException exceptionAtInvoke =
null;
191 RuntimeException exceptionAtDispose =
null;
192 final List<AnimException> exceptionsAtGLAnimatorControl =
new ArrayList<AnimException>();
193 final GLAnimatorControl.UncaughtExceptionHandler uncaughtExceptionHandler;
198 uncaughtExceptionHandler =
null;
204 final AnimException ae =
new AnimException(animator.
getThread(), animator, drawable, cause);
205 exceptionsAtGLAnimatorControl.add(ae);
211 glWindow.
setSize(width, height);
219 }
catch (
final RuntimeException re) {
220 exceptionAtInitReshapeDisplay = re;
225 glWindow.
invoke(
true, glRunnableInject);
226 glWindow.
invoke(
true, glRunnableCount);
227 }
catch (
final RuntimeException re) {
228 exceptionAtInvoke = re;
232 final long t0 = System.currentTimeMillis();
234 while(0 == exceptionSent.get() && ( onThread || animator.isAnimating() ) && t1-t0<duration ) {
238 }
catch (
final RuntimeException re) {
239 exceptionAtInitReshapeDisplay = re;
244 t1 = System.currentTimeMillis();
252 }
catch (
final RuntimeException re) {
253 exceptionAtDispose = re;
257 final boolean onAnimThread = !onThread && !throwInDispose;
259 System.err.println(
"This-Thread : "+onThread);
260 System.err.println(
"Anim-Thread : "+onAnimThread);
261 System.err.println(
"ExceptionSent : "+exceptionSent.get());
262 System.err.println(
"Exception @ Init/Reshape/Display: "+(
null != exceptionAtInitReshapeDisplay));
263 System.err.println(
"Exception @ Invoke : "+(
null != exceptionAtInvoke));
264 System.err.println(
"Exception @ Dispose : "+(
null != exceptionAtDispose));
265 System.err.println(
"Exception @ GLAnimatorControl : "+exceptionsAtGLAnimatorControl.size());
266 System.err.println(
"Init Count : "+cleanInitCount.get()+
" / "+allInitCount.get());
267 System.err.println(
"Reshape Count : "+cleanReshapeCount.get()+
" / "+allReshapeCount.get());
268 System.err.println(
"Display Count : "+cleanDisplayCount.get()+
" / "+allDisplayCount.get());
269 System.err.println(
"Invoke Count : "+cleanInvokeCount.get()+
" / "+allInvokeCount.get());
270 System.err.println(
"Dispose Count : "+cleanDisposeCount.get()+
" / "+allDisposeCount.get());
272 if( throwInInit || throwInReshape || throwInDisplay || throwInDispose || throwInInvoke ) {
273 Assert.assertTrue(
"Not one exception sent, but "+exceptionSent.get(), 0 < exceptionSent.get());
275 Assert.assertEquals(
"No exception forwarded from init to animator-handler", 1, exceptionsAtGLAnimatorControl.size());
276 Assert.assertNull(
"Exception forwarded from init, on-thread", exceptionAtInitReshapeDisplay);
279 if( !onAnimThread ) {
280 Assert.assertNotNull(
"No exception forwarded from init, on-thread", exceptionAtInitReshapeDisplay);
281 Assert.assertEquals(
"Exception forwarded from init to animator-handler", 0, exceptionsAtGLAnimatorControl.size());
283 Assert.assertEquals(
"Init Count", 0, cleanInitCount.get());
284 Assert.assertEquals(
"Reshape Count", 0, cleanReshapeCount.get());
285 Assert.assertEquals(
"Display Count", 0, cleanDisplayCount.get());
286 Assert.assertEquals(
"Invoke Count", 0, cleanInvokeCount.get());
287 Assert.assertEquals(
"Dispose Count", 0, cleanDisposeCount.get());
288 }
else if( throwInReshape ) {
289 if( !onAnimThread ) {
290 Assert.assertNotNull(
"No exception forwarded from reshape, on-thread", exceptionAtInitReshapeDisplay);
291 Assert.assertEquals(
"Exception forwarded from init to animator-handler", 0, exceptionsAtGLAnimatorControl.size());
293 Assert.assertEquals(
"Init Count", 1, cleanInitCount.get());
294 Assert.assertEquals(
"Reshape Count", 0, cleanReshapeCount.get());
295 Assert.assertEquals(
"Display Count", 0, cleanDisplayCount.get());
296 Assert.assertEquals(
"Invoke Count", 0, cleanInvokeCount.get());
297 Assert.assertEquals(
"Dispose Count", 0, cleanDisposeCount.get());
298 }
else if( throwInDisplay ) {
299 if( !onAnimThread ) {
300 Assert.assertNotNull(
"No exception forwarded from display, on-thread", exceptionAtInitReshapeDisplay);
301 Assert.assertEquals(
"Exception forwarded from init to animator-handler", 0, exceptionsAtGLAnimatorControl.size());
303 Assert.assertEquals(
"Init Count", 1, cleanInitCount.get());
304 Assert.assertEquals(
"Reshape Count", 1, cleanReshapeCount.get());
305 Assert.assertEquals(
"Display Count", 0, cleanDisplayCount.get());
306 Assert.assertEquals(
"Invoke Count", 0, cleanInvokeCount.get());
307 Assert.assertEquals(
"Dispose Count", 0, cleanDisposeCount.get());
308 }
else if( throwInInvoke ) {
309 if( !onAnimThread ) {
310 Assert.assertNotNull(
"No exception forwarded from invoke, on-thread", exceptionAtInvoke);
311 Assert.assertEquals(
"Exception forwarded from init to animator-handler", 0, exceptionsAtGLAnimatorControl.size());
313 Assert.assertEquals(
"Init Count", 1, cleanInitCount.get());
314 Assert.assertEquals(
"Reshape Count", 1, cleanReshapeCount.get());
315 Assert.assertTrue (
"Display count not greater-equal 1, but "+cleanDisplayCount.get(), 1 <= cleanDisplayCount.get());
316 Assert.assertEquals(
"Invoke Count", 0, cleanInvokeCount.get());
317 Assert.assertEquals(
"Dispose Count", 0, cleanDisposeCount.get());
318 }
else if( throwInDispose ) {
319 if( !onAnimThread ) {
320 Assert.assertNotNull(
"No exception forwarded from dispose, on-thread", exceptionAtDispose);
321 Assert.assertEquals(
"Exception forwarded from init to animator-handler", 0, exceptionsAtGLAnimatorControl.size());
323 Assert.assertEquals(
"Init Count", 1, cleanInitCount.get());
324 Assert.assertEquals(
"Reshape Count", 1, cleanReshapeCount.get());
325 Assert.assertTrue (
"Display count not greater-equal 1, but "+cleanDisplayCount.get(), 1 <= cleanDisplayCount.get());
326 Assert.assertEquals(
"Invoke Count", 1, cleanInvokeCount.get());
327 Assert.assertEquals(
"Dispose Count", 0, cleanDisposeCount.get());
336 runTestGL(caps,
true ,
true ,
false ,
false ,
false ,
false );
342 runTestGL(caps,
true ,
false ,
false ,
true ,
false ,
false );
348 runTestGL(caps,
true ,
false ,
true ,
false ,
false ,
false );
354 runTestGL(caps,
true ,
false ,
true ,
false ,
true ,
false );
360 runTestGL(caps,
true ,
false ,
false ,
false ,
false ,
true );
367 runTestGL(caps,
false ,
true ,
false ,
false ,
false ,
false );
373 runTestGL(caps,
false ,
false ,
false ,
true ,
false ,
false );
379 runTestGL(caps,
false ,
false ,
true ,
false ,
false ,
false );
385 runTestGL(caps,
false ,
false ,
true ,
false ,
true ,
false );
391 runTestGL(caps,
false ,
false ,
false ,
false ,
false ,
true );
394 static long duration = 500;
396 public static void main(
final String args[]) {
397 boolean waitForKey =
false;
399 for(
int i=0; i<args.length; i++) {
400 if(args[i].equals(
"-time")) {
403 }
else if(args[i].equals(
"-wait")) {
void setBackgroundOpaque(final boolean opaque)
Sets whether the surface shall be opaque or translucent.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final void setTitle(final String title)
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 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.
Specifies the the OpenGL profile.
static GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
void runTestGL(final GLCapabilities caps, final boolean onThread, final boolean throwInInit, final boolean throwInDisplay, final boolean throwInReshape, final boolean throwInInvoke, final boolean throwInDispose)
void test13OffThreadAtDisplay()
void test12OffThreadAtReshape()
void test03OnThreadAtDisplay()
static void main(final String args[])
void test14OffThreadAtInvoke()
void test11OffThreadAtInit()
void test15OffThreadAtDispose()
void test02OnThreadAtReshape()
static void dumpThrowable(final Throwable t)
void test05OnThreadAtDispose()
void test01OnThreadAtInit()
void test04OnThreadAtInvoke()
GearsES2 setVerbose(final boolean v)
static long atol(final String str, final long def)
final void setUncaughtExceptionHandler(final UncaughtExceptionHandler handler)
Set the handler invoked when this animator abruptly stops due to an uncaught exception from one of it...
final void setUpdateFPSFrames(final int frames, final PrintStream out)
final synchronized boolean start()
Starts this animator, if not running.
final synchronized boolean stop()
Stops this animator.
A registered UncaughtExceptionHandler instance is invoked when an animator abruptly stops due to an u...
An animator control interface, which implementation may drive a com.jogamp.opengl....
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
boolean invoke(boolean wait, GLRunnable glRunnable)
Enqueues a one-shot GLRunnable, which will be executed within the next display() call after all regis...
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.