JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestNVSwapGroupNEWT.java
Go to the documentation of this file.
1/**
2 * Copyright 2011 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 com.jogamp.newt.opengl.GLWindow;
32
33import com.jogamp.nativewindow.util.InsetsImmutable;
34import com.jogamp.opengl.GLAutoDrawable;
35import com.jogamp.opengl.GLCapabilities;
36import com.jogamp.opengl.GLContext;
37import com.jogamp.opengl.GLEventListener;
38import com.jogamp.opengl.GLProfile;
39import com.jogamp.opengl.util.Animator;
40
41import com.jogamp.opengl.test.junit.util.UITestCase;
42import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
43
44import org.junit.Assert;
45import org.junit.BeforeClass;
46import org.junit.Test;
47import org.junit.FixMethodOrder;
48import org.junit.runners.MethodSorters;
49
50@FixMethodOrder(MethodSorters.NAME_ASCENDING)
51public class TestNVSwapGroupNEWT extends UITestCase {
52 static GLProfile glp;
53 static GLCapabilities caps;
54 static int width, height;
55
56 @BeforeClass
57 public static void initClass() {
58 glp = GLProfile.getGL2ES2();
59 Assert.assertNotNull(glp);
60 caps = new GLCapabilities(glp);
61 Assert.assertNotNull(caps);
62 width = 256;
63 height = 256;
64 }
65
66 protected GLWindow runTestGL(final Animator animator, final int x, final int y, final int group, final int barrier) {
67 final GLWindow glWindow = GLWindow.create(caps);
68 Assert.assertNotNull(glWindow);
69 glWindow.setTitle("Shared Gears NEWT Test: "+x+"/"+y);
70
71 glWindow.setSize(width, height);
72
73 final GearsES2 gears = new GearsES2(1);
74 glWindow.addGLEventListener(new GLEventListener() {
75 @Override
76 public void init(final GLAutoDrawable drawable) {
77 final int[] maxVals = new int[] { -1, -1 } ;
78 final GLContext glc = drawable.getContext();
79 final boolean r = glc.queryMaxSwapGroups(maxVals, 0, maxVals, 1);
80 System.err.println("swap group max groups "+maxVals[0]+", barriers "+maxVals[0]+", "+r);
81 if(maxVals[0]>=group) {
82 System.err.println("swap group joing 1: "+glc.joinSwapGroup(group));
83 if(maxVals[1]>=barrier) {
84 System.err.println("swap group bind 1-1: "+glc.bindSwapBarrier(group, barrier));
85 }
86 }
87 }
88 @Override
89 public void dispose(final GLAutoDrawable drawable) {}
90 @Override
91 public void display(final GLAutoDrawable drawable) {}
92 @Override
93 public void reshape(final GLAutoDrawable drawable, final int x, final int y,
94 final int width, final int height) {}
95 });
96 glWindow.addGLEventListener(gears);
97
98 animator.add(glWindow);
99
100 glWindow.setVisible(true);
101
102 /** insets (if supported) are available only if window is set visible and hence is created */
103 glWindow.setTopLevelPosition(x, y);
104
105 return glWindow;
106 }
107
108 /** NV swap group is currently disabled .. needs more testing */
109 @Test
110 public void test01() throws InterruptedException {
111 // make sure it won't be active for now !
112 final int swap_group = 9999;
113 final int swap_barrier = 9999;
114
115 final Animator animator = new Animator(0 /* w/o AWT */);
116 final GLWindow f1 = runTestGL(animator, 0, 0, swap_group, swap_barrier);
117 final InsetsImmutable insets = f1.getInsets();
118 final GLWindow f2 = runTestGL(animator, width+insets.getTotalWidth(), 0, swap_group, swap_barrier);
119 animator.setUpdateFPSFrames(1, null);
120 animator.start();
121 while(animator.isAnimating() && animator.getTotalFPSDuration()<duration) {
122 Thread.sleep(100);
123 }
124 animator.stop();
125
126 f1.destroy();
127 f2.destroy();
128
129 // see above ..
130 // releaseShared();
131 }
132
133 static long duration = 500; // ms
134
135 public static void main(final String args[]) {
136 for(int i=0; i<args.length; i++) {
137 if(args[i].equals("-time")) {
138 i++;
139 try {
140 duration = Integer.parseInt(args[i]);
141 } catch (final Exception ex) { ex.printStackTrace(); }
142 }
143 }
144 org.junit.runner.JUnitCore.main(TestNVSwapGroupNEWT.class.getName());
145 }
146}
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
final void setTitle(final String title)
Definition: GLWindow.java:297
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
void setTopLevelPosition(final int x, final int y)
Sets the location of the top-level window inclusive insets (window decorations) in window units.
Definition: GLWindow.java:529
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.
Abstraction for an OpenGL rendering context.
Definition: GLContext.java:74
final boolean joinSwapGroup(final int group)
final boolean bindSwapBarrier(final int group, final int barrier)
final boolean queryMaxSwapGroups(final int[] maxGroups, final int maxGroups_offset, final int[] maxBarriers, final int maxBarriers_offset)
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
Definition: GLProfile.java:913
GLWindow runTestGL(final Animator animator, final int x, final int y, final int group, final int barrier)
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
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.
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.
GLContext getContext()
Returns the context associated with this drawable.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.