JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestGLContextDrawableSwitch12AWT.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
36import jogamp.nativewindow.jawt.JAWTUtil;
37
38import com.jogamp.opengl.GLEventListenerState;
39import com.jogamp.opengl.util.Animator;
40
41import com.jogamp.opengl.test.junit.util.GLEventListenerCounter;
42
43import org.junit.Test;
44import org.junit.FixMethodOrder;
45import org.junit.runners.MethodSorters;
46
47/**
48 * Test re-association of GLContext/GLDrawables,
49 * here GLContext's survival of GLDrawable destruction
50 * and reuse w/ new or recreated GLDrawable.
51 * <p>
52 * Test utilizes {@link GLEventListenerState} for preserving the
53 * GLAutoDrawable state, i.e. GLContext, all GLEventListener
54 * and the GLAnimatorControl association.
55 * </p>
56 * <p>
57 * This test is using JOGL's AWT GLCanvas
58 * </p>
59 * <p>
60 * See Bug 665 - https://jogamp.org/bugzilla/show_bug.cgi?id=665.
61 * </p>
62 */
63@FixMethodOrder(MethodSorters.NAME_ASCENDING)
65
66 @Test(timeout=30000)
67 public void test01GLCanvasOnscreenGL2ES2() throws InterruptedException {
68 final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2ES2);
69 if(null == reqGLCaps) return;
70 testGLCanvasImpl(reqGLCaps, false);
71 }
72
73 @Test(timeout=30000)
74 public void test02GLCanvasOnscreenGLES2() throws InterruptedException {
75 final GLCapabilities reqGLCaps = getCaps(GLProfile.GLES2);
76 if(null == reqGLCaps) return;
77 testGLCanvasImpl(reqGLCaps, false);
78 }
79
80 @Test(timeout=30000)
81 public void test11GLCanvasOffscreenGL2ES2() throws InterruptedException {
82 final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2ES2);
83 if(null == reqGLCaps) return;
84 testGLCanvasImpl(reqGLCaps, true);
85 }
86
87 @Test(timeout=30000)
88 public void test12GLCanvasOffscreenGLES2() throws InterruptedException {
89 final GLCapabilities reqGLCaps = getCaps(GLProfile.GLES2);
90 if(null == reqGLCaps) return;
91 testGLCanvasImpl(reqGLCaps, true);
92 }
93
94 private void testGLCanvasImpl(final GLCapabilities caps, final boolean offscreenLayer) throws InterruptedException {
95 if( offscreenLayer ) {
96 if( !JAWTUtil.isOffscreenLayerSupported() ) {
97 System.err.println("Platform doesn't support offscreen rendering.");
98 return;
99 }
100 } else {
101 if( JAWTUtil.isOffscreenLayerRequired() ) {
102 System.err.println("Platform requires offscreen rendering.");
103 return;
104 }
105 }
106 final SnapshotGLEventListener snapshotGLEventListener = new SnapshotGLEventListener();
107 final GLEventListenerCounter glelTracker = new GLEventListenerCounter();
108 final Animator animator = new Animator();
109 animator.start();
110
111 final GLEventListenerState glels[] = new GLEventListenerState[1];
112
113 // - create glad1 w/o context
114 // - create context using glad1 and assign it to glad1
115 {
116 testGLADOneLifecycle(null, caps, offscreenLayer ? GLADType.GLCanvasOffscreen : GLADType.GLCanvasOnscreen, width,
117 height, glelTracker,
118 snapshotGLEventListener,
119 null, glels, animator);
120 }
121
122 // - create glad2 w/ survived context
123 {
124 testGLADOneLifecycle(null, caps, offscreenLayer ? GLADType.GLCanvasOffscreen : GLADType.GLCanvasOnscreen, width+100,
125 height+100, glelTracker,
126 snapshotGLEventListener,
127 glels[0], null, null);
128 }
129 animator.stop();
130 }
131
132 public static void main(final String args[]) throws IOException {
133 for(int i=0; i<args.length; i++) {
134 if(args[i].equals("-time")) {
135 i++;
136 try {
137 duration = Integer.parseInt(args[i]);
138 } catch (final Exception ex) { ex.printStackTrace(); }
139 }
140 }
141 /**
142 BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
143 System.err.println("Press enter to continue");
144 System.err.println(stdin.readLine()); */
145 org.junit.runner.JUnitCore.main(TestGLContextDrawableSwitch12AWT.class.getName());
146 }
147}
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...