JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestGLContextDrawableSwitch13Newt2AWT.java
Go to the documentation of this file.
1/**
2 * Copyright 2013 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.opengl.test.junit.jogl.acore.glels;
30
31import java.io.IOException;
32
33import com.jogamp.opengl.GLCapabilities;
34import com.jogamp.opengl.GLProfile;
35
36
37import com.jogamp.newt.Display;
38import com.jogamp.newt.NewtFactory;
39import com.jogamp.newt.Screen;
40import com.jogamp.opengl.GLEventListenerState;
41import com.jogamp.opengl.GLRendererQuirks;
42import com.jogamp.opengl.util.Animator;
43
44import com.jogamp.opengl.test.junit.util.GLEventListenerCounter;
45
46import org.junit.Test;
47import org.junit.FixMethodOrder;
48import org.junit.runners.MethodSorters;
49
50/**
51 * Test re-association of GLContext/GLDrawables,
52 * here GLContext's survival of GLDrawable destruction
53 * and reuse w/ new or recreated GLDrawable.
54 * <p>
55 * Test utilizes {@link GLEventListenerState} for preserving the
56 * GLAutoDrawable state, i.e. GLContext, all GLEventListener
57 * and the GLAnimatorControl association.
58 * </p>
59 * <p>
60 * This test moves the {@link GLEventListenerState} from a
61 * NEWT GLWindow before it's destruction to an AWT GLCanvas after it's creation
62 * and vice versa
63 * </p>
64 * <p>
65 * See Bug 665 - https://jogamp.org/bugzilla/show_bug.cgi?id=665.
66 * </p>
67 * <p>
68 * Interesting artifact w/ ATI proprietary driver is that the
69 * bug causing the quirk {@link GLRendererQuirks#DontCloseX11Display}
70 * also causes an XCB crash when reusing the X11 display connection
71 * from AWT -> NEWT. Pre-allocating the X11 Display and keeping it referenced
72 * to avoid such re-usage worksaround this problem.
73 * </p>
74 */
75@FixMethodOrder(MethodSorters.NAME_ASCENDING)
77
78 @Test(timeout=30000)
79 public void test01GLCanvasOnScrn2GLWindowGL2ES2() throws InterruptedException {
80 final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2ES2);
81 if(null == reqGLCaps) return;
82 testGLCanvas2GLWindowImpl(null, reqGLCaps, GLADType.GLCanvasOnscreen, GLADType.GLWindow);
83 }
84
85 @Test(timeout=30000)
86 public void test02GLCanvasOnScrn2GLWindowGLES2() throws InterruptedException {
87 final GLCapabilities reqGLCaps = getCaps(GLProfile.GLES2);
88 if(null == reqGLCaps) return;
89 testGLCanvas2GLWindowImpl(null, reqGLCaps, GLADType.GLCanvasOnscreen, GLADType.GLWindow);
90 }
91
92 @Test(timeout=30000)
93 public void test11GLWindow2GLCanvasOnScrnGL2ES2() throws InterruptedException {
94 final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2ES2);
95 if(null == reqGLCaps) return;
96 final Display dpy = NewtFactory.createDisplay(null);
97 final Screen screen = NewtFactory.createScreen(dpy, 0);
98 screen.addReference();
99 testGLCanvas2GLWindowImpl(screen, reqGLCaps, GLADType.GLWindow, GLADType.GLCanvasOnscreen);
100 screen.removeReference();
101 }
102
103 @Test(timeout=30000)
104 public void test12GLWindow2GLCanvasOnScrnGLES2() throws InterruptedException {
105 final GLCapabilities reqGLCaps = getCaps(GLProfile.GLES2);
106 if(null == reqGLCaps) return;
107 final Display dpy = NewtFactory.createDisplay(null);
108 final Screen screen = NewtFactory.createScreen(dpy, 0);
109 screen.addReference();
110 testGLCanvas2GLWindowImpl(screen, reqGLCaps, GLADType.GLWindow, GLADType.GLCanvasOnscreen);
111 screen.removeReference();
112 }
113
114 @Test(timeout=30000)
115 public void test21GLCanvasOffScrn2GLWindowGL2ES2() throws InterruptedException {
116 final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2ES2);
117 if(null == reqGLCaps) return;
118 testGLCanvas2GLWindowImpl(null, reqGLCaps, GLADType.GLCanvasOffscreen, GLADType.GLWindow);
119 }
120
121 @Test(timeout=30000)
122 public void test22GLCanvasOffScrn2GLWindowGLES2() throws InterruptedException {
123 final GLCapabilities reqGLCaps = getCaps(GLProfile.GLES2);
124 if(null == reqGLCaps) return;
125 testGLCanvas2GLWindowImpl(null, reqGLCaps, GLADType.GLCanvasOffscreen, GLADType.GLWindow);
126 }
127
128 @Test(timeout=30000)
129 public void test31GLWindow2GLCanvasOffScrnGL2ES2() throws InterruptedException {
130 final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2ES2);
131 if(null == reqGLCaps) return;
132 final Display dpy = NewtFactory.createDisplay(null);
133 final Screen screen = NewtFactory.createScreen(dpy, 0);
134 screen.addReference();
135 testGLCanvas2GLWindowImpl(screen, reqGLCaps, GLADType.GLWindow, GLADType.GLCanvasOffscreen);
136 screen.removeReference();
137 }
138
139 @Test(timeout=30000)
140 public void test32GLWindow2GLCanvasOffScrnGLES2() throws InterruptedException {
141 final GLCapabilities reqGLCaps = getCaps(GLProfile.GLES2);
142 if(null == reqGLCaps) return;
143 final Display dpy = NewtFactory.createDisplay(null);
144 final Screen screen = NewtFactory.createScreen(dpy, 0);
145 screen.addReference();
146 testGLCanvas2GLWindowImpl(screen, reqGLCaps, GLADType.GLWindow, GLADType.GLCanvasOffscreen);
147 screen.removeReference();
148 }
149
150 private void testGLCanvas2GLWindowImpl(final Screen screen, final GLCapabilities caps, final GLADType gladType1, final GLADType gladType2) throws InterruptedException {
151 if( !validateOnOffscreenLayer(gladType1, gladType2) ) {
152 return;
153 }
154 final SnapshotGLEventListener snapshotGLEventListener = new SnapshotGLEventListener();
155 final GLEventListenerCounter glelTracker = new GLEventListenerCounter();
156 final Animator animator = new Animator();
157 animator.start();
158
159 final GLEventListenerState glels[] = new GLEventListenerState[1];
160
161 // - create glad1 w/o context
162 // - create context using glad1 and assign it to glad1
163 {
164 testGLADOneLifecycle(screen, caps, gladType1, width,
165 height, glelTracker,
166 snapshotGLEventListener,
167 null, glels, animator);
168 }
169
170 // - create glad2 w/ survived context
171 {
172 testGLADOneLifecycle(screen, caps, gladType2, width+100,
173 height+100, glelTracker,
174 snapshotGLEventListener,
175 glels[0], null, null);
176 }
177 animator.stop();
178 }
179
180 public static void main(final String args[]) throws IOException {
181 for(int i=0; i<args.length; i++) {
182 if(args[i].equals("-time")) {
183 i++;
184 try {
185 duration = Integer.parseInt(args[i]);
186 } catch (final Exception ex) { ex.printStackTrace(); }
187 }
188 }
189 /**
190 BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
191 System.err.println("Press enter to continue");
192 System.err.println(stdin.readLine()); */
193 org.junit.runner.JUnitCore.main(TestGLContextDrawableSwitch13Newt2AWT.class.getName());
194 }
195}
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.
Definition: Screen.java:58
abstract int addReference()
See Display#addReference().
abstract int removeReference()
See Display#removeReference().
Specifies a set of OpenGL capabilities.
GLEventListenerState is holding GLAutoDrawable components crucial to relocating all its GLEventListen...
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static final String GL2ES2
The intersection of the desktop GL3, GL2 and embedded ES2 profile.
Definition: GLProfile.java:594
static final String GLES2
The embedded OpenGL profile ES 2.x, with x >= 0.
Definition: GLProfile.java:585
Test re-association of GLContext/GLDrawables, here GLContext's survival of GLDrawable destruction and...
Test re-association of GLContext/GLDrawables, here GLContext's survival of GLDrawable destruction and...
final synchronized boolean start()
Starts this animator, if not running.
Definition: Animator.java:344
final synchronized boolean stop()
Stops this animator.
Definition: Animator.java:368