diff options
author | Sven Gothel <[email protected]> | 2012-04-16 21:18:03 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-04-16 21:18:03 +0200 |
commit | 35beeabffed61e1597aaffc0c5926ab5ef86d32e (patch) | |
tree | 6a7e91c07e7d61613b03f35a17486faf01b211fc /src/test/com | |
parent | 2f0583aad39f93a934629c21beac66a758373249 (diff) |
TextureSequence Shader Support; GLMediaPlayer uses 'int' where possible; General enhancments.
For details about TextureSequence/GLMediaPlayer shader collaboration w/ your own shader source,
see TextureSequence and TexCubeES2 / MovieSimple demo.
TextureSequence allows implementations to provide their own texture lookup function
which may provide color space conversion (YUV) .. or other runtime hw-accel features.
Have a look at the next commit, which provides an Libav/FFMpeg implementation w/ YUV/RGB shader conversion.
MovieCube adds keyboard control (Android: firm touch on display to launch keyboard, don't break it though :)
Diffstat (limited to 'src/test/com')
12 files changed, 252 insertions, 67 deletions
diff --git a/src/test/com/jogamp/opengl/test/android/MovieCubeActivity0.java b/src/test/com/jogamp/opengl/test/android/MovieCubeActivity0.java index 4b84525f6..59e78936d 100644 --- a/src/test/com/jogamp/opengl/test/android/MovieCubeActivity0.java +++ b/src/test/com/jogamp/opengl/test/android/MovieCubeActivity0.java @@ -46,19 +46,25 @@ import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.test.junit.jogl.demos.es2.av.MovieCube; import com.jogamp.opengl.util.Animator; +import android.content.Context; import android.os.Bundle; import android.util.Log; +import android.view.inputmethod.InputMethodManager; public class MovieCubeActivity0 extends NewtBaseActivity { static String TAG = "MovieCubeActivity0"; - MouseAdapter toFrontMouseListener = new MouseAdapter() { - public void mouseClicked(MouseEvent e) { - Object src = e.getSource(); - if(src instanceof AndroidWindow) { - ((AndroidWindow)src).requestFocus(false); + MouseAdapter showKeyboardMouseListener = new MouseAdapter() { + @Override + public void mousePressed(MouseEvent e) { + if(e.getPressure()>2f) { + final AndroidWindow win = (AndroidWindow)e.getSource(); + InputMethodManager mgr = (InputMethodManager) win.getAndroidView().getContext().getSystemService(Context.INPUT_METHOD_SERVICE); + mgr.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); // shows keyboard .. + win.getAndroidView().requestFocus(); } - } }; + } + }; @Override public void onCreate(Bundle savedInstanceState) { @@ -89,6 +95,7 @@ public class MovieCubeActivity0 extends NewtBaseActivity { final GLWindow glWindowMain = GLWindow.create(scrn, capsMain); glWindowMain.setFullscreen(true); setContentView(getWindow(), glWindowMain); + glWindowMain.addMouseListener(showKeyboardMouseListener); glWindowMain.addGLEventListener(demoMain); animator.add(glWindowMain); glWindowMain.setVisible(true); diff --git a/src/test/com/jogamp/opengl/test/android/MovieCubeActivityLauncher0.java b/src/test/com/jogamp/opengl/test/android/MovieCubeActivityLauncher0.java index 0332906b7..4f24fc9b8 100644 --- a/src/test/com/jogamp/opengl/test/android/MovieCubeActivityLauncher0.java +++ b/src/test/com/jogamp/opengl/test/android/MovieCubeActivityLauncher0.java @@ -57,14 +57,14 @@ public class MovieCubeActivityLauncher0 extends LauncherUtil.BaseActivityLaunche props.setProperty("jogl.debug.GLDrawable", "true"); props.setProperty("jogl.debug.GLContext", "true"); props.setProperty("jogl.debug.GLSLCode", "true"); - props.setProperty("jogl.debug.CapabilitiesChooser", "true"); + // props.setProperty("jogl.debug.CapabilitiesChooser", "true"); // props.setProperty("jogl.debug.GLSLState", "true"); // props.setProperty("jogl.debug.DebugGL", "true"); // props.setProperty("jogl.debug.TraceGL", "true"); // props.setProperty("newt.debug", "all"); - props.setProperty("newt.debug.Window", "true"); + // props.setProperty("newt.debug.Window", "true"); // props.setProperty("newt.debug.Window.MouseEvent", "true"); - // props.setProperty("newt.debug.Window.KeyEvent", "true"); + // props.setProperty("newt.debug.Window.KeyEvent", "true"); props.setProperty("jogamp.debug.IOUtil", "true"); } diff --git a/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher00a.java b/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher00a.java index 3ad462691..fbb0223f8 100644 --- a/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher00a.java +++ b/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher00a.java @@ -60,12 +60,12 @@ public class MovieSimpleActivityLauncher00a extends LauncherUtil.BaseActivityLau props.setProperty("jogl.debug.GLDrawable", "true"); props.setProperty("jogl.debug.GLContext", "true"); props.setProperty("jogl.debug.GLSLCode", "true"); - props.setProperty("jogl.debug.CapabilitiesChooser", "true"); + // props.setProperty("jogl.debug.CapabilitiesChooser", "true"); // props.setProperty("jogl.debug.GLSLState", "true"); // props.setProperty("jogl.debug.DebugGL", "true"); // props.setProperty("jogl.debug.TraceGL", "true"); // props.setProperty("newt.debug", "all"); - props.setProperty("newt.debug.Window", "true"); + // props.setProperty("newt.debug.Window", "true"); // props.setProperty("newt.debug.Window.MouseEvent", "true"); // props.setProperty("newt.debug.Window.KeyEvent", "true"); props.setProperty("jogamp.debug.IOUtil", "true"); diff --git a/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher00b.java b/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher00b.java index e3c87bd7a..8c08e987f 100644 --- a/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher00b.java +++ b/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher00b.java @@ -60,12 +60,12 @@ public class MovieSimpleActivityLauncher00b extends LauncherUtil.BaseActivityLau props.setProperty("jogl.debug.GLDrawable", "true"); props.setProperty("jogl.debug.GLContext", "true"); props.setProperty("jogl.debug.GLSLCode", "true"); - props.setProperty("jogl.debug.CapabilitiesChooser", "true"); + // props.setProperty("jogl.debug.CapabilitiesChooser", "true"); // props.setProperty("jogl.debug.GLSLState", "true"); // props.setProperty("jogl.debug.DebugGL", "true"); // props.setProperty("jogl.debug.TraceGL", "true"); // props.setProperty("newt.debug", "all"); - props.setProperty("newt.debug.Window", "true"); + // props.setProperty("newt.debug.Window", "true"); // props.setProperty("newt.debug.Window.MouseEvent", "true"); // props.setProperty("newt.debug.Window.KeyEvent", "true"); props.setProperty("jogamp.debug.IOUtil", "true"); diff --git a/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher01a.java b/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher01a.java index 5fcb9d584..b2a3facbd 100644 --- a/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher01a.java +++ b/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher01a.java @@ -60,12 +60,12 @@ public class MovieSimpleActivityLauncher01a extends LauncherUtil.BaseActivityLau props.setProperty("jogl.debug.GLDrawable", "true"); props.setProperty("jogl.debug.GLContext", "true"); props.setProperty("jogl.debug.GLSLCode", "true"); - props.setProperty("jogl.debug.CapabilitiesChooser", "true"); + // props.setProperty("jogl.debug.CapabilitiesChooser", "true"); // props.setProperty("jogl.debug.GLSLState", "true"); // props.setProperty("jogl.debug.DebugGL", "true"); // props.setProperty("jogl.debug.TraceGL", "true"); // props.setProperty("newt.debug", "all"); - props.setProperty("newt.debug.Window", "true"); + // props.setProperty("newt.debug.Window", "true"); // props.setProperty("newt.debug.Window.MouseEvent", "true"); // props.setProperty("newt.debug.Window.KeyEvent", "true"); props.setProperty("jogamp.debug.IOUtil", "true"); diff --git a/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher01b.java b/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher01b.java index 2801acf48..905e2628d 100644 --- a/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher01b.java +++ b/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher01b.java @@ -60,12 +60,12 @@ public class MovieSimpleActivityLauncher01b extends LauncherUtil.BaseActivityLau props.setProperty("jogl.debug.GLDrawable", "true"); props.setProperty("jogl.debug.GLContext", "true"); props.setProperty("jogl.debug.GLSLCode", "true"); - props.setProperty("jogl.debug.CapabilitiesChooser", "true"); + // props.setProperty("jogl.debug.CapabilitiesChooser", "true"); // props.setProperty("jogl.debug.GLSLState", "true"); // props.setProperty("jogl.debug.DebugGL", "true"); // props.setProperty("jogl.debug.TraceGL", "true"); // props.setProperty("newt.debug", "all"); - props.setProperty("newt.debug.Window", "true"); + // props.setProperty("newt.debug.Window", "true"); // props.setProperty("newt.debug.Window.MouseEvent", "true"); // props.setProperty("newt.debug.Window.KeyEvent", "true"); props.setProperty("jogamp.debug.IOUtil", "true"); diff --git a/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher02.java b/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher02.java index f862b5ee9..369457946 100644 --- a/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher02.java +++ b/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher02.java @@ -60,12 +60,12 @@ public class MovieSimpleActivityLauncher02 extends LauncherUtil.BaseActivityLaun props.setProperty("jogl.debug.GLDrawable", "true"); props.setProperty("jogl.debug.GLContext", "true"); props.setProperty("jogl.debug.GLSLCode", "true"); - props.setProperty("jogl.debug.CapabilitiesChooser", "true"); + // props.setProperty("jogl.debug.CapabilitiesChooser", "true"); // props.setProperty("jogl.debug.GLSLState", "true"); // props.setProperty("jogl.debug.DebugGL", "true"); // props.setProperty("jogl.debug.TraceGL", "true"); // props.setProperty("newt.debug", "all"); - props.setProperty("newt.debug.Window", "true"); + // props.setProperty("newt.debug.Window", "true"); // props.setProperty("newt.debug.Window.MouseEvent", "true"); // props.setProperty("newt.debug.Window.KeyEvent", "true"); props.setProperty("jogamp.debug.IOUtil", "true"); diff --git a/src/test/com/jogamp/opengl/test/android/NEWTRedSquareES2ActivityLauncher.java b/src/test/com/jogamp/opengl/test/android/NEWTRedSquareES2ActivityLauncher.java index b6265b72b..96299e873 100644 --- a/src/test/com/jogamp/opengl/test/android/NEWTRedSquareES2ActivityLauncher.java +++ b/src/test/com/jogamp/opengl/test/android/NEWTRedSquareES2ActivityLauncher.java @@ -12,7 +12,7 @@ public class NEWTRedSquareES2ActivityLauncher extends Activity { super.onCreate(savedInstanceState); final Uri uri = Uri.parse("launch://jogamp.org/com.jogamp.opengl.test.android.NEWTRedSquareES2Activity?pkg=com.jogamp.opengl.test"); - final Intent intent = new Intent("org.jogamp.launcher.action.LAUNCH_ACTIVITY_NORMAL", uri); + final Intent intent = new Intent("org.jogamp.launcher.action.LAUNCH_ACTIVITY_NORMAL", uri); Log.d(getClass().getSimpleName(), "Launching Activity: "+intent); startActivity (intent); 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 index 5e607feb3..6dfb11855 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/TestTextureSequence.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/TestTextureSequence.java @@ -19,8 +19,10 @@ public class TestTextureSequence implements TextureSequence { 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 }; - - public TestTextureSequence() { + final boolean useBuildInTexLookup; + + public TestTextureSequence(boolean useBuildInTexLookup) { + this.useBuildInTexLookup = useBuildInTexLookup; } public void initGLResources(GL gl) throws GLException { @@ -57,11 +59,6 @@ public class TestTextureSequence implements TextureSequence { } @Override - public int getTextureTarget() { - return frame.getTexture().getTarget(); - } - - @Override public int getTextureUnit() { return textureUnit; } @@ -77,13 +74,47 @@ public class TestTextureSequence implements TextureSequence { } @Override - public TextureSequence.TextureFrame getLastTexture() { + public TextureSequence.TextureFrame getLastTexture() throws IllegalStateException { return frame; // may return null } @Override - public TextureSequence.TextureFrame getNextTexture(GL gl, boolean blocking) { + 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 index f330dde0d..e85468bcb 100644 --- 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 @@ -1,3 +1,30 @@ +/** + * 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; @@ -23,6 +50,7 @@ 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; @@ -30,18 +58,19 @@ 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.texSource = texSource; + this.texSeq = texSource; this.innerCube = innerCube; this.zoom0 = zoom0; this.view_rotx = rotx; this.view_roty = roty; } - private TextureSequence texSource; + private TextureSequence texSeq; private ShaderState st; private PMVMatrix pmvMatrix; private GLUniformData pmvMatrixUniform; @@ -117,17 +146,40 @@ public class TexCubeES2 implements GLEventListener { } }; + 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, boolean useExternalTexture) { + private void initShader(GL2ES2 gl) { // Create & Compile the shader objects - final String vShaderBasename = gl.isGLES2() ? "texsimple_es2" : "texsimple_gl2" ; - final String fShaderBasename = gl.isGLES2() ? ( useExternalTexture ? "texsimple_es2_exttex" : "texsimple_es2" ) : "texsimple_gl2"; + 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); - ShaderCode rsVp = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, 1, TexCubeES2.class, - "shader", "shader/bin", vShaderBasename); - ShaderCode rsFp = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, 1, TexCubeES2.class, - "shader", "shader/bin", fShaderBasename); - // Create & Link the shader program ShaderProgram sp = new ShaderProgram(); sp.add(rsVp); @@ -146,13 +198,14 @@ public class TexCubeES2 implements GLEventListener { 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 == texSource.getTextureTarget(); + 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, useExternalTexture); + initShader(gl); // Push the 1st uniform down the path st.useProgram(gl, true); @@ -163,26 +216,31 @@ public class TexCubeES2 implements GLEventListener { if(!st.uniform(gl, pmvMatrixUniform)) { throw new GLException("Error setting PMVMatrix in shader: "+st); } - if(!st.uniform(gl, new GLUniformData("mgl_ActiveTexture", texSource.getTextureUnit()))) { + if(!st.uniform(gl, new GLUniformData("mgl_ActiveTexture", texSeq.getTextureUnit()))) { throw new GLException("Error setting mgl_ActiveTexture in shader: "+st); } { - final Texture tex= texSource.getLastTexture().getTexture(); 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: "+tex.getImageTexCoords()); + 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<s_cubeTexCoords.length; i+=2) { - s_cubeTexCoords[i+0] *= ss; - final float t = s_cubeTexCoords[i+1]; - if(t==0 && !tex.getMustFlipVertically() || t!=0 && tex.getMustFlipVertically()) { - s_cubeTexCoords[i+1] = 0f + dy; + final float tx = s_cubeTexCoords[i+0]; + final float ty = s_cubeTexCoords[i+1]; + if(tx!=0) { + s_cubeTexCoords[i+0] = tc_x1 * ss; + } + if(ty==0 && !tex.getMustFlipVertically() || ty!=0 && tex.getMustFlipVertically()) { + s_cubeTexCoords[i+1] = 0f + dy; } else { - s_cubeTexCoords[i+1] = 1f * ts + dy; + s_cubeTexCoords[i+1] = tc_y1 * ts + dy; } } } @@ -274,7 +332,7 @@ public class TexCubeES2 implements GLEventListener { public void dispose(GLAutoDrawable drawable) { GL2ES2 gl = drawable.getGL().getGL2ES2(); - texSource = null; + texSeq = null; pmvMatrixUniform = null; pmvMatrix.destroy(); pmvMatrix=null; @@ -298,11 +356,11 @@ public class TexCubeES2 implements GLEventListener { st.uniform(gl, pmvMatrixUniform); interleavedVBO.enableBuffer(gl, true); Texture tex = null; - if(null!=texSource) { - final TextureSequence.TextureFrame texFrame = texSource.getNextTexture(gl, true); + if(null!=texSeq) { + final TextureSequence.TextureFrame texFrame = texSeq.getNextTexture(gl, true); if(null != texFrame) { tex = texFrame.getTexture(); - gl.glActiveTexture(GL.GL_TEXTURE0+texSource.getTextureUnit()); + gl.glActiveTexture(GL.GL_TEXTURE0+texSeq.getTextureUnit()); tex.enable(gl); tex.bind(gl); } @@ -401,14 +459,27 @@ public class TexCubeES2 implements GLEventListener { public static void main(String[] args) { int width = 510; int height = 300; + boolean useBuildInTexLookup = false; System.err.println("TexCubeES2.run()"); + for(int i=0; i<args.length; i++) { + if(args[i].equals("-width")) { + i++; + width = MiscUtils.atoi(args[i], width); + } else if(args[i].equals("-height")) { + i++; + height = MiscUtils.atoi(args[i], height); + } else if(args[i].equals("-shaderBuildIn")) { + useBuildInTexLookup = true; + } + } + final GLWindow window = GLWindow.create(new GLCapabilities(GLProfile.getGL2ES2())); // Size OpenGL to Video Surface window.setSize(width, height); window.setFullscreen(false); window.setSize(width, height); - final TestTextureSequence texSource = new TestTextureSequence(); + final TestTextureSequence texSource = new TestTextureSequence(useBuildInTexLookup); window.addGLEventListener(new GLEventListener() { @Override public void init(GLAutoDrawable drawable) { diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java index 343c4b2a6..9ecb15018 100755 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java @@ -45,6 +45,10 @@ import javax.media.opengl.GLEventListener; import javax.media.opengl.GLException; import javax.media.opengl.GLProfile; +import com.jogamp.newt.Window; +import com.jogamp.newt.event.KeyAdapter; +import com.jogamp.newt.event.KeyEvent; +import com.jogamp.newt.event.KeyListener; import com.jogamp.newt.event.WindowAdapter; import com.jogamp.newt.event.WindowEvent; import com.jogamp.newt.opengl.GLWindow; @@ -61,15 +65,55 @@ public class MovieCube implements GLEventListener, GLMediaEventListener { boolean quit = false; TexCubeES2 cube=null; GLMediaPlayer mPlayer=null; - URLConnection stream = null; + URLConnection stream = null; public MovieCube(URLConnection stream, float zoom0, float rotx, float roty) throws IOException { this.stream = stream; mPlayer = GLMediaPlayerFactory.create(); mPlayer.addEventListener(this); - cube = new TexCubeES2(mPlayer, false, zoom0, rotx, roty); + cube = new TexCubeES2(mPlayer, false, zoom0, rotx, roty); } + private final KeyListener keyAction = new KeyAdapter() { + public void keyTyped(KeyEvent e) { + System.err.println("MC "+e); + int pts0 = mPlayer.getCurrentPosition(); + int pts1 = 0; + switch(e.getKeyCode()) { + case KeyEvent.VK_3: + case KeyEvent.VK_RIGHT: pts1 = pts0 + 1000; break; + case KeyEvent.VK_4: + case KeyEvent.VK_UP: pts1 = pts0 + 10000; break; + case KeyEvent.VK_2: + case KeyEvent.VK_LEFT: pts1 = pts0 - 1000; break; + case KeyEvent.VK_1: + case KeyEvent.VK_DOWN: pts1 = pts0 - 10000; break; + case KeyEvent.VK_ESCAPE: + case KeyEvent.VK_DELETE: + case KeyEvent.VK_BACK_SPACE: { + mPlayer.seek(0); + mPlayer.setPlaySpeed(1.0f); + mPlayer.start(); + break; + } + case KeyEvent.VK_SPACE: { + if(GLMediaPlayer.State.Paused == mPlayer.getState()) { + mPlayer.start(); + } else { + mPlayer.pause(); + } + break; + } + case KeyEvent.VK_S: mPlayer.setPlaySpeed(mPlayer.getPlaySpeed()/2.0f); break; + case KeyEvent.VK_F: mPlayer.setPlaySpeed(mPlayer.getPlaySpeed()*2.0f); break; + } + + if( 0 != pts1 ) { + mPlayer.seek(pts1); + } + } + }; + @Override public void attributesChanges(GLMediaPlayer mp, int event_mask, long when) { System.out.println("attributesChanges: "+mp+", 0x"+Integer.toHexString(event_mask)+", when "+when); @@ -99,6 +143,14 @@ public class MovieCube implements GLEventListener, GLMediaEventListener { cube.init(drawable); mPlayer.start(); + + boolean added; + if (drawable instanceof Window) { + Window window = (Window) drawable; + window.addKeyListener(keyAction); + added = true; + } else { added = false; } + System.err.println("MC.init: kl-added "+added+", "+drawable.getClass().getName()); } public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java index fa2870437..8210065ab 100755 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java @@ -129,7 +129,7 @@ public class MovieSimple implements GLEventListener, GLMediaEventListener { if(y>winHeight/2) { final float dp = (float)(x-prevMouseX)/(float)winWidth; - mPlayer.seek(mPlayer.getCurrentPosition() + (long) (mPlayer.getDuration() * dp)); + mPlayer.seek(mPlayer.getCurrentPosition() + (int) (mPlayer.getDuration() * dp)); } else { mPlayer.start(); rotate = 1; @@ -198,16 +198,39 @@ public class MovieSimple implements GLEventListener, GLMediaEventListener { ShaderState st; PMVMatrix pmvMatrix; GLUniformData pmvMatrixUniform; + 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, boolean useExternalTexture) { + private void initShader(GL2ES2 gl) { // Create & Compile the shader objects - final String vShaderBasename = gl.isGLES2() ? "texsimple_es2" : "texsimple_gl2" ; - final String fShaderBasename = gl.isGLES2() ? ( useExternalTexture ? "texsimple_es2_exttex" : "texsimple_es2" ) : "texsimple_gl2"; + ShaderCode rsVp = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, MovieSimple.class, + "../shader", "../shader/bin", shaderBasename, true); + ShaderCode rsFp = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, MovieSimple.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, mPlayer.getRequiredExtensionsShaderStub()); + if(gl.isGLES2()) { + rsFpPos = rsFp.insertShaderSource(0, rsFpPos, es2_prelude[1]); + } + final String texLookupFuncName = mPlayer.getTextureLookupFunctionName(myTextureLookupName); + rsFp.replaceInShaderSource(myTextureLookupName, texLookupFuncName); - ShaderCode rsVp = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, 1, MovieSimple.class, - "../shader", "../shader/bin", vShaderBasename); - ShaderCode rsFp = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, 1, MovieSimple.class, - "../shader", "../shader/bin", fShaderBasename); + // Inject TextureSequence shader details + final StringBuilder sFpIns = new StringBuilder(); + sFpIns.append("uniform ").append(mPlayer.getTextureSampler2DType()).append(" mgl_ActiveTexture;\n"); + sFpIns.append(mPlayer.getTextureLookupFragmentShaderImpl()); + rsFp.insertShaderSource(0, "TEXTURE-SEQUENCE-CODE-BEGIN", 0, sFpIns); // Create & Link the shader program ShaderProgram sp = new ShaderProgram(); @@ -232,14 +255,16 @@ public class MovieSimple implements GLEventListener, GLMediaEventListener { System.err.println("Alpha: "+alpha+", opaque "+drawable.getChosenGLCapabilities().isBackgroundOpaque()+ ", "+drawable.getClass().getName()+", "+drawable); + final Texture tex; boolean useExternalTexture = false; try { System.out.println("p0 "+mPlayer+", shared "+mPlayerShared); if(!mPlayerShared) { mPlayer.initGLStream(gl, stream); } + tex = mPlayer.getLastTexture().getTexture(); System.out.println("p1 "+mPlayer+", shared "+mPlayerShared); - useExternalTexture = GLES2.GL_TEXTURE_EXTERNAL_OES == mPlayer.getTextureTarget(); + 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"); } @@ -254,7 +279,7 @@ public class MovieSimple implements GLEventListener, GLMediaEventListener { throw new GLException(glex); } - initShader(gl, useExternalTexture); + initShader(gl); // Push the 1st uniform down the path st.useProgram(gl, true); @@ -313,7 +338,6 @@ public class MovieSimple implements GLEventListener, GLMediaEventListener { interleavedVBO.addGLSLSubArray("mgl_MultiTexCoord", 2, GL.GL_ARRAY_BUFFER); final FloatBuffer ib = (FloatBuffer)interleavedVBO.getBuffer(); - final Texture tex= mPlayer.getLastTexture().getTexture(); final TextureCoords tc = tex.getImageTexCoords(); final float aspect = tex.getAspectRatio(); System.err.println("XXX0: tex aspect: "+aspect); |