From e8078eb70f6f82613d730ae5b8f837ccb46b81fb Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 18 Jun 2012 03:39:39 +0200 Subject: Texture Unit Tests: AWT/NEWT GL2/ES2 PNGJ/AWT-PNG-Loading and Rendering (TestPNGTextureFromFile[AWT/NEWT]) Properly test combinations of TextureIO usage w/ - NEWT / AWT usage - GL2 / ES2 usage - PNG implementations: PNGJ (internal) and AWT - adding screenshots of result for later analysis Misc: - IOUtil.getResource(..) usage CLASS.class.getClassLoader() -> this.getClass().getClassLoader() --- .../jogamp/opengl/util/av/NullGLMediaPlayer.java | 2 +- .../junit/jogl/demos/TextureDraw01Accessor.java | 35 +++ .../junit/jogl/demos/TextureSequenceDemo01.java | 4 +- .../jogl/demos/es2/TextureDraw01ES2Listener.java | 249 +++++++++++++++++++++ .../jogl/demos/es2/TextureSequenceCubeES2.java | 19 +- .../junit/jogl/demos/es2/shader/texture01_xxx.fp | 20 ++ .../junit/jogl/demos/es2/shader/texture01_xxx.vp | 17 ++ .../jogl/demos/gl2/TextureDraw01GL2Listener.java | 104 +++++++++ .../test/junit/jogl/util/TestPNGImage01NEWT.java | 2 +- .../texture/TestGrayTextureFromFileAWTBug417.java | 149 ------------ .../util/texture/TestPNGTextureFromFileAWT.java | 238 ++++++++++++++++++++ .../util/texture/TestPNGTextureFromFileNEWT.java | 173 ++++++++++++++ .../junit/jogl/util/texture/TestTexture01AWT.java | 3 +- .../util/texture/TestTextureSequence01NEWT.java | 2 - .../jogl/util/texture/TextureGL2ListenerDraw1.java | 112 --------- 15 files changed, 851 insertions(+), 278 deletions(-) create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/TextureDraw01Accessor.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TextureDraw01ES2Listener.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texture01_xxx.fp create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texture01_xxx.vp create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/TextureDraw01GL2Listener.java delete mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestGrayTextureFromFileAWTBug417.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPNGTextureFromFileAWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPNGTextureFromFileNEWT.java delete mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TextureGL2ListenerDraw1.java (limited to 'src') diff --git a/src/jogl/classes/jogamp/opengl/util/av/NullGLMediaPlayer.java b/src/jogl/classes/jogamp/opengl/util/av/NullGLMediaPlayer.java index 3d740d6b2..cd48c3962 100644 --- a/src/jogl/classes/jogamp/opengl/util/av/NullGLMediaPlayer.java +++ b/src/jogl/classes/jogamp/opengl/util/av/NullGLMediaPlayer.java @@ -110,7 +110,7 @@ public class NullGLMediaPlayer extends GLMediaPlayerImpl { @Override protected void initGLStreamImpl(GL gl, int[] texNames) throws IOException { try { - URLConnection urlConn = IOUtil.getResource("jogl/util/data/av/test-ntsc01-160x90.png", NullGLMediaPlayer.class.getClassLoader()); + URLConnection urlConn = IOUtil.getResource("jogl/util/data/av/test-ntsc01-160x90.png", this.getClass().getClassLoader()); if(null != urlConn) { texData = TextureIO.newTextureData(GLProfile.getGL2ES2(), urlConn.getInputStream(), false, TextureIO.PNG); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/TextureDraw01Accessor.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/TextureDraw01Accessor.java new file mode 100644 index 000000000..b9ac9faad --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/TextureDraw01Accessor.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012 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.demos; + +import com.jogamp.opengl.util.texture.Texture; + +public interface TextureDraw01Accessor { + public Texture getTexture(); +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/TextureSequenceDemo01.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/TextureSequenceDemo01.java index a1d4b4466..6fd47e63f 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/TextureSequenceDemo01.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/TextureSequenceDemo01.java @@ -6,8 +6,6 @@ import javax.media.opengl.GL; import javax.media.opengl.GLException; import javax.media.opengl.GLProfile; -import jogamp.opengl.util.av.NullGLMediaPlayer; - import com.jogamp.common.util.IOUtil; import com.jogamp.opengl.util.texture.Texture; import com.jogamp.opengl.util.texture.TextureData; @@ -29,7 +27,7 @@ public class TextureSequenceDemo01 implements TextureSequence { if(null == frame) { TextureData texData = null; try { - URLConnection urlConn = IOUtil.getResource("jogl/util/data/av/test-ntsc01-160x90.png", NullGLMediaPlayer.class.getClassLoader()); + URLConnection urlConn = IOUtil.getResource("jogl/util/data/av/test-ntsc01-160x90.png", this.getClass().getClassLoader()); if(null != urlConn) { texData = TextureIO.newTextureData(GLProfile.getGL2ES2(), urlConn.getInputStream(), false, TextureIO.PNG); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TextureDraw01ES2Listener.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TextureDraw01ES2Listener.java new file mode 100644 index 000000000..6e701658c --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TextureDraw01ES2Listener.java @@ -0,0 +1,249 @@ +/** + * Copyright 2012 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.demos.es2; + +import java.nio.FloatBuffer; + +import com.jogamp.opengl.test.junit.jogl.demos.TextureDraw01Accessor; +import com.jogamp.opengl.util.GLArrayDataServer; +import com.jogamp.opengl.util.PMVMatrix; +import com.jogamp.opengl.util.glsl.ShaderCode; +import com.jogamp.opengl.util.glsl.ShaderProgram; +import com.jogamp.opengl.util.glsl.ShaderState; +import com.jogamp.opengl.util.texture.Texture; +import com.jogamp.opengl.util.texture.TextureData; +import com.jogamp.opengl.util.texture.TextureIO; + +import javax.media.opengl.GL; +import javax.media.opengl.GL2ES2; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLException; +import javax.media.opengl.GLUniformData; +import javax.media.opengl.fixedfunc.GLMatrixFunc; + +public class TextureDraw01ES2Listener implements GLEventListener, TextureDraw01Accessor { + TextureData textureData; + Texture texture; + + ShaderState st; + PMVMatrix pmvMatrix; + GLUniformData pmvMatrixUniform; + GLArrayDataServer interleavedVBO; + + + public TextureDraw01ES2Listener(TextureData td) { + this.textureData = td; + } + + static final String[] es2_prelude = { "#version 100\n", "precision mediump float;\n" }; + static final String gl2_prelude = "#version 110\n"; + static final String shaderBasename = "texture01_xxx"; + + private void initShader(GL2ES2 gl, boolean use_program) { + // Create & Compile the shader objects + ShaderCode rsVp = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, this.getClass(), + "shader", "shader/bin", shaderBasename, true); + ShaderCode rsFp = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, this.getClass(), + "shader", "shader/bin", shaderBasename, true); + + // Prelude shader code w/ GLSL profile specifics [ 1. pre-proc, 2. other ] + int rsFpPos; + if(gl.isGLES2()) { + rsVp.insertShaderSource(0, 0, es2_prelude[0]); + rsFpPos = rsFp.insertShaderSource(0, 0, es2_prelude[0]); + } else { + rsVp.insertShaderSource(0, 0, gl2_prelude); + rsFpPos = rsFp.insertShaderSource(0, 0, gl2_prelude); + } + if(gl.isGLES2()) { + rsFpPos = rsFp.insertShaderSource(0, rsFpPos, es2_prelude[1]); + } + + // Create & Link the shader program + ShaderProgram sp = new ShaderProgram(); + sp.add(rsVp); + sp.add(rsFp); + if(!sp.link(gl, System.err)) { + throw new GLException("Couldn't link program: "+sp); + } + + // Let's manage all our states using ShaderState. + st = new ShaderState(); + st.attachShaderProgram(gl, sp, use_program); + } + + public void init(GLAutoDrawable glad) { + if(null!=textureData) { + this.texture = TextureIO.newTexture(glad.getGL(), textureData); + } + GL2ES2 gl = glad.getGL().getGL2ES2(); + + initShader(gl, true); + + // setup mgl_PMVMatrix + pmvMatrix = new PMVMatrix(); + pmvMatrix.glMatrixMode(PMVMatrix.GL_PROJECTION); + pmvMatrix.glLoadIdentity(); + pmvMatrix.glMatrixMode(PMVMatrix.GL_MODELVIEW); + pmvMatrix.glLoadIdentity(); + pmvMatrixUniform = new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()); // P, Mv + + st.ownUniform(pmvMatrixUniform); + if(!st.uniform(gl, pmvMatrixUniform)) { + throw new GLException("Error setting PMVMatrix in shader: "+st); + } + if(!st.uniform(gl, new GLUniformData("mgl_ActiveTexture", 0))) { + throw new GLException("Error setting mgl_ActiveTexture in shader: "+st); + } + + // fetch the flipped texture coordinates + texture.getImageTexCoords().getST_LB_RB_LT_RT(s_quadTexCoords, 0, 1f, 1f); + + interleavedVBO = GLArrayDataServer.createGLSLInterleaved(3+4+2, GL.GL_FLOAT, false, 3*4, GL.GL_STATIC_DRAW); + { + interleavedVBO.addGLSLSubArray("mgl_Vertex", 3, GL.GL_ARRAY_BUFFER); + interleavedVBO.addGLSLSubArray("mgl_Color", 4, GL.GL_ARRAY_BUFFER); + //interleavedVBO.addGLSLSubArray("mgl_Normal", 3, GL.GL_ARRAY_BUFFER); + interleavedVBO.addGLSLSubArray("mgl_MultiTexCoord", 2, GL.GL_ARRAY_BUFFER); + + FloatBuffer ib = (FloatBuffer)interleavedVBO.getBuffer(); + + for(int i=0; i<4; i++) { + ib.put(s_quadVertices, i*3, 3); + ib.put(s_quadColors, i*4, 4); + //ib.put(s_cubeNormals, i*3, 3); + ib.put(s_quadTexCoords, i*2, 2); + } + } + interleavedVBO.seal(gl, true); + interleavedVBO.enableBuffer(gl, false); + st.ownAttribute(interleavedVBO, true); + + // OpenGL Render Settings + gl.glClearColor(0, 0, 0, 1); + gl.glEnable(GL2ES2.GL_DEPTH_TEST); + st.useProgram(gl, false); + } + + public Texture getTexture( ) { + return this.texture; + } + + /** + public void setTextureData(GL gl, TextureData textureData ) { + if(null!=texture) { + texture.disable(gl); + texture.destroy(gl); + } + if(null!=this.textureData) { + this.textureData.destroy(); + } + this.textureData = textureData; + this.texture = TextureIO.newTexture(this.textureData); + + // fix VBO ! + } */ + + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + GL2ES2 gl = drawable.getGL().getGL2ES2(); + + gl.glViewport(0, 0, width, height); + + // Clear background to white + gl.glClearColor(1.0f, 1.0f, 1.0f, 0.4f); + + if(null != st) { + pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION); + pmvMatrix.glLoadIdentity(); + pmvMatrix.glOrthof(-1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 10.0f); + + pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); + pmvMatrix.glLoadIdentity(); + + st.useProgram(gl, true); + st.uniform(gl, pmvMatrixUniform); + st.useProgram(gl, false); + } + } + + public void dispose(GLAutoDrawable drawable) { + GL2ES2 gl = drawable.getGL().getGL2ES2(); + if(null!=texture) { + texture.disable(gl); + texture.destroy(gl); + } + if(null!=textureData) { + textureData.destroy(); + } + + pmvMatrixUniform = null; + pmvMatrix.destroy(); + pmvMatrix=null; + st.destroy(gl); + st=null; + } + + public void display(GLAutoDrawable drawable) { + GL2ES2 gl = drawable.getGL().getGL2ES2(); + + gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); + + st.useProgram(gl, true); + interleavedVBO.enableBuffer(gl, true); + gl.glActiveTexture(GL.GL_TEXTURE0); + texture.enable(gl); + texture.bind(gl); + + gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4); + + texture.disable(gl); + interleavedVBO.enableBuffer(gl, false); + st.useProgram(gl, false); + } + + private static final float[] s_quadVertices = { + -1f, -1f, 0f, // LB + 1f, -1f, 0f, // RB + -1f, 1f, 0f, // LT + 1f, 1f, 0f // RT + }; + private static final float[] s_quadColors = { + 1f, 1f, 1f, 1f, + 1f, 1f, 1f, 1f, + 1f, 1f, 1f, 1f, + 1f, 1f, 1f, 1f }; + private static final float[] s_quadTexCoords = { + 0f, 0f, // LB + 1f, 0f, // RB + 0f, 1f, // LT + 1f, 1f // RT + }; +} + diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TextureSequenceCubeES2.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TextureSequenceCubeES2.java index c2fbc65af..b04bd07c1 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TextureSequenceCubeES2.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TextureSequenceCubeES2.java @@ -146,9 +146,9 @@ public class TextureSequenceCubeES2 implements GLEventListener { private void initShader(GL2ES2 gl) { // Create & Compile the shader objects - ShaderCode rsVp = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, TextureSequenceCubeES2.class, + ShaderCode rsVp = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, this.getClass(), "shader", "shader/bin", shaderBasename, true); - ShaderCode rsFp = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, TextureSequenceCubeES2.class, + ShaderCode rsFp = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, this.getClass(), "shader", "shader/bin", shaderBasename, true); // Prelude shader code w/ GLSL profile specifics [ 1. pre-proc, 2. other ] @@ -205,7 +205,7 @@ public class TextureSequenceCubeES2 implements GLEventListener { pmvMatrix = new PMVMatrix(); reshapePMV(drawable.getWidth(), drawable.getHeight()); - pmvMatrixUniform = new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()); + pmvMatrixUniform = new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()); // P, Mv if(!st.uniform(gl, pmvMatrixUniform)) { throw new GLException("Error setting PMVMatrix in shader: "+st); } @@ -214,6 +214,8 @@ public class TextureSequenceCubeES2 implements GLEventListener { } + // calculate centered tex coords w/ aspect ratio + float[] fixedCubeTexCoords = new float[s_cubeTexCoords.length]; { final float aspect = tex.getAspectRatio(); final TextureCoords tc = tex.getImageTexCoords(); @@ -228,17 +230,16 @@ public class TextureSequenceCubeES2 implements GLEventListener { final float tx = s_cubeTexCoords[i+0]; final float ty = s_cubeTexCoords[i+1]; if(tx!=0) { - s_cubeTexCoords[i+0] = tc_x1 * ss; + fixedCubeTexCoords[i+0] = tc_x1 * ss; } if(ty==0 && !tex.getMustFlipVertically() || ty!=0 && tex.getMustFlipVertically()) { - s_cubeTexCoords[i+1] = 0f + dy; + fixedCubeTexCoords[i+1] = 0f + dy; } else { - s_cubeTexCoords[i+1] = tc_y1 * ts + dy; + fixedCubeTexCoords[i+1] = tc_y1 * ts + dy; } } } - - + interleavedVBO = GLArrayDataServer.createGLSLInterleaved(3+4+2, GL.GL_FLOAT, false, 3*6*4, GL.GL_STATIC_DRAW); { interleavedVBO.addGLSLSubArray("mgl_Vertex", 3, GL.GL_ARRAY_BUFFER); @@ -252,7 +253,7 @@ public class TextureSequenceCubeES2 implements GLEventListener { ib.put(s_cubeVertices, i*3, 3); ib.put(s_cubeColors, i*4, 4); //ib.put(s_cubeNormals, i*3, 3); - ib.put(s_cubeTexCoords, i*2, 2); + ib.put(fixedCubeTexCoords, i*2, 2); } } interleavedVBO.seal(gl, true); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texture01_xxx.fp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texture01_xxx.fp new file mode 100644 index 000000000..1a4254163 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texture01_xxx.fp @@ -0,0 +1,20 @@ +// Copyright 2012 JogAmp Community. All rights reserved. + +varying vec2 mgl_texCoord; +varying vec4 frontColor; + +uniform sampler2D mgl_ActiveTexture; + +void main (void) +{ + vec4 texColor; + if(0.0 <= mgl_texCoord.t && mgl_texCoord.t<=1.0) { + texColor = texture2D(mgl_ActiveTexture, mgl_texCoord); + } else { + texColor = vec4(1, 1, 1, 1); + } + + // mix frontColor with texture .. + gl_FragColor = vec4(frontColor*texColor); +} + diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texture01_xxx.vp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texture01_xxx.vp new file mode 100644 index 000000000..c521e3757 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texture01_xxx.vp @@ -0,0 +1,17 @@ +// Copyright 2012 JogAmp Community. All rights reserved. + +uniform mat4 mgl_PMVMatrix[2]; +// uniform mat4 mgl_STMatrix; +attribute vec4 mgl_Vertex; +attribute vec4 mgl_Color; +attribute vec4 mgl_MultiTexCoord; +varying vec4 frontColor; +varying vec2 mgl_texCoord; + +void main(void) +{ + frontColor=mgl_Color; + // mgl_texCoord = (mgl_STMatrix * mgl_MultiTexCoord).st; + mgl_texCoord = mgl_MultiTexCoord.st; + gl_Position = mgl_PMVMatrix[0] * mgl_PMVMatrix[1] * mgl_Vertex; +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/TextureDraw01GL2Listener.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/TextureDraw01GL2Listener.java new file mode 100644 index 000000000..af30c265b --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/TextureDraw01GL2Listener.java @@ -0,0 +1,104 @@ +/** + * 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.demos.gl2; + +import com.jogamp.opengl.test.junit.jogl.demos.TextureDraw01Accessor; +import com.jogamp.opengl.util.texture.Texture; +import com.jogamp.opengl.util.texture.TextureCoords; +import com.jogamp.opengl.util.texture.TextureData; +import com.jogamp.opengl.util.texture.TextureIO; +import javax.media.opengl.GL2ES1; +import javax.media.opengl.GL2; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.glu.GLU; + +public class TextureDraw01GL2Listener implements GLEventListener, TextureDraw01Accessor { + private GLU glu = new GLU(); + private TextureData textureData; + private Texture texture; + + public TextureDraw01GL2Listener(TextureData td) { + this.textureData = td; + } + + public void init(GLAutoDrawable drawable) { + if(null!=textureData) { + this.texture = TextureIO.newTexture(drawable.getGL(), textureData); + } + } + + public Texture getTexture( ) { + return this.texture; + } + + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + GL2 gl = drawable.getGL().getGL2(); + gl.glMatrixMode(GL2ES1.GL_PROJECTION); + gl.glLoadIdentity(); + glu.gluOrtho2D(0, 1, 0, 1); + gl.glMatrixMode(GL2ES1.GL_MODELVIEW); + gl.glLoadIdentity(); + } + + public void dispose(GLAutoDrawable drawable) { + GL2 gl = drawable.getGL().getGL2(); + if(null!=texture) { + texture.disable(gl); + texture.destroy(gl); + } + if(null!=textureData) { + textureData.destroy(); + } + } + + public void display(GLAutoDrawable drawable) { + GL2 gl = drawable.getGL().getGL2(); + + // draw one quad with the texture + if(null!=texture) { + texture.enable(gl); + texture.bind(gl); + gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_REPLACE); + TextureCoords coords = texture.getImageTexCoords(); + gl.glBegin(GL2.GL_QUADS); + gl.glTexCoord2f(coords.left(), coords.bottom()); + gl.glVertex3f(0, 0, 0); + gl.glTexCoord2f(coords.right(), coords.bottom()); + gl.glVertex3f(1, 0, 0); + gl.glTexCoord2f(coords.right(), coords.top()); + gl.glVertex3f(1, 1, 0); + gl.glTexCoord2f(coords.left(), coords.top()); + gl.glVertex3f(0, 1, 0); + gl.glEnd(); + texture.disable(gl); + } + } +} + diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/TestPNGImage01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/TestPNGImage01NEWT.java index 5a0c18de7..c7e975ff6 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/util/TestPNGImage01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/TestPNGImage01NEWT.java @@ -18,7 +18,7 @@ public class TestPNGImage01NEWT extends UITestCase { final File out1_f=new File(getSimpleTestName(".")+"-PNGImageTest1.png"); final File out2_f=new File(getSimpleTestName(".")+"-PNGImageTest2.png"); final String url_s="jogl/util/data/av/test-ntsc01-160x90.png"; - URLConnection urlConn = IOUtil.getResource(url_s, PNGImage.class.getClassLoader()); + URLConnection urlConn = IOUtil.getResource(url_s, this.getClass().getClassLoader()); PNGImage image0 = PNGImage.read(urlConn.getInputStream()); System.err.println("PNGImage - Orig: "+image0); image0.write(out1_f, true); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestGrayTextureFromFileAWTBug417.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestGrayTextureFromFileAWTBug417.java deleted file mode 100644 index a1e453fda..000000000 --- a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestGrayTextureFromFileAWTBug417.java +++ /dev/null @@ -1,149 +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 com.jogamp.opengl.test.junit.util.UITestCase; - -import javax.media.opengl.GLAutoDrawable; -import javax.media.opengl.GLException; -import javax.media.opengl.GLProfile; -import javax.media.opengl.GLCapabilities; -import javax.media.opengl.awt.GLCanvas; -import com.jogamp.opengl.util.texture.TextureIO; -import com.jogamp.opengl.util.Animator; - -import java.awt.Frame; - -import java.io.IOException; -import java.io.InputStream; - -import org.junit.Assert; -import org.junit.After; -import org.junit.Assume; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * Unit test for bug 417, which shows a GLException when reading a grayscale texture. - * Couldn't duplicate the failure, so it must have been fixed unknowingly sometime - * after the bug was submitted. - * @author Wade Walker - */ -public class TestGrayTextureFromFileAWTBug417 extends UITestCase { - static GLProfile glp; - static GLCapabilities caps; - InputStream textureStream; - - @BeforeClass - public static void initClass() { - if(!GLProfile.isAvailable(GLProfile.GL2GL3)) { - UITestCase.setTestSupported(false); - return; - } - glp = GLProfile.getGL2GL3(); - Assert.assertNotNull(glp); - caps = new GLCapabilities(glp); - Assert.assertNotNull(caps); - } - - @Before - public void initTest() { - textureStream = TestGrayTextureFromFileAWTBug417.class.getResourceAsStream( "grayscale_texture.png" ); - Assert.assertNotNull(textureStream); - } - - @After - public void cleanupTest() { - textureStream=null; - } - - @Test - public void test1() throws InterruptedException { - final GLCanvas glCanvas = new GLCanvas(caps); - final Frame frame = new Frame("Texture Test"); - Assert.assertNotNull(frame); - frame.add(glCanvas); - frame.setSize( 256, 128 ); - - // load texture from file inside current GL context to match the way - // the bug submitter was doing it - glCanvas.addGLEventListener(new TextureGL2ListenerDraw1( null ) { - @Override - public void init(GLAutoDrawable drawable) { - try { - setTexture( TextureIO.newTexture( textureStream, true, TextureIO.PNG ) ); - } - catch(GLException glexception) { - glexception.printStackTrace(); - Assume.assumeNoException(glexception); - } - catch(IOException ioexception) { - ioexception.printStackTrace(); - Assume.assumeNoException(ioexception); - } - } - }); - - Animator animator = new Animator(glCanvas); - frame.setVisible(true); - animator.start(); - - Thread.sleep(500); // 500 ms - - animator.stop(); - try { - javax.swing.SwingUtilities.invokeAndWait(new Runnable() { - public void run() { - frame.setVisible(false); - frame.remove(glCanvas); - frame.dispose(); - }}); - } catch( Throwable throwable ) { - throwable.printStackTrace(); - Assume.assumeNoException( throwable ); - } - } - - public static void main(String args[]) throws IOException { - String tstname = TestGrayTextureFromFileAWTBug417.class.getName(); - org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { - tstname, - "filtertrace=true", - "haltOnError=false", - "haltOnFailure=false", - "showoutput=true", - "outputtoformatters=true", - "logfailedtests=true", - "logtestlistenerevents=true", - "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", - "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); - } -} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPNGTextureFromFileAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPNGTextureFromFileAWT.java new file mode 100644 index 000000000..068732696 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPNGTextureFromFileAWT.java @@ -0,0 +1,238 @@ +/** + * 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 com.jogamp.common.util.IOUtil; +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.jogl.demos.gl2.TextureDraw01GL2Listener; +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 javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLProfile; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.awt.GLCanvas; + +import com.jogamp.opengl.util.texture.TextureData; +import com.jogamp.opengl.util.texture.TextureIO; +import com.jogamp.opengl.util.texture.spi.TextureProvider; +import com.jogamp.opengl.util.Animator; +import com.jogamp.opengl.util.GLReadBufferUtil; + +import java.awt.Dimension; +import java.awt.Frame; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URLConnection; + +import org.junit.Assert; +import org.junit.After; +import org.junit.Assume; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Unit test for bug 417, which shows a GLException when reading a grayscale texture. + * Couldn't duplicate the failure, so it must have been fixed unknowingly sometime + * after the bug was submitted. + * @author Wade Walker, et.al. + */ +public class TestPNGTextureFromFileAWT extends UITestCase { + static boolean showFPS = false; + static long duration = 100; // ms + InputStream grayTextureStream; + InputStream testTextureStream; + + @BeforeClass + public static void initClass() { + } + + @Before + public void initTest() throws IOException { + grayTextureStream = TestPNGTextureFromFileAWT.class.getResourceAsStream( "grayscale_texture.png" ); + Assert.assertNotNull(grayTextureStream); + URLConnection testTextureUrlConn = IOUtil.getResource("jogl/util/data/av/test-ntsc01-160x90.png", this.getClass().getClassLoader()); + Assert.assertNotNull(testTextureUrlConn); + testTextureStream = testTextureUrlConn.getInputStream(); + Assert.assertNotNull(testTextureStream); + } + + @After + public void cleanupTest() { + grayTextureStream = null; + testTextureStream = null; + } + + protected void snapshot(GLAutoDrawable drawable, String filename) { + GLReadBufferUtil screenshot = new GLReadBufferUtil(false, false); + if(screenshot.readPixels(drawable.getGL(), drawable, false)) { + screenshot.write(new File(filename)); + } + } + + public void testImpl(boolean useFFP, final InputStream istream, final boolean useAWTIIOP) + throws InterruptedException, IOException + { + GLProfile glp; + if(useFFP && GLProfile.isAvailable(GLProfile.GL2GL3)) { + glp = GLProfile.getGL2GL3(); + } else if(!useFFP && GLProfile.isAvailable(GLProfile.GL2ES2)) { + glp = GLProfile.getGL2ES2(); + } else { + System.err.println(getSimpleTestName(".")+": GLProfile n/a, useFFP: "+useFFP); + return; + } + final GLCapabilities caps = new GLCapabilities(glp); + final TextureData texData; + if(useAWTIIOP) { + final TextureProvider texProvider = new com.jogamp.opengl.util.texture.spi.awt.IIOTextureProvider(); + texData = texProvider.newTextureData(glp, istream, 0 /* internalFormat */, 0 /* pixelFormat */, false /* mipmap */, TextureIO.PNG); + } else { + texData = TextureIO.newTextureData(glp, istream, false /* mipmap */, TextureIO.PNG); + } + System.err.println("TextureData: "+texData); + + final GLCanvas glc = new GLCanvas(caps); + Dimension glc_sz = new Dimension(texData.getWidth(), texData.getHeight()); + glc.setMinimumSize(glc_sz); + glc.setPreferredSize(glc_sz); + final Frame frame = new Frame("TestPNGTextureGL2FromFileAWT"); + Assert.assertNotNull(frame); + frame.add(glc); + + // load texture from file inside current GL context to match the way + // the bug submitter was doing it + final GLEventListener gle = useFFP ? new TextureDraw01GL2Listener( texData ) : new TextureDraw01ES2Listener( texData ) ; + glc.addGLEventListener(gle); + glc.addGLEventListener(new GLEventListener() { + boolean shot = false; + + @Override public void init(GLAutoDrawable drawable) {} + + @Override + public void display(GLAutoDrawable drawable) { + // 1 snapshot + if(null!=((TextureDraw01Accessor)gle).getTexture() && !shot) { + shot = true; + snapshot(drawable, getSimpleTestName(".")+".png"); + } + } + + @Override public void dispose(GLAutoDrawable drawable) { } + @Override public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { } + }); + + Animator animator = new Animator(glc); + animator.setUpdateFPSFrames(60, showFPS ? System.err : null); + QuitAdapter quitAdapter = new QuitAdapter(); + new com.jogamp.newt.event.awt.AWTKeyAdapter(quitAdapter).addTo(glc); + new com.jogamp.newt.event.awt.AWTWindowAdapter(quitAdapter).addTo(glc); + try { + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame.pack(); + frame.setVisible(true); + }}); + } catch( Throwable throwable ) { + throwable.printStackTrace(); + Assume.assumeNoException( throwable ); + } + animator.start(); + + while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration()