From b222d19e5f45fc3683b58dd788262597a1e14635 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 10 Apr 2014 06:52:16 +0200 Subject: Reduce jar-size / cleanup: Replace 1 kB test-ntsc01-57x32.png w/ 400kB test-ntsc01-28x16.png asset ; Generalize TextureSequenceDemo01 -> SingleTextureSeqFrame ; Unit tests use test-data, not assets. --- .../junit/jogl/demos/TextureSequenceDemo01.java | 126 --------------------- .../opengl/test/junit/jogl/demos/gl2/Teapot.java | 23 ++-- .../jogl/util/DemoGL2ES1TextureImmModeSink.java | 17 +-- .../jogl/util/texture/SingleTextureSeqFrame.java | 126 +++++++++++++++++++++ .../util/texture/TestTextureSequence01AWT.java | 28 ++--- .../util/texture/TestTextureSequence01NEWT.java | 22 ++-- 6 files changed, 172 insertions(+), 170 deletions(-) delete mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/TextureSequenceDemo01.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/util/texture/SingleTextureSeqFrame.java (limited to 'src/test/com/jogamp/opengl') 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 deleted file mode 100644 index 7034f2c67..000000000 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/TextureSequenceDemo01.java +++ /dev/null @@ -1,126 +0,0 @@ -package com.jogamp.opengl.test.junit.jogl.demos; - -import java.net.URLConnection; - -import javax.media.opengl.GL; -import javax.media.opengl.GLException; -import javax.media.opengl.GLProfile; - -import com.jogamp.common.util.IOUtil; -import com.jogamp.opengl.util.texture.Texture; -import com.jogamp.opengl.util.texture.TextureData; -import com.jogamp.opengl.util.texture.TextureIO; -import com.jogamp.opengl.util.texture.TextureSequence; - -public class TextureSequenceDemo01 implements TextureSequence { - TextureSequence.TextureFrame frame = null; - int textureUnit = 0; - protected int[] texMinMagFilter = { GL.GL_NEAREST, GL.GL_NEAREST }; - protected int[] texWrapST = { GL.GL_CLAMP_TO_EDGE, GL.GL_CLAMP_TO_EDGE }; - final boolean useBuildInTexLookup; - - public TextureSequenceDemo01(boolean useBuildInTexLookup) { - this.useBuildInTexLookup = useBuildInTexLookup; - } - - public void initGLResources(GL gl) throws GLException { - if(null == frame) { - TextureData texData = null; - try { - URLConnection urlConn = IOUtil.getResource("jogl/util/data/av/test-ntsc01-57x32.png", this.getClass().getClassLoader()); - if(null != urlConn) { - texData = TextureIO.newTextureData(GLProfile.getGL2ES2(), urlConn.getInputStream(), false, TextureIO.PNG); - } - } catch (Exception e) { - e.printStackTrace(); - } - final Texture tex = new Texture(gl, texData); - frame = new TextureSequence.TextureFrame(tex); - tex.bind(gl); - gl.glTexParameteri(tex.getTarget(), GL.GL_TEXTURE_MIN_FILTER, texMinMagFilter[0]); - gl.glTexParameteri(tex.getTarget(), GL.GL_TEXTURE_MAG_FILTER, texMinMagFilter[1]); - gl.glTexParameteri(tex.getTarget(), GL.GL_TEXTURE_WRAP_S, texWrapST[0]); - gl.glTexParameteri(tex.getTarget(), GL.GL_TEXTURE_WRAP_T, texWrapST[1]); - } - } - - public void destroyGLResources(GL gl) { - if(null != frame) { - frame.getTexture().destroy(gl); - frame = null; - } - } - - public void destroy(GL gl) throws GLException { - frame.getTexture().destroy(gl); - frame = null; - } - - @Override - public int getTextureTarget() { - return GL.GL_TEXTURE_2D; - } - - @Override - public int getTextureUnit() { - return textureUnit; - } - - @Override - public int[] getTextureMinMagFilter() { - return texMinMagFilter; - } - - @Override - public int[] getTextureWrapST() { - return texWrapST; - } - - @Override - public boolean isTextureAvailable() { return true; } - - @Override - public TextureSequence.TextureFrame getLastTexture() throws IllegalStateException { - return frame; // may return null - } - - @Override - public TextureSequence.TextureFrame getNextTexture(GL gl) throws IllegalStateException { - return frame; - } - - @Override - public String getRequiredExtensionsShaderStub() throws IllegalStateException { - return "// TextTextureSequence: No extensions required\n"; - } - - @Override - public String getTextureSampler2DType() throws IllegalStateException { - return "sampler2D" ; - } - - private String textureLookupFunctionName = "myTexture2D"; - - @Override - public String getTextureLookupFunctionName(String desiredFuncName) throws IllegalStateException { - if(useBuildInTexLookup) { - return "texture2D"; - } - if(null != desiredFuncName && desiredFuncName.length()>0) { - textureLookupFunctionName = desiredFuncName; - } - return textureLookupFunctionName; - } - - @Override - public String getTextureLookupFragmentShaderImpl() throws IllegalStateException { - if(useBuildInTexLookup) { - return ""; - } - return - "\n"+ - "vec4 "+textureLookupFunctionName+"(in "+getTextureSampler2DType()+" image, in vec2 texCoord) {\n"+ - " return texture2D(image, texCoord);\n"+ - "}\n\n"; - } -} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/Teapot.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/Teapot.java index dac917ee2..64e4472c0 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/Teapot.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/Teapot.java @@ -8,6 +8,7 @@ import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLEventListener; import com.jogamp.common.util.IOUtil; +import com.jogamp.opengl.test.junit.jogl.util.texture.PNGTstFiles; import com.jogamp.opengl.util.gl2.GLUT; import com.jogamp.opengl.util.texture.Texture; import com.jogamp.opengl.util.texture.TextureIO; @@ -21,8 +22,8 @@ public class Teapot implements GLEventListener { private GLUT glut; /* glTexGen stuff: */ - private float sgenparams[] = { 1.0f, 1.0f, 1.0f, 0.0f }; - + private final float sgenparams[] = { 1.0f, 1.0f, 1.0f, 0.0f }; + private Texture tex = null; @Override @@ -33,7 +34,7 @@ public class Teapot implements GLEventListener { gl.glClearColor(0.5f, 0.5f, 0.5f, 0.0f); try { - URLConnection urlConn = IOUtil.getResource("jogl/util/data/av/test-ntsc01-57x32.png", this.getClass().getClassLoader()); + URLConnection urlConn = IOUtil.getResource(PNGTstFiles.class, "test-ntscP_3-01-160x90.png"); tex = TextureIO.newTexture(gl, TextureIO.newTextureData(gl.getGLProfile(), urlConn.getInputStream(), false, TextureIO.PNG)); } catch (Exception e) { e.printStackTrace(); @@ -55,7 +56,7 @@ public class Teapot implements GLEventListener { // GL.GL_RGB, GL.GL_UNSIGNED_BYTE, stripeImageBuf); gl.glTexParameterf(GL2.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT); - + // gl.glTexGeni(GL2.GL_S, GL2.GL_TEXTURE_GEN_MODE, GL2.GL_OBJECT_LINEAR); // gl.glTexGenfv(GL2.GL_S, GL2.GL_OBJECT_PLANE, sgenparams, 0); @@ -77,14 +78,14 @@ public class Teapot implements GLEventListener { float angleZ = 0.0f; float rotDir = 1.0f; public float rotIncr = 0.4f; - + @Override public void display(GLAutoDrawable gLDrawable) { final GL2 gl = gLDrawable.getGL().getGL2(); tex.bind(gl); gl.glEnable(GL2.GL_TEXTURE_2D); - + gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glPushMatrix(); gl.glRotatef(angleZ, 0.0f, 1.0f, 0.0f); @@ -97,7 +98,7 @@ public class Teapot implements GLEventListener { } else if (angleZ <= 0.0f ) { rotDir = +1.0f; } - angleZ += rotIncr * rotDir; + angleZ += rotIncr * rotDir; } @Override @@ -108,11 +109,11 @@ public class Teapot implements GLEventListener { gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); if (w <= h) { - gl.glOrtho(-3.5, 3.5, -3.5 * (float) h / (float) w, - 3.5 * (float) h / (float) w, -3.5, 3.5); + gl.glOrtho(-3.5, 3.5, -3.5 * h / w, + 3.5 * h / w, -3.5, 3.5); } else { - gl.glOrtho(-3.5 * (float) w / (float) h, - 3.5 * (float) w / (float) h, -3.5, 3.5, -3.5, 3.5); + gl.glOrtho(-3.5 * w / h, + 3.5 * w / h, -3.5, 3.5, -3.5, 3.5); } gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/DemoGL2ES1TextureImmModeSink.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/DemoGL2ES1TextureImmModeSink.java index d776021ba..81fa5ded3 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/util/DemoGL2ES1TextureImmModeSink.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/DemoGL2ES1TextureImmModeSink.java @@ -3,14 +3,14 @@ * * 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 @@ -20,7 +20,7 @@ * 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. @@ -33,6 +33,7 @@ import java.net.URLConnection; import com.jogamp.common.util.IOUtil; import com.jogamp.opengl.test.junit.jogl.demos.TextureDraw01Accessor; +import com.jogamp.opengl.test.junit.jogl.util.texture.PNGTstFiles; import com.jogamp.opengl.util.ImmModeSink; import com.jogamp.opengl.util.glsl.fixedfunc.FixedFuncUtil; import com.jogamp.opengl.util.glsl.fixedfunc.ShaderSelectionMode; @@ -54,8 +55,8 @@ public class DemoGL2ES1TextureImmModeSink implements GLEventListener, TextureDra private boolean verboseFFPEmu = false; private boolean traceFFPEmu = false; private boolean forceFFPEmu = false; - private ImmModeSink ims; - private GLU glu = new GLU(); + private final ImmModeSink ims; + private final GLU glu = new GLU(); private TextureData textureData; private Texture texture; boolean keepTextureBound; @@ -81,7 +82,7 @@ public class DemoGL2ES1TextureImmModeSink implements GLEventListener, TextureDra public Texture getTexture( ) { return this.texture; } - + @Override public void init(GLAutoDrawable drawable) { GL _gl = drawable.getGL(); @@ -95,7 +96,7 @@ public class DemoGL2ES1TextureImmModeSink implements GLEventListener, TextureDra } GL2ES1 gl = FixedFuncUtil.wrapFixedFuncEmul(_gl, ShaderSelectionMode.AUTO, null, forceFFPEmu, verboseFFPEmu); - URLConnection testTextureUrlConn = IOUtil.getResource("jogl/util/data/av/test-ntsc01-57x32.png", this.getClass().getClassLoader()); + URLConnection testTextureUrlConn = IOUtil.getResource(PNGTstFiles.class, "test-ntscP_3-01-160x90.png"); try { InputStream testTextureStream = testTextureUrlConn.getInputStream(); textureData = TextureIO.newTextureData(gl.getGLProfile(), testTextureStream , false /* mipmap */, TextureIO.PNG); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/SingleTextureSeqFrame.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/SingleTextureSeqFrame.java new file mode 100644 index 000000000..aef48d82c --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/SingleTextureSeqFrame.java @@ -0,0 +1,126 @@ +package com.jogamp.opengl.test.junit.jogl.util.texture; + +import java.net.URLConnection; + +import javax.media.opengl.GL; +import javax.media.opengl.GLException; +import javax.media.opengl.GLProfile; + +import com.jogamp.common.util.IOUtil; +import com.jogamp.opengl.util.texture.Texture; +import com.jogamp.opengl.util.texture.TextureData; +import com.jogamp.opengl.util.texture.TextureIO; +import com.jogamp.opengl.util.texture.TextureSequence; + +public class SingleTextureSeqFrame implements TextureSequence { + TextureSequence.TextureFrame frame = null; + int textureUnit = 0; + protected int[] texMinMagFilter = { GL.GL_NEAREST, GL.GL_NEAREST }; + protected int[] texWrapST = { GL.GL_CLAMP_TO_EDGE, GL.GL_CLAMP_TO_EDGE }; + final boolean useBuildInTexLookup; + + public SingleTextureSeqFrame(boolean useBuildInTexLookup) { + this.useBuildInTexLookup = useBuildInTexLookup; + } + + public void initGLResources(GL gl, Class context, String imageResourcePath, String imageSuffix) throws GLException { + if(null == frame) { + TextureData texData = null; + try { + URLConnection urlConn = IOUtil.getResource(context, imageResourcePath); + if(null != urlConn) { + texData = TextureIO.newTextureData(GLProfile.getGL2ES2(), urlConn.getInputStream(), false, imageSuffix); + } + } catch (Exception e) { + e.printStackTrace(); + } + final Texture tex = new Texture(gl, texData); + frame = new TextureSequence.TextureFrame(tex); + tex.bind(gl); + gl.glTexParameteri(tex.getTarget(), GL.GL_TEXTURE_MIN_FILTER, texMinMagFilter[0]); + gl.glTexParameteri(tex.getTarget(), GL.GL_TEXTURE_MAG_FILTER, texMinMagFilter[1]); + gl.glTexParameteri(tex.getTarget(), GL.GL_TEXTURE_WRAP_S, texWrapST[0]); + gl.glTexParameteri(tex.getTarget(), GL.GL_TEXTURE_WRAP_T, texWrapST[1]); + } + } + + public void destroyGLResources(GL gl) { + if(null != frame) { + frame.getTexture().destroy(gl); + frame = null; + } + } + + public void destroy(GL gl) throws GLException { + frame.getTexture().destroy(gl); + frame = null; + } + + @Override + public int getTextureTarget() { + return GL.GL_TEXTURE_2D; + } + + @Override + public int getTextureUnit() { + return textureUnit; + } + + @Override + public int[] getTextureMinMagFilter() { + return texMinMagFilter; + } + + @Override + public int[] getTextureWrapST() { + return texWrapST; + } + + @Override + public boolean isTextureAvailable() { return true; } + + @Override + public TextureSequence.TextureFrame getLastTexture() throws IllegalStateException { + return frame; // may return null + } + + @Override + public TextureSequence.TextureFrame getNextTexture(GL gl) throws IllegalStateException { + return frame; + } + + @Override + public String getRequiredExtensionsShaderStub() throws IllegalStateException { + return "// TextTextureSequence: No extensions required\n"; + } + + @Override + public String getTextureSampler2DType() throws IllegalStateException { + return "sampler2D" ; + } + + private String textureLookupFunctionName = "myTexture2D"; + + @Override + public String getTextureLookupFunctionName(String desiredFuncName) throws IllegalStateException { + if(useBuildInTexLookup) { + return "texture2D"; + } + if(null != desiredFuncName && desiredFuncName.length()>0) { + textureLookupFunctionName = desiredFuncName; + } + return textureLookupFunctionName; + } + + @Override + public String getTextureLookupFragmentShaderImpl() throws IllegalStateException { + if(useBuildInTexLookup) { + return ""; + } + return + "\n"+ + "vec4 "+textureLookupFunctionName+"(in "+getTextureSampler2DType()+" image, in vec2 texCoord) {\n"+ + " return texture2D(image, texCoord);\n"+ + "}\n\n"; + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestTextureSequence01AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestTextureSequence01AWT.java index 2b3ead5b9..9dc17dce1 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestTextureSequence01AWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestTextureSequence01AWT.java @@ -15,12 +15,12 @@ import org.junit.Test; import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; -import com.jogamp.opengl.test.junit.jogl.demos.TextureSequenceDemo01; import com.jogamp.opengl.test.junit.jogl.demos.es2.TextureSequenceCubeES2; 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.texture.TextureIO; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class TestTextureSequence01AWT extends UITestCase { @@ -31,7 +31,7 @@ public class TestTextureSequence01AWT extends UITestCase { static long duration = 500; // ms static GLProfile glp; static GLCapabilities caps; - + @BeforeClass public static void initClass() { glp = GLProfile.getGL2ES2(); @@ -45,19 +45,19 @@ public class TestTextureSequence01AWT extends UITestCase { final Frame frame = new Frame("TestTextureSequence01AWT"); Assert.assertNotNull(frame); frame.add(glc); - - final TextureSequenceDemo01 texSource = new TextureSequenceDemo01(useBuildInTexLookup); + + final SingleTextureSeqFrame texSource = new SingleTextureSeqFrame(useBuildInTexLookup); glc.addGLEventListener(new GLEventListener() { @Override public void init(GLAutoDrawable drawable) { - texSource.initGLResources(drawable.getGL()); + texSource.initGLResources(drawable.getGL(), TestTextureSequence01AWT.class, "test-ntscP_3-01-160x90.png", TextureIO.PNG); } @Override public void dispose(GLAutoDrawable drawable) { } @Override public void display(GLAutoDrawable drawable) { } @Override - public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { } + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { } }); glc.addGLEventListener(new TextureSequenceCubeES2(texSource, false, -2.3f, 0f, 0f)); final Animator animator = new Animator(glc); @@ -74,13 +74,13 @@ public class TestTextureSequence01AWT extends UITestCase { } catch( Throwable throwable ) { throwable.printStackTrace(); Assume.assumeNoException( throwable ); - } + } animator.start(); - + while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration()