29package com.jogamp.opengl.test.junit.jogl.awt;
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.GLAutoDrawable;
40import com.jogamp.opengl.GLCapabilities;
41import com.jogamp.opengl.GLEventListener;
42import com.jogamp.opengl.GLProfile;
43import com.jogamp.opengl.awt.GLCanvas;
44import javax.swing.JFrame;
45import javax.swing.JPanel;
46import javax.swing.SwingUtilities;
47import javax.swing.WindowConstants;
49import jogamp.nativewindow.jawt.JAWTUtil;
51import org.junit.AfterClass;
52import org.junit.Assert;
53import org.junit.BeforeClass;
55import org.junit.FixMethodOrder;
56import org.junit.runners.MethodSorters;
58import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
59import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
60import com.jogamp.opengl.test.junit.util.UITestCase;
61import com.jogamp.opengl.util.Animator;
63@FixMethodOrder(MethodSorters.NAME_ASCENDING)
65 static long durationPerTest = 500;
66 static boolean shallUseOffscreenFBOLayer =
false;
67 static boolean shallUseOffscreenPBufferLayer =
false;
69 static int width, height;
70 static boolean waitForKey =
false;
76 Assert.assertNotNull(glp);
80 setTestSupported(
false);
88 protected JPanel
create(
final JFrame[] top,
final int width,
final int height,
final int num)
89 throws InterruptedException, InvocationTargetException
91 final JPanel[] jPanel =
new JPanel[] {
null };
92 SwingUtilities.invokeAndWait(
new Runnable() {
94 jPanel[0] =
new JPanel();
95 jPanel[0].setLayout(
new BorderLayout());
97 final JFrame jFrame1 =
new JFrame(
"JFrame #"+num);
99 jFrame1.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
100 jFrame1.getContentPane().add(jPanel[0]);
101 jFrame1.setSize(width, height);
108 protected void add(
final Container cont,
final Component comp,
final JFrame jFrame)
109 throws InterruptedException, InvocationTargetException
111 SwingUtilities.invokeAndWait(
new Runnable() {
113 cont.add(comp, BorderLayout.CENTER);
120 throws InterruptedException, InvocationTargetException
122 SwingUtilities.invokeAndWait(
new Runnable() {
128 protected void setFrameVisible(
final JFrame jFrame,
final boolean visible)
throws InterruptedException, InvocationTargetException {
129 SwingUtilities.invokeAndWait(
new Runnable() {
131 jFrame.setVisible(visible);
135 protected void setComponentVisible(
final Component comp,
final boolean visible)
throws InterruptedException, InvocationTargetException {
136 SwingUtilities.invokeAndWait(
new Runnable() {
138 comp.setVisible(visible);
142 protected void dispose(
final JFrame jFrame)
throws InterruptedException, InvocationTargetException {
143 SwingUtilities.invokeAndWait(
new Runnable() {
149 private volatile int frameCount = 0;
152 throws AWTException, InterruptedException, InvocationTargetException
155 for(
int i=0; i<1; i++) {
158 Assert.assertNotNull(glc);
163 final Dimension glc_sz =
new Dimension(width, height);
164 glc.setMinimumSize(glc_sz);
165 glc.setPreferredSize(glc_sz);
177 public void reshape(
final GLAutoDrawable drawable,
final int x,
final int y,
final int width,
final int height) {}
183 final JFrame[] top =
new JFrame[] {
null };
184 final Container glcCont = create(top, width, height, i);
185 add(glcCont, glc, top[0]);
187 System.err.println(
"XXXX Visible Part 1/3");
189 setFrameVisible(top[0],
true);
201 System.err.println(
"XXXXX Invisible Part 2/3");
202 setComponentVisible(glc,
false);
204 final int frameCountT0 = frameCount;
211 final int frameCountT1 = frameCount;
212 System.err.println(
"GLCanvas invisible frame count: Before "+frameCountT0+
", after "+frameCountT1);
213 Assert.assertTrue(
"GLCanvas rendered more that 4 times while being invisible, before "+frameCountT0+
", after "+frameCountT1,
214 4 >= frameCountT1 - frameCountT0);
216 System.err.println(
"XXXX Visible Part 3/3");
217 setComponentVisible(glc,
true);
233 throws AWTException, InterruptedException, InvocationTargetException
235 if( shallUseOffscreenFBOLayer || shallUseOffscreenPBufferLayer || JAWTUtil.isOffscreenLayerRequired() ) {
236 System.err.println(
"Offscreen test requested or platform requires it.");
240 if(shallUseOffscreenPBufferLayer) {
244 runTestGL(
true, caps);
249 throws AWTException, InterruptedException, InvocationTargetException
251 if( !JAWTUtil.isOffscreenLayerSupported() ) {
252 System.err.println(
"Platform doesn't support offscreen test.");
256 if(shallUseOffscreenPBufferLayer) {
260 runTestGL(
false, caps);
263 public static void main(
final String args[])
throws IOException {
264 for(
int i=0; i<args.length; i++) {
265 if(args[i].equals(
"-time")) {
268 durationPerTest = Long.parseLong(args[i]);
269 }
catch (
final Exception ex) { ex.printStackTrace(); }
270 }
else if(args[i].equals(
"-layeredFBO")) {
271 shallUseOffscreenFBOLayer =
true;
272 }
else if(args[i].equals(
"-layeredPBuffer")) {
273 shallUseOffscreenPBufferLayer =
true;
274 }
else if(args[i].equals(
"-wait")) {
278 System.err.println(
"waitForKey "+waitForKey);
280 System.err.println(
"shallUseOffscreenFBOLayer "+shallUseOffscreenFBOLayer);
281 System.err.println(
"shallUseOffscreenPBufferLayer "+shallUseOffscreenPBufferLayer);
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 getDefault(final AbstractGraphicsDevice device)
Returns a default GLProfile object, reflecting the best for the running platform.
static GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
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...
JPanel create(final JFrame[] top, final int width, final int height, final int num)
void runTestGL(final boolean onscreen, final GLCapabilities caps)
static void main(final String args[])
void dispose(final JFrame jFrame)
void setFrameVisible(final JFrame jFrame, final boolean visible)
static void releaseClass()
void dispose(final GLCanvas glc)
void setComponentVisible(final Component comp, final boolean visible)
void add(final Container cont, final Component comp, final JFrame jFrame)
GearsES2 setVerbose(final boolean v)
static boolean waitForRealized(final java.awt.Component comp, final boolean realized, final Runnable waitAction)
static boolean waitForVisible(final java.awt.Component comp, final boolean visible, final Runnable waitAction)
final long getTotalFPSDuration()
final void resetFPSCounter()
Reset all performance counter (startTime, currentTime, frame number)
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
final void setUpdateFPSFrames(final int frames, final PrintStream out)
final synchronized boolean start()
Starts this animator, if not running.
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.
void setSize(int width, int height)
Requests a new width and height for this AWTGLAutoDrawable.