29package com.jogamp.opengl.test.junit.jogl.swt;
31import com.jogamp.opengl.GL2ES1;
32import com.jogamp.opengl.GLContext;
33import com.jogamp.opengl.GLDrawableFactory;
34import com.jogamp.opengl.GLProfile;
36import org.eclipse.swt.SWT;
37import org.eclipse.swt.events.PaintEvent;
38import org.eclipse.swt.events.PaintListener;
39import org.eclipse.swt.graphics.Rectangle;
40import org.eclipse.swt.layout.FillLayout;
41import org.eclipse.swt.opengl.GLCanvas;
42import org.eclipse.swt.opengl.GLData;
43import org.eclipse.swt.widgets.Composite;
44import org.eclipse.swt.widgets.Display;
45import org.eclipse.swt.widgets.Event;
46import org.eclipse.swt.widgets.Listener;
47import org.eclipse.swt.widgets.Shell;
49import org.junit.Assert;
50import org.junit.Assume;
51import org.junit.Before;
52import org.junit.BeforeClass;
53import org.junit.After;
55import org.junit.FixMethodOrder;
56import org.junit.runners.MethodSorters;
58import com.jogamp.nativewindow.swt.SWTAccessor;
59import com.jogamp.opengl.test.junit.jogl.demos.es1.OneTriangle;
60import com.jogamp.opengl.test.junit.util.SWTTestUtil;
61import com.jogamp.opengl.test.junit.util.UITestCase;
70@FixMethodOrder(MethodSorters.NAME_ASCENDING)
73 static int duration = 250;
75 static final int iwidth = 640;
76 static final int iheight = 480;
78 Display display =
null;
80 Composite composite =
null;
82 volatile boolean triangleSet =
false;
95 display =
new Display();
96 Assert.assertNotNull( display );
100 shell =
new Shell( display );
101 Assert.assertNotNull( shell );
102 shell.setLayout(
new FillLayout() );
103 composite =
new Composite( shell, SWT.NONE );
104 composite.setLayout(
new FillLayout() );
105 Assert.assertNotNull( composite );
111 Assert.assertNotNull( display );
112 Assert.assertNotNull( shell );
113 Assert.assertNotNull( composite );
117 if(
null != glcanvas ) {
125 catch(
final Throwable throwable ) {
126 throwable.printStackTrace();
127 Assume.assumeNoException( throwable );
140 shell.setText( getClass().getName() );
141 shell.setSize( 640, 480 );
144 final GLData gldata =
new GLData();
145 gldata.doubleBuffer =
true;
149 glcanvas =
new GLCanvas( composite, SWT.NO_BACKGROUND, gldata );
150 Assert.assertNotNull( glcanvas );
152 glcanvas.setCurrent();
154 Assert.assertNotNull( glcontext[0] );
157 glcanvas.addListener( SWT.Resize,
new Listener() {
158 public void handleEvent(
final Event event ) {
159 final Rectangle rectangle = glcanvas.getClientArea();
160 glcanvas.setCurrent();
166 System.err.println(
"resize");
171 glcanvas.addPaintListener(
new PaintListener() {
172 public void paintControl(
final PaintEvent paintevent ) {
173 final Rectangle rectangle = glcanvas.getClientArea();
174 glcanvas.setCurrent();
184 System.err.println(
"paint");
191 final long lStartTime = System.currentTimeMillis();
192 final long lEndTime = lStartTime + duration;
194 while( (System.currentTimeMillis() < lEndTime) && !glcanvas.isDisposed() ) {
202 generalWaitAction.run();
204 }
catch(
final Throwable throwable ) {
205 throwable.printStackTrace();
206 Assume.assumeNoException( throwable );
211 public void test() throws InterruptedException {
213 runTestAGL( glprofile );
216 static int atoi(
final String a) {
219 i = Integer.parseInt(a);
220 }
catch (
final Exception ex) { ex.printStackTrace(); }
224 public static void main(
final String args[]) {
225 for(
int i=0; i<args.length; i++) {
226 if(args[i].equals(
"-time")) {
227 duration = atoi(args[++i]);
230 System.out.println(
"durationPerTest: "+duration);
static void invokeOnOSTKThread(final boolean blocking, final Runnable runnable)
Runs the specified action in an SWT compatible OS toolkit thread, which is:
static void invokeOnSWTThread(final org.eclipse.swt.widgets.Display display, final boolean blocking, final Runnable runnable)
Runs the specified action on the SWT UI thread.
Abstraction for an OpenGL rendering context.
abstract int makeCurrent()
Makes this GLContext current on the calling thread.
abstract void release()
Releases control of this GLContext from the current thread.
abstract GL getGL()
Returns the GL pipeline object for this GLContext.
abstract GLContext createExternalGLContext()
static GLDrawableFactory getFactory(final GLProfile glProfile)
Returns the sole GLDrawableFactory instance.
Specifies the the OpenGL profile.
static String glAvailabilityToString(final AbstractGraphicsDevice device)
static GLProfile getGL2ES1(final AbstractGraphicsDevice device)
Returns the GL2ES1 profile implementation, hence compatible w/ GL2ES1.
A heavyweight AWT component which provides OpenGL rendering support.
void swapBuffers()
Swaps the front and back buffers of this drawable.
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 runTestAGL(final GLProfile glprofile)
GL2ES1 getGL2ES1()
Casts this object to the GL2ES1 interface.
void setSize(int width, int height)
Requests a new width and height for this AWTGLAutoDrawable.