29package com.jogamp.opengl.test.junit.jogl.acore.glels;
31import java.io.IOException;
33import com.jogamp.newt.NewtFactory;
34import com.jogamp.newt.Window;
35import com.jogamp.newt.event.WindowAdapter;
36import com.jogamp.newt.event.WindowEvent;
37import com.jogamp.newt.event.WindowListener;
38import com.jogamp.newt.event.WindowUpdateEvent;
39import com.jogamp.newt.opengl.GLWindow;
41import com.jogamp.opengl.GLAutoDrawable;
42import com.jogamp.opengl.GLCapabilities;
43import com.jogamp.opengl.GLContext;
44import com.jogamp.opengl.GLDrawable;
45import com.jogamp.opengl.GLDrawableFactory;
46import com.jogamp.opengl.GLProfile;
48import com.jogamp.opengl.GLAutoDrawableDelegate;
49import com.jogamp.opengl.util.Animator;
50import com.jogamp.opengl.util.GLDrawableUtil;
52import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
53import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2;
54import com.jogamp.opengl.test.junit.util.NewtTestUtil;
55import com.jogamp.opengl.test.junit.util.QuitAdapter;
56import com.jogamp.opengl.test.junit.util.UITestCase;
58import org.junit.Assert;
59import org.junit.BeforeClass;
61import org.junit.FixMethodOrder;
62import org.junit.runners.MethodSorters;
68@FixMethodOrder(MethodSorters.NAME_ASCENDING)
70 static int width, height;
74 System.err.println(
"Profile "+profile+
" n/a");
88 Assert.assertNotNull(window);
97 Assert.assertNotNull(drawable);
103 Assert.assertNotNull(context);
107 protected void destroyImplInLock() {
122 public void windowRepaint(
final WindowUpdateEvent e) {
126 public void windowResized(
final WindowEvent e) {
136 public
void testSwitch2WindowSingleContextGL2ES2() throws InterruptedException {
138 if(
null == reqGLCaps)
return;
139 testSwitch2WindowSingleContextImpl(reqGLCaps);
143 public
void testSwitch2WindowSingleContextGLES2() throws InterruptedException {
145 if(
null == reqGLCaps)
return;
146 testSwitch2WindowSingleContextImpl(reqGLCaps);
149 private void testSwitch2WindowSingleContextImpl(
final GLCapabilities caps)
throws InterruptedException {
152 final GLAutoDrawable glad1 = createGLAutoDrawable(caps, 64, 64, width, height, quitAdapter);
153 final GLAutoDrawable glad2 = createGLAutoDrawable(caps, 2*64+width, 64, width+100, height+100, quitAdapter);
159 Assert.assertNotNull(newCtx);
161 Assert.assertNotNull(oldCtx);
168 final SnapshotGLEventListener snapshotGLEventListener =
new SnapshotGLEventListener();
172 snapshotGLEventListener.setMakeSnapshot();
180 final long t0 = System.currentTimeMillis();
183 while( !quitAdapter.shouldQuit() && ( t1 - t0 ) < duration ) {
184 if( ( t1 - t0 ) / period > s) {
186 System.err.println(s+
" - switch - START "+ ( t1 - t0 ));
191 System.err.println(s+
" - switch - END "+ ( t1 - t0 ));
194 t1 = System.currentTimeMillis();
203 public
void testSwitch2GLWindowOneDemoGL2ES2() throws InterruptedException {
205 if(
null == reqGLCaps)
return;
206 testSwitch2GLWindowOneDemoImpl(reqGLCaps);
210 public
void testSwitch2GLWindowOneDemoGLES2() throws InterruptedException {
212 if(
null == reqGLCaps)
return;
213 testSwitch2GLWindowOneDemoImpl(reqGLCaps);
216 private void testSwitch2GLWindowOneDemoImpl(
final GLCapabilities caps)
throws InterruptedException {
217 final SnapshotGLEventListener snapshotGLEventListener =
new SnapshotGLEventListener();
223 glWindow1.
setSize(width, height);
231 glWindow2.
setSize(width+100, height+100);
236 animator.
add(glWindow1);
237 animator.
add(glWindow2);
243 snapshotGLEventListener.setMakeSnapshot();
246 final long t0 = System.currentTimeMillis();
249 while( !quitAdapter.shouldQuit() && ( t1 - t0 ) < duration ) {
250 if( ( t1 - t0 ) / period > s) {
252 System.err.println(s+
" - switch - START "+ ( t1 - t0 ));
253 System.err.println(s+
" - A w1-h 0x"+Long.toHexString(glWindow1.
getHandle())+
",-ctx 0x"+Long.toHexString(glWindow1.
getContext().
getHandle()));
254 System.err.println(s+
" - A w2-h 0x"+Long.toHexString(glWindow2.
getHandle())+
",-ctx 0x"+Long.toHexString(glWindow2.
getContext().
getHandle()));
259 System.err.println(s+
" - B w1-h 0x"+Long.toHexString(glWindow1.
getHandle())+
",-ctx 0x"+Long.toHexString(glWindow1.
getContext().
getHandle()));
260 System.err.println(s+
" - B w2-h 0x"+Long.toHexString(glWindow2.
getHandle())+
",-ctx 0x"+Long.toHexString(glWindow2.
getContext().
getHandle()));
261 System.err.println(s+
" - switch - END "+ ( t1 - t0 ));
263 snapshotGLEventListener.setMakeSnapshot();
266 t1 = System.currentTimeMillis();
276 public
void testSwitch2GLWindowEachWithOwnDemoGL2ES2() throws InterruptedException {
278 if(
null == reqGLCaps)
return;
279 testSwitch2GLWindowEachWithOwnDemoImpl(reqGLCaps);
283 public
void testSwitch2GLWindowEachWithOwnDemoGLES2() throws InterruptedException {
285 if(
null == reqGLCaps)
return;
286 testSwitch2GLWindowEachWithOwnDemoImpl(reqGLCaps);
298 glWindow1.
setSize(width, height);
306 glWindow2.
setSize(width+100, height+100);
313 animator.
add(glWindow1);
314 animator.
add(glWindow2);
324 final long t0 = System.currentTimeMillis();
327 while( !quitAdapter.shouldQuit() && ( t1 - t0 ) < duration ) {
328 if( ( t1 - t0 ) / period > s) {
330 System.err.println(s+
" - switch - START "+ ( t1 - t0 ));
331 System.err.println(s+
" - A w1-h 0x"+Long.toHexString(glWindow1.
getHandle())+
",-ctx 0x"+Long.toHexString(glWindow1.
getContext().
getHandle()));
332 System.err.println(s+
" - A w2-h 0x"+Long.toHexString(glWindow2.
getHandle())+
",-ctx 0x"+Long.toHexString(glWindow2.
getContext().
getHandle()));
334 System.err.println(s+
" - B w1-h 0x"+Long.toHexString(glWindow1.
getHandle())+
",-ctx 0x"+Long.toHexString(glWindow1.
getContext().
getHandle()));
335 System.err.println(s+
" - B w2-h 0x"+Long.toHexString(glWindow2.
getHandle())+
",-ctx 0x"+Long.toHexString(glWindow2.
getContext().
getHandle()));
336 System.err.println(s+
" - switch - END "+ ( t1 - t0 ));
341 t1 = System.currentTimeMillis();
355 static long duration = 2200;
356 static long period = 1000;
358 public static void main(
final String args[])
throws IOException {
359 for(
int i=0; i<args.length; i++) {
360 if(args[i].equals(
"-time")) {
363 duration = Integer.parseInt(args[i]);
364 }
catch (
final Exception ex) { ex.printStackTrace(); }
365 }
else if(args[i].equals(
"-period")) {
368 period = Integer.parseInt(args[i]);
369 }
catch (
final Exception ex) { ex.printStackTrace(); }
static Window createWindow(final CapabilitiesImmutable caps)
Create a top level Window entity on the default Display and default Screen.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final void setPosition(final int x, final int y)
Sets the location of the window's client area excluding insets (window decorations) in window units.
final void setTitle(final String title)
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
final void addWindowListener(final WindowListener l)
Appends the given com.jogamp.newt.event.WindowListener to the end of the list.
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Fully functional GLAutoDrawable implementation utilizing already created GLDrawable and GLContext ins...
final void windowResizedOp(final int newWidth, final int newHeight)
Handling resize events from the windowing system.
final void windowDestroyNotifyOp()
Implementation to handle destroy notifications from the windowing system.
final void windowRepaintOp()
Default implementation to handle repaint events from the windowing system.
Specifies a set of OpenGL capabilities.
Abstraction for an OpenGL rendering context.
abstract int makeCurrent()
Makes this GLContext current on the calling thread.
final boolean isCreated()
Indicates whether the underlying native OpenGL context has been created.
static final int CONTEXT_CURRENT
Indicates that the context was made current during the last call to makeCurrent, value {@value}.
abstract void release()
Releases control of this GLContext from the current thread.
static final int CONTEXT_CURRENT_NEW
Indicates that a newly-created context was made current during the last call to makeCurrent,...
final long getHandle()
Returns the underlying native OpenGL context handle.
abstract GLDrawable createGLDrawable(NativeSurface target)
Returns an unrealized GLDrawable according to it's chosen GLCapabilitiesImmutable,...
static GLDrawableFactory getFactory(final GLProfile glProfile)
Returns the sole GLDrawableFactory instance.
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 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.
Test re-association (switching) of GLContext/GLDrawables, i.e.
static void main(final String args[])
void testSwitch2GLWindowEachWithOwnDemoImpl(final GLCapabilities caps)
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 synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
final synchronized boolean start()
Starts this animator, if not running.
final synchronized boolean stop()
Stops this animator.
Providing utility functions dealing w/ GLDrawables, GLAutoDrawable and their GLEventListener.
static final void swapGLContextAndAllGLEventListener(final GLAutoDrawable a, final GLAutoDrawable b)
Swaps the GLContext and all GLEventListener between GLAutoDrawable a and b, while preserving it's ini...
int getSurfaceWidth()
Returns the width of the client area excluding insets (window decorations) in pixel units.
int getSurfaceHeight()
Returns the height of the client area excluding insets (window decorations) in pixel units.
Specifying NEWT's Window functionality:
void addWindowListener(WindowListener l)
Appends the given com.jogamp.newt.event.WindowListener to the end of the list.
void setWindowDestroyNotifyAction(Runnable r)
Set a custom action handling destruction issued by a toolkit triggered window destroy replacing the d...
void setSize(int width, int height)
Sets the size of the window's client area in window units, excluding decorations.
void setVisible(boolean visible)
Calls setVisible(true, visible), i.e.
void setPosition(int x, int y)
Sets the location of the window's client area excluding insets (window decorations) in window units.
void destroy()
Destroys this window incl.releasing all related resources.
NEWT WindowEvent listener.
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GLContext setContext(GLContext newCtx, boolean destroyPrevCtx)
Associate the new context, newtCtx, to this auto-drawable.
GLContext createContext(GLContext shareWith)
Creates a new context for drawing to this drawable that will optionally share buffer objects,...
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
GLContext getContext()
Returns the context associated with this drawable.
An abstraction for an OpenGL rendering target.
long getHandle()
Returns the GL drawable handle, guaranteed to be valid after realization and while it's surface is be...
boolean isRealized()
Returns true if this drawable is realized, otherwise false.
void setRealized(boolean realized)
Indicates to GLDrawable implementations whether the underlying surface has been created and can be dr...
GLContext createContext(GLContext shareWith)
Creates a new context for drawing to this drawable that will optionally share buffer objects,...