JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestGLReadBuffer01GLCanvasAWT.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;
32import java.awt.Frame;
33
34import com.jogamp.opengl.GL;
35import com.jogamp.opengl.GLAutoDrawable;
36import com.jogamp.opengl.GLCapabilitiesImmutable;
37import com.jogamp.opengl.GLEventListener;
38import com.jogamp.opengl.GLProfile;
39import com.jogamp.opengl.awt.GLCanvas;
40import javax.swing.SwingUtilities;
41
42import org.junit.Assume;
43import org.junit.BeforeClass;
44import org.junit.FixMethodOrder;
45import org.junit.runners.MethodSorters;
46
47import com.jogamp.common.util.VersionUtil;
48import com.jogamp.opengl.JoglVersion;
49import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
50import com.jogamp.opengl.test.junit.jogl.demos.es2.MultisampleDemoES2;
51import com.jogamp.opengl.test.junit.util.MiscUtils;
52import com.jogamp.opengl.util.Animator;
53import com.jogamp.opengl.util.awt.AWTGLReadBufferUtil;
54
55/**
56 * Test synchronous GLAutoDrawable display, swap-buffer and read-pixels with AWT GLCanvas
57 * including non-MSAA and MSAA framebuffer.
58 * <p>
59 * See {@link GLReadBuffer00Base} for related bugs and further details.
60 * </p>
61 */
62@FixMethodOrder(MethodSorters.NAME_ASCENDING)
64
65 @BeforeClass
66 public static void initClass() {
68 }
69
70 @Override
71 public void test(final GLCapabilitiesImmutable caps, final boolean useSwingDoubleBuffer, final boolean skipGLOrientationVerticalFlip) {
72 if( skipGLOrientationVerticalFlip || useSwingDoubleBuffer ) {
73 return; // NOP
74 }
75 final AWTGLReadBufferUtil awtGLReadBufferUtil = new AWTGLReadBufferUtil(caps.getGLProfile(), false);
76 final Frame frame = new Frame();
77 final Dimension d = new Dimension(320, 240);
78 final GLCanvas glad = createGLCanvas(caps, d);
79 final TextRendererGLEL textRendererGLEL = new TextRendererGLEL(caps.getGLProfile());
80 final SnapshotGLELAWT snapshotGLEL = doSnapshot ? new SnapshotGLELAWT(textRendererGLEL, awtGLReadBufferUtil, false) : null;
81 try {
82 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
83 @Override
84 public void run() {
85 frame.setLocation(64, 64);
86 frame.setLayout(new BorderLayout());
87 // final JPanel panel = new JPanel();
88 // panel.setLayout(new BorderLayout());
89 // panel.setDoubleBuffered(useSwingDoubleBuffer);
90 // frame.getContentPane().add(panel);
91
93 @Override
94 public void init(final GLAutoDrawable drawable) {
95 final GL gl = drawable.getGL();
96 System.err.println(VersionUtil.getPlatformInfo());
97 System.err.println("GLEventListener init on "+Thread.currentThread());
98 System.err.println("Chosen GLCapabilities: " + drawable.getChosenGLCapabilities());
99 System.err.println("INIT GL IS: " + gl.getClass().getName());
100 System.err.println(JoglVersion.getGLStrings(gl, null, false).toString());
101 }
102 @Override
103 public void dispose(final GLAutoDrawable drawable) {}
104 @Override
105 public void display(final GLAutoDrawable drawable) {}
106 @Override
107 public void reshape(final GLAutoDrawable drawable, final int x,final int y, final int width, final int height) {}
108 });
109 {
110 final GearsES2 gears = new GearsES2(1);
111 gears.setVerbose(false);
112 glad.addGLEventListener(gears);
113 }
114 {
116 demo.setClearBuffers(false);;
117 glad.addGLEventListener(demo);
118 }
119
120 glad.addGLEventListener(textRendererGLEL);
121 if( doSnapshot ) {
122 glad.addGLEventListener(snapshotGLEL);
123 }
124 // panel.add(glad);
125 frame.add(glad, BorderLayout.CENTER);
126 frame.pack();
127 frame.setVisible(true);
128 } } );
129 } catch( final Throwable throwable ) {
130 throwable.printStackTrace();
131 Assume.assumeNoException( throwable );
132 }
133 glad.display(); // trigger initialization to get chosen-caps!
134 final Dimension size0 = frame.getSize();
135 final Dimension size1 = new Dimension(size0.width+100, size0.height+100);
136 final Dimension size2 = new Dimension(size0.width-100, size0.height-100);
137 try {
138 for(int i=0; i<3; i++) {
139 final String str = "Frame# "+textRendererGLEL.frameNo+", user #"+(i+1);
140 System.err.println(str);
141 if( keyFrame ) {
142 waitForKey(str);
143 }
144 textRendererGLEL.userCounter = i + 1;
145 glad.display();
146 }
147 try { Thread.sleep(duration); } catch (final InterruptedException e) { }
148 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
149 @Override
150 public void run() {
151 frame.setSize(size1);
152 frame.validate();
153 } } );
154 try { Thread.sleep(duration); } catch (final InterruptedException e) { }
155 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
156 @Override
157 public void run() {
158 frame.setSize(size2);
159 frame.validate();
160 } } );
161 try { Thread.sleep(duration); } catch (final InterruptedException e) { }
162 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
163 @Override
164 public void run() {
165 frame.setSize(size0);
166 frame.validate();
167 } } );
168 try { Thread.sleep(duration); } catch (final InterruptedException e) { }
169
170 if( doSnapshot ) {
171 glad.disposeGLEventListener(snapshotGLEL, true /* remove */);
172 }
173 final Animator anim = new Animator(glad);
174 anim.start();
175 try { Thread.sleep(2*duration); } catch (final InterruptedException e) { }
176 anim.stop();
177 } catch (final Exception e1) {
178 e1.printStackTrace();
179 }
180 try {
181 SwingUtilities.invokeAndWait(new Runnable() {
182 @Override
183 public void run() {
184 frame.dispose();
185 } } );
186 } catch (final Exception e1) {
187 e1.printStackTrace();
188 }
189 }
190
191 private GLCanvas createGLCanvas(final GLCapabilitiesImmutable caps, final Dimension size) {
192 final GLCanvas canvas = new GLCanvas(caps);
193 canvas.setSize(size);
194 canvas.setPreferredSize(size);
195 canvas.setMinimumSize(size);
196 return canvas;
197 }
198
199 static GLCapabilitiesImmutable caps = null;
200 static boolean doSnapshot = true;
201 static boolean keyFrame = false;
202
203 public static void main(final String[] args) {
204 for(int i=0; i<args.length; i++) {
205 if(args[i].equals("-time")) {
206 i++;
207 duration = MiscUtils.atol(args[i], duration);
208 } else if(args[i].equals("-keyFrame")) {
209 keyFrame = true;
210 } else if(args[i].equals("-noSnapshot")) {
211 doSnapshot = false;
212 }
213 }
214 org.junit.runner.JUnitCore.main(TestGLReadBuffer01GLCanvasAWT.class.getName());
215 }
216
217}
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 heavyweight AWT component which provides OpenGL rendering support.
Definition: GLCanvas.java:170
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: GLCanvas.java:1100
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Definition: GLCanvas.java:1065
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 GLCanvas 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.