JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestSharedContextListNEWT.java
Go to the documentation of this file.
1/**
2 * Copyright 2010 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;
30
31import java.io.IOException;
32
33import com.jogamp.newt.opengl.GLWindow;
34
35import com.jogamp.nativewindow.util.InsetsImmutable;
36import com.jogamp.opengl.GLCapabilities;
37import com.jogamp.opengl.GLDrawableFactory;
38import com.jogamp.opengl.GLOffscreenAutoDrawable;
39import com.jogamp.opengl.GLProfile;
40import com.jogamp.opengl.util.Animator;
41
42import com.jogamp.opengl.test.junit.util.NewtTestUtil;
43import com.jogamp.opengl.test.junit.util.UITestCase;
44import com.jogamp.opengl.test.junit.jogl.demos.gl2.Gears;
45
46import org.junit.Assert;
47import org.junit.BeforeClass;
48import org.junit.Test;
49import org.junit.FixMethodOrder;
50import org.junit.runners.MethodSorters;
51
52@FixMethodOrder(MethodSorters.NAME_ASCENDING)
54 static GLProfile glp;
55 static GLCapabilities caps;
56 static int width, height;
57 GLOffscreenAutoDrawable sharedDrawable;
58 Gears sharedGears;
59
60 @BeforeClass
61 public static void initClass() {
64 Assert.assertNotNull(glp);
65 caps = new GLCapabilities(glp);
66 Assert.assertNotNull(caps);
67 width = 256;
68 height = 256;
69 } else {
70 setTestSupported(false);
71 }
72 }
73
74 private void initShared() {
75 sharedDrawable = GLDrawableFactory.getFactory(glp).createOffscreenAutoDrawable(null, caps, null, width, height);
76 Assert.assertNotNull(sharedDrawable);
77 sharedGears = new Gears();
78 Assert.assertNotNull(sharedGears);
79 sharedDrawable.addGLEventListener(sharedGears);
80 // init and render one frame, which will setup the Gears display lists
81 sharedDrawable.display();
82 }
83
84 private void releaseShared() {
85 Assert.assertNotNull(sharedDrawable);
86 sharedDrawable.destroy();
87 sharedDrawable = null;
88 }
89
90 protected GLWindow runTestGL(final Animator animator, final int x, final int y, final boolean useShared, final boolean vsync) throws InterruptedException {
91 final GLWindow glWindow = GLWindow.create(caps);
92 Assert.assertNotNull(glWindow);
93 glWindow.setTitle("Shared Gears NEWT Test: "+x+"/"+y+" shared "+useShared);
94 if(useShared) {
95 glWindow.setSharedAutoDrawable(sharedDrawable);
96 }
97
98 glWindow.setSize(width, height);
99
100 final Gears gears = new Gears(vsync ? 1 : 0);
101 if(useShared) {
102 gears.setSharedGears(sharedGears);
103 }
104 glWindow.addGLEventListener(gears);
105
106 animator.add(glWindow);
107
108 glWindow.setVisible(true);
109 Assert.assertTrue(NewtTestUtil.waitForRealized(glWindow, true, null));
110 Assert.assertTrue(NewtTestUtil.waitForVisible(glWindow, true, null));
111 glWindow.setPosition(x, y);
112
113 return glWindow;
114 }
115
116 @Test
117 public void test01() throws InterruptedException {
118 initShared();
119 final Animator animator = new Animator(0 /* w/o AWT */);
120 final GLWindow f1 = runTestGL(animator, 0, 0, true, false);
121 final InsetsImmutable insets = f1.getInsets();
122 final GLWindow f2 = runTestGL(animator, f1.getX()+width+insets.getTotalWidth(),
123 f1.getY()+0, true, false);
124 final GLWindow f3 = runTestGL(animator, f1.getX()+0,
125 f1.getY()+height+insets.getTotalHeight(), false, true);
126 animator.setUpdateFPSFrames(1, null);
127 animator.start();
128 while(animator.isAnimating() && animator.getTotalFPSDuration()<duration) {
129 Thread.sleep(100);
130 }
131 animator.stop();
132
133 f1.destroy();
134 f2.destroy();
135 f3.destroy();
136
137 releaseShared();
138 }
139
140 static long duration = 500; // ms
141
142 public static void main(final String args[]) throws IOException {
143 for(int i=0; i<args.length; i++) {
144 if(args[i].equals("-time")) {
145 i++;
146 try {
147 duration = Integer.parseInt(args[i]);
148 } catch (final Exception ex) { ex.printStackTrace(); }
149 }
150 }
151 /**
152 BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
153 System.err.println("Press enter to continue");
154 System.err.println(stdin.readLine()); */
155 org.junit.runner.JUnitCore.main(TestSharedContextListNEWT.class.getName());
156 }
157}
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
final void setPosition(final int x, final int y)
Sets the location of the window's client area excluding insets (window decorations) in window units.
Definition: GLWindow.java:525
final void setTitle(final String title)
Definition: GLWindow.java:297
final int getX()
Returns the current x position of this window, relative to it's parent.
Definition: GLWindow.java:436
final int getY()
Returns the current y position of the top-left corner of the client area relative to it's parent in w...
Definition: GLWindow.java:441
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
Definition: GLWindow.java:625
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
Definition: GLWindow.java:615
final InsetsImmutable getInsets()
Returns the insets defined as the width and height of the window decoration on the left,...
Definition: GLWindow.java:431
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
Definition: GLWindow.java:605
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Definition: GLWindow.java:169
Specifies a set of OpenGL capabilities.
abstract GLOffscreenAutoDrawable createOffscreenAutoDrawable(AbstractGraphicsDevice device, GLCapabilitiesImmutable caps, GLCapabilitiesChooser chooser, int width, int height)
Creates a realized GLOffscreenAutoDrawable incl it's offscreen NativeSurface with the given capabilit...
static GLDrawableFactory getFactory(final GLProfile glProfile)
Returns the sole GLDrawableFactory instance.
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 GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
static final String GL2
The desktop OpenGL profile 1.x up to 3.0.
Definition: GLProfile.java:579
GLWindow runTestGL(final Animator animator, final int x, final int y, final boolean useShared, final boolean vsync)
Gears.java author: Brian Paul (converted to Java by Ron Cemer and Sven Gothel)
Definition: Gears.java:34
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 void setUpdateFPSFrames(final int frames, final PrintStream out)
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
Immutable insets representing rectangular window decoration insets on all four edges in window units.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
Platform-independent GLAutoDrawable specialization, exposing offscreen functionality.