29package com.jogamp.opengl.test.junit.jogl.acore.glels;
31import java.lang.reflect.InvocationTargetException;
33import com.jogamp.opengl.GLAutoDrawable;
34import com.jogamp.opengl.GLCapabilities;
35import com.jogamp.opengl.GLCapabilitiesImmutable;
36import com.jogamp.opengl.GLProfile;
37import com.jogamp.opengl.Threading;
39import com.jogamp.opengl.util.Animator;
40import com.jogamp.opengl.util.GLDrawableUtil;
41import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
42import com.jogamp.opengl.test.junit.util.QuitAdapter;
43import com.jogamp.opengl.test.junit.util.UITestCase;
45import org.junit.BeforeClass;
47import org.junit.FixMethodOrder;
48import org.junit.runners.MethodSorters;
54@FixMethodOrder(MethodSorters.NAME_ASCENDING)
56 static int width, height;
57 static boolean testEvenUnsafeSwapGLContext =
false;
61 System.err.println(
"Profile "+profile+
" n/a");
77 public
void test01aSwitch2Onscreen2OnscreenGL2ES2_Def() throws InterruptedException, InvocationTargetException {
79 if(
null == reqGLCaps)
return;
80 testImpl(reqGLCaps,
true);
84 public
void test01bSwitch2Onscreen2OffscreenGL2ES2_Def() throws InterruptedException, InvocationTargetException {
86 if(
null == reqGLCaps)
return;
87 testImpl(reqGLCaps,
false);
91 public
void test01cSwitch2Offscreen2OffscreenGL2ES2_Def() throws InterruptedException, InvocationTargetException {
93 if(
null == reqGLCaps)
return;
95 testImpl(reqGLCaps,
false);
99 public
void test01dSwitch2Offscreen2OnscreenGL2ES2_Def() throws InterruptedException, InvocationTargetException {
101 if(
null == reqGLCaps)
return;
103 testImpl(reqGLCaps,
true);
107 public
void test02aSwitch2Onscreen2OnscreenGL2ES2_MSAA() throws InterruptedException, InvocationTargetException {
109 if(
null == reqGLCaps)
return;
112 testImpl(reqGLCaps,
true);
116 public
void test02bSwitch2Onscreen2OffscreenGL2ES2_MSAA() throws InterruptedException, InvocationTargetException {
118 if(
null == reqGLCaps)
return;
121 testImpl(reqGLCaps,
false);
125 public
void test02cSwitch2Offscreen2OffscreenGL2ES2_MSAA() throws InterruptedException, InvocationTargetException {
127 if(
null == reqGLCaps)
return;
131 testImpl(reqGLCaps,
false);
135 public
void test02dSwitch2Offscreen2OnscreenGL2ES2_MSAA() throws InterruptedException, InvocationTargetException {
137 if(
null == reqGLCaps)
return;
141 testImpl(reqGLCaps,
true);
145 public
void test03aSwitch2Onscreen2OnscreenGL2ES2_Accu() throws InterruptedException, InvocationTargetException {
147 if(
null == reqGLCaps)
return;
151 testImpl(reqGLCaps,
true);
155 public
void test03bSwitch2Onscreen2OffscreenGL2ES2_Accu() throws InterruptedException, InvocationTargetException {
157 if(
null == reqGLCaps)
return;
161 testImpl(reqGLCaps,
false);
165 public
void test03cSwitch2Offscreen2OffscreenGL2ES2_Accu() throws InterruptedException, InvocationTargetException {
167 if(
null == reqGLCaps)
return;
172 testImpl(reqGLCaps,
false);
176 public
void test03dSwitch2Offscreen2OnscreenGL2ES2_Accu() throws InterruptedException, InvocationTargetException {
178 if(
null == reqGLCaps)
return;
183 testImpl(reqGLCaps,
true);
186 private void testImpl(
final GLCapabilitiesImmutable srcCapsRequested,
final boolean dstOnscreen)
throws InterruptedException, InvocationTargetException {
188 final GLAutoDrawable gladSource = createGLAutoDrawable(quitAdapter, srcCapsRequested, width, height);
196 System.err.println(
"Source Caps Requested: "+srcCapsRequested);
197 System.err.println(
"Source Caps Chosen : "+srcCapsChosen);
198 System.err.println(
"Dest Caps Requested: "+dstCaps);
199 System.err.println(
"Is SwapGLContext safe: "+isSwapGLContextSafe);
201 if( !isSwapGLContextSafe && !testEvenUnsafeSwapGLContext ) {
202 System.err.println(
"Supressing unsafe tests ...");
203 destroyGLAutoDrawable(gladSource);
207 final SnapshotGLEventListener snapshotGLEventListener =
new SnapshotGLEventListener();
212 snapshotGLEventListener.setMakeSnapshot();
215 animator.
add(gladSource);
219 final long t0 = System.currentTimeMillis();
222 final GLAutoDrawable gladDest = createGLAutoDrawable(quitAdapter, dstCaps, width, height);
223 RuntimeException caught =
null;
225 while( !quitAdapter.shouldQuit() && ( t1 - t0 ) < duration ) {
226 if( ( t1 - t0 ) / period > s) {
228 System.err.println(s+
" - switch - START "+ ( t1 - t0 ));
230 final Runnable switchAction =
new Runnable() {
241 snapshotGLEventListener.setMakeSnapshot();
243 System.err.println(s+
" - switch - END "+ ( t1 - t0 ));
246 t1 = System.currentTimeMillis();
248 }
catch (
final RuntimeException t) {
253 destroyGLAutoDrawable(gladDest);
254 destroyGLAutoDrawable(gladSource);
256 if(
null != caught ) {
262 static long duration = 2900;
263 static long period = 1000;
void setOnscreen(final boolean onscreen)
Sets whether the surface shall be on- or offscreen.
Specifies a set of OpenGL capabilities.
void setAccumRedBits(final int accumRedBits)
Sets the number of bits requested for the accumulation buffer's red component.
void setAccumGreenBits(final int accumGreenBits)
Sets the number of bits requested for the accumulation buffer's green component.
void setNumSamples(final int numSamples)
If sample buffers are enabled, indicates the number of buffers to be allocated.
void setAccumBlueBits(final int accumBlueBits)
Sets the number of bits requested for the accumulation buffer's blue component.
void setSampleBuffers(final boolean enable)
Defaults to false.
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.
This API provides access to the threading model for the implementation of the classes in this package...
static final void invokeOnOpenGLThread(final boolean wait, final Runnable r)
Executes the passed Runnable on the single thread used for all OpenGL work in this com....
Test re-association (switching) of GLWindow /GLDrawables, from GLWindow/GLOffscreenAutoDrawable to an...
abstract GLAutoDrawable createGLAutoDrawable(final QuitAdapter quitAdapter, final GLCapabilitiesImmutable caps, final int width, final int height)
abstract void destroyGLAutoDrawable(final GLAutoDrawable glad)
GearsES2 setVerbose(final boolean v)
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.
Providing utility functions dealing w/ GLDrawables, GLAutoDrawable and their GLEventListener.
static final void swapGLContextAndAllGLEventListener(final GLAutoDrawable a, final GLAutoDrawable b)
Swaps the GLContext and all GLEventListener between GLAutoDrawable a and b, while preserving it's ini...
static boolean isSwapGLContextSafe(final GLCapabilitiesImmutable requestedCaps, final GLCapabilitiesImmutable chosenCapsA, final GLCapabilitiesImmutable chosenCapsB)
Return a heuristic value whether switching the GLContext is safe between GLAutoDrawables,...
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
boolean isThreadGLCapable()
Indicates whether the current thread is capable of performing OpenGL-related work.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Specifies an immutable set of OpenGL capabilities.
GLCapabilitiesImmutable getChosenGLCapabilities()
Fetches the GLCapabilitiesImmutable corresponding to the chosen OpenGL capabilities (pixel format / v...