JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestBug817GLReadBufferUtilGLCTXDefFormatTypeES2NEWT.java
Go to the documentation of this file.
1/**
2 * Copyright 2013 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.opengl.GLAutoDrawable;
32import com.jogamp.opengl.GLCapabilities;
33import com.jogamp.opengl.GLEventListener;
34import com.jogamp.opengl.GLProfile;
35
36import org.junit.Test;
37import org.junit.FixMethodOrder;
38import org.junit.runners.MethodSorters;
39
40import com.jogamp.newt.opengl.GLWindow;
41import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
42import com.jogamp.opengl.test.junit.util.MiscUtils;
43import com.jogamp.opengl.test.junit.util.UITestCase;
44import com.jogamp.opengl.util.GLPixelBuffer.GLPixelAttributes;
45import com.jogamp.opengl.util.GLPixelBuffer.GLPixelBufferProvider;
46import com.jogamp.opengl.util.GLReadBufferUtil;
47import com.jogamp.opengl.util.texture.TextureIO;
48
49@FixMethodOrder(MethodSorters.NAME_ASCENDING)
51 static long durationPerTest = 60; // ms
52
53 public static void main(final String[] args) {
54 for(int i=0; i<args.length; i++) {
55 if(args[i].equals("-time")) {
56 durationPerTest = MiscUtils.atoi(args[++i], 500);
57 }
58 }
59 System.out.println("durationPerTest: "+durationPerTest);
60 final String tstname = TestBug817GLReadBufferUtilGLCTXDefFormatTypeES2NEWT.class.getName();
61 org.junit.runner.JUnitCore.main(tstname);
62 }
63
64 @Test
65 public void test00_RGBtoRGB() throws InterruptedException {
66 testImpl(false, false, false, false);
67 }
68 @Test
69 public void test01_RGBtoRGBA() throws InterruptedException {
70 testImpl(false, true, false, false);
71 }
72
73 @Test
74 public void test10_RGBAtoRGB() throws InterruptedException {
75 testImpl(true, false, false, false);
76 }
77 @Test
78 public void test11_RGBAtoRGBA() throws InterruptedException {
79 testImpl(true, true, false, false);
80 }
81 @Test
82 public void test21_RGBtoRGBA_pbuffer() throws InterruptedException {
83 testImpl(false, true, true, false);
84 }
85 @Test
86 public void test22_RGBtoRGBA_fbo() throws InterruptedException {
87 testImpl(false, true, false, true);
88 }
89 @Test
90 public void test31_RGBAtoRGBA_pbuffer() throws InterruptedException {
91 testImpl(true, true, true, false);
92 }
93 @Test
94 public void test32_RGBAtoRGBA_fbo() throws InterruptedException {
95 testImpl(true, true, false, true);
96 }
97
98 private void testImpl(final boolean alphaCaps, final boolean readAlpha, final boolean pbuffer, final boolean fbo) throws InterruptedException {
99 final GLReadBufferUtil screenshot = new GLReadBufferUtil(readAlpha ? true : false, false);
100 final GLProfile glp = GLProfile.getGL2ES2();
101 final GLCapabilities caps = new GLCapabilities(glp);
102
103 caps.setAlphaBits( alphaCaps ? 1 : 0 );
104 caps.setPBuffer( pbuffer );
105 caps.setFBO( fbo);
106
107 final GLWindow window = GLWindow.create(caps);
108 window.addGLEventListener(new GearsES2());
110 int displayCount = 0;
111 public void init(final GLAutoDrawable drawable) {}
112 public void dispose(final GLAutoDrawable drawable) {}
113 public void display(final GLAutoDrawable drawable) {
114 final GLPixelBufferProvider pixelBufferProvider = screenshot.getPixelBufferProvider();
115 final GLPixelAttributes pixelAttribs = pixelBufferProvider.getAttributes(drawable.getGL(), readAlpha ? 4 : 3, true);
116 System.err.println("GLPixelAttributes: "+pixelAttribs);
117 snapshot(displayCount++, null, drawable.getGL(), screenshot, TextureIO.PNG, null);
118 }
119 public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { }
120 });
121 window.setSize(512, 512);
122 window.setVisible(true);
123 window.requestFocus();
124
125 Thread.sleep(durationPerTest);
126
127 window.destroy();
128 }
129
130}
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 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
final void requestFocus()
Request focus for this native window.
Definition: GLWindow.java:416
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.
void setPBuffer(final boolean enable)
Requesting offscreen pbuffer mode.
void setFBO(final boolean enable)
Requesting offscreen FBO mode.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
Definition: GLProfile.java:913
static int atoi(final String str, final int def)
Definition: MiscUtils.java:57
Utility to read out the current FB to TextureData, optionally writing the data back to a texture obje...
GLPixelBufferProvider getPixelBufferProvider()
Returns the GLPixelBufferProvider used by this instance.
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.
GLPixelAttributes getAttributes(GL gl, int componentCount, boolean pack)
Returns RGB[A] GLPixelAttributes matching GL, componentCount and pack.