29package com.jogamp.opengl.test.junit.jogl.demos.es2.swt;
31import java.io.IOException;
32import java.lang.reflect.InvocationTargetException;
34import com.jogamp.nativewindow.swt.SWTAccessor;
35import com.jogamp.opengl.swt.GLCanvas;
36import com.jogamp.opengl.test.junit.util.GLTestUtil;
37import com.jogamp.opengl.test.junit.util.MiscUtils;
38import com.jogamp.opengl.test.junit.util.NewtTestUtil;
39import com.jogamp.opengl.test.junit.util.SWTTestUtil;
40import com.jogamp.opengl.test.junit.util.UITestCase;
41import com.jogamp.opengl.util.Animator;
42import com.jogamp.opengl.util.AnimatorBase;
43import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
45import com.jogamp.nativewindow.util.Dimension;
46import com.jogamp.nativewindow.util.Point;
47import com.jogamp.nativewindow.util.PointImmutable;
48import com.jogamp.nativewindow.util.DimensionImmutable;
49import com.jogamp.opengl.GLCapabilities;
50import com.jogamp.opengl.GLCapabilitiesImmutable;
51import com.jogamp.opengl.GLProfile;
53import org.eclipse.swt.SWT;
54import org.eclipse.swt.layout.FillLayout;
55import org.eclipse.swt.widgets.Composite;
56import org.eclipse.swt.widgets.Display;
57import org.eclipse.swt.widgets.Shell;
58import org.junit.After;
59import org.junit.Assert;
60import org.junit.Assume;
61import org.junit.Before;
62import org.junit.BeforeClass;
63import org.junit.AfterClass;
65import org.junit.FixMethodOrder;
66import org.junit.runners.MethodSorters;
68@FixMethodOrder(MethodSorters.NAME_ASCENDING)
70 static int screenIdx = 0;
74 static long duration = 500;
75 static boolean opaque =
true;
76 static int forceAlpha = -1;
77 static boolean fullscreen =
false;
78 static int swapInterval = 1;
79 static boolean showFPS =
false;
81 static boolean loop_shutdown =
false;
82 static boolean forceES2 =
false;
83 static boolean forceGL3 =
false;
84 static boolean mainRun =
false;
85 static boolean exclusiveContext =
false;
98 Display display =
null;
100 Composite composite =
null;
107 display =
new Display();
108 Assert.assertNotNull( display );
110 display.syncExec(
new Runnable() {
113 shell =
new Shell( display );
114 Assert.assertNotNull( shell );
115 shell.setLayout(
new FillLayout() );
116 composite =
new Composite( shell, SWT.NONE );
117 composite.setLayout(
new FillLayout() );
118 Assert.assertNotNull( composite );
124 Assert.assertNotNull( display );
125 Assert.assertNotNull( shell );
126 Assert.assertNotNull( composite );
128 display.syncExec(
new Runnable() {
140 catch(
final Throwable throwable ) {
141 throwable.printStackTrace();
142 Assume.assumeNoException( throwable );
150 System.err.println(
"requested: vsync "+swapInterval+
", "+caps);
153 Assert.assertNotNull( canvas );
161 animator.
add(canvas);
164 Assert.assertTrue(animator.isAnimating());
167 display.syncExec(
new Runnable() {
170 shell.setText( getSimpleTestName(
".") );
173 shell.setLocation( wpos.
getX(), wpos.
getY() );
183 System.err.println(
"TestGearsES2SWT.test: 2.0: Exception "+(
null != waitAction.getException(
true)));
185 System.err.println(
"TestGearsES2SWT.test: 2.1: Exception "+(
null != waitAction.getException(
true)));
190 System.err.println(
"TestGearsES2SWT.test: 3.0: Exception "+(
null != waitAction.getException(
true)));
193 display.syncExec(
new Runnable() {
199 if(
null != rwsize ) {
200 for(
int i=0; i<50; i++) {
203 System.err.println(
"TestGearsES2SWT.test: 4.0: Exception "+(
null != waitAction.getException(
true)));
204 display.syncExec(
new Runnable() {
216 System.err.println(
"TestGearsES2SWT.test: 5.0: Exception "+(
null != waitAction.getException(
true)));
220 Assert.assertFalse(animator.isAnimating());
221 Assert.assertFalse(animator.
isStarted());
224 display.syncExec(
new Runnable() {
232 public void test01GL2ES2() throws InterruptedException, InvocationTargetException {
233 for(
int i=1; i<=loops; i++) {
234 System.err.println(
"Loop "+i+
"/"+loops);
238 }
else if(forceES2) {
245 if(-1 < forceAlpha) {
256 public void test02GL3() throws InterruptedException, InvocationTargetException {
260 System.err.println(
"GL3 n/a");
268 public static void main(
final String args[])
throws IOException {
271 int x=0, y=0, w=640, h=480, rw=-1, rh=-1;
272 boolean usePos =
false;
274 for(
int i=0; i<args.length; i++) {
275 if(args[i].equals(
"-time")) {
278 }
else if(args[i].equals(
"-translucent")) {
280 }
else if(args[i].equals(
"-forceAlpha")) {
283 }
else if(args[i].equals(
"-fullscreen")) {
285 }
else if(args[i].equals(
"-vsync")) {
288 }
else if(args[i].equals(
"-exclctx")) {
289 exclusiveContext =
true;
290 }
else if(args[i].equals(
"-es2")) {
292 }
else if(args[i].equals(
"-gl3")) {
294 }
else if(args[i].equals(
"-showFPS")) {
296 }
else if(args[i].equals(
"-width")) {
299 }
else if(args[i].equals(
"-height")) {
302 }
else if(args[i].equals(
"-x")) {
306 }
else if(args[i].equals(
"-y")) {
310 }
else if(args[i].equals(
"-rwidth")) {
313 }
else if(args[i].equals(
"-rheight")) {
316 }
else if(args[i].equals(
"-screen")) {
319 }
else if(args[i].equals(
"-loops")) {
322 }
else if(args[i].equals(
"-loop-shutdown")) {
323 loop_shutdown =
true;
327 if( 0 < rw && 0 < rh ) {
332 wpos =
new Point(x, y);
334 System.err.println(
"position "+wpos);
335 System.err.println(
"size "+wsize);
336 System.err.println(
"resize "+rwsize);
337 System.err.println(
"screen "+screenIdx);
338 System.err.println(
"translucent "+(!opaque));
339 System.err.println(
"forceAlpha "+forceAlpha);
340 System.err.println(
"fullscreen "+fullscreen);
341 System.err.println(
"loops "+loops);
342 System.err.println(
"loop shutdown "+loop_shutdown);
343 System.err.println(
"forceES2 "+forceES2);
344 System.err.println(
"forceGL3 "+forceGL3);
345 System.err.println(
"swapInterval "+swapInterval);
346 System.err.println(
"exclusiveContext "+exclusiveContext);
void setBackgroundOpaque(final boolean opaque)
Sets whether the surface shall be opaque or translucent.
void setAlphaBits(final int alphaBits)
Sets the number of bits requested for the color buffer's alpha component.
static void invokeOnOSTKThread(final boolean blocking, final Runnable runnable)
Runs the specified action in an SWT compatible OS toolkit thread, which is:
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 final String GL3
The desktop OpenGL core profile 3.x, with x >= 1.
static void shutdown()
Manual shutdown method, may be called after your last JOGL use within the running JVM.
static final String GLES2
The embedded OpenGL profile ES 2.x, with x >= 0.
static GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
static GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
Native SWT Canvas implementing GLAutoDrawable.
final GLDrawable getDelegatedDrawable()
If the implementation uses delegation, return the delegated GLDrawable instance, otherwise return thi...
boolean isRealized()
Returns true if this drawable is realized, otherwise false.
int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
static GLCanvas create(final Composite parent, final int style, final GLCapabilitiesImmutable caps, final GLCapabilitiesChooser chooser)
Creates an instance using GLCanvas(Composite, int, GLCapabilitiesImmutable, GLCapabilitiesChooser) on...
final Thread getExclusiveContextThread()
GLCapabilitiesImmutable getChosenGLCapabilities()
Fetches the GLCapabilitiesImmutable corresponding to the chosen OpenGL capabilities (pixel format / v...
int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
void dispose()
@Override public boolean forceFocus() { final boolean r = super.forceFocus(); if(r && 0 !...
void runTestGL(final GLCapabilitiesImmutable caps)
static void releaseClass()
static void main(final String args[])
static boolean waitForRealized(final GLAutoDrawable glad, final boolean realized, final Runnable waitAction)
static int atoi(final String str, final int def)
static long atol(final String str, final long def)
final long getTotalFPSDuration()
final synchronized Thread getThread()
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
final synchronized Thread setExclusiveContext(final Thread t)
Dedicate all GLAutoDrawable's context to the given exclusive context thread.
final void setUpdateFPSFrames(final int frames, final PrintStream out)
synchronized boolean isStarted()
Indicates whether this animator has been started.
final synchronized boolean start()
Starts this animator, if not running.
final synchronized boolean stop()
Stops this animator.
Immutable Dimension Interface, consisting of it's read only components:
Immutable Point interface.
Specifies an immutable set of OpenGL capabilities.
GLCapabilitiesImmutable getChosenGLCapabilities()
Fetches the GLCapabilitiesImmutable corresponding to the chosen OpenGL capabilities (pixel format / v...