29package com.jogamp.opengl.test.junit.jogl.demos.es2.newt;
31import java.io.IOException;
32import java.lang.reflect.InvocationTargetException;
34import com.jogamp.nativewindow.NativeWindowFactory;
35import com.jogamp.nativewindow.swt.SWTAccessor;
36import com.jogamp.newt.NewtFactory;
37import com.jogamp.newt.event.KeyAdapter;
38import com.jogamp.newt.event.KeyEvent;
39import com.jogamp.newt.event.WindowEvent;
40import com.jogamp.newt.event.WindowAdapter;
41import com.jogamp.newt.opengl.GLWindow;
42import com.jogamp.newt.opengl.util.NEWTDemoListener;
43import com.jogamp.newt.swt.NewtCanvasSWT;
44import com.jogamp.opengl.test.junit.util.GLTestUtil;
45import com.jogamp.opengl.test.junit.util.MiscUtils;
46import com.jogamp.opengl.test.junit.util.NewtTestUtil;
47import com.jogamp.opengl.test.junit.util.UITestCase;
48import com.jogamp.opengl.test.junit.util.QuitAdapter;
49import com.jogamp.opengl.test.junit.util.SWTTestUtil;
50import com.jogamp.opengl.util.Animator;
51import com.jogamp.opengl.util.AnimatorBase;
53import jogamp.newt.DisplayImpl;
55import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
57import com.jogamp.nativewindow.util.Dimension;
58import com.jogamp.nativewindow.util.Point;
59import com.jogamp.nativewindow.util.PointImmutable;
60import com.jogamp.nativewindow.util.DimensionImmutable;
61import com.jogamp.opengl.GLCapabilities;
62import com.jogamp.opengl.GLCapabilitiesImmutable;
63import com.jogamp.opengl.GLProfile;
65import org.eclipse.swt.SWT;
66import org.eclipse.swt.layout.FillLayout;
67import org.eclipse.swt.widgets.Composite;
68import org.eclipse.swt.widgets.Display;
69import org.eclipse.swt.widgets.Shell;
70import org.junit.After;
71import org.junit.Assert;
72import org.junit.Assume;
73import org.junit.Before;
74import org.junit.BeforeClass;
75import org.junit.AfterClass;
77import org.junit.FixMethodOrder;
78import org.junit.runners.MethodSorters;
80@FixMethodOrder(MethodSorters.NAME_ASCENDING)
82 static int screenIdx = 0;
86 static long duration = 500;
87 static boolean opaque =
true;
88 static int forceAlpha = -1;
89 static boolean fullscreen =
false;
90 static int swapInterval = 1;
91 static boolean showFPS =
false;
93 static boolean loop_shutdown =
false;
94 static boolean forceES2 =
false;
95 static boolean forceGL3 =
false;
96 static boolean mainRun =
false;
97 static boolean exclusiveContext =
false;
112 Composite composite =
null;
121 Assert.assertNotNull( display );
123 display.syncExec(
new Runnable() {
126 shell =
new Shell( display );
127 Assert.assertNotNull( shell );
128 shell.setLayout(
new FillLayout() );
129 composite =
new Composite( shell, SWT.NONE );
130 composite.setLayout(
new FillLayout() );
131 Assert.assertNotNull( composite );
138 Assert.assertNotNull( display );
139 Assert.assertNotNull( shell );
140 Assert.assertNotNull( composite );
142 display.syncExec(
new Runnable() {
154 catch(
final Throwable throwable ) {
155 throwable.printStackTrace();
156 Assume.assumeNoException( throwable );
158 swtNewtDisplay =
null;
164 private String isOSXMainThread() {
166 return ", isOSX-Main-Thread: " + jogamp.nativewindow.macosx.OSXUtil.IsMainThread();
172 System.err.println(
"CCC00: Run Thread: "+Thread.currentThread()+isOSXMainThread());
173 display.syncExec(
new Runnable() {
176 System.err.println(
"CCC01: SWT Thread: "+Thread.currentThread()+isOSXMainThread());
180 d.runOnEDTIfAvail(
true,
new Runnable() {
183 System.err.println(
"CCC02: NEWT EDT Thread: "+Thread.currentThread()+isOSXMainThread());
188 System.err.println(
"requested: vsync "+swapInterval+
", "+caps);
191 Assert.assertNotNull(glWindow);
218 public void keyReleased(
final KeyEvent e) {
223 glWindow.invokeOnNewThread(
null,
false,
new Runnable() {
239 animator.
add(glWindow);
242 Assert.assertTrue(animator.isAnimating());
246 Assert.assertNotNull( canvas1 );
248 display.syncExec(
new Runnable() {
251 shell.setText( getSimpleTestName(
".") );
254 shell.setLocation( wpos.
getX(), wpos.
getY() );
269 if(
null != rwsize ) {
270 for(
int i=0; i<50; i++) {
273 display.syncExec(
new Runnable() {
281 while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.
getTotalFPSDuration()<duration) {
287 Assert.assertFalse(animator.isAnimating());
288 Assert.assertFalse(animator.
isStarted());
291 display.syncExec(
new Runnable() {
302 public void test01GL2ES2() throws InterruptedException, InvocationTargetException {
303 for(
int i=1; i<=loops; i++) {
304 System.err.println(
"Loop "+i+
"/"+loops);
308 }
else if(forceES2) {
315 if(-1 < forceAlpha) {
326 public void test02GL3() throws InterruptedException, InvocationTargetException {
330 System.err.println(
"GL3 n/a");
338 public static void main(
final String args[])
throws IOException {
341 int x=0, y=0, w=640, h=480, rw=-1, rh=-1;
342 boolean usePos =
false;
344 for(
int i=0; i<args.length; i++) {
345 if(args[i].equals(
"-time")) {
348 }
else if(args[i].equals(
"-translucent")) {
350 }
else if(args[i].equals(
"-forceAlpha")) {
353 }
else if(args[i].equals(
"-fullscreen")) {
355 }
else if(args[i].equals(
"-vsync")) {
358 }
else if(args[i].equals(
"-exclctx")) {
359 exclusiveContext =
true;
360 }
else if(args[i].equals(
"-es2")) {
362 }
else if(args[i].equals(
"-gl3")) {
364 }
else if(args[i].equals(
"-showFPS")) {
366 }
else if(args[i].equals(
"-width")) {
369 }
else if(args[i].equals(
"-height")) {
372 }
else if(args[i].equals(
"-x")) {
376 }
else if(args[i].equals(
"-y")) {
380 }
else if(args[i].equals(
"-rwidth")) {
383 }
else if(args[i].equals(
"-rheight")) {
386 }
else if(args[i].equals(
"-screen")) {
389 }
else if(args[i].equals(
"-loops")) {
392 }
else if(args[i].equals(
"-loop-shutdown")) {
393 loop_shutdown =
true;
397 if( 0 < rw && 0 < rh ) {
402 wpos =
new Point(x, y);
404 System.err.println(
"position "+wpos);
405 System.err.println(
"size "+wsize);
406 System.err.println(
"resize "+rwsize);
407 System.err.println(
"screen "+screenIdx);
408 System.err.println(
"translucent "+(!opaque));
409 System.err.println(
"forceAlpha "+forceAlpha);
410 System.err.println(
"fullscreen "+fullscreen);
411 System.err.println(
"loops "+loops);
412 System.err.println(
"loop shutdown "+loop_shutdown);
413 System.err.println(
"forceES2 "+forceES2);
414 System.err.println(
"forceGL3 "+forceGL3);
415 System.err.println(
"swapInterval "+swapInterval);
416 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.
Provides a pluggable mechanism for arbitrary window toolkits to adapt their components to the NativeW...
static final String TYPE_MACOSX
Mac OS X type, as retrieved with getNativeWindowType(boolean).
static String getNativeWindowType(final boolean useCustom)
static void invokeOnOSTKThread(final boolean blocking, final Runnable runnable)
Runs the specified action in an SWT compatible OS toolkit thread, which is:
static Display createDisplay(final String name)
Create a Display entity.
static Screen createScreen(final Display display, final int index)
Create a Screen entity.
A screen may span multiple MonitorDevices representing their combined virtual size.
final char getKeyChar()
Returns the UTF-16 character reflecting the key symbol incl.
static boolean isPrintableKey(final short uniChar, final boolean isKeyChar)
Returns true if given uniChar represents a printable character, i.e.
NEWT Window events are provided for notification purposes ONLY.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final boolean isFullscreen()
final int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
final void addMouseListener(final MouseListener l)
Appends the given MouseListener to the end of the list.
final int getX()
Returns the current x position of this window, relative to it's parent.
final boolean isAlwaysOnTop()
final void addKeyListener(final KeyListener l)
Appends the given com.jogamp.newt.event.KeyListener to the end of the list.
final int getY()
Returns the current y position of the top-left corner of the client area relative to it's parent in w...
final int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
final boolean setFullscreen(final boolean fullscreen)
Enable or disable fullscreen mode for this window.
final void addWindowListener(final WindowListener l)
Appends the given com.jogamp.newt.event.WindowListener to the end of the list.
final CapabilitiesImmutable getChosenCapabilities()
Gets an immutable set of chosen capabilities.
final InsetsImmutable getInsets()
Returns the insets defined as the width and height of the window decoration on the left,...
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
final Window getDelegatedWindow()
If the implementation uses delegation, return the delegated Window instance, otherwise return this in...
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
NEWT GLWindow Demo functionality.
void quitAdapterEnable(final boolean v)
SWT Canvas containing a NEWT Window using native parenting.
static NewtCanvasSWT create(final Composite parent, final int style, final Window child)
Creates an instance using NewtCanvasSWT(Composite, int, Window) on the SWT thread.
void dispose()
Destroys this resource:
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.
static void main(final String args[])
static void releaseClass()
void runTestGL(final GLCapabilitiesImmutable caps)
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)
static boolean waitForRealized(final Screen screen, final boolean realized, final Runnable waitAction)
static boolean waitForVisible(final Window win, final boolean visible, final Runnable waitAction)
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.
CapabilitiesImmutable getChosenCapabilities()
Gets an immutable set of chosen capabilities.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Thread getExclusiveContextThread()
Specifies an immutable set of OpenGL capabilities.