JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestGLReadBuffer01GLJPanelAWT.java
Go to the documentation of this file.
1/**
2 * Copyright 2014 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 java.awt.BorderLayout;
31import java.awt.Dimension;
32
33import com.jogamp.opengl.GL;
34import com.jogamp.opengl.GLAutoDrawable;
35import com.jogamp.opengl.GLCapabilitiesImmutable;
36import com.jogamp.opengl.GLEventListener;
37import com.jogamp.opengl.GLProfile;
38import com.jogamp.opengl.awt.GLJPanel;
39import javax.swing.JFrame;
40import javax.swing.JPanel;
41import javax.swing.SwingUtilities;
42
43import org.junit.Assume;
44import org.junit.BeforeClass;
45import org.junit.FixMethodOrder;
46import org.junit.runners.MethodSorters;
47
48import com.jogamp.common.GlueGenVersion;
49import com.jogamp.common.util.VersionUtil;
50import com.jogamp.opengl.JoglVersion;
51import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
52import com.jogamp.opengl.test.junit.jogl.demos.es2.MultisampleDemoES2;
53import com.jogamp.opengl.test.junit.util.MiscUtils;
54import com.jogamp.opengl.util.Animator;
55import com.jogamp.opengl.util.awt.AWTGLReadBufferUtil;
56
57/**
58 * Test synchronous GLAutoDrawable display, swap-buffer and read-pixels with AWT GLJPanel
59 * including non-MSAA and MSAA framebuffer.
60 * <p>
61 * See {@link GLReadBuffer00Base} for related bugs and further details.
62 * </p>
63 */
64@FixMethodOrder(MethodSorters.NAME_ASCENDING)
66
67 @BeforeClass
68 public static void initClass() {
70 }
71
72 @Override
73 public void test(final GLCapabilitiesImmutable caps, final boolean useSwingDoubleBuffer, final boolean skipGLOrientationVerticalFlip) {
74 final AWTGLReadBufferUtil awtGLReadBufferUtil = new AWTGLReadBufferUtil(caps.getGLProfile(), false);
75 final JFrame frame = new JFrame();
76 final Dimension d = new Dimension(320, 240);
77 final GLJPanel glad = createGLJPanel(skipGLOrientationVerticalFlip, useSwingDoubleBuffer, caps, d);
78 final TextRendererGLEL textRendererGLEL = new TextRendererGLEL(caps.getGLProfile());
79 final SnapshotGLELAWT snapshotGLEL = doSnapshot ? new SnapshotGLELAWT(textRendererGLEL, awtGLReadBufferUtil, skipGLOrientationVerticalFlip) : null;
80 try {
81 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
82 @Override
83 public void run() {
84 frame.setLocation(64, 64);
85 final JPanel panel = new JPanel();
86 panel.setLayout(new BorderLayout());
87 panel.setDoubleBuffered(useSwingDoubleBuffer);
88 frame.getContentPane().add(panel);
89
91 @Override
92 public void init(final GLAutoDrawable drawable) {
93 final GL gl = drawable.getGL();
94 System.err.println(VersionUtil.getPlatformInfo());
95 System.err.println("GLEventListener init on "+Thread.currentThread());
96 System.err.println("Chosen GLCapabilities: " + drawable.getChosenGLCapabilities());
97 System.err.println("INIT GL IS: " + gl.getClass().getName());
98 System.err.println(JoglVersion.getGLStrings(gl, null, false).toString());
99 }
100 @Override
101 public void dispose(final GLAutoDrawable drawable) {}
102 @Override
103 public void display(final GLAutoDrawable drawable) {}
104 @Override
105 public void reshape(final GLAutoDrawable drawable, final int x,final int y, final int width, final int height) {}
106 });
107 {
108 final GearsES2 gears = new GearsES2(1);
109 gears.setFlipVerticalInGLOrientation(skipGLOrientationVerticalFlip);
110 gears.setVerbose(false);
111 glad.addGLEventListener(gears);
112 }
113 {
115 demo.setClearBuffers(false);;
116 glad.addGLEventListener(demo);
117 }
118 textRendererGLEL.setFlipVerticalInGLOrientation(skipGLOrientationVerticalFlip);
119 glad.addGLEventListener(textRendererGLEL);
120 if( doSnapshot ) {
121 glad.addGLEventListener(snapshotGLEL);
122 }
123 panel.add(glad);
124 frame.pack();
125 frame.setVisible(true);
126 } } );
127 } catch( final Throwable throwable ) {
128 throwable.printStackTrace();
129 Assume.assumeNoException( throwable );
130 }
131 if( keyFrame ) {
132 waitForKey("Post init: Frame# "+textRendererGLEL.frameNo);
133 }
134 glad.display(); // trigger initialization to get chosen-caps!
135 final Dimension size0 = frame.getSize();
136 final Dimension size1 = new Dimension(size0.width+100, size0.height+100);
137 final Dimension size2 = new Dimension(size0.width-100, size0.height-100);
138 try {
139 for(int i=0; i<3; i++) {
140 final String str = "Frame# "+textRendererGLEL.frameNo+", user #"+(i+1);
141 System.err.println(str);
142 if( keyFrame ) {
143 waitForKey(str);
144 }
145 textRendererGLEL.userCounter = i + 1;
146 glad.display();
147 }
148 try { Thread.sleep(duration); } catch (final InterruptedException e) { }
149 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
150 @Override
151 public void run() {
152 frame.setSize(size1);
153 frame.validate();
154 } } );
155 try { Thread.sleep(duration); } catch (final InterruptedException e) { }
156 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
157 @Override
158 public void run() {
159 frame.setSize(size2);
160 frame.validate();
161 } } );
162 try { Thread.sleep(duration); } catch (final InterruptedException e) { }
163 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
164 @Override
165 public void run() {
166 frame.setSize(size0);
167 frame.validate();
168 } } );
169 try { Thread.sleep(duration); } catch (final InterruptedException e) { }
170
171 if( doSnapshot ) {
172 glad.disposeGLEventListener(snapshotGLEL, true /* remove */);
173 }
174 final Animator anim = new Animator(glad);
175 anim.start();
176 try { Thread.sleep(2*duration); } catch (final InterruptedException e) { }
177 anim.stop();
178 } catch (final Exception e1) {
179 e1.printStackTrace();
180 }
181 try {
182 SwingUtilities.invokeAndWait(new Runnable() {
183 @Override
184 public void run() {
185 frame.dispose();
186 } } );
187 } catch (final Exception e1) {
188 e1.printStackTrace();
189 }
190 }
191
192 private GLJPanel createGLJPanel(final boolean skipGLOrientationVerticalFlip, final boolean useSwingDoubleBuffer, final GLCapabilitiesImmutable caps, final Dimension size) {
193 final GLJPanel canvas = new GLJPanel(caps);
194 canvas.setSize(size);
195 canvas.setPreferredSize(size);
196 canvas.setMinimumSize(size);
197 canvas.setDoubleBuffered(useSwingDoubleBuffer);
198 canvas.setSkipGLOrientationVerticalFlip(skipGLOrientationVerticalFlip);
199 return canvas;
200 }
201
202 static GLCapabilitiesImmutable caps = null;
203 static boolean doSnapshot = true;
204 static boolean keyFrame = false;
205
206 public static void main(final String[] args) {
207 for(int i=0; i<args.length; i++) {
208 if(args[i].equals("-time")) {
209 i++;
210 duration = MiscUtils.atol(args[i], duration);
211 } else if(args[i].equals("-keyFrame")) {
212 keyFrame = true;
213 } else if(args[i].equals("-noSnapshot")) {
214 doSnapshot = false;
215 }
216 }
217 org.junit.runner.JUnitCore.main(TestGLReadBuffer01GLJPanelAWT.class.getName());
218 }
219
220}
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static void initSingleton()
Static initialization of JOGL.
Definition: GLProfile.java:204
static StringBuilder getGLStrings(final GL gl, final StringBuilder sb)
A lightweight Swing component which provides OpenGL rendering support.
Definition: GLJPanel.java:189
final void setSkipGLOrientationVerticalFlip(final boolean v)
Skip isGLOriented() based vertical flip, which usually is required by the offscreen backend,...
Definition: GLJPanel.java:1255
GLEventListener disposeGLEventListener(final GLEventListener listener, final boolean remove)
Disposes the given listener via dispose(..) if it has been initialized and added to this queue.
Definition: GLJPanel.java:1024
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Definition: GLJPanel.java:989
Test synchronous GLAutoDrawable display, swap-buffer and read-pixels including non-MSAA and MSAA fram...
Test synchronous GLAutoDrawable display, swap-buffer and read-pixels with AWT GLJPanel including non-...
void test(final GLCapabilitiesImmutable caps, final boolean useSwingDoubleBuffer, final boolean skipGLOrientationVerticalFlip)
static long atol(final String str, final long def)
Definition: MiscUtils.java:66
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
GLReadBufferUtil specialization allowing to read out a frambuffer to an AWT BufferedImage utilizing A...
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
Specifies an immutable set of OpenGL capabilities.
boolean getSampleBuffers()
Returns whether sample buffers for full-scene antialiasing (FSAA) should be allocated for this drawab...
GLProfile getGLProfile()
Returns the GL profile you desire or used by the drawable.
GLCapabilitiesImmutable getChosenGLCapabilities()
Fetches the GLCapabilitiesImmutable corresponding to the chosen OpenGL capabilities (pixel format / v...
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.
void setSize(int width, int height)
Requests a new width and height for this AWTGLAutoDrawable.