diff options
Diffstat (limited to 'src/test')
19 files changed, 971 insertions, 78 deletions
diff --git a/src/test/com/jogamp/opengl/test/android/MovieCubeActivity0.java b/src/test/com/jogamp/opengl/test/android/MovieCubeActivity0.java new file mode 100644 index 000000000..4b84525f6 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/android/MovieCubeActivity0.java @@ -0,0 +1,118 @@ +/** + * Copyright 2011 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.android; + +import java.io.IOException; +import java.net.URLConnection; +import java.util.Arrays; + +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; + +import jogamp.newt.driver.android.AndroidWindow; +import jogamp.newt.driver.android.NewtBaseActivity; + +import com.jogamp.common.util.IOUtil; +import com.jogamp.newt.NewtFactory; +import com.jogamp.newt.event.MouseAdapter; +import com.jogamp.newt.event.MouseEvent; +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.os.Bundle; +import android.util.Log; + +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); + } + } }; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + String[] urls0 = new String[] { + System.getProperty("jnlp.media0_url2"), + System.getProperty("jnlp.media0_url1"), + System.getProperty("jnlp.media0_url0") }; + final URLConnection urlConnection0 = getResource(urls0, 0); + if(null == urlConnection0) { throw new RuntimeException("no media reachable: "+Arrays.asList(urls0)); } + + // also initializes JOGL + final GLCapabilities capsMain = new GLCapabilities(GLProfile.getGL2ES2()); + capsMain.setBackgroundOpaque(false); + + // screen for layout params .. + final com.jogamp.newt.Display dpy = NewtFactory.createDisplay(null); + final com.jogamp.newt.Screen scrn = NewtFactory.createScreen(dpy, 0); + scrn.addReference(); + + try { + final Animator animator = new Animator(); + setAnimator(animator); + + // Main + final MovieCube demoMain = new MovieCube(urlConnection0, -2.3f, 0f, 0f); + final GLWindow glWindowMain = GLWindow.create(scrn, capsMain); + glWindowMain.setFullscreen(true); + setContentView(getWindow(), glWindowMain); + glWindowMain.addGLEventListener(demoMain); + animator.add(glWindowMain); + glWindowMain.setVisible(true); + + // animator.setUpdateFPSFrames(60, System.err); + animator.setUpdateFPSFrames(-1, null); + animator.resetFPSCounter(); + } catch (IOException e) { + e.printStackTrace(); + } + + scrn.removeReference(); + + Log.d(TAG, "onCreate - X"); + } + + static URLConnection getResource(String path[], int off) { + URLConnection uc = null; + for(int i=off; null==uc && i<path.length; i++) { + if(null != path[i] && path[i].length()>0) { + uc = IOUtil.getResource(path[i], null); + Log.d(TAG, "Stream: <"+path[i]+">: "+(null!=uc)); + } + } + return uc; + } +} diff --git a/src/test/com/jogamp/opengl/test/android/MovieCubeActivityLauncher0.java b/src/test/com/jogamp/opengl/test/android/MovieCubeActivityLauncher0.java new file mode 100644 index 000000000..0332906b7 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/android/MovieCubeActivityLauncher0.java @@ -0,0 +1,79 @@ +/** + * 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.android; + +import java.util.Arrays; +import java.util.List; + +import com.jogamp.opengl.test.android.LauncherUtil.OrderedProperties; + +public class MovieCubeActivityLauncher0 extends LauncherUtil.BaseActivityLauncher { + + static String demo = "com.jogamp.opengl.test.android.MovieCubeActivity0"; + // static String[] pkgs = new String[] { "com.jogamp.common", "javax.media.opengl", "com.jogamp.opengl.test" }; + static String[] pkgs = new String[] { "com.jogamp.opengl.test" }; + + @Override + public void init() { + final OrderedProperties props = getProperties(); + // props.setProperty("jnlp.media0_url2", "http://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_640x360.m4v"); + props.setProperty("jnlp.media0_url2", ""); + props.setProperty("jnlp.media0_url1", "http://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_320x180.mp4"); + props.setProperty("jnlp.media0_url0", "file:///mnt/sdcard/Movies/BigBuckBunny_320x180.mp4"); + props.setProperty("jnlp.media1_url0", "http://archive.org/download/ElephantsDream/ed_1024_512kb.mp4"); + // props.setProperty("jogamp.debug.JNILibLoader", "true"); + // props.setProperty("jogamp.debug.NativeLibrary", "true"); + // props.setProperty("jogamp.debug.NativeLibrary.Lookup", "true"); + // props.setProperty("jogamp.debug.IOUtil", "true"); + // props.setProperty("nativewindow.debug", "all"); + props.setProperty("nativewindow.debug.GraphicsConfiguration", "true"); + // props.setProperty("jogl.debug", "all"); + // props.setProperty("jogl.debug.GLProfile", "true"); + 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.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.MouseEvent", "true"); + // props.setProperty("newt.debug.Window.KeyEvent", "true"); + props.setProperty("jogamp.debug.IOUtil", "true"); + } + + @Override + public String getActivityName() { + return demo; + } + @Override + public List<String> getPackages() { + return Arrays.asList(pkgs); + } +} diff --git a/src/test/com/jogamp/opengl/test/android/MovieSimpleActivity0.java b/src/test/com/jogamp/opengl/test/android/MovieSimpleActivity0.java index 0698e421e..11babf187 100644 --- a/src/test/com/jogamp/opengl/test/android/MovieSimpleActivity0.java +++ b/src/test/com/jogamp/opengl/test/android/MovieSimpleActivity0.java @@ -50,7 +50,7 @@ import android.os.Bundle; import android.util.Log; public class MovieSimpleActivity0 extends NewtBaseActivity { - static String TAG = "NEWTGearsES2Activity"; + static String TAG = "MovieSimpleActivity0"; MouseAdapter toFrontMouseListener = new MouseAdapter() { public void mouseClicked(MouseEvent e) { diff --git a/src/test/com/jogamp/opengl/test/android/MovieSimpleActivity.java b/src/test/com/jogamp/opengl/test/android/MovieSimpleActivity1.java index 86b3ffb48..a5e5f4ccb 100644 --- a/src/test/com/jogamp/opengl/test/android/MovieSimpleActivity.java +++ b/src/test/com/jogamp/opengl/test/android/MovieSimpleActivity1.java @@ -45,16 +45,16 @@ import com.jogamp.newt.event.MouseAdapter; import com.jogamp.newt.event.MouseEvent; import com.jogamp.newt.opengl.GLWindow; -import com.jogamp.opengl.av.GLMediaPlayer; import com.jogamp.opengl.test.junit.jogl.demos.es2.av.MovieSimple; import com.jogamp.opengl.util.Animator; +import com.jogamp.opengl.util.av.GLMediaPlayer; import android.os.Bundle; import android.util.Log; import android.view.Gravity; -public class MovieSimpleActivity extends NewtBaseActivity { - static String TAG = "NEWTGearsES2Activity"; +public class MovieSimpleActivity1 extends NewtBaseActivity { + static String TAG = "MovieSimpleActivity1"; MouseAdapter toFrontMouseListener = new MouseAdapter() { public void mouseClicked(MouseEvent e) { diff --git a/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher00b.java b/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher00b.java index a5370e90b..e3c87bd7a 100644 --- a/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher00b.java +++ b/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher00b.java @@ -34,7 +34,7 @@ import com.jogamp.opengl.test.android.LauncherUtil.OrderedProperties; public class MovieSimpleActivityLauncher00b extends LauncherUtil.BaseActivityLauncher { - static String demo = "com.jogamp.opengl.test.android.MovieSimpleActivity"; + static String demo = "com.jogamp.opengl.test.android.MovieSimpleActivity1"; // static String[] pkgs = new String[] { "com.jogamp.common", "javax.media.opengl", "com.jogamp.opengl.test" }; static String[] pkgs = new String[] { "com.jogamp.opengl.test" }; diff --git a/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher01a.java b/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher01a.java index ff3fadadf..5fcb9d584 100644 --- a/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher01a.java +++ b/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher01a.java @@ -34,7 +34,7 @@ import com.jogamp.opengl.test.android.LauncherUtil.OrderedProperties; public class MovieSimpleActivityLauncher01a extends LauncherUtil.BaseActivityLauncher { - static String demo = "com.jogamp.opengl.test.android.MovieSimpleActivity"; + static String demo = "com.jogamp.opengl.test.android.MovieSimpleActivity1"; // static String[] pkgs = new String[] { "com.jogamp.common", "javax.media.opengl", "com.jogamp.opengl.test" }; static String[] pkgs = new String[] { "com.jogamp.opengl.test" }; diff --git a/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher01b.java b/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher01b.java index 9992ac65a..2801acf48 100644 --- a/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher01b.java +++ b/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher01b.java @@ -34,7 +34,7 @@ import com.jogamp.opengl.test.android.LauncherUtil.OrderedProperties; public class MovieSimpleActivityLauncher01b extends LauncherUtil.BaseActivityLauncher { - static String demo = "com.jogamp.opengl.test.android.MovieSimpleActivity"; + static String demo = "com.jogamp.opengl.test.android.MovieSimpleActivity1"; // static String[] pkgs = new String[] { "com.jogamp.common", "javax.media.opengl", "com.jogamp.opengl.test" }; static String[] pkgs = new String[] { "com.jogamp.opengl.test" }; diff --git a/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher02.java b/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher02.java index 082cc6335..f862b5ee9 100644 --- a/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher02.java +++ b/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher02.java @@ -34,7 +34,7 @@ import com.jogamp.opengl.test.android.LauncherUtil.OrderedProperties; public class MovieSimpleActivityLauncher02 extends LauncherUtil.BaseActivityLauncher { - static String demo = "com.jogamp.opengl.test.android.MovieSimpleActivity"; + static String demo = "com.jogamp.opengl.test.android.MovieSimpleActivity1"; // static String[] pkgs = new String[] { "com.jogamp.common", "javax.media.opengl", "com.jogamp.opengl.test" }; static String[] pkgs = new String[] { "com.jogamp.opengl.test" }; 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 new file mode 100644 index 000000000..5e607feb3 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/TestTextureSequence.java @@ -0,0 +1,89 @@ +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 }; + + public TestTextureSequence() { + } + + 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 getTextureTarget() { + return frame.getTexture().getTarget(); + } + + @Override + public int getTextureUnit() { + return textureUnit; + } + + @Override + public int[] getTextureMinMagFilter() { + return texMinMagFilter; + } + + @Override + public int[] getTextureWrapST() { + return texWrapST; + } + + @Override + public TextureSequence.TextureFrame getLastTexture() { + return frame; // may return null + } + + @Override + public TextureSequence.TextureFrame getNextTexture(GL gl, boolean blocking) { + return frame; + } + +} 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 new file mode 100644 index 000000000..f330dde0d --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TexCubeES2.java @@ -0,0 +1,436 @@ +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.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.TextureSequence; + +public class TexCubeES2 implements GLEventListener { + public TexCubeES2 (TextureSequence texSource, boolean innerCube, float zoom0, float rotx, float roty) { + this.texSource = texSource; + this.innerCube = innerCube; + this.zoom0 = zoom0; + this.view_rotx = rotx; + this.view_roty = roty; + } + + private TextureSequence texSource; + 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); + } + }; + + + private void initShader(GL2ES2 gl, boolean useExternalTexture) { + // 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, 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); + 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 boolean useExternalTexture = GLES2.GL_TEXTURE_EXTERNAL_OES == texSource.getTextureTarget(); + if(useExternalTexture && !gl.isExtensionAvailable("GL_OES_EGL_image_external")) { + throw new GLException("GL_OES_EGL_image_external requested but not available"); + } + + initShader(gl, useExternalTexture); + + // 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", texSource.getTextureUnit()))) { + throw new GLException("Error setting mgl_ActiveTexture in shader: "+st); + } + + + { + final Texture tex= texSource.getLastTexture().getTexture(); + final float aspect = tex.getAspectRatio(); + System.err.println("XXX0: aspect: "+aspect); + System.err.println("XXX0: y-flip: "+tex.getMustFlipVertically()); + System.err.println("XXX0: "+tex.getImageTexCoords()); + 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; + } else { + s_cubeTexCoords[i+1] = 1f * 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); + 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<6*4; i++) { + 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); + } + } + interleavedVBO.seal(gl, true); + interleavedVBO.enableBuffer(gl, false); + st.ownAttribute(interleavedVBO, true); + cubeIndices = ByteBuffer.wrap(s_cubeIndices); + + gl.glEnable(GL2ES2.GL_DEPTH_TEST); + + st.useProgram(gl, false); + + if (drawable instanceof Window) { + Window window = (Window) drawable; + window.addMouseListener(mouseAction); + } + + // Let's show the completed shader state .. + System.out.println("iVBO: "+interleavedVBO); + System.out.println(st); + } + + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + GL2ES2 gl = drawable.getGL().getGL2ES2(); + + gl.glViewport(0, 0, width, height); + + if(innerCube) { + // Clear background to white + gl.glClearColor(1.0f, 1.0f, 1.0f, 0.4f); + } else { + // Clear background to blue + gl.glClearColor(0.0f, 0.0f, 1.0f, 1.0f); + } + + if(!innerCube) { + // lights on + } else { + // lights off + } + // gl.glEnable(GL.GL_CULL_FACE); + // gl.glDisable(GL.GL_DITHER); + + if(null != st) { + reshapePMV(width, height); + st.useProgram(gl, true); + st.uniform(gl, pmvMatrixUniform); + st.useProgram(gl, false); + } + } + + + private void reshapePMV(int width, int height) { + pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION); + pmvMatrix.glLoadIdentity(); + if(!innerCube) { + pmvMatrix.gluPerspective(45.0f, (float)width / (float)height, 1f, 10.0f); + nearPlaneNormalized = 1f/(100f-1f); + } else { + pmvMatrix.glOrthof(-1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 10.0f); + nearPlaneNormalized = 0f; + } + System.err.println("XXX0: Perspective nearPlaneNormalized: "+nearPlaneNormalized); + + pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); + pmvMatrix.glLoadIdentity(); + pmvMatrix.glTranslatef(0, 0, zoom0); + } + + + public void dispose(GLAutoDrawable drawable) { + GL2ES2 gl = drawable.getGL().getGL2ES2(); + + texSource = null; + 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); + + pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); + pmvMatrix.glLoadIdentity(); + pmvMatrix.glTranslatef(0, 0, zoom); + pmvMatrix.glRotatef(view_rotx, 1.0f, 0.0f, 0.0f); + pmvMatrix.glRotatef(view_roty, 0.0f, 1.0f, 0.0f); + pmvMatrix.glRotatef(view_rotz, 0.0f, 0.0f, 1.0f); + st.uniform(gl, pmvMatrixUniform); + interleavedVBO.enableBuffer(gl, true); + Texture tex = null; + if(null!=texSource) { + final TextureSequence.TextureFrame texFrame = texSource.getNextTexture(gl, true); + if(null != texFrame) { + tex = texFrame.getTexture(); + gl.glActiveTexture(GL.GL_TEXTURE0+texSource.getTextureUnit()); + tex.enable(gl); + tex.bind(gl); + } + } + gl.glDrawElements(GL.GL_TRIANGLES, 6 * 6, GL.GL_UNSIGNED_BYTE, cubeIndices); + if(null != tex) { + tex.disable(gl); + } + interleavedVBO.enableBuffer(gl, false); + st.useProgram(gl, false); + } + + public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { + } + + static final float[] light_position = { -50.f, 50.f, 50.f, 0.f }; + static final float[] light_ambient = { 0.125f, 0.125f, 0.125f, 1.f }; + static final float[] light_diffuse = { 1.0f, 1.0f, 1.0f, 1.f }; + static final float[] material_spec = { 1.0f, 1.0f, 1.0f, 0.f }; + static final float[] zero_vec4 = { 0.0f, 0.0f, 0.0f, 0.f }; + + private static final float[] s_cubeVertices = /* f b t b r l */ + { + -1f, 1f, 1f, 1f, -1f, 1f, 1f, 1f, 1f, -1f, -1f, 1f, + + -1f, 1f, -1f, 1f, -1f, -1f, 1f, 1f, -1f, -1f, -1f, -1f, + + -1f, -1f, 1f, 1f, -1f, -1f, 1f, -1f, 1f, -1f, -1f, -1f, + + -1f, 1f, 1f, 1f, 1f, -1f, 1f, 1f, 1f, -1f, 1f, -1f, + + 1f, -1f, 1f, 1f, 1f, -1f, 1f, 1f, 1f, 1f, -1f, -1f, + + -1f, -1f, 1f, -1f, 1f, -1f, -1f, 1f, 1f, -1f, -1f, -1f + }; + + private static final float[] s_cubeTexCoords = + { // LT RB RT LB + 0f, 1f, 1f, 0f, 1f, 1f, 0f, 0f, + + 0f, 1f, 1f, 0f, 1f, 1f, 0f, 0f, + + 0f, 1f, 1f, 0f, 1f, 1f, 0f, 0f, + + 0f, 1f, 1f, 0f, 1f, 1f, 0f, 0f, + + 0f, 0f, 1f, 1f, 0f, 1f, 1f, 0f, + + 0f, 0f, 1f, 1f, 0f, 1f, 1f, 0f, + }; + + private static final float[] s_cubeColors = + { + 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, + + 40f/255f, 80f/255f, 160f/255f, 255f/255f, 40f/255f, 80f/255f, 160f/255f, 255f/255f, + 40f/255f, 80f/255f, 160f/255f, 255f/255f, 40f/255f, 80f/255f, 160f/255f, 255f/255f, + + 40f/255f, 80f/255f, 160f/255f, 255f/255f, 40f/255f, 80f/255f, 160f/255f, 255f/255f, + 40f/255f, 80f/255f, 160f/255f, 255f/255f, 40f/255f, 80f/255f, 160f/255f, 255f/255f, + + 128f/255f, 128f/255f, 128f/255f, 255f/255f, 128f/255f, 128f/255f, 128f/255f, 255f/255f, + 128f/255f, 128f/255f, 128f/255f, 255f/255f, 128f/255f, 128f/255f, 128f/255f, 255f/255f, + + 255f/255f, 110f/255f, 10f/255f, 255f/255f, 255f/255f, 110f/255f, 10f/255f, 255f/255f, + 255f/255f, 110f/255f, 10f/255f, 255f/255f, 255f/255f, 110f/255f, 10f/255f, 255f/255f, + + 255f/255f, 70f/255f, 60f/255f, 255f/255f, 255f/255f, 70f/255f, 60f/255f, 255f/255f, + 255f/255f, 70f/255f, 60f/255f, 255f/255f, 255f/255f, 70f/255f, 60f/255f, 255f/255f + }; + + private static final float[] s_cubeNormals = + { + 0f, 0f, 1f, 0f, 0f, 1f, 0f, 0f, 1f, 0f, 0f, 1f, + + 0f, 0f, -1f, 0f, 0f, -1f, 0f, 0f, -1f, 0f, 0f, -1f, + + 0f, -1f, 0f, 0f, -1f, 0f, 0f, -1f, 0f, 0f, -1f, 0f, + + 0f, 1f, 0f, 0f, 1f, 0f, 0f, 1f, 0f, 0f, 1f, 0f, + + 1f, 0f, 0f, 1f, 0f, 0f, 1f, 0f, 0f, 1f, 0f, 0f, + + -1f, 0f, 0f, -1f, 0f, 0f, -1f, 0f, 0f, -1f, 0f, 0f + }; + private static final byte[] s_cubeIndices = + { + 0, 3, 1, 2, 0, 1, /* front */ + 6, 5, 4, 5, 7, 4, /* back */ + 8, 11, 9, 10, 8, 9, /* top */ + 15, 12, 13, 12, 14, 13, /* bottom */ + 16, 19, 17, 18, 16, 17, /* right */ + 23, 20, 21, 20, 22, 21 /* left */ + }; + + public static void main(String[] args) { + int width = 510; + int height = 300; + System.err.println("TexCubeES2.run()"); + + 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(); + window.addGLEventListener(new GLEventListener() { + @Override + public void init(GLAutoDrawable drawable) { + texSource.initGLResources(drawable.getGL()); + } + @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) { } + }); + window.addGLEventListener(new TexCubeES2(texSource, false, -2.3f, 0f, 0f)); + window.setVisible(true); + final Animator anim = new Animator(window); + // anim.setUpdateFPSFrames(60, System.err); + anim.start(); + window.addWindowListener(new WindowAdapter() { + public void windowDestroyed(WindowEvent e) { + anim.stop(); + } + }); + } +} + 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 new file mode 100755 index 000000000..343c4b2a6 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.opengl.test.junit.jogl.demos.es2.av; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; + +import javax.media.opengl.GL2ES2; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLException; +import javax.media.opengl.GLProfile; + +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.es2.TexCubeES2; +import com.jogamp.opengl.test.junit.util.MiscUtils; +import com.jogamp.opengl.util.Animator; +import com.jogamp.opengl.util.av.GLMediaPlayer; +import com.jogamp.opengl.util.av.GLMediaPlayer.GLMediaEventListener; +import com.jogamp.opengl.util.av.GLMediaPlayerFactory; + +public class MovieCube implements GLEventListener, GLMediaEventListener { + GLWindow window; + boolean quit = false; + TexCubeES2 cube=null; + GLMediaPlayer mPlayer=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); + } + + @Override + public void attributesChanges(GLMediaPlayer mp, int event_mask, long when) { + System.out.println("attributesChanges: "+mp+", 0x"+Integer.toHexString(event_mask)+", when "+when); + } + + @Override + public void newFrameAvailable(GLMediaPlayer mp, long when) { + // System.out.println("newFrameAvailable: "+mp+", when "+when); + } + + public void init(GLAutoDrawable drawable) { + GL2ES2 gl = drawable.getGL().getGL2ES2(); + System.err.println(JoglVersion.getGLInfo(gl, null)); + + try { + System.out.println("p0 "+mPlayer); + mPlayer.initGLStream(gl, stream); + System.out.println("p1 "+mPlayer); + } catch (Exception e) { + e.printStackTrace(); + if(null != mPlayer) { + mPlayer.destroy(gl); + mPlayer = null; + } + throw new GLException(e); + } + + cube.init(drawable); + mPlayer.start(); + } + + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + if(null == mPlayer) { return; } + cube.reshape(drawable, x, y, width, height); + } + + public void dispose(GLAutoDrawable drawable) { + if(null == mPlayer) { return; } + mPlayer.stop(); + GL2ES2 gl = drawable.getGL().getGL2ES2(); + mPlayer.destroy(gl); + mPlayer=null; + cube.dispose(drawable); + cube=null; + } + + public void display(GLAutoDrawable drawable) { + if(null == mPlayer) { return; } + cube.display(drawable); + } + + public void displayChanged(javax.media.opengl.GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { + } + + public static void main(String[] args) throws MalformedURLException, IOException { + int width = 510; + int height = 300; + System.err.println("TexCubeES2.run()"); + + String url_s="http://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_320x180.mp4"; + 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("-url")) { + i++; + url_s = args[i]; + } + } + final MovieCube mc = new MovieCube(new URL(url_s).openConnection(), -2.3f, 0f, 0f); + + 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); + window.addGLEventListener(mc); + window.setVisible(true); + final Animator anim = new Animator(window); + // anim.setUpdateFPSFrames(60, System.err); + anim.start(); + window.addWindowListener(new WindowAdapter() { + public void windowDestroyed(WindowEvent e) { + anim.stop(); + } + }); + } +} + 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 d32283473..fa2870437 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 @@ -36,7 +36,6 @@ import java.nio.FloatBuffer; import javax.media.opengl.GL; import javax.media.opengl.GL2ES2; -import javax.media.opengl.GLArrayData; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLES2; @@ -54,18 +53,19 @@ 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.av.GLMediaPlayer; -import com.jogamp.opengl.av.GLMediaEventListener; -import com.jogamp.opengl.av.GLMediaPlayerFactory; 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.av.GLMediaPlayer; +import com.jogamp.opengl.util.av.GLMediaPlayer.GLMediaEventListener; +import com.jogamp.opengl.util.av.GLMediaPlayerFactory; 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 MovieSimple implements GLEventListener, GLMediaEventListener { private int winWidth, winHeight; @@ -93,8 +93,15 @@ public class MovieSimple implements GLEventListener, GLMediaEventListener { public void setTransparency(float alpha) { this.effects |= EFFECT_TRANSPARENT; this.alpha = alpha; - } - + } + + GLMediaPlayer mPlayer; + URLConnection stream = null; + boolean mPlayerExternal; + boolean mPlayerShared; + boolean mPlayerScaleOrig; + GLArrayDataServer interleavedVBO; + private final MouseListener mouseAction = new MouseAdapter() { public void mousePressed(MouseEvent e) { if(e.getY()<=winHeight/2 && null!=mPlayer && 1 == e.getClickCount()) { @@ -133,22 +140,11 @@ public class MovieSimple implements GLEventListener, GLMediaEventListener { // prevMouseY = y; } public void mouseWheelMoved(MouseEvent e) { - int r = e.getWheelRotation(); - if(r>0) { - zoom += 0.1; - } else if(r<0) { - zoom -= 0.1; - } + zoom += e.getWheelRotation()/10f; System.err.println("zoom: "+zoom); } }; - - GLMediaPlayer mPlayer; - URLConnection stream = null; - boolean mPlayerExternal; - boolean mPlayerShared; - boolean mPlayerScaleOrig; - + public MovieSimple(URLConnection stream) throws IOException { mPlayerScaleOrig = false; mPlayerShared = false; @@ -182,7 +178,7 @@ public class MovieSimple implements GLEventListener, GLMediaEventListener { @Override public void newFrameAvailable(GLMediaPlayer mp, long when) { - // System.out.println("newFrameAvailable: "+mp+", when "+when); + // System.out.println("newFrameAvailable: "+mp+", when "+when); } public void start() { @@ -205,8 +201,8 @@ public class MovieSimple implements GLEventListener, GLMediaEventListener { private void initShader(GL2ES2 gl, boolean useExternalTexture) { // Create & Compile the shader objects - final String vShaderBasename = gl.isGLES2() ? "moviesimple_es2" : "moviesimple_gl2" ; - final String fShaderBasename = gl.isGLES2() ? ( useExternalTexture ? "moviesimple_es2_exttex" : "moviesimple_es2" ) : "moviesimple_gl2"; + 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, 1, MovieSimple.class, "../shader", "../shader/bin", vShaderBasename); @@ -236,8 +232,6 @@ public class MovieSimple implements GLEventListener, GLMediaEventListener { System.err.println("Alpha: "+alpha+", opaque "+drawable.getChosenGLCapabilities().isBackgroundOpaque()+ ", "+drawable.getClass().getName()+", "+drawable); - gl.glFinish(); - boolean useExternalTexture = false; try { System.out.println("p0 "+mPlayer+", shared "+mPlayerShared); @@ -281,6 +275,7 @@ public class MovieSimple implements GLEventListener, GLMediaEventListener { float mWidth = mPlayer.getWidth(); float mHeight = mPlayer.getHeight(); float mAspect = mWidth/mHeight; + System.err.println("XXX0: mov aspect: "+mAspect); float[] verts; float xs, ys; if(orthoProjection) { @@ -311,56 +306,59 @@ public class MovieSimple implements GLEventListener, GLMediaEventListener { } final float ss = 1f, ts = 1f; // scale tex-coord - final GLArrayDataServer interleaved = GLArrayDataServer.createGLSLInterleaved(9, GL.GL_FLOAT, false, 12, GL.GL_STATIC_DRAW); + interleavedVBO = GLArrayDataServer.createGLSLInterleaved(3+4+2, GL.GL_FLOAT, false, 3*4, GL.GL_STATIC_DRAW); { - GLArrayData vertices = interleaved.addGLSLSubArray("mgl_Vertex", 3, GL.GL_ARRAY_BUFFER); - FloatBuffer verticeb = (FloatBuffer)vertices.getBuffer(); + interleavedVBO.addGLSLSubArray("mgl_Vertex", 3, GL.GL_ARRAY_BUFFER); + interleavedVBO.addGLSLSubArray("mgl_Color", 4, GL.GL_ARRAY_BUFFER); + interleavedVBO.addGLSLSubArray("mgl_MultiTexCoord", 2, GL.GL_ARRAY_BUFFER); - GLArrayData texcoord = interleaved.addGLSLSubArray("mgl_MultiTexCoord", 2, GL.GL_ARRAY_BUFFER); - TextureCoords tc = mPlayer.getTextureCoords(); - FloatBuffer texcoordb = (FloatBuffer)texcoord.getBuffer(); + 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); + System.err.println("XXX0: tex y-flip: "+tex.getMustFlipVertically()); + System.err.println("XXX0: "+tex.getImageTexCoords()); - GLArrayData colors = interleaved.addGLSLSubArray("mgl_Color", 4, GL.GL_ARRAY_BUFFER); - FloatBuffer colorb = (FloatBuffer)colors.getBuffer(); - // left-bottom - verticeb.put(verts[0]); verticeb.put(verts[1]); verticeb.put(verts[2]); - texcoordb.put( tc.left() *ss); texcoordb.put( tc.bottom() *ts); + ib.put(verts[0]); ib.put(verts[1]); ib.put(verts[2]); if( hasEffect(EFFECT_GRADIENT_BOTTOM2TOP) ) { - colorb.put( 0); colorb.put( 0); colorb.put( 0); colorb.put(alpha); + ib.put( 0); ib.put( 0); ib.put( 0); ib.put(alpha); } else { - colorb.put( 1); colorb.put( 1); colorb.put( 1); colorb.put(alpha); + ib.put( 1); ib.put( 1); ib.put( 1); ib.put(alpha); } + ib.put( tc.left() *ss); ib.put( tc.bottom() *ts); // right-bottom - verticeb.put(verts[3]); verticeb.put(verts[1]); verticeb.put(verts[2]); - texcoordb.put( tc.right() *ss); texcoordb.put( tc.bottom() *ts); + ib.put(verts[3]); ib.put(verts[1]); ib.put(verts[2]); if( hasEffect(EFFECT_GRADIENT_BOTTOM2TOP) ) { - colorb.put( 0); colorb.put( 0); colorb.put( 0); colorb.put(alpha); + ib.put( 0); ib.put( 0); ib.put( 0); ib.put(alpha); } else { - colorb.put( 1); colorb.put( 1); colorb.put( 1); colorb.put(alpha); + ib.put( 1); ib.put( 1); ib.put( 1); ib.put(alpha); } + ib.put( tc.right() *ss); ib.put( tc.bottom() *ts); // left-top - verticeb.put(verts[0]); verticeb.put(verts[4]); verticeb.put(verts[2]); - texcoordb.put( tc.left() *ss); texcoordb.put( tc.top() *ts); + ib.put(verts[0]); ib.put(verts[4]); ib.put(verts[2]); if( hasEffect(EFFECT_GRADIENT_BOTTOM2TOP) ) { - colorb.put( 1); colorb.put( 1); colorb.put( 1); colorb.put(alpha); + ib.put( 1); ib.put( 1); ib.put( 1); ib.put(alpha); } else { - colorb.put( 1); colorb.put( 1); colorb.put( 1); colorb.put(alpha); + ib.put( 1); ib.put( 1); ib.put( 1); ib.put(alpha); } + ib.put( tc.left() *ss); ib.put( tc.top() *ts); // right-top - verticeb.put(verts[3]); verticeb.put(verts[4]); verticeb.put(verts[2]); - texcoordb.put( tc.right() *ss); texcoordb.put( tc.top() *ts); + ib.put(verts[3]); ib.put(verts[4]); ib.put(verts[2]); if( hasEffect(EFFECT_GRADIENT_BOTTOM2TOP) ) { - colorb.put( 1); colorb.put( 1); colorb.put( 1); colorb.put(alpha); + ib.put( 1); ib.put( 1); ib.put( 1); ib.put(alpha); } else { - colorb.put( 1); colorb.put( 1); colorb.put( 1); colorb.put(alpha); + ib.put( 1); ib.put( 1); ib.put( 1); ib.put(alpha); } + ib.put( tc.right() *ss); ib.put( tc.top() *ts); } - interleaved.seal(gl, true); - + interleavedVBO.seal(gl, true); + interleavedVBO.enableBuffer(gl, false); + st.ownAttribute(interleavedVBO, true); gl.glClearColor(0.3f, 0.3f, 0.3f, 0.3f); gl.glEnable(GL2ES2.GL_DEPTH_TEST); @@ -368,6 +366,7 @@ public class MovieSimple implements GLEventListener, GLMediaEventListener { st.useProgram(gl, false); // Let's show the completed shader state .. + System.out.println("iVBO: "+interleavedVBO); System.out.println(st); if(null!=mPlayer) { @@ -460,24 +459,27 @@ public class MovieSimple implements GLEventListener, GLMediaEventListener { rotate = 0; } st.uniform(gl, pmvMatrixUniform); - + interleavedVBO.enableBuffer(gl, true); + Texture tex = null; if(null!=mPlayer) { - final GLMediaPlayer.TextureFrame texFrame; + final TextureSequence.TextureFrame texFrame; if(mPlayerShared) { texFrame=mPlayer.getLastTexture(); } else { texFrame=mPlayer.getNextTexture(gl, true); } if(null != texFrame) { - final Texture tex = texFrame.getTexture(); + tex = texFrame.getTexture(); gl.glActiveTexture(GL.GL_TEXTURE0+mPlayer.getTextureUnit()); tex.enable(gl); tex.bind(gl); - gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4); - tex.disable(gl); } } - + gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4); + if(null != tex) { + tex.disable(gl); + } + interleavedVBO.enableBuffer(gl, false); st.useProgram(gl, false); } @@ -485,19 +487,19 @@ public class MovieSimple implements GLEventListener, GLMediaEventListener { } public static void main(String[] args) throws IOException, MalformedURLException { - int w = 640; - int h = 480; + int width = 640; + int height = 600; boolean ortho = true; boolean zoom = false; - String url_s="file:///mnt/sdcard/Movies/BigBuckBunny_320x180.mp4"; + String url_s="http://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_320x180.mp4"; for(int i=0; i<args.length; i++) { if(args[i].equals("-width")) { i++; - w = MiscUtils.atoi(args[i], w); + width = MiscUtils.atoi(args[i], width); } else if(args[i].equals("-height")) { i++; - h = MiscUtils.atoi(args[i], h); + height = MiscUtils.atoi(args[i], height); } else if(args[i].equals("-projection")) { ortho=false; } else if(args[i].equals("-zoom")) { @@ -507,7 +509,7 @@ public class MovieSimple implements GLEventListener, GLMediaEventListener { url_s = args[i]; } } - MovieSimple ms = new MovieSimple(new URL(url_s).openConnection()); + final MovieSimple ms = new MovieSimple(new URL(url_s).openConnection()); ms.setScaleOrig(!zoom); ms.setOrthoProjection(ortho); @@ -517,7 +519,7 @@ public class MovieSimple implements GLEventListener, GLMediaEventListener { window.addGLEventListener(ms); - window.setSize(w, h); + window.setSize(width, height); window.setVisible(true); final Animator anim = new Animator(window); anim.start(); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/moviesimple_es2.fp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texsimple_es2.fp index e3b9eea04..3a7dcf7a2 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/moviesimple_es2.fp +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texsimple_es2.fp @@ -6,4 +6,4 @@ precision mediump float; uniform sampler2D mgl_ActiveTexture; -#include moviesimple_xxx.fp +#include texsimple_xxx.fp diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/moviesimple_es2.vp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texsimple_es2.vp index 6708d546e..16c070a31 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/moviesimple_es2.vp +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texsimple_es2.vp @@ -4,4 +4,4 @@ precision mediump float; -#include moviesimple_xxx.vp
\ No newline at end of file +#include texsimple_xxx.vp diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/moviesimple_es2_exttex.fp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texsimple_es2_exttex.fp index 39b0fe8d0..c45cebaf3 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/moviesimple_es2_exttex.fp +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texsimple_es2_exttex.fp @@ -8,4 +8,4 @@ precision mediump float; uniform samplerExternalOES mgl_ActiveTexture; -#include moviesimple_xxx.fp +#include texsimple_xxx.fp diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/moviesimple_gl2.fp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texsimple_gl2.fp index 6e0e7063c..31a63e6a4 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/moviesimple_gl2.fp +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texsimple_gl2.fp @@ -4,4 +4,4 @@ uniform sampler2D mgl_ActiveTexture; -#include moviesimple_xxx.fp +#include texsimple_xxx.fp diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/moviesimple_gl2.vp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texsimple_gl2.vp index f8675eea4..8fcdc0ac9 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/moviesimple_gl2.vp +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texsimple_gl2.vp @@ -2,4 +2,4 @@ #version 110 -#include moviesimple_xxx.vp
\ No newline at end of file +#include texsimple_xxx.vp diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/moviesimple_xxx.fp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texsimple_xxx.fp index d32c1d293..1465b28ed 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/moviesimple_xxx.fp +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texsimple_xxx.fp @@ -5,7 +5,12 @@ varying vec4 frontColor; void main (void) { - vec4 texColor = texture2D(mgl_ActiveTexture, mgl_texCoord); + 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/moviesimple_xxx.vp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texsimple_xxx.vp index dea57ca9e..dea57ca9e 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/moviesimple_xxx.vp +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texsimple_xxx.vp |