JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestGLReadBufferUtilTextureIOWrite02NEWT.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.util.texture;
30
31import com.jogamp.common.util.InterruptSource;
32import com.jogamp.newt.opengl.GLWindow;
33
34import com.jogamp.opengl.GLAutoDrawable;
35import com.jogamp.opengl.GLCapabilities;
36import com.jogamp.opengl.GLEventListener;
37import com.jogamp.opengl.GLProfile;
38
39import com.jogamp.opengl.util.Animator;
40import com.jogamp.opengl.util.GLReadBufferUtil;
41import com.jogamp.opengl.util.texture.TextureIO;
42
43import com.jogamp.opengl.test.junit.util.UITestCase;
44import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
45import com.jogamp.opengl.test.junit.jogl.offscreen.WindowUtilNEWT;
46
47import org.junit.Assert;
48import org.junit.BeforeClass;
49import org.junit.Test;
50import org.junit.FixMethodOrder;
51import org.junit.runners.MethodSorters;
52
53@FixMethodOrder(MethodSorters.NAME_ASCENDING)
55 static GLProfile glp;
56 static GLCapabilities caps;
57 static int width, height;
58
59 @BeforeClass
60 public static void initClass() {
61 glp = GLProfile.getDefault();
62 Assert.assertNotNull(glp);
63 caps = new GLCapabilities(glp);
64 Assert.assertNotNull(caps);
65 caps.setAlphaBits(1); // req. alpha channel
66 width = 64;
67 height = 64;
68 }
69
70 private void testWritePNGWithResizeImpl(final boolean offscreen) throws InterruptedException {
71 final GLReadBufferUtil screenshot = new GLReadBufferUtil(true, false);
72 final GLCapabilities caps2 = offscreen ? WindowUtilNEWT.fixCaps(caps, false, true, false) : caps;
73 final GLWindow glWindow = GLWindow.create(caps2);
74 Assert.assertNotNull(glWindow);
75 glWindow.setTitle("Shared Gears NEWT Test");
76 glWindow.setSize(width, height);
77 glWindow.addGLEventListener(new GearsES2(1));
78 glWindow.addGLEventListener(new GLEventListener() {
79 int i=0, dw_old=0, c=0;
80 public void init(final GLAutoDrawable drawable) {
81 System.err.println("XXX: init");
82 }
83 public void dispose(final GLAutoDrawable drawable) {
84 System.err.println("XXX: dispose");
85 }
86 public void display(final GLAutoDrawable drawable) {
87 final int dw = drawable.getSurfaceWidth();
88 final int dh = drawable.getSurfaceHeight();
89 final boolean sz_changed = dw_old != dw && dw <= 512;
90 final boolean snap;
91 if(sz_changed) {
92 c++;
93 snap = c>1; // only snap the 3rd image ..
94 } else {
95 snap = false;
96 }
97
98 if(snap) {
99 System.err.println("XXX: ["+dw_old+"], "+dw+"x"+dh+", sz_changed "+sz_changed+", snap "+snap);
100 c=0;
101 snapshot(i++, null, drawable.getGL(), screenshot, TextureIO.PNG, null);
102 dw_old = dw;
103 new InterruptSource.Thread() {
104 @Override
105 public void run() {
106 glWindow.setSize(2*dw, 2*dh);
107 } }.start();
108 }
109 }
110 public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { }
111 });
112 final Animator animator = new Animator(glWindow);
113 animator.setUpdateFPSFrames(60, null);
114
115 glWindow.setVisible(true);
116 animator.start();
117
118 while(animator.getTotalFPSFrames() < 50) {
119 Thread.sleep(60);
120 }
121
122 animator.stop();
123 glWindow.destroy();
124 }
125
126 @Test
127 public void testOnscreenWritePNGWithResize() throws InterruptedException {
128 testWritePNGWithResizeImpl(false);
129 }
130
131 @Test
132 public void testOffscreenWritePNGWithResize() throws InterruptedException {
133 testWritePNGWithResizeImpl(true);
134 }
135
136 public static void main(final String args[]) {
137 org.junit.runner.JUnitCore.main(TestGLReadBufferUtilTextureIOWrite02NEWT.class.getName());
138 }
139}
void setAlphaBits(final int alphaBits)
Sets the number of bits requested for the color buffer's alpha component.
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
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.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static GLProfile getDefault(final AbstractGraphicsDevice device)
Returns a default GLProfile object, reflecting the best for the running platform.
Definition: GLProfile.java:739
static GLCapabilities fixCaps(final GLCapabilities caps, final boolean onscreen, final boolean pbuffer, final boolean undecorated)
Utility to read out the current FB to TextureData, optionally writing the data back to a texture obje...
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
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.