29package com.jogamp.opengl.test.junit.jogl.acore;
31import java.awt.AWTException;
32import java.awt.BorderLayout;
33import java.awt.Component;
34import java.awt.Container;
35import java.awt.Dimension;
36import java.io.IOException;
37import java.lang.reflect.InvocationTargetException;
39import com.jogamp.opengl.GLCapabilities;
40import com.jogamp.opengl.GLProfile;
41import com.jogamp.opengl.awt.GLCanvas;
42import javax.swing.JFrame;
43import javax.swing.JPanel;
44import javax.swing.SwingUtilities;
45import javax.swing.WindowConstants;
47import jogamp.nativewindow.jawt.JAWTUtil;
49import org.junit.AfterClass;
50import org.junit.Assert;
51import org.junit.BeforeClass;
53import org.junit.FixMethodOrder;
54import org.junit.runners.MethodSorters;
56import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
57import com.jogamp.opengl.test.junit.util.MiscUtils;
58import com.jogamp.opengl.test.junit.util.UITestCase;
60@FixMethodOrder(MethodSorters.NAME_ASCENDING)
62 static long durationPerTest = 100;
63 static int addRemoveCount = 15;
64 static int pauseEach = 0;
65 static int pauseDuration = 500;
66 static boolean noOnscreenTest =
false;
67 static boolean noOffscreenTest =
false;
68 static boolean offscreenPBufferOnly =
false;
69 static boolean offscreenFBOOnly =
false;
71 static int width, height;
72 static boolean waitForKey =
false;
73 static boolean waitForKeyPost =
false;
81 Assert.assertNotNull(glpGL2ES2);
85 Assert.assertNotNull(glpGL2);
93 protected JPanel
create(
final JFrame[] top,
final int width,
final int height,
final int num)
94 throws InterruptedException, InvocationTargetException
96 final JPanel[] jPanel =
new JPanel[] {
null };
97 SwingUtilities.invokeAndWait(
new Runnable() {
99 jPanel[0] =
new JPanel();
100 jPanel[0].setLayout(
new BorderLayout());
102 final JFrame jFrame1 =
new JFrame(
"JFrame #"+num);
104 jFrame1.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
105 jFrame1.getContentPane().add(jPanel[0]);
106 jFrame1.setSize(width, height);
113 protected void add(
final Container cont,
final Component comp)
114 throws InterruptedException, InvocationTargetException
116 SwingUtilities.invokeAndWait(
new Runnable() {
118 cont.add(comp, BorderLayout.CENTER);
123 throws InterruptedException, InvocationTargetException
125 SwingUtilities.invokeAndWait(
new Runnable() {
131 protected void setVisible(
final JFrame jFrame,
final boolean visible)
throws InterruptedException, InvocationTargetException {
132 SwingUtilities.invokeAndWait(
new Runnable() {
138 jFrame.setVisible(visible);
142 protected void dispose(
final JFrame jFrame)
throws InterruptedException, InvocationTargetException {
143 SwingUtilities.invokeAndWait(
new Runnable() {
150 throws AWTException, InterruptedException, InvocationTargetException
155 for(
int i=0; i<addRemoveOpCount; i++) {
157 System.err.println(
"Loop."+(ti++)+
" "+(i+1)+
"/"+addRemoveOpCount);
159 Assert.assertNotNull(glc);
164 glc.setMinimumSize(glc_sz);
165 glc.setPreferredSize(glc_sz);
171 final JFrame[] top =
new JFrame[] {
null };
172 final Container glcCont = create(top, width, height, i);
175 setVisible(top[0],
true);
177 final long t0 = System.currentTimeMillis();
181 }
while ( ( System.currentTimeMillis() - t0 ) < durationPerTest ) ;
187 if( 0 < pauseEach && 0 == i % pauseEach ) {
188 System.err.println(
"******* P A U S E - Start ********");
190 Thread.sleep(pauseDuration);
191 System.err.println(
"******* P A U S E - End ********");
201 throws AWTException, InterruptedException, InvocationTargetException
203 if( noOnscreenTest || JAWTUtil.isOffscreenLayerRequired() ) {
204 System.err.println(
"No onscreen test requested or platform doesn't support onscreen rendering.");
208 runTestGL(
true, caps, addRemoveCount);
213 throws AWTException, InterruptedException, InvocationTargetException
215 if( noOffscreenTest || !JAWTUtil.isOffscreenLayerSupported() ) {
216 System.err.println(
"No offscreen test requested or platform doesn't support offscreen rendering.");
219 if( offscreenPBufferOnly ) {
220 System.err.println(
"Only PBuffer test is requested.");
224 if(offscreenPBufferOnly) {
228 runTestGL(
false, caps, addRemoveCount);
233 throws AWTException, InterruptedException, InvocationTargetException
235 if( noOffscreenTest || !JAWTUtil.isOffscreenLayerSupported() ) {
236 System.err.println(
"No offscreen test requested or platform doesn't support offscreen rendering.");
239 if( offscreenFBOOnly ) {
240 System.err.println(
"Only FBO test is requested.");
246 runTestGL(
false, caps, addRemoveCount);
249 public static void main(
final String args[])
throws IOException {
250 for(
int i=0; i<args.length; i++) {
251 if(args[i].equals(
"-time")) {
254 durationPerTest = Long.parseLong(args[i]);
255 }
catch (
final Exception ex) { ex.printStackTrace(); }
256 }
else if(args[i].equals(
"-loops")) {
259 }
else if(args[i].equals(
"-pauseEach")) {
262 }
else if(args[i].equals(
"-pauseDuration")) {
265 }
else if(args[i].equals(
"-noOnscreen")) {
266 noOnscreenTest =
true;
267 }
else if(args[i].equals(
"-noOffscreen")) {
268 noOffscreenTest =
true;
269 }
else if(args[i].equals(
"-layeredFBO")) {
270 offscreenFBOOnly =
true;
271 }
else if(args[i].equals(
"-layeredPBuffer")) {
272 offscreenPBufferOnly =
true;
273 }
else if(args[i].equals(
"-wait")) {
275 }
else if(args[i].equals(
"-waitPost")) {
276 waitForKeyPost =
true;
279 System.err.println(
"waitForKey "+waitForKey);
280 System.err.println(
"waitForKeyPost "+waitForKeyPost);
282 System.err.println(
"addRemoveCount "+addRemoveCount);
283 System.err.println(
"pauseEach "+pauseEach);
284 System.err.println(
"pauseDuration "+pauseDuration);
286 System.err.println(
"noOnscreenTest "+noOnscreenTest);
287 System.err.println(
"noOffscreenTest "+noOffscreenTest);
288 System.err.println(
"offscreenPBufferOnly "+offscreenPBufferOnly);
289 System.err.println(
"offscreenFBOOnly "+offscreenFBOOnly);
void setOnscreen(final boolean onscreen)
Sets whether the surface shall be on- or offscreen.
Specifies a set of OpenGL capabilities.
void setPBuffer(final boolean enable)
Requesting offscreen pbuffer mode.
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.
static final String GL2
The desktop OpenGL profile 1.x up to 3.0.
A heavyweight AWT component which provides OpenGL rendering support.
void setShallUseOffscreenLayer(final boolean v)
Request an offscreen layer, if supported.
final boolean isOffscreenLayerSurfaceEnabled()
Returns true if this instance uses an offscreen layer, otherwise false.
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
GLCapabilitiesImmutable getChosenGLCapabilities()
Fetches the GLCapabilitiesImmutable corresponding to the chosen OpenGL capabilities (pixel format / v...
void dispose(final JFrame jFrame)
void dispose(final GLCanvas glc)
void runTestGL(final boolean onscreen, final GLCapabilities caps, final int addRemoveOpCount)
void test02OffscreenFBO()
void add(final Container cont, final Component comp)
void setVisible(final JFrame jFrame, final boolean visible)
static void main(final String args[])
static void releaseClass()
void test03OffscreenPBuffer()
JPanel create(final JFrame[] top, final int width, final int height, final int num)
GearsES2 setVerbose(final boolean v)
static int atoi(final String str, final int def)
void setSize(int width, int height)
Requests a new width and height for this AWTGLAutoDrawable.