JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestGearsAWTAnalyzeBug455.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.demos.gl2.awt;
30
31import com.jogamp.opengl.*;
32
33import com.jogamp.opengl.util.Animator;
34
35import com.jogamp.opengl.awt.GLCanvas;
36
37import com.jogamp.newt.event.awt.AWTKeyAdapter;
38import com.jogamp.newt.event.awt.AWTWindowAdapter;
39import com.jogamp.newt.event.TraceKeyAdapter;
40import com.jogamp.newt.event.TraceWindowAdapter;
41import com.jogamp.opengl.test.junit.jogl.demos.gl2.Gears;
42import com.jogamp.opengl.test.junit.util.UITestCase;
43import com.jogamp.opengl.test.junit.util.QuitAdapter;
44
45import java.awt.Frame;
46import java.io.BufferedReader;
47import java.io.IOException;
48import java.io.InputStreamReader;
49import java.lang.reflect.InvocationTargetException;
50
51import org.junit.Assert;
52import org.junit.BeforeClass;
53import org.junit.AfterClass;
54import org.junit.Test;
55import org.junit.FixMethodOrder;
56import org.junit.runners.MethodSorters;
57
58@FixMethodOrder(MethodSorters.NAME_ASCENDING)
60 static long duration = 500; // ms
61 static boolean waitForKey = false; // for manual profiling
62 static boolean altSwap = true; // using alternate GL swap method (copy pixel) no [auto-]swap
63
64 static GLProfile glp;
65 static int width, height;
66
67 @BeforeClass
68 public static void initClass() {
71 Assert.assertNotNull(glp);
72 width = 512;
73 height = 512;
74 } else {
75 setTestSupported(false);
76 }
77 }
78
79 @AfterClass
80 public static void releaseClass() {
81 }
82
83 static class Swapper implements GLEventListener {
84 public void init(final GLAutoDrawable drawable) {
85 System.err.println("auto-swap: "+drawable.getAutoSwapBufferMode());
86 }
87 public void dispose(final GLAutoDrawable drawable) {
88 }
89 public void display(final GLAutoDrawable drawable) {
90 if(!drawable.getAutoSwapBufferMode()) {
91 final GL2 gl = drawable.getGL().getGL2();
92 // copy the colored content of the back buffer into the front buffer
93 // gl.glPushAttrib(GL.GL_COLOR_BUFFER_BIT);
94 gl.glReadBuffer(GL.GL_BACK); // def. in dbl buff mode: GL_BACK
95 gl.glDrawBuffer(GL.GL_FRONT); // def. in dbl buff mode: GL_BACK
96 gl.glCopyPixels(0, 0, drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), GL2ES3.GL_COLOR);
97 // gl.glPopAttrib();
98 gl.glDrawBuffer(GL.GL_BACK); // def. in dbl buff mode: GL_BACK
99 }
100 }
101 public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width,
102 final int height) {
103 }
104 }
105 protected void runTestGL(final GLCapabilities caps) throws InterruptedException, InvocationTargetException {
106 final Frame frame = new Frame("Gears AWT Test");
107 Assert.assertNotNull(frame);
108
109 final GLCanvas glCanvas = new GLCanvas(caps);
110 Assert.assertNotNull(glCanvas);
111 glCanvas.setAutoSwapBufferMode(!altSwap);
112 frame.add(glCanvas);
113
114 glCanvas.addGLEventListener(new Gears(0));
115 glCanvas.addGLEventListener(new Swapper());
116
117 final QuitAdapter quitAdapter = new QuitAdapter();
118 new AWTKeyAdapter(new TraceKeyAdapter(quitAdapter), glCanvas).addTo(glCanvas);
119 new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter), glCanvas).addTo(frame);
120
121 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
122 public void run() {
123 frame.setSize(512, 512);
124 frame.setVisible(true);
125 }});
126
127 final Animator animator = new Animator(glCanvas);
128 animator.setUpdateFPSFrames(60, System.err);
129 animator.start();
130
131 while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration()<duration) {
132 Thread.sleep(100);
133 }
134
135 Assert.assertNotNull(frame);
136 Assert.assertNotNull(glCanvas);
137 Assert.assertNotNull(animator);
138
139 animator.stop();
140 Assert.assertEquals(false, animator.isAnimating());
141 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
142 public void run() {
143 frame.setVisible(false);
144 }});
145 Assert.assertEquals(false, frame.isVisible());
146 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
147 public void run() {
148 frame.remove(glCanvas);
149 frame.dispose();
150 }});
151 }
152
153 @Test
154 public void test01() throws InterruptedException, InvocationTargetException {
155 final GLCapabilities caps = new GLCapabilities(glp);
156 caps.setDoubleBuffered(true); // code assumes dbl buffer setup
157 runTestGL(caps);
158 }
159
160 public static void main(final String args[]) {
161 for(int i=0; i<args.length; i++) {
162 if(args[i].equals("-time")) {
163 i++;
164 try {
165 duration = Integer.parseInt(args[i]);
166 } catch (final Exception ex) { ex.printStackTrace(); }
167 } else if(args[i].equals("-wait")) {
168 waitForKey = true;
169 } else if(args[i].equals("-autoswap")) {
170 altSwap = false;
171 }
172 }
173 System.err.println("altSwap "+altSwap);
174 if(waitForKey) {
175 final BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
176 System.err.println("Press enter to continue");
177 try {
178 System.err.println(stdin.readLine());
179 } catch (final IOException e) { }
180 }
181 org.junit.runner.JUnitCore.main(TestGearsAWTAnalyzeBug455.class.getName());
182 }
183}
AWT: printable: PRESSED (t0), TYPED (t0), RELEASED (t1) non-printable: PRESSED (t0),...
synchronized AWTAdapter addTo(final java.awt.Component awtComponent)
Due to the fact that some NEWT com.jogamp.newt.event.NEWTEventListener are mapped to more than one ja...
synchronized AWTAdapter addTo(final java.awt.Component awtComponent)
Due to the fact that some NEWT com.jogamp.newt.event.NEWTEventListener are mapped to more than one ja...
Specifies a set of OpenGL capabilities.
void setDoubleBuffered(final boolean enable)
Enables or disables double buffering.
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
A heavyweight AWT component which provides OpenGL rendering support.
Definition: GLCanvas.java:170
void setAutoSwapBufferMode(final boolean onOrOff)
Enables or disables automatic buffer swapping for this drawable.
Definition: GLCanvas.java:1191
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Definition: GLCanvas.java:1065
Gears.java author: Brian Paul (converted to Java by Ron Cemer and Sven Gothel)
Definition: Gears.java:34
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
void glReadBuffer(int mode)
Entry point to C language function: void {@native glReadBuffer}(GLenum mode) Part of GL_ES_VERSION...
static final int GL_COLOR
GL_ES_VERSION_3_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_EXT_discard_framebuffer Alias for: GL_COLOR_EXT...
Definition: GL2ES3.java:426
void glDrawBuffer(int mode)
Entry point to C language function: void {@native glDrawBuffer}(GLenum mode) Part of GL_VERSION_1_...
void glCopyPixels(int x, int y, int width, int height, int type)
Entry point to C language function: void {@native glCopyPixels}(GLint x, GLint y,...
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
boolean getAutoSwapBufferMode()
Indicates whether automatic buffer swapping is enabled for this drawable.
GL2 getGL2()
Casts this object to the GL2 interface.
int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.
static final int GL_BACK
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_BACK" with expression...
Definition: GL.java:330
static final int GL_FRONT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_FRONT" with expressio...
Definition: GL.java:597