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;
40import com.jogamp.opengl.GLAutoDrawable;
41import com.jogamp.opengl.GLCapabilities;
42import com.jogamp.opengl.GLContext;
43import com.jogamp.opengl.GLDrawable;
44import com.jogamp.opengl.GLDrawableFactory;
45import com.jogamp.opengl.GLProfile;
48import com.jogamp.opengl.GLAutoDrawableDelegate;
49import com.jogamp.opengl.GLEventListenerState;
50import com.jogamp.opengl.util.Animator;
52import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
53import com.jogamp.opengl.test.junit.util.GLEventListenerCounter;
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;
80@FixMethodOrder(MethodSorters.NAME_ASCENDING)
83 static long duration = 1000;
85 static int width, height;
89 System.err.println(
"Profile "+profile+
" n/a");
103 Assert.assertNotNull(window);
113 Assert.assertNotNull(drawable);
122 protected void destroyImplInLock() {
137 public void windowRepaint(
final WindowUpdateEvent e) {
141 public void windowResized(
final WindowEvent e) {
151 public
void test01GLADDelegateGL2ES2() throws InterruptedException {
153 if(
null == reqGLCaps)
return;
154 testGLADDelegateImpl(reqGLCaps);
158 public
void test02GLADDelegateGLES2() throws InterruptedException {
160 if(
null == reqGLCaps)
return;
161 testGLADDelegateImpl(reqGLCaps);
164 private void testGLADDelegateImpl(
final GLCapabilities caps)
throws InterruptedException {
166 final SnapshotGLEventListener snapshotGLEventListener =
new SnapshotGLEventListener();
176 final GLAutoDrawable glad1 = createGLAutoDrawableWithoutContext(caps, 64, 64, width, height, quitAdapter);
184 snapshotGLEventListener.setMakeSnapshot();
186 final long t0 = System.currentTimeMillis();
189 while( !quitAdapter.shouldQuit() && ( t1 - t0 ) < duration ) {
191 t1 = System.currentTimeMillis();
194 Assert.assertEquals(1, glelCounter.
initCount);
198 Assert.assertEquals(context1, glad1.
getContext());
207 Assert.assertEquals(1, glelCounter.
initCount);
211 Assert.assertEquals(context1, glls1.
context);
215 Assert.assertEquals(
true, glls1.
isOwner());
216 Assert.assertEquals(
null, glad1.
getContext());
220 Assert.assertEquals(1, glelCounter.
initCount);
228 final QuitAdapter quitAdapter =
new QuitAdapter();
229 final GLAutoDrawable glad2 = createGLAutoDrawableWithoutContext(caps, 2*64+width, 64, width+100, height+100, quitAdapter);
230 snapshotGLEventListener.setMakeSnapshot();
232 Assert.assertEquals(
null, glad2.
getContext());
239 Assert.assertEquals(1, glelCounter.
initCount);
247 Assert.assertEquals(
false, glls1.
isOwner());
249 final long t0 = System.currentTimeMillis();
252 while( !quitAdapter.shouldQuit() && ( t1 - t0 ) < duration ) {
254 t1 = System.currentTimeMillis();
258 Assert.assertEquals(1, glelCounter.
initCount);
266 public static void main(
final String args[])
throws IOException {
267 for(
int i=0; i<args.length; i++) {
268 if(args[i].equals(
"-time")) {
271 duration = Integer.parseInt(args[i]);
272 }
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.
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 GLDrawable getGLDrawable()
Returns the write-drawable this context uses for framebuffer operations.
abstract GLDrawable getGLReadDrawable()
Returns the read-Drawable this context uses for read framebuffer operations.
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.
GLEventListenerState is holding GLAutoDrawable components crucial to relocating all its GLEventListen...
final boolean isOwner()
Returns true, if this instance is the current owner of the components, otherwise false.
final void moveTo(final GLAutoDrawable dest)
Moves all GLEventListenerState components to the given GLAutoDrawable from this instance,...
static GLEventListenerState moveFrom(final GLAutoDrawable src)
Moves all GLEventListenerState components from the given GLAutoDrawable to a newly created instance.
final int listenerCount()
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 of GLContext/GLDrawables, here GLContext's survival of GLDrawable destruction and...
static void main(final String args[])
static boolean waitForSize(final Window window, final int width, final int height, final Runnable waitAction)
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.
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.
int getGLEventListenerCount()
Returns the number of GLEventListener 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.
GLDrawable getDelegatedDrawable()
If the implementation uses delegation, return the delegated GLDrawable instance, otherwise return thi...
An abstraction for an OpenGL rendering target.
int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
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...
int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.