29package com.jogamp.opengl.test.junit.jogl.swt;
32import java.lang.reflect.InvocationTargetException;
34import com.jogamp.opengl.GL2ES1;
35import com.jogamp.opengl.GLAutoDrawable;
36import com.jogamp.opengl.GLCapabilities;
37import com.jogamp.opengl.GLEventListener;
38import com.jogamp.opengl.GLProfile;
39import com.jogamp.opengl.awt.GLCanvas;
42import org.eclipse.swt.SWT;
43import org.eclipse.swt.awt.SWT_AWT;
44import org.eclipse.swt.graphics.Rectangle;
45import org.eclipse.swt.layout.FillLayout;
46import org.eclipse.swt.widgets.Composite;
47import org.eclipse.swt.widgets.Display;
48import org.eclipse.swt.widgets.Shell;
50import org.junit.Assert;
51import org.junit.Assume;
52import org.junit.BeforeClass;
54import org.junit.FixMethodOrder;
55import org.junit.runners.MethodSorters;
57import com.jogamp.common.os.Platform;
58import com.jogamp.junit.util.JunitTracer;
59import com.jogamp.nativewindow.swt.SWTAccessor;
60import com.jogamp.opengl.test.junit.jogl.demos.es1.OneTriangle;
61import com.jogamp.opengl.test.junit.util.MiscUtils;
62import com.jogamp.opengl.test.junit.util.UITestCase;
69@FixMethodOrder(MethodSorters.NAME_ASCENDING)
72 static int duration = 250;
74 Display display =
null;
76 Composite composite =
null;
82 if( Platform.getOSType() == Platform.OSType.MACOS ) {
86 JunitTracer.setTestSupported(
false);
90 final Frame f0 =
new Frame(
"Test - AWT 1st");
91 f0.add(
new java.awt.Label(
"AWT was here 1st"));
93 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
98 }
catch (
final Exception e) {
99 throw new RuntimeException(e);
102 setTestSupported(
false);
106 protected void init() throws InterruptedException, InvocationTargetException {
109 display =
new Display();
110 Assert.assertNotNull( display );
112 shell =
new Shell( display );
113 Assert.assertNotNull( shell );
114 shell.setLayout(
new FillLayout() );
115 composite =
new Composite( shell, SWT.EMBEDDED | SWT.NO_BACKGROUND );
116 composite.setLayout(
new FillLayout() );
117 Assert.assertNotNull( composite );
118 frame = SWT_AWT.new_Frame( composite );
119 Assert.assertNotNull( frame );
123 protected void release() throws InterruptedException, InvocationTargetException {
124 Assert.assertNotNull( display );
125 Assert.assertNotNull( shell );
126 Assert.assertNotNull( composite );
127 Assert.assertNotNull( glcanvas );
128 final Runnable releaseAWT =
new Runnable() {
131 frame.setVisible(
false);
132 frame.remove(glcanvas);
153 protected void runTestGL(
final GLProfile glprofile )
throws InterruptedException, InvocationTargetException {
157 glcanvas =
new GLCanvas( glcapabilities );
158 Assert.assertNotNull( glcanvas );
159 frame.add( glcanvas );
178 public void reshape(
final GLAutoDrawable glautodrawable,
final int x,
final int y,
final int width,
final int height ) {
187 shell.setText( getClass().getName() );
188 shell.setSize( 640, 480 );
192 final long lStartTime = System.currentTimeMillis();
193 final long lEndTime = lStartTime + duration;
195 while( (System.currentTimeMillis() < lEndTime) && !composite.isDisposed() ) {
198 if( !display.readAndDispatch() ) {
202 }
catch (
final InterruptedException e) { }
207 catch(
final Throwable throwable ) {
208 throwable.printStackTrace();
209 Assume.assumeNoException( throwable );
217 public void test() throws InterruptedException, InvocationTargetException {
219 runTestGL( glprofile );
222 public static void main(
final String args[]) {
223 for(
int i=0; i<args.length; i++) {
224 if(args[i].equals(
"-time")) {
static void invokeOnOSTKThread(final boolean blocking, final Runnable runnable)
Runs the specified action in an SWT compatible OS toolkit thread, which is:
static void printInfo(final PrintStream out, final Display d)
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
static boolean isAvailable(final AbstractGraphicsDevice device, final String profile)
Returns the availability of a profile on a device.
static String glAvailabilityToString(final AbstractGraphicsDevice device)
static GLProfile getGL2ES1(final AbstractGraphicsDevice device)
Returns the GL2ES1 profile implementation, hence compatible w/ GL2ES1.
static final String GL2
The desktop OpenGL profile 1.x up to 3.0.
A heavyweight AWT component which provides OpenGL rendering support.
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
A utility class to encapsulate drawing a single triangle for unit tests.
static void setup(final GL2ES1 gl, final int width, final int height)
static void render(final GL2ES1 gl, final int width, final int height)
Tests that a basic SWT app can open without crashing under different GL profiles.
static void main(final String args[])
void runTestGL(final GLProfile glprofile)
static int atoi(final String str, final int def)
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
GL2ES1 getGL2ES1()
Casts this object to the GL2ES1 interface.
int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.