29package com.jogamp.opengl.test.junit.jogl.acore.glels;
31import java.awt.Dimension;
34import com.jogamp.opengl.GLAnimatorControl;
35import com.jogamp.opengl.GLAutoDrawable;
36import com.jogamp.opengl.GLCapabilities;
37import com.jogamp.opengl.GLContext;
38import com.jogamp.opengl.GLDrawableFactory;
39import com.jogamp.opengl.GLOffscreenAutoDrawable;
40import com.jogamp.opengl.GLProfile;
41import com.jogamp.opengl.awt.GLCanvas;
43import jogamp.nativewindow.jawt.JAWTUtil;
45import com.jogamp.newt.Screen;
46import com.jogamp.newt.opengl.GLWindow;
48import com.jogamp.opengl.GLEventListenerState;
49import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
50import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
51import com.jogamp.opengl.test.junit.util.GLEventListenerCounter;
52import com.jogamp.opengl.test.junit.util.GLTestUtil;
53import com.jogamp.opengl.test.junit.util.TestUtil;
54import com.jogamp.opengl.test.junit.util.UITestCase;
56import org.junit.Assert;
57import org.junit.Assume;
58import org.junit.BeforeClass;
77 static long duration = 1000;
79 static int width, height;
83 System.err.println(
"Profile "+profile+
" n/a");
95 static void setGLCanvasSize(
final GLCanvas glc,
final Dimension new_sz) {
97 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
99 glc.setMinimumSize(new_sz);
100 glc.setPreferredSize(new_sz);
103 }
catch(
final Throwable throwable ) {
104 throwable.printStackTrace();
105 Assume.assumeNoException( throwable );
109 static void setFrameVisible(
final Frame frame)
throws InterruptedException {
111 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
114 frame.setVisible(
true);
116 }
catch(
final Throwable throwable ) {
117 throwable.printStackTrace();
118 Assume.assumeNoException( throwable );
122 static void destroyFrame(
final Frame frame)
throws InterruptedException {
124 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
128 }
catch(
final Throwable throwable ) {
129 throwable.printStackTrace();
130 Assume.assumeNoException( throwable );
134 private GLOffscreenAutoDrawable createGLOffscreenAutoDrawable(
final GLCapabilities caps,
final int width,
final int height)
throws InterruptedException {
135 final GLDrawableFactory factory = GLDrawableFactory.getFactory(caps.getGLProfile());
136 return factory.createOffscreenAutoDrawable(
null, caps,
null, width, height);
140 final boolean useOffscreenLayer = GLADType.GLCanvasOffscreen == gladType1 || GLADType.GLCanvasOffscreen == gladType2 ;
141 final boolean useOnscreenLayer = GLADType.GLCanvasOnscreen == gladType1 || GLADType.GLCanvasOnscreen == gladType2 ;
142 if( useOffscreenLayer ) {
143 if( !JAWTUtil.isOffscreenLayerSupported() ) {
144 System.err.println(
"Platform doesn't support offscreen rendering.");
147 }
else if( useOnscreenLayer ) {
148 if( JAWTUtil.isOffscreenLayerRequired() ) {
149 System.err.println(
"Platform requires offscreen rendering.");
159 throws InterruptedException {
161 System.err.println(
"GLAD Lifecycle.0 "+gladType+
", restoring "+((
null!=glelsIn)?
true:
false)+
", preserving "+((
null!=glelsOut)?
true:
false));
165 if( jogamp.nativewindow.jawt.JAWTUtil.isOffscreenLayerRequired() ) {
166 throw new InternalError(
"Platform requires offscreen rendering, but onscreen requested: "+gladType);
168 frame =
new Frame(
"AWT GLCanvas");
171 setGLCanvasSize((
GLCanvas)glad,
new Dimension(width, height));
174 if( !jogamp.nativewindow.jawt.JAWTUtil.isOffscreenLayerSupported() ) {
175 throw new InternalError(
"Platform doesn't support offscreen rendering: "+gladType);
177 frame =
new Frame(
"AWT GLCanvas");
180 ((
GLCanvas)glad).setShallUseOffscreenLayer(
true);
181 setGLCanvasSize((
GLCanvas)glad,
new Dimension(width, height));
186 if(
null != screen ) {
192 ((
GLWindow)glad).setSize(width, height);
196 glad = this.createGLOffscreenAutoDrawable(caps, width, height);
198 throw new InternalError(
"Unsupported: "+gladType);
201 if(
null == glelsIn ) {
202 if(
null != animator ) {
209 snapshotGLEventListener.setMakeSnapshot();
212 setFrameVisible(frame);
221 if(
null != glelsIn ) {
223 System.err.println(
".. restoring.0");
224 glelsIn.moveTo(glad);
225 System.err.println(
".. restoring.X");
227 Assert.assertEquals(1, glelTracker.initCount);
228 Assert.assertTrue(1 <= glelTracker.reshapeCount);
229 Assert.assertTrue(1 <= glelTracker.displayCount);
230 Assert.assertEquals(0, glelTracker.disposeCount);
233 Assert.assertEquals(glelsIn.context, glad.
getContext());
237 Assert.assertEquals(
false, glelsIn.isOwner());
240 for (
int wait=0; wait<TestUtil.POLL_DIVIDER &&
241 ( 1 > glelTracker.initCount || 1 > glelTracker.reshapeCount || 1 > glelTracker.displayCount );
246 final long t0 = System.currentTimeMillis();
249 while( ( t1 - t0 ) < duration ) {
251 t1 = System.currentTimeMillis();
254 Assert.assertEquals(1, glelTracker.initCount);
255 Assert.assertTrue(1 <= glelTracker.reshapeCount);
256 Assert.assertTrue(1 <= glelTracker.displayCount);
257 Assert.assertEquals(0, glelTracker.disposeCount);
259 if(
null != glelsOut ) {
261 System.err.println(
".. preserving.0");
263 System.err.println(
".. preserving.X");
265 Assert.assertEquals(context1, glelsOut[0].context);
268 Assert.assertEquals(3, glelsOut[0].listenerCount());
269 Assert.assertEquals(
true, glelsOut[0].isOwner());
283 Assert.assertEquals(1, glelTracker.initCount);
284 Assert.assertTrue(1 <= glelTracker.reshapeCount);
285 Assert.assertTrue(1 <= glelTracker.displayCount);
286 if(
null != glelsOut ) {
287 Assert.assertEquals(0, glelTracker.disposeCount);
289 Assert.assertEquals(1, glelTracker.disposeCount);
291 System.err.println(
"GLAD Lifecycle.X "+gladType);
A screen may span multiple MonitorDevices representing their combined virtual size.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final void setTitle(final String title)
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
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.
GLEventListenerState is holding GLAutoDrawable components crucial to relocating all its GLEventListen...
static GLEventListenerState moveFrom(final GLAutoDrawable src)
Moves all GLEventListenerState components from the given GLAutoDrawable to a newly created 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 GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
A heavyweight AWT component which provides OpenGL rendering support.
Test re-association of GLContext/GLDrawables, here GLContext's survival of GLDrawable destruction and...
static boolean validateOnOffscreenLayer(final GLADType gladType1, final GLADType gladType2)
void testGLADOneLifecycle(final Screen screen, final GLCapabilities caps, final GLADType gladType, final int width, final int height, final GLEventListenerCounter glelTracker, final SnapshotGLEventListener snapshotGLEventListener, final GLEventListenerState glelsIn, final GLEventListenerState glelsOut[], final GLAnimatorControl animator)
static boolean waitForVisible(final java.awt.Component comp, final boolean visible, final Runnable waitAction)
static boolean waitForRealized(final GLAutoDrawable glad, final boolean realized, final Runnable waitAction)
static final int TIME_SLICE
An animator control interface, which implementation may drive a com.jogamp.opengl....
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
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...
boolean isRealized()
Returns true if this drawable is realized, otherwise false.
void setSize(int width, int height)
Requests a new width and height for this AWTGLAutoDrawable.