From 7f341c7bc0d0f5770191bb58f2c0053c3453bc8a Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 17 Jun 2012 18:21:59 +0200 Subject: Unit Test: Cleanup TextureSequence Demo Code and Tests, adding AWT Test 'launcher' --- .../test/junit/jogl/demos/TestTextureSequence.java | 120 ----- .../junit/jogl/demos/TextureSequenceDemo01.java | 120 +++++ .../test/junit/jogl/demos/es2/TexCubeES2.java | 507 --------------------- .../jogl/demos/es2/TextureSequenceCubeES2.java | 456 ++++++++++++++++++ .../test/junit/jogl/demos/es2/av/MovieCube.java | 6 +- .../util/texture/TestTextureSequence01AWT.java | 112 +++++ .../util/texture/TestTextureSequence01NEWT.java | 99 ++++ 7 files changed, 790 insertions(+), 630 deletions(-) delete mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/TestTextureSequence.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/TextureSequenceDemo01.java delete mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TexCubeES2.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TextureSequenceCubeES2.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestTextureSequence01AWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestTextureSequence01NEWT.java (limited to 'src/test/com/jogamp/opengl') diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/TestTextureSequence.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/TestTextureSequence.java deleted file mode 100644 index 6dfb11855..000000000 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/TestTextureSequence.java +++ /dev/null @@ -1,120 +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 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; -import com.jogamp.opengl.util.texture.TextureIO; -import com.jogamp.opengl.util.texture.TextureSequence; - -public class TestTextureSequence 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 TestTextureSequence(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-160x90.png", NullGLMediaPlayer.class.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 getTextureUnit() { - return textureUnit; - } - - @Override - public int[] getTextureMinMagFilter() { - return texMinMagFilter; - } - - @Override - public int[] getTextureWrapST() { - return texWrapST; - } - - @Override - public TextureSequence.TextureFrame getLastTexture() throws IllegalStateException { - return frame; // may return null - } - - @Override - public TextureSequence.TextureFrame getNextTexture(GL gl, boolean blocking) 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/TextureSequenceDemo01.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/TextureSequenceDemo01.java new file mode 100644 index 000000000..a1d4b4466 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/TextureSequenceDemo01.java @@ -0,0 +1,120 @@ +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 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; +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-160x90.png", NullGLMediaPlayer.class.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 getTextureUnit() { + return textureUnit; + } + + @Override + public int[] getTextureMinMagFilter() { + return texMinMagFilter; + } + + @Override + public int[] getTextureWrapST() { + return texWrapST; + } + + @Override + public TextureSequence.TextureFrame getLastTexture() throws IllegalStateException { + return frame; // may return null + } + + @Override + public TextureSequence.TextureFrame getNextTexture(GL gl, boolean blocking) 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/es2/TexCubeES2.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TexCubeES2.java deleted file mode 100644 index e85468bcb..000000000 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TexCubeES2.java +++ /dev/null @@ -1,507 +0,0 @@ -/** - * 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.ByteBuffer; -import java.nio.FloatBuffer; - -import javax.media.opengl.GL; -import javax.media.opengl.GL2ES2; -import javax.media.opengl.GLAutoDrawable; -import javax.media.opengl.GLCapabilities; -import javax.media.opengl.GLES2; -import javax.media.opengl.GLEventListener; -import javax.media.opengl.GLException; -import javax.media.opengl.GLProfile; -import javax.media.opengl.GLUniformData; -import javax.media.opengl.fixedfunc.GLMatrixFunc; - -import com.jogamp.newt.Window; -import com.jogamp.newt.event.MouseAdapter; -import com.jogamp.newt.event.MouseEvent; -import com.jogamp.newt.event.MouseListener; -import com.jogamp.newt.event.WindowAdapter; -import com.jogamp.newt.event.WindowEvent; -import com.jogamp.newt.opengl.GLWindow; -import com.jogamp.opengl.JoglVersion; -import com.jogamp.opengl.test.junit.jogl.demos.TestTextureSequence; -import com.jogamp.opengl.test.junit.util.MiscUtils; -import com.jogamp.opengl.util.Animator; -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.TextureCoords; -import com.jogamp.opengl.util.texture.TextureSequence; - -public class TexCubeES2 implements GLEventListener { - public TexCubeES2 (TextureSequence texSource, boolean innerCube, float zoom0, float rotx, float roty) { - this.texSeq = texSource; - this.innerCube = innerCube; - this.zoom0 = zoom0; - this.view_rotx = rotx; - this.view_roty = roty; - } - - private TextureSequence texSeq; - private ShaderState st; - private PMVMatrix pmvMatrix; - private GLUniformData pmvMatrixUniform; - // private TextureCoords[] textureCoords = null; - private float nearPlaneNormalized; - // private float zoom0=-5.0f, zoom=zoom0; - // private float view_rotx = 20.0f, view_roty = 30.0f, view_rotz = 0.0f; - private float zoom0=-2.3f, zoom=zoom0; - private float view_rotx = 0.0f, view_roty = 0.0f, view_rotz = 0.0f; - int[] vboNames = new int[4]; - boolean innerCube; - boolean initialized = false; - private ByteBuffer cubeIndices; - - private final MouseListener mouseAction = new MouseAdapter() { - int lx = 0; - int ly = 0; - boolean first = false; - - public void mousePressed(MouseEvent e) { - first = true; - } - public void mouseMoved(MouseEvent e) { - first = false; - } - public void mouseDragged(MouseEvent e) { - int width, height; - Object source = e.getSource(); - Window window = null; - if(source instanceof Window) { - window = (Window) source; - width=window.getWidth(); - height=window.getHeight(); - } else if (GLProfile.isAWTAvailable() && source instanceof java.awt.Component) { - java.awt.Component comp = (java.awt.Component) source; - width=comp.getWidth(); - height=comp.getHeight(); - } else { - throw new RuntimeException("Event source neither Window nor Component: "+source); - } - if(e.getPointerCount()==2) { - // 2 pointers zoom .. - if(first) { - lx = Math.abs(e.getY(0)-e.getY(1)); - first=false; - return; - } - int nv = Math.abs(e.getY(0)-e.getY(1)); - int dy = nv - lx; - - zoom += 40f*Math.signum(dy)/(float)height; - - lx = nv; - } else { - // 1 pointer rotate - if(first) { - lx = e.getX(); - ly = e.getY(); - first=false; - return; - } - int nx = e.getX(); - int ny = e.getY(); - view_roty += 360f * ( (float)( nx - lx ) / (float)width ); - view_rotx += 360f * ( (float)( ny - ly ) / (float)height ); - lx = nx; - ly = ny; - } - } - public void mouseWheelMoved(MouseEvent e) { - zoom += e.getWheelRotation()/10f; - System.err.println("zoom: "+zoom); - } - }; - - static final String[] es2_prelude = { "#version 100\n", "precision mediump float;\n" }; - static final String gl2_prelude = "#version 110\n"; - static final String shaderBasename = "texsequence_xxx"; - static final String myTextureLookupName = "myTexture2D"; - - private void initShader(GL2ES2 gl) { - // Create & Compile the shader objects - ShaderCode rsVp = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, TexCubeES2.class, - "shader", "shader/bin", shaderBasename, true); - ShaderCode rsFp = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, TexCubeES2.class, - "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); - } - rsFpPos = rsFp.insertShaderSource(0, rsFpPos, texSeq.getRequiredExtensionsShaderStub()); - if(gl.isGLES2()) { - rsFpPos = rsFp.insertShaderSource(0, rsFpPos, es2_prelude[1]); - } - final String texLookupFuncName = texSeq.getTextureLookupFunctionName(myTextureLookupName); - rsFp.replaceInShaderSource(myTextureLookupName, texLookupFuncName); - - // Inject TextureSequence shader details - final StringBuilder sFpIns = new StringBuilder(); - sFpIns.append("uniform ").append(texSeq.getTextureSampler2DType()).append(" mgl_ActiveTexture;\n"); - sFpIns.append(texSeq.getTextureLookupFragmentShaderImpl()); - rsFp.insertShaderSource(0, "TEXTURE-SEQUENCE-CODE-BEGIN", 0, sFpIns); - - // 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, false); - } - - GLArrayDataServer interleavedVBO; - - public void init(GLAutoDrawable drawable) { - GL2ES2 gl = drawable.getGL().getGL2ES2(); - System.err.println(JoglVersion.getGLInfo(gl, null)); - final Texture tex= texSeq.getLastTexture().getTexture(); - - final boolean useExternalTexture = GLES2.GL_TEXTURE_EXTERNAL_OES == tex.getTarget(); - if(useExternalTexture && !gl.isExtensionAvailable("GL_OES_EGL_image_external")) { - throw new GLException("GL_OES_EGL_image_external requested but not available"); - } - - initShader(gl); - - // Push the 1st uniform down the path - st.useProgram(gl, true); - - pmvMatrix = new PMVMatrix(); - reshapePMV(drawable.getWidth(), drawable.getHeight()); - pmvMatrixUniform = new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()); - if(!st.uniform(gl, pmvMatrixUniform)) { - throw new GLException("Error setting PMVMatrix in shader: "+st); - } - if(!st.uniform(gl, new GLUniformData("mgl_ActiveTexture", texSeq.getTextureUnit()))) { - throw new GLException("Error setting mgl_ActiveTexture in shader: "+st); - } - - - { - final float aspect = tex.getAspectRatio(); - final TextureCoords tc = tex.getImageTexCoords(); - System.err.println("XXX0: aspect: "+aspect); - System.err.println("XXX0: y-flip: "+tex.getMustFlipVertically()); - System.err.println("XXX0: "+tc); - final float tc_x1 = Math.max(tc.left(), tc.right()); - final float tc_y1 = Math.max(tc.bottom(), tc.top()); - final float ss=1f, ts=aspect; // scale tex-coord - final float dy = ( 1f - aspect ) / 2f ; - for(int i=0; i