JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestTextureIONEWT.java
Go to the documentation of this file.
1/**
2 * Copyright 2015 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.newt.opengl.GLWindow;
32import com.jogamp.opengl.GLAutoDrawable;
33import com.jogamp.opengl.GLCapabilities;
34import com.jogamp.opengl.GLEventListener;
35import com.jogamp.opengl.GLProfile;
36import com.jogamp.opengl.test.junit.jogl.demos.TextureDraw01Accessor;
37import com.jogamp.opengl.test.junit.jogl.demos.es2.TextureDraw01ES2Listener;
38import com.jogamp.opengl.test.junit.jogl.demos.gl2.TextureDraw01GL2Listener;
39import com.jogamp.opengl.test.junit.util.MiscUtils;
40import com.jogamp.opengl.test.junit.util.QuitAdapter;
41import com.jogamp.opengl.test.junit.util.UITestCase;
42import com.jogamp.opengl.util.Animator;
43import com.jogamp.opengl.util.GLReadBufferUtil;
44import com.jogamp.opengl.util.texture.ImageType;
45import com.jogamp.opengl.util.texture.TextureData;
46import com.jogamp.opengl.util.texture.TextureIO;
47
48import org.junit.Assert;
49
50import java.io.IOException;
51import java.io.InputStream;
52import java.util.List;
53
54import org.junit.After;
55import org.junit.Before;
56import org.junit.Test;
57import org.junit.FixMethodOrder;
58import org.junit.runners.MethodSorters;
59
60@FixMethodOrder(MethodSorters.NAME_ASCENDING)
61public class TestTextureIONEWT extends UITestCase {
62 static long duration = 100; // ms
63
64 ImageTstFiles imageTstFiles;
65
66 @Before
67 public void initTest() throws IOException {
68 imageTstFiles = new ImageTstFiles();
69 imageTstFiles.init();
70 }
71
72 @After
73 public void cleanupTest() {
74 imageTstFiles.clear();
75 }
76
77 public void testImpl(final List<ImageTstFiles.NamedInputStream> streams, final ImageType expImageType) throws InterruptedException, IOException {
78 for(int i=0; i<streams.size(); i++) {
79 final ImageTstFiles.NamedInputStream s = streams.get(i);
80 System.err.printf("Test %3d: path %s, exp-type %s%n", i, s.basePath, expImageType);
81 testImpl(s.stream, expImageType);
82 }
83 }
84 public void testImpl(final InputStream istream, final ImageType expImageType) throws InterruptedException, IOException {
85 final GLReadBufferUtil screenshot = new GLReadBufferUtil(true, false);
87 final GLCapabilities caps = new GLCapabilities(glp);
88 caps.setAlphaBits(1);
89
90 final TextureData texData = TextureIO.newTextureData(glp, istream, false /* mipmap */, expImageType.type);
91 System.err.println("TextureData: "+texData);
92 Assert.assertEquals(expImageType, texData.getSourceImageType());
93
94 final GLWindow glad = GLWindow.create(caps);
95 glad.setTitle("TestTextureIONEWT."+expImageType.type);
96 // Size OpenGL to Video Surface
97 glad.setSize(texData.getWidth(), texData.getHeight());
98
99 // load texture from file inside current GL context to match the way
100 // the bug submitter was doing it
101 final GLEventListener gle = glp.isGL2ES2() ? new TextureDraw01ES2Listener( texData, 0 ) : new TextureDraw01GL2Listener( texData ) ;
102 glad.addGLEventListener(gle);
104 boolean shot = false;
105
106 @Override public void init(final GLAutoDrawable drawable) {}
107
108 public void display(final GLAutoDrawable drawable) {
109 // 1 snapshot
110 if(null!=((TextureDraw01Accessor)gle).getTexture() && !shot) {
111 shot = true;
112 snapshot(0, null, drawable.getGL(), screenshot, TextureIO.PNG, null);
113 }
114 }
115
116 @Override public void dispose(final GLAutoDrawable drawable) { }
117 @Override public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { }
118 });
119
120 final Animator animator = new Animator(glad);
121 animator.setUpdateFPSFrames(60, null);
122 final QuitAdapter quitAdapter = new QuitAdapter();
123 glad.addKeyListener(quitAdapter);
124 glad.addWindowListener(quitAdapter);
125 glad.setVisible(true);
126 animator.start();
127
128 while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration()<duration) {
129 Thread.sleep(100);
130 }
131
132 animator.stop();
133 glad.destroy();
134 }
135
136 @Test
137 public void test01AllPNG() throws InterruptedException, IOException {
138 testImpl(imageTstFiles.pngStreams, new ImageType(ImageType.T_PNG));
139 }
140
141 @Test
142 public void test02AllJPG() throws InterruptedException, IOException {
143 testImpl(imageTstFiles.jpgStreams, new ImageType(ImageType.T_JPG));
144 }
145
146 @Test
147 public void test03AllTGA() throws InterruptedException, IOException {
148 testImpl(imageTstFiles.tgaStreams, new ImageType(ImageType.T_TGA));
149 }
150
151 @Test
152 public void test04AllDDS() throws InterruptedException, IOException {
153 testImpl(imageTstFiles.ddsStreams, new ImageType(ImageType.T_DDS));
154 }
155
156 public static void main(final String args[]) throws IOException {
157 for(int i=0; i<args.length; i++) {
158 if(args[i].equals("-time")) {
159 i++;
160 duration = MiscUtils.atol(args[i], duration);
161 }
162 }
163 org.junit.runner.JUnitCore.main(TestTextureIONEWT.class.getName());
164 }
165}
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 addKeyListener(final KeyListener l)
Appends the given com.jogamp.newt.event.KeyListener to the end of the list.
Definition: GLWindow.java:902
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 addWindowListener(final WindowListener l)
Appends the given com.jogamp.newt.event.WindowListener to the end of the list.
Definition: GLWindow.java:882
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 boolean isAvailable(final AbstractGraphicsDevice device, final String profile)
Returns the availability of a profile on a device.
Definition: GLProfile.java:305
static final String GL2ES2
The intersection of the desktop GL3, GL2 and embedded ES2 profile.
Definition: GLProfile.java:594
final boolean isGL2ES2()
Indicates whether this profile is capable of GL2ES2.
static GLProfile getDefault(final AbstractGraphicsDevice device)
Returns a default GLProfile object, reflecting the best for the running platform.
Definition: GLProfile.java:739
static GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
Definition: GLProfile.java:913
void testImpl(final InputStream istream, final ImageType expImageType)
void testImpl(final List< ImageTstFiles.NamedInputStream > streams, final ImageType expImageType)
static long atol(final String str, final long def)
Definition: MiscUtils.java:66
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
Utility to read out the current FB to TextureData, optionally writing the data back to a texture obje...
Image type classification.
Definition: ImageType.java:42
static final String T_TGA
Constant which can be used as a file suffix to indicate a Targa stream, value {@value}.
static final String T_PNG
Constant which can be used as a file suffix to indicate a PNG stream, value {@value}.
Definition: ImageType.java:63
static final String T_DDS
Constant which can be used as a file suffix to indicate a DirectDraw Surface stream,...
Definition: ImageType.java:220
static final String T_JPG
Constant which can be used as a file suffix to indicate a JPEG stream, value {@value}.
Definition: ImageType.java:55
Represents the data for an OpenGL texture.
final ImageType getSourceImageType()
Returns the source ImageType if applicable and known, otherwise null.
int getHeight()
Returns the height in pixels of the texture data.
int getWidth()
Returns the width in pixels of the texture data.
static final String PNG
Constant which can be used as a file suffix to indicate a PNG file, value {@value}.
Definition: TextureIO.java:171
static TextureData newTextureData(final GLProfile glp, final File file, final boolean mipmap, String fileSuffix)
Creates a TextureData from the given file.
Definition: TextureIO.java:233
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.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.