From bd98b927b910d9421e63cf0dbc2b746eec019f80 Mon Sep 17 00:00:00 2001
From: Sven Gothel
Date: Wed, 8 Jan 2014 21:56:26 +0100
Subject: Bug 935: NEWT PointerIcon: Utilize Toolkit Agnostic PixelFormat and
Conversion Utilities (Allowing 'arbitrary' PointerIcon data input)
Commit fe28bc125429b38cdcd016746081f4a6d521c6fd added the notion of toolkit agnostic PixelFormat and conversion utilities,
utilized and further tested by this patch.
+++
- PointerIcon is a PixelRectangle
and hence holds the decoded data.
This allows on-the-fly conversion if required
as well as recreation w/o PNG re-decoding.
- Using array-backed PointerIcon data where possible,
allowing better performance when converting PixelFormat etc.
- NEWT Display adds 'createPointerIcon(final IOUtil.ClassResources pngResource...'
method to support agnostic PointerIcon creation.
- NEWT Display adds methods to allow users to avoid PixelFormat and
Buffer NIO type forced conversion:
- PixelFormat getNativePointerIconPixelFormat()
- boolean getNativePointerIconForceDirectNIO()
+++
PNGImage -> PNGPixelRect
Deleted: com.jogamp.opengl.util.texture.spi.PNGImage
Added: com.jogamp.opengl.util.PNGPixelRect
(We hope nobody was using PNGImage directly since it was a service-plugin for TextureIO)
PNGPixelRect is a PixelRectangle
PNGPixelRect actually is implemented OpenGL agnostic,
however - since our PNGJ support lives under package 'jogamp.opengl.util.pngj'
it cannot be moved up (yet).
PNGPixelRect now handles all PixelFormat for the target format
and also added support for grayscale+alpha (2 channels).
The latter is force-converted to RGB* - similar to paletted.
Further more, PNGPixelRect allows simply passing an OutputStream to write the PNG data.
Used by: TextureIO and NEWT
+++
- OffscreenSurfaceLayer's setCursor(..) uses the agnostic PixelRectangle
instead of a PNG resource.
- AWTMisc uses the PixelRectangle to produce the AWT Cursor
and converts it to the required format.
Hence same pixels are used for NEWT and AWT pointer/cursor icon.
- TestGearsES2Newt and NewtAWTReparentingKeyAdapter 'tests'
iterate over 3 custom PointerIcon when pressed 'c'.
- JOGLNewtAppletBase uses the new custom PointerIcon
'newt/data/crosshair-lumina-trans-32x32.png', which is included in NEWT (213 bytes only).
-
---
.../jogl/demos/es2/newt/TestGearsES2NEWT.java | 59 +++++-
.../test/junit/jogl/util/texture/PNGTstFiles.java | 54 +++++
.../jogl/util/texture/TestPNGImage00NEWT.java | 92 ---------
.../jogl/util/texture/TestPNGImage01NEWT.java | 182 -----------------
.../jogl/util/texture/TestPNGPixelRect00NEWT.java | 224 +++++++++++++++++++++
.../jogl/util/texture/TestPNGPixelRect01NEWT.java | 198 ++++++++++++++++++
.../util/texture/TestPixelFormatUtil01NEWT.java | 105 ++++++++++
.../util/texture/crosshair-lumina-trans-32x32.png | Bin 0 -> 213 bytes
.../util/texture/crosshair-lumina-trans-64x64.png | Bin 0 -> 424 bytes
.../parenting/NewtAWTReparentingKeyAdapter.java | 62 +++++-
10 files changed, 682 insertions(+), 294 deletions(-)
create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/util/texture/PNGTstFiles.java
delete mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPNGImage00NEWT.java
delete mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPNGImage01NEWT.java
create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPNGPixelRect00NEWT.java
create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPNGPixelRect01NEWT.java
create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPixelFormatUtil01NEWT.java
create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/util/texture/crosshair-lumina-trans-32x32.png
create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/util/texture/crosshair-lumina-trans-64x64.png
(limited to 'src/test/com')
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java
index 8cc676291..780338492 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java
@@ -29,6 +29,7 @@
package com.jogamp.opengl.test.junit.jogl.demos.es2.newt;
import java.io.IOException;
+import java.net.URLConnection;
import com.jogamp.common.util.IOUtil;
import com.jogamp.newt.Display;
@@ -47,6 +48,7 @@ import com.jogamp.opengl.test.junit.util.MiscUtils;
import com.jogamp.opengl.test.junit.util.UITestCase;
import com.jogamp.opengl.test.junit.util.QuitAdapter;
import com.jogamp.opengl.util.Animator;
+import com.jogamp.opengl.util.PNGPixelRect;
import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
import javax.media.nativewindow.NativeWindowFactory;
@@ -171,25 +173,55 @@ public class TestGearsES2NEWT extends UITestCase {
}
});
- final PointerIcon pointerIconOne;
+ final PointerIcon[] pointerIcons = { null, null, null };
{
- PointerIcon _pointerIconOne = null;
- final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "jogamp-pointer-64x64.png" } );
final Display disp = glWindow.getScreen().getDisplay();
disp.createNative();
- try {
- _pointerIconOne = disp.createPointerIcon(res, 32, 0);
- } catch (Exception e) {
- e.printStackTrace();
+ {
+ PointerIcon _pointerIcon = null;
+ final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "newt/data/crosshair-lumina-trans-32x32.png" } );
+ try {
+ _pointerIcon = disp.createPointerIcon(res, 16, 16);
+ System.err.println("Create PointerIcon #01: "+_pointerIcon);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ pointerIcons[0] = _pointerIcon;
+ }
+ {
+ PointerIcon _pointerIcon = null;
+ final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "jogamp-pointer-64x64.png" } );
+ try {
+ _pointerIcon = disp.createPointerIcon(res, 32, 0);
+ System.err.println("Create PointerIcon #02: "+_pointerIcon);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ pointerIcons[1] = _pointerIcon;
+ }
+ {
+ PointerIcon _pointerIcon = null;
+ final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "crosshair-lumina-trans-64x64.png" } );
+ try {
+ final URLConnection urlConn = res.resolve(0);
+ final PNGPixelRect image = PNGPixelRect.read(urlConn.getInputStream(), null, false /* directBuffer */, 0 /* destMinStrideInBytes */, false /* destIsGLOriented */);
+ System.err.println("Create PointerIcon #03: "+image);
+ _pointerIcon = disp.createPointerIcon(image, 32, 32);
+ System.err.println("Create PointerIcon #03: "+_pointerIcon);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ pointerIcons[2] = _pointerIcon;
}
- pointerIconOne = _pointerIconOne;
}
if( setPointerIcon ) {
- glWindow.setPointerIcon(pointerIconOne);
+ glWindow.setPointerIcon(pointerIcons[0]);
System.err.println("Set PointerIcon: "+glWindow.getPointerIcon());
}
glWindow.addKeyListener(new KeyAdapter() {
+ int pointerIconIdx = 0;
+
@Override
public void keyPressed(final KeyEvent e) {
if( e.isAutoRepeat() ) {
@@ -246,7 +278,14 @@ public class TestGearsES2NEWT extends UITestCase {
final Thread t = glWindow.setExclusiveContextThread(null);
System.err.println("[set pointer-icon pre]");
final PointerIcon currentPI = glWindow.getPointerIcon();
- glWindow.setPointerIcon( currentPI == pointerIconOne ? null : pointerIconOne);
+ final PointerIcon newPI;
+ if( pointerIconIdx >= pointerIcons.length ) {
+ newPI=null;
+ pointerIconIdx=0;
+ } else {
+ newPI=pointerIcons[pointerIconIdx++];
+ }
+ glWindow.setPointerIcon( newPI );
System.err.println("[set pointer-icon post] "+currentPI+" -> "+glWindow.getPointerIcon());
glWindow.setExclusiveContextThread(t);
} }.start();
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/PNGTstFiles.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/PNGTstFiles.java
new file mode 100644
index 000000000..bb9bc42a8
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/PNGTstFiles.java
@@ -0,0 +1,54 @@
+/**
+ * Copyright 2014 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package com.jogamp.opengl.test.junit.jogl.util.texture;
+
+public class PNGTstFiles {
+ static public final String[] allBasenames = {
+ "test-ntscN_3-01-160x90",
+ "test-ntscN_4-01-160x90",
+ "test-ntscNG4-01-160x90",
+ "test-ntscI_3-01-160x90",
+ "test-ntscI_4-01-160x90",
+ "test-ntscIG3-01-160x90",
+ "test-ntscIG4-01-160x90",
+ "test-ntscP_3-01-160x90",
+ "test-ntscP_4-01-160x90",
+ "grayscale_texture",
+ "bug724-transparent-grey_orig",
+ "bug724-transparent-grey_gimpexp",
+ "crosshair-lumina-trans-32x32",
+ "crosshair-lumina-trans-64x64",
+ };
+ static public final String[] greyBasenames = {
+ "grayscale_texture",
+ "bug724-transparent-grey_orig",
+ "bug724-transparent-grey_gimpexp",
+ "crosshair-lumina-trans-32x32",
+ "crosshair-lumina-trans-64x64",
+ };
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPNGImage00NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPNGImage00NEWT.java
deleted file mode 100644
index 3ace5ab6a..000000000
--- a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPNGImage00NEWT.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/**
- * Copyright 2010 JogAmp Community. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are
- * permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * The views and conclusions contained in the software and documentation are those of the
- * authors and should not be interpreted as representing official policies, either expressed
- * or implied, of JogAmp Community.
- */
-package com.jogamp.opengl.test.junit.jogl.util.texture;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URLConnection;
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.FixMethodOrder;
-import org.junit.runners.MethodSorters;
-
-import com.jogamp.common.util.IOUtil;
-import com.jogamp.opengl.test.junit.util.UITestCase;
-import com.jogamp.opengl.util.texture.spi.PNGImage;
-
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class TestPNGImage00NEWT extends UITestCase {
- @Test
- public void testPNGReadWriteAndCompare() throws InterruptedException, IOException, MalformedURLException {
- final File out1_f=new File(getSimpleTestName(".")+"-PNGImageTest1.png");
- final File out2_f=new File(getSimpleTestName(".")+"-PNGImageTest2.png");
- final File out2F_f=new File(getSimpleTestName(".")+"-PNGImageTest2Flipped.png");
- final File out2R_f=new File(getSimpleTestName(".")+"-PNGImageTest2Reversed.png");
- final File out2RF_f=new File(getSimpleTestName(".")+"-PNGImageTest2ReversedFlipped.png");
- final String url_s="jogl/util/data/av/test-ntsc01-57x32.png";
- URLConnection urlConn = IOUtil.getResource(url_s, this.getClass().getClassLoader());
- PNGImage image1 = PNGImage.read(urlConn.getInputStream());
- System.err.println("PNGImage - Orig: "+image1);
- image1.write(out1_f, true);
- {
- Assert.assertEquals(image1.getData(), PNGImage.read(out1_f.toURI().toURL().openStream()).getData());
- }
-
- final PNGImage image2 = PNGImage.createFromData(image1.getWidth(), image1.getHeight(),
- image1.getDpi()[0], image1.getDpi()[1],
- image1.getBytesPerPixel(), false /* reverseChannels */, image1.isGLOriented(), image1.getData());
- image2.write(out2_f, true);
- {
- Assert.assertEquals(image1.getData(), PNGImage.read(out2_f.toURI().toURL().openStream()).getData());
- }
-
- // flipped
- final PNGImage image2F = PNGImage.createFromData(image1.getWidth(), image1.getHeight(),
- image1.getDpi()[0], image1.getDpi()[1],
- image1.getBytesPerPixel(), false /* reverseChannels */, !image1.isGLOriented(), image1.getData());
- image2F.write(out2F_f, true);
-
- // reversed channels
- final PNGImage image2R = PNGImage.createFromData(image1.getWidth(), image1.getHeight(),
- image1.getDpi()[0], image1.getDpi()[1],
- image1.getBytesPerPixel(), true /* reverseChannels */, image1.isGLOriented(), image1.getData());
- image2R.write(out2R_f, true);
-
- // reversed channels and flipped
- final PNGImage image2RF = PNGImage.createFromData(image1.getWidth(), image1.getHeight(),
- image1.getDpi()[0], image1.getDpi()[1],
- image1.getBytesPerPixel(), true /* reverseChannels */, !image1.isGLOriented(), image1.getData());
- image2RF.write(out2RF_f, true);
- }
-
- public static void main(String args[]) {
- org.junit.runner.JUnitCore.main(TestPNGImage00NEWT.class.getName());
- }
-}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPNGImage01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPNGImage01NEWT.java
deleted file mode 100644
index 29e041908..000000000
--- a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPNGImage01NEWT.java
+++ /dev/null
@@ -1,182 +0,0 @@
-/**
- * Copyright 2010 JogAmp Community. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are
- * permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * The views and conclusions contained in the software and documentation are those of the
- * authors and should not be interpreted as representing official policies, either expressed
- * or implied, of JogAmp Community.
- */
-package com.jogamp.opengl.test.junit.jogl.util.texture;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URLConnection;
-
-import javax.media.opengl.GL;
-import javax.media.opengl.GLAutoDrawable;
-import javax.media.opengl.GLCapabilities;
-import javax.media.opengl.GLEventListener;
-import javax.media.opengl.GLProfile;
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.FixMethodOrder;
-import org.junit.runners.MethodSorters;
-
-import com.jogamp.common.util.IOUtil;
-import com.jogamp.newt.opengl.GLWindow;
-import com.jogamp.opengl.test.junit.jogl.demos.TextureDraw01Accessor;
-import com.jogamp.opengl.test.junit.jogl.demos.es2.TextureDraw01ES2Listener;
-import com.jogamp.opengl.test.junit.util.MiscUtils;
-import com.jogamp.opengl.test.junit.util.QuitAdapter;
-import com.jogamp.opengl.test.junit.util.UITestCase;
-import com.jogamp.opengl.util.Animator;
-import com.jogamp.opengl.util.GLReadBufferUtil;
-import com.jogamp.opengl.util.GLPixelBuffer.GLPixelAttributes;
-import com.jogamp.opengl.util.texture.TextureData;
-import com.jogamp.opengl.util.texture.TextureIO;
-import com.jogamp.opengl.util.texture.spi.PNGImage;
-
-/**
- * Test reading and displaying a PNG image.
- *
- * Main function accepts arbitrary PNG file name for manual tests.
- *
- */
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class TestPNGImage01NEWT extends UITestCase {
-
- static boolean showFPS = false;
- static long duration = 200; // ms
-
- public void testImpl(final InputStream istream) throws InterruptedException, IOException {
- final PNGImage image = PNGImage.read(istream);
- Assert.assertNotNull(image);
- final boolean hasAlpha = 4 == image.getBytesPerPixel();
- System.err.println("PNGImage: "+image);
-
- final GLReadBufferUtil screenshot = new GLReadBufferUtil(true, false);
- final GLProfile glp = GLProfile.getGL2ES2();
- final GLCapabilities caps = new GLCapabilities(glp);
- if( hasAlpha ) {
- caps.setAlphaBits(1);
- }
-
- final int internalFormat;
- if(glp.isGL2ES3()) {
- internalFormat = hasAlpha ? GL.GL_RGBA8 : GL.GL_RGB8;
- } else {
- internalFormat = hasAlpha ? GL.GL_RGBA : GL.GL_RGB;
- }
- final TextureData texData = new TextureData(glp, internalFormat,
- image.getWidth(),
- image.getHeight(),
- 0,
- new GLPixelAttributes(image.getGLFormat(), image.getGLType()),
- false /* mipmap */,
- false /* compressed */,
- false /* must flip-vert */,
- image.getData(),
- null);
-
- // final TextureData texData = TextureIO.newTextureData(glp, istream, false /* mipmap */, TextureIO.PNG);
- System.err.println("TextureData: "+texData);
-
- final GLWindow glad = GLWindow.create(caps);
- glad.setTitle("TestPNGImage01NEWT");
- // Size OpenGL to Video Surface
- glad.setSize(texData.getWidth(), texData.getHeight());
-
- // load texture from file inside current GL context to match the way
- // the bug submitter was doing it
- final TextureDraw01ES2Listener gle = new TextureDraw01ES2Listener( texData, 0 ) ;
- // gle.setClearColor(new float[] { 1.0f, 0.0f, 0.0f, 1.0f } );
-
- glad.addGLEventListener(gle);
- glad.addGLEventListener(new GLEventListener() {
- boolean shot = false;
-
- @Override public void init(GLAutoDrawable drawable) {
- System.err.println("Chosen Caps: " + drawable.getChosenGLCapabilities());
- System.err.println("GL ctx: " + drawable.getGL().getContext());
- }
-
- @Override public void display(GLAutoDrawable drawable) {
- // 1 snapshot
- if(null!=((TextureDraw01Accessor)gle).getTexture() && !shot) {
- shot = true;
- snapshot(0, null, drawable.getGL(), screenshot, TextureIO.PNG, null);
- }
- }
-
- @Override public void dispose(GLAutoDrawable drawable) { }
- @Override public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { }
- });
-
- Animator animator = new Animator(glad);
- animator.setUpdateFPSFrames(60, showFPS ? System.err : null);
- QuitAdapter quitAdapter = new QuitAdapter();
- glad.addKeyListener(quitAdapter);
- glad.addWindowListener(quitAdapter);
- glad.setVisible(true);
- animator.start();
-
- while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration()
+ * Main function accepts arbitrary PNG file name for manual tests.
+ *
+ */
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestPNGPixelRect01NEWT extends UITestCase {
+ static boolean showFPS = false;
+ static long duration = 200; // ms
+
+ public void testImpl(final int num, final String basename, final InputStream istream, final PixelFormat destFmt) throws InterruptedException, IOException {
+ final GLProfile glp = GLProfile.getGL2ES2();
+ final PNGPixelRect image = PNGPixelRect.read(istream, destFmt, true /* directBuffer */, 0 /* destMinStrideInBytes */, true /* destIsGLOriented */);
+ Assert.assertNotNull(image);
+ final GLPixelAttributes glpa = GLPixelAttributes.convert(image.getPixelformat(), glp);
+ final boolean hasAlpha = 4 == glpa.bytesPerPixel;
+ System.err.println("PNGPixelRect: "+basename+", "+image+", glpa "+glpa);
+
+ final GLReadBufferUtil screenshot = new GLReadBufferUtil(true, false);
+ final GLCapabilities caps = new GLCapabilities(glp);
+ if( hasAlpha ) {
+ caps.setAlphaBits(1);
+ }
+
+ final int internalFormat;
+ if(glp.isGL2ES3()) {
+ internalFormat = hasAlpha ? GL.GL_RGBA8 : GL.GL_RGB8;
+ } else {
+ internalFormat = hasAlpha ? GL.GL_RGBA : GL.GL_RGB;
+ }
+ final TextureData texData = new TextureData(glp, internalFormat,
+ image.getSize().getWidth(),
+ image.getSize().getHeight(),
+ 0,
+ glpa,
+ false /* mipmap */,
+ false /* compressed */,
+ false /* must flip-vert */,
+ image.getPixels(),
+ null);
+
+ // final TextureData texData = TextureIO.newTextureData(glp, istream, false /* mipmap */, TextureIO.PNG);
+ System.err.println("TextureData: "+texData);
+
+ final GLWindow glad = GLWindow.create(caps);
+ glad.setTitle(this.getSimpleTestName("."));
+ // Size OpenGL to Video Surface
+ glad.setSize(texData.getWidth(), texData.getHeight());
+
+ // load texture from file inside current GL context to match the way
+ // the bug submitter was doing it
+ final TextureDraw01ES2Listener gle = new TextureDraw01ES2Listener( texData, 0 ) ;
+ // gle.setClearColor(new float[] { 1.0f, 0.0f, 0.0f, 1.0f } );
+
+ glad.addGLEventListener(gle);
+ glad.addGLEventListener(new GLEventListener() {
+ boolean shot = false;
+
+ @Override public void init(GLAutoDrawable drawable) {
+ System.err.println("Chosen Caps: " + drawable.getChosenGLCapabilities());
+ System.err.println("GL ctx: " + drawable.getGL().getContext());
+ }
+
+ @Override public void display(GLAutoDrawable drawable) {
+ // 1 snapshot
+ if(null!=((TextureDraw01Accessor)gle).getTexture() && !shot) {
+ shot = true;
+ snapshot(num, basename, drawable.getGL(), screenshot, TextureIO.PNG, null);
+ }
+ }
+
+ @Override public void dispose(GLAutoDrawable drawable) { }
+ @Override public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { }
+ });
+
+ Animator animator = new Animator(glad);
+ animator.setUpdateFPSFrames(60, showFPS ? System.err : null);
+ QuitAdapter quitAdapter = new QuitAdapter();
+ glad.addKeyListener(quitAdapter);
+ glad.addWindowListener(quitAdapter);
+ glad.setVisible(true);
+ animator.start();
+
+ while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration() "+destFmt);
+ final PixelRectangle imageConv1 = PixelFormatUtil.convert32(image1, destFmt, destMinStrideInBytes, destIsGLOriented, false /* nio */);
+ System.err.println("PNGPixelRect - Conv1: "+imageConv1);
+ final PixelRectangle imageConv2 = PixelFormatUtil.convert32(imageConv1, image1.getPixelformat(), image1.getStride(), image1.isGLOriented(), false /* nio */);
+ System.err.println("PNGPixelRect - Conv2: "+imageConv2);
+ Assert.assertEquals(image1.getPixels(), imageConv2.getPixels());
+ }
+ }
+
+ public static void main(String args[]) {
+ org.junit.runner.JUnitCore.main(TestPixelFormatUtil01NEWT.class.getName());
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/crosshair-lumina-trans-32x32.png b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/crosshair-lumina-trans-32x32.png
new file mode 100644
index 000000000..92279640b
Binary files /dev/null and b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/crosshair-lumina-trans-32x32.png differ
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/crosshair-lumina-trans-64x64.png b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/crosshair-lumina-trans-64x64.png
new file mode 100644
index 000000000..9be285335
Binary files /dev/null and b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/crosshair-lumina-trans-64x64.png differ
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/NewtAWTReparentingKeyAdapter.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/NewtAWTReparentingKeyAdapter.java
index 69874df6b..70d01ae66 100644
--- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/NewtAWTReparentingKeyAdapter.java
+++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/NewtAWTReparentingKeyAdapter.java
@@ -28,25 +28,27 @@
package com.jogamp.opengl.test.junit.newt.parenting;
import java.awt.Frame;
+import java.net.URLConnection;
import javax.media.nativewindow.util.InsetsImmutable;
import com.jogamp.common.util.IOUtil;
import com.jogamp.newt.Display;
-import com.jogamp.newt.Window;
import com.jogamp.newt.Display.PointerIcon;
import com.jogamp.newt.awt.NewtCanvasAWT;
import com.jogamp.newt.event.KeyAdapter;
import com.jogamp.newt.event.KeyEvent;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.test.junit.util.QuitAdapter;
+import com.jogamp.opengl.util.PNGPixelRect;
public class NewtAWTReparentingKeyAdapter extends KeyAdapter {
final Frame frame;
final NewtCanvasAWT newtCanvasAWT;
final GLWindow glWindow;
final QuitAdapter quitAdapter;
- PointerIcon pointerIconTest = null;
+ PointerIcon[] pointerIcons = null;
+ int pointerIconIdx = 0;
public NewtAWTReparentingKeyAdapter(Frame frame, NewtCanvasAWT newtCanvasAWT, GLWindow glWindow, QuitAdapter quitAdapter) {
this.frame = frame;
@@ -144,13 +146,46 @@ public class NewtAWTReparentingKeyAdapter extends KeyAdapter {
}
} }.start();
} else if(e.getKeySymbol() == KeyEvent.VK_C ) {
- if( null == pointerIconTest ) {
- final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "newt/data/jogamp-32x32.png" } );
- final Display disp = glWindow.getScreen().getDisplay();
- try {
- pointerIconTest = disp.createPointerIcon(res, 16, 0);
- } catch (Exception err) {
- err.printStackTrace();
+ if( null == pointerIcons ) {
+ {
+ pointerIcons = new PointerIcon[3];
+ final Display disp = glWindow.getScreen().getDisplay();
+ {
+ PointerIcon _pointerIcon = null;
+ final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "newt/data/crosshair-lumina-trans-32x32.png" } );
+ try {
+ _pointerIcon = disp.createPointerIcon(res, 16, 16);
+ System.err.println("Create PointerIcon #01: "+_pointerIcon);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ pointerIcons[0] = _pointerIcon;
+ }
+ {
+ PointerIcon _pointerIcon = null;
+ final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "jogamp-pointer-64x64.png" } );
+ try {
+ _pointerIcon = disp.createPointerIcon(res, 32, 0);
+ System.err.println("Create PointerIcon #02: "+_pointerIcon);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ pointerIcons[1] = _pointerIcon;
+ }
+ {
+ PointerIcon _pointerIcon = null;
+ final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "crosshair-lumina-trans-64x64.png" } );
+ try {
+ final URLConnection urlConn = res.resolve(0);
+ final PNGPixelRect image = PNGPixelRect.read(urlConn.getInputStream(), null, false /* directBuffer */, 0 /* destMinStrideInBytes */, false /* destIsGLOriented */);
+ System.err.println("Create PointerIcon #03: "+image);
+ _pointerIcon = disp.createPointerIcon(image, 32, 32);
+ System.err.println("Create PointerIcon #03: "+_pointerIcon);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ pointerIcons[2] = _pointerIcon;
+ }
}
}
new Thread() {
@@ -158,7 +193,14 @@ public class NewtAWTReparentingKeyAdapter extends KeyAdapter {
final Thread t = glWindow.setExclusiveContextThread(null);
System.err.println("[set pointer-icon pre]");
final PointerIcon currentPI = glWindow.getPointerIcon();
- glWindow.setPointerIcon( currentPI == pointerIconTest ? null : pointerIconTest);
+ final PointerIcon newPI;
+ if( pointerIconIdx >= pointerIcons.length ) {
+ newPI=null;
+ pointerIconIdx=0;
+ } else {
+ newPI=pointerIcons[pointerIconIdx++];
+ }
+ glWindow.setPointerIcon( newPI );
System.err.println("[set pointer-icon post] "+currentPI+" -> "+glWindow.getPointerIcon());
glWindow.setExclusiveContextThread(t);
} }.start();
--
cgit v1.2.3