JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestBug669RecursiveGLContext02NEWT.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 */
28package com.jogamp.opengl.test.junit.jogl.acore;
29
30import com.jogamp.opengl.GLAutoDrawable;
31import com.jogamp.opengl.GLCapabilities;
32import com.jogamp.opengl.GLEventListener;
33import com.jogamp.opengl.GLProfile;
34
35import org.junit.Assert;
36import org.junit.Test;
37import org.junit.FixMethodOrder;
38import org.junit.runners.MethodSorters;
39
40import com.jogamp.newt.opengl.GLWindow;
41import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
42import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2;
43import com.jogamp.opengl.test.junit.util.UITestCase;
44import com.jogamp.opengl.util.Animator;
45
46/**
47 * Tests recursive GLContext behavior.
48 *
49 * <p>
50 * Issues {@link GLAutoDrawable#display()} of another {@link GLAutoDrawable}
51 * from within {@link GLEventListener#display(GLAutoDrawable)}.
52 * </p>
53 *
54 * <https://jogamp.org/bugzilla/show_bug.cgi?id=669>
55 */
56@FixMethodOrder(MethodSorters.NAME_ASCENDING)
58
59 @Test(timeout=10000)
60 public void test01_Plain() {
61 test01Impl(false);
62 }
63
64 @Test(timeout=10000)
65 public void test01_Anim() {
66 test01Impl(true);
67 }
68
69 private void test01Impl(final boolean anim) {
70 final String profile = GLProfile.GL2ES2;
71 if(!GLProfile.isAvailable(profile)) { System.err.println(profile+" n/a"); return; }
72
73 final GLProfile pro = GLProfile.get(profile);
74 final GLCapabilities caps = new GLCapabilities(pro);
75
76 final GLWindow window2 = GLWindow.create(caps); // display() triggered by window's GLEventListener!
77 window2.setPosition(0, 0);
78 window2.setSize(200, 200);
79 window2.addGLEventListener(new RedSquareES2());
80
81 final GLWindow window1 = GLWindow.create(caps);
82
83 final Animator animator1 = new Animator(0 /* w/o AWT */);
84 final Animator animator2 = new Animator(0 /* w/o AWT */);
85 if(anim) {
86 animator1.add(window1);
87 animator2.add(window2);
88 }
89 animator1.start();
90 animator2.start();
91
92 window1.setPosition(250, 0);
93 window1.setSize(200, 200);
94 window1.addGLEventListener(new GLEventListener() {
95 @Override
96 public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { }
97
98 @Override
99 public void init(final GLAutoDrawable drawable) { }
100
101 @Override
102 public void dispose(final GLAutoDrawable drawable) { }
103
104 @Override
105 public void display(final GLAutoDrawable drawable) {
106 window2.display();
107 }
108 });
109 window1.addGLEventListener(new GearsES2());
110
111 try {
112 window2.setVisible(true);
113 window1.setVisible(true);
114 window1.display();
115 window2.display();
116 if(anim) {
117 try {
118 Thread.sleep(500);
119 } catch(final InterruptedException ie) {}
120 }
121 } finally {
122 animator1.stop();
123
124 final int win1Frames = window1.getTotalFPSFrames();
125 final int win2Frames = window2.getTotalFPSFrames();
126 System.err.println("Window1: frames "+win1Frames);
127 System.err.println("Window2: frames "+win2Frames);
128 Assert.assertTrue("Win2 frames not double the amount of Win1 frames", 2*win2Frames >= win1Frames);
129 window1.destroy();
130 window2.destroy();
131 }
132 }
133
134 public static void main(final String args[]) {
135 org.junit.runner.JUnitCore.main(TestBug669RecursiveGLContext02NEWT.class.getName());
136 }
137
138}
139
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static boolean isAvailable(final AbstractGraphicsDevice device, final String profile)
Returns the availability of a profile on a device.
Definition: GLProfile.java:305
static final String GL2ES2
The intersection of the desktop GL3, GL2 and embedded ES2 profile.
Definition: GLProfile.java:594
static GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.
void display(GLAutoDrawable drawable)
Called by the drawable to initiate OpenGL rendering by the client.