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.newt.awt.NewtCanvasAWT;
57import com.jogamp.newt.opengl.GLWindow;
58import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
59import com.jogamp.opengl.test.junit.util.MiscUtils;
60import com.jogamp.opengl.test.junit.util.UITestCase;
62@FixMethodOrder(MethodSorters.NAME_ASCENDING)
64 static long durationPerTest = 50;
65 static int addRemoveCount = 15;
66 static int pauseEach = 0;
67 static int pauseDuration = 500;
68 static boolean noOnscreenTest =
false;
69 static boolean noOffscreenTest =
false;
70 static boolean offscreenPBufferOnly =
false;
71 static boolean offscreenFBOOnly =
false;
73 static int width, height;
74 static boolean waitForKey =
false;
75 static boolean waitForKeyPost =
false;
81 Assert.assertNotNull(glp);
85 setTestSupported(
false);
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
153 for(
int i=0; i<addRemoveOpCount; i++) {
154 System.err.println(
"Loop # "+i+
" / "+addRemoveCount);
156 Assert.assertNotNull(glw);
158 Assert.assertNotNull(glc);
163 glc.setMinimumSize(glc_sz);
164 glc.setPreferredSize(glc_sz);
170 final JFrame[] top =
new JFrame[] {
null };
171 final Container glcCont = create(top, width, height, i);
174 setVisible(top[0],
true);
176 final long t0 = System.currentTimeMillis();
180 }
while ( ( System.currentTimeMillis() - t0 ) < durationPerTest ) ;
187 if( 0 < pauseEach && 0 == i % pauseEach ) {
188 System.err.println(
"******* P A U S E ********");
189 Thread.sleep(pauseDuration);
199 throws AWTException, InterruptedException, InvocationTargetException
201 if( noOnscreenTest || JAWTUtil.isOffscreenLayerRequired() ) {
202 System.err.println(
"No onscreen test requested or platform doesn't support onscreen rendering.");
206 runTestGL(
true, caps, addRemoveCount);
211 throws AWTException, InterruptedException, InvocationTargetException
213 if( noOffscreenTest || !JAWTUtil.isOffscreenLayerSupported() ) {
214 System.err.println(
"No offscreen test requested or platform doesn't support offscreen rendering.");
217 if( offscreenPBufferOnly ) {
218 System.err.println(
"Only PBuffer test is requested.");
222 runTestGL(
false, caps, addRemoveCount);
227 throws AWTException, InterruptedException, InvocationTargetException
229 if( noOffscreenTest || !JAWTUtil.isOffscreenLayerSupported() ) {
230 System.err.println(
"No offscreen test requested or platform doesn't support offscreen rendering.");
233 if( offscreenFBOOnly ) {
234 System.err.println(
"Only FBO test is requested.");
240 runTestGL(
false, caps, addRemoveCount);
243 public static void main(
final String args[])
throws IOException {
244 for(
int i=0; i<args.length; i++) {
245 if(args[i].equals(
"-time")) {
248 durationPerTest = Long.parseLong(args[i]);
249 }
catch (
final Exception ex) { ex.printStackTrace(); }
250 }
else if(args[i].equals(
"-loops")) {
253 }
else if(args[i].equals(
"-pauseEach")) {
256 }
else if(args[i].equals(
"-pauseDuration")) {
259 }
else if(args[i].equals(
"-noOnscreen")) {
260 noOnscreenTest =
true;
261 }
else if(args[i].equals(
"-noOffscreen")) {
262 noOffscreenTest =
true;
263 }
else if(args[i].equals(
"-layeredFBO")) {
264 offscreenFBOOnly =
true;
265 }
else if(args[i].equals(
"-layeredPBuffer")) {
266 offscreenPBufferOnly =
true;
267 }
else if(args[i].equals(
"-wait")) {
269 }
else if(args[i].equals(
"-waitPost")) {
270 waitForKeyPost =
true;
273 System.err.println(
"waitForKey "+waitForKey);
274 System.err.println(
"waitForKeyPost "+waitForKeyPost);
276 System.err.println(
"addRemoveCount "+addRemoveCount);
277 System.err.println(
"pauseEach "+pauseEach);
278 System.err.println(
"pauseDuration "+pauseDuration);
280 System.err.println(
"noOnscreenTest "+noOnscreenTest);
281 System.err.println(
"noOffscreenTest "+noOffscreenTest);
282 System.err.println(
"offscreenPBufferOnly "+offscreenPBufferOnly);
283 System.err.println(
"offscreenFBOOnly "+offscreenFBOOnly);
void setOnscreen(final boolean onscreen)
Sets whether the surface shall be on- or offscreen.
AWT Canvas containing a NEWT Window using native parenting.
final boolean isOffscreenLayerSurfaceEnabled()
Returns true if this instance uses an offscreen layer, otherwise false.
void setShallUseOffscreenLayer(final boolean v)
Request an offscreen layer, if supported.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
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.
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.
A heavyweight AWT component which provides OpenGL rendering support.
void dispose(final GLCanvas glc)
void dispose(final JFrame jFrame)
void setVisible(final JFrame jFrame, final boolean visible)
void add(final Container cont, final Component comp)
static void main(final String args[])
static void releaseClass()
JPanel create(final JFrame[] top, final int width, final int height, final int num)
void runTestGL(final boolean onscreen, final GLCapabilities caps, final int addRemoveOpCount)
void test02OffscreenFBO()
void test03OffscreenPBuffer()
GearsES2 setVerbose(final boolean v)
static int atoi(final String str, final int def)
void addGLEventListener(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...