From f10b30c16aeec428378d1d560d030b2d39801c4e Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 11 Apr 2012 19:46:37 +0200 Subject: Refine GLMediaPlayer/TextureSequence, add MovieCube demo, fix minor bug in Texture - Add TextureSequence, base interface of GLMediaPlayer to genralize texture streams - TextureSequence / GLMediaPlayer: Use inner classes for event and texture data - getLastTexture() shall never return 'null', initialization of TextureSequence (initGLStream(..), etc) shall provide a TextureFrame w/ the stream's dimension. - GLMediaPlayerImpl.createTexImageImpl() y-flip defaults to 'false' impl. shall define y-flip, if required. - Added MovieCube demo - Fix Texture: initialize aspectRation for 'wrapping' ctor - --- make/build-jogl.xml | 7 +- make/resources/android/AndroidManifest-test.xml | 10 + make/resources/android/res-test/values/strings.xml | 2 + make/scripts/tests.sh | 6 +- .../opengl/util/av/GLMediaEventListener.java | 28 -- .../com/jogamp/opengl/util/av/GLMediaPlayer.java | 69 ++-- .../opengl/util/av/GLMediaPlayerFactory.java | 4 +- .../com/jogamp/opengl/util/texture/Texture.java | 1 + .../jogamp/opengl/util/texture/TextureCoords.java | 20 +- .../opengl/util/texture/TextureSequence.java | 90 +++++ .../android/av/AndroidGLMediaPlayerAPI14.java | 26 +- .../jogamp/opengl/omx/OMXGLMediaPlayer.java | 28 +- .../jogamp/opengl/util/av/EGLMediaPlayerImpl.java | 9 +- .../jogamp/opengl/util/av/GLMediaPlayerImpl.java | 62 +-- .../jogamp/opengl/util/av/NullGLMediaPlayer.java | 34 +- .../opengl/test/android/MovieCubeActivity0.java | 118 ++++++ .../test/android/MovieCubeActivityLauncher0.java | 79 ++++ .../opengl/test/android/MovieSimpleActivity.java | 204 ---------- .../opengl/test/android/MovieSimpleActivity0.java | 2 +- .../opengl/test/android/MovieSimpleActivity1.java | 204 ++++++++++ .../android/MovieSimpleActivityLauncher00b.java | 2 +- .../android/MovieSimpleActivityLauncher01a.java | 2 +- .../android/MovieSimpleActivityLauncher01b.java | 2 +- .../android/MovieSimpleActivityLauncher02.java | 2 +- .../test/junit/jogl/demos/TestTextureSequence.java | 89 +++++ .../test/junit/jogl/demos/es2/TexCubeES2.java | 436 +++++++++++++++++++++ .../test/junit/jogl/demos/es2/av/MovieCube.java | 164 ++++++++ .../test/junit/jogl/demos/es2/av/MovieSimple.java | 130 +++--- .../junit/jogl/demos/es2/shader/moviesimple_es2.fp | 9 - .../junit/jogl/demos/es2/shader/moviesimple_es2.vp | 7 - .../demos/es2/shader/moviesimple_es2_exttex.fp | 11 - .../junit/jogl/demos/es2/shader/moviesimple_gl2.fp | 7 - .../junit/jogl/demos/es2/shader/moviesimple_gl2.vp | 5 - .../junit/jogl/demos/es2/shader/moviesimple_xxx.fp | 13 - .../junit/jogl/demos/es2/shader/moviesimple_xxx.vp | 17 - .../junit/jogl/demos/es2/shader/texsimple_es2.fp | 9 + .../junit/jogl/demos/es2/shader/texsimple_es2.vp | 7 + .../jogl/demos/es2/shader/texsimple_es2_exttex.fp | 11 + .../junit/jogl/demos/es2/shader/texsimple_gl2.fp | 7 + .../junit/jogl/demos/es2/shader/texsimple_gl2.vp | 5 + .../junit/jogl/demos/es2/shader/texsimple_xxx.fp | 18 + .../junit/jogl/demos/es2/shader/texsimple_xxx.vp | 17 + 42 files changed, 1452 insertions(+), 521 deletions(-) delete mode 100644 src/jogl/classes/com/jogamp/opengl/util/av/GLMediaEventListener.java create mode 100644 src/jogl/classes/com/jogamp/opengl/util/texture/TextureSequence.java create mode 100644 src/test/com/jogamp/opengl/test/android/MovieCubeActivity0.java create mode 100644 src/test/com/jogamp/opengl/test/android/MovieCubeActivityLauncher0.java delete mode 100644 src/test/com/jogamp/opengl/test/android/MovieSimpleActivity.java create mode 100644 src/test/com/jogamp/opengl/test/android/MovieSimpleActivity1.java create 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/es2/TexCubeES2.java create mode 100755 src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java delete mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/moviesimple_es2.fp delete mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/moviesimple_es2.vp delete mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/moviesimple_es2_exttex.fp delete mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/moviesimple_gl2.fp delete mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/moviesimple_gl2.vp delete mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/moviesimple_xxx.fp delete mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/moviesimple_xxx.vp create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texsimple_es2.fp create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texsimple_es2.vp create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texsimple_es2_exttex.fp create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texsimple_gl2.fp create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texsimple_gl2.vp create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texsimple_xxx.fp create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texsimple_xxx.vp diff --git a/make/build-jogl.xml b/make/build-jogl.xml index 9a4ad8b8e..b723c211b 100644 --- a/make/build-jogl.xml +++ b/make/build-jogl.xml @@ -150,7 +150,7 @@ value="com/jogamp/opengl/**/swt/**"/> + value="com/jogamp/opengl/util/* com/jogamp/opengl/util/texture/** com/jogamp/opengl/util/av/* com/jogamp/opengl/util/packrect/** jogamp/opengl/util/* jogamp/opengl/util/av/* jogamp/opengl/util/pngj/**"/> @@ -176,9 +176,6 @@ - - @@ -1667,7 +1664,7 @@ diff --git a/make/resources/android/AndroidManifest-test.xml b/make/resources/android/AndroidManifest-test.xml index c8779cda9..4e6a5a2ba 100644 --- a/make/resources/android/AndroidManifest-test.xml +++ b/make/resources/android/AndroidManifest-test.xml @@ -145,6 +145,16 @@ + + + + + + diff --git a/make/resources/android/res-test/values/strings.xml b/make/resources/android/res-test/values/strings.xml index 5f41a1be7..fcaf102ac 100644 --- a/make/resources/android/res-test/values/strings.xml +++ b/make/resources/android/res-test/values/strings.xml @@ -25,4 +25,6 @@ MovieSimple1b MovieSimple2 MovieSimple + MovieCube0 + MovieCube diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh index 248663a96..c2081691c 100755 --- a/make/scripts/tests.sh +++ b/make/scripts/tests.sh @@ -62,6 +62,8 @@ function jrun() { #D_ARGS="-Djogl.debug.GLDebugMessageHandler -Djogl.debug.TraceGL -Djogl.debug.DebugGL -Djogl.debug.GLSLCode -Djogl.debug.GLSLState" #D_ARGS="-Djogl.debug.GLDebugMessageHandler -Djogl.debug.DebugGL -Djogl.debug.TraceGL" #D_ARGS="-Djogl.debug.TraceGL -Djogl.debug.DebugGL -Djogl.debug.GLSLCode" + #D_ARGS="-Djogamp.debug.IOUtil -Djogl.debug.GLSLCode" + #D_ARGS="-Djogl.debug.GLArrayData" #D_ARGS="-Djogl.debug.EGL -Dnativewindow.debug.GraphicsConfiguration -Djogl.debug.GLDrawable" #D_ARGS="-Dnewt.test.Screen.disableScreenMode -Dnewt.debug.Screen" #D_ARGS="-Djogl.debug.ExtensionAvailabilityCache -Djogl.debug=all -Dnativewindow.debug=all -Djogamp.debug.ProcAddressHelper=true -Djogamp.debug.NativeLibrary=true -Djogamp.debug.NativeLibrary.Lookup=true" @@ -238,8 +240,10 @@ function testawtswt() { #testnoawt -Djava.awt.headless=true com.jogamp.opengl.test.junit.newt.TestGLWindows01NEWT #testnoawt com.jogamp.opengl.test.junit.jogl.util.TestGLReadBufferUtilTextureIOWrite01NEWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.util.TestGLReadBufferUtilTextureIOWrite02NEWT $* -testnoawt com.jogamp.opengl.test.junit.jogl.util.TestPNGImage01NEWT $* +#testnoawt com.jogamp.opengl.test.junit.jogl.util.TestPNGImage01NEWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.av.MovieSimple $* +testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.av.MovieCube $* +#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.TexCubeES2 $* # # awt (testawt) diff --git a/src/jogl/classes/com/jogamp/opengl/util/av/GLMediaEventListener.java b/src/jogl/classes/com/jogamp/opengl/util/av/GLMediaEventListener.java deleted file mode 100644 index 9887a417c..000000000 --- a/src/jogl/classes/com/jogamp/opengl/util/av/GLMediaEventListener.java +++ /dev/null @@ -1,28 +0,0 @@ - -package com.jogamp.opengl.av; - -import javax.media.opengl.GL; - -public interface GLMediaEventListener { - - static final int EVENT_CHANGE_SIZE = 1<<0; - static final int EVENT_CHANGE_FPS = 1<<1; - static final int EVENT_CHANGE_BPS = 1<<2; - static final int EVENT_CHANGE_LENGTH = 1<<3; - - /** - * @param mp the event source - * @param event_mask the changes attributes - * @param when system time in msec. - */ - public void attributesChanges(GLMediaPlayer mp, int event_mask, long when); - - /** - * Signaling listeners that {@link GLMediaPlayer#getNextTexture(GL, boolean)} is able to deliver a new frame. - * @param mp the event source - * @param when system time in msec. - **/ - public void newFrameAvailable(GLMediaPlayer mp, long when); - -} - diff --git a/src/jogl/classes/com/jogamp/opengl/util/av/GLMediaPlayer.java b/src/jogl/classes/com/jogamp/opengl/util/av/GLMediaPlayer.java index b3827d520..d86c8bfd0 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/av/GLMediaPlayer.java +++ b/src/jogl/classes/com/jogamp/opengl/util/av/GLMediaPlayer.java @@ -25,7 +25,7 @@ * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ -package com.jogamp.opengl.av; +package com.jogamp.opengl.util.av; import java.io.IOException; import java.net.URLConnection; @@ -35,8 +35,7 @@ import javax.media.opengl.GLException; import jogamp.opengl.Debug; -import com.jogamp.opengl.util.texture.Texture; -import com.jogamp.opengl.util.texture.TextureCoords; +import com.jogamp.opengl.util.texture.TextureSequence; /** * Lifecycle of an GLMediaPlayer: @@ -49,8 +48,23 @@ import com.jogamp.opengl.util.texture.TextureCoords; * {@link #destroy(GL)} ANY Uninitialized * */ -public interface GLMediaPlayer { +public interface GLMediaPlayer extends TextureSequence { public static final boolean DEBUG = Debug.debug("GLMediaPlayer"); + + public interface GLMediaEventListener extends TexSeqEventListener { + + static final int EVENT_CHANGE_SIZE = 1<<0; + static final int EVENT_CHANGE_FPS = 1<<1; + static final int EVENT_CHANGE_BPS = 1<<2; + static final int EVENT_CHANGE_LENGTH = 1<<3; + + /** + * @param mp the event source + * @param event_mask the changes attributes + * @param when system time in msec. + */ + public void attributesChanges(GLMediaPlayer mp, int event_mask, long when); + } public enum State { Uninitialized(0), Stopped(1), Playing(2), Paused(3); @@ -62,38 +76,14 @@ public interface GLMediaPlayer { } } - public static class TextureFrame { - public TextureFrame(Texture t) { - texture = t; - // stMatrix = new float[4*4]; - // ProjectFloat.makeIdentityf(stMatrix, 0); - } - - public final Texture getTexture() { return texture; } - // public final float[] getSTMatrix() { return stMatrix; } - - public String toString() { - return "TextureFrame[" + texture + "]"; - } - protected final Texture texture; - // protected final float[] stMatrix; - } - public int getTextureCount(); - public int getTextureTarget(); - /** Defaults to 0 */ public void setTextureUnit(int u); - public int getTextureUnit(); - /** Sets the texture min-mag filter, defaults to {@link GL#GL_NEAREST}. */ public void setTextureMinMagFilter(int[] minMagFilter); - public int[] getTextureMinMagFilter(); - /** Sets the texture min-mag filter, defaults to {@link GL#GL_CLAMP_TO_EDGE}. */ public void setTextureWrapST(int[] wrapST); - public int[] getTextureWrapST(); /** * Sets the stream to be used. Initializes all stream related states inclusive OpenGL ones, @@ -157,27 +147,17 @@ public interface GLMediaPlayer { public long seek(long msec); /** - * @return the last updated texture. Maybe null in case no last frame is available. - * Not blocking. + * {@inheritDoc} */ - public TextureFrame getLastTexture(); - + public TextureSequence.TextureFrame getLastTexture(); + /** - * Returns the next texture to be rendered. - *

- * Implementation shall block until next frame is available if blocking is true, - * otherwise it shall return the last frame in case a new frame is not available. - *

- *

- * Shall return null in case no frame is available. - *

+ * {@inheritDoc} * * @see #addEventListener(GLMediaEventListener) * @see GLMediaEventListener#newFrameAvailable(GLMediaPlayer, long) */ - public TextureFrame getNextTexture(GL gl, boolean blocking); - - public TextureCoords getTextureCoords(); + public TextureSequence.TextureFrame getNextTexture(GL gl, boolean blocking); public URLConnection getURLConnection(); @@ -226,5 +206,6 @@ public interface GLMediaPlayer { public void removeEventListener(GLMediaEventListener l); - public GLMediaEventListener[] getEventListeners(); + public GLMediaEventListener[] getEventListeners(); + } diff --git a/src/jogl/classes/com/jogamp/opengl/util/av/GLMediaPlayerFactory.java b/src/jogl/classes/com/jogamp/opengl/util/av/GLMediaPlayerFactory.java index 1894f411f..df12fd12c 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/av/GLMediaPlayerFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/util/av/GLMediaPlayerFactory.java @@ -25,9 +25,9 @@ * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ -package com.jogamp.opengl.av; +package com.jogamp.opengl.util.av; -import jogamp.opengl.av.NullGLMediaPlayer; +import jogamp.opengl.util.av.NullGLMediaPlayer; import com.jogamp.common.os.AndroidVersion; import com.jogamp.common.os.Platform; diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/Texture.java b/src/jogl/classes/com/jogamp/opengl/util/texture/Texture.java index 208fd053d..a94b1f827 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/Texture.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/Texture.java @@ -197,6 +197,7 @@ public class Texture { this.mustFlipVertically = mustFlipVertically; this.texWidth = texWidth; this.texHeight = texHeight; + aspectRatio = (float) imgWidth / (float) imgHeight; setImageSize(imgWidth, imgHeight, target); } diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureCoords.java b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureCoords.java index 61f5d116c..39647039b 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureCoords.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureCoords.java @@ -36,8 +36,6 @@ package com.jogamp.opengl.util.texture; -import java.nio.FloatBuffer; - /** Specifies texture coordinates for a rectangular area of a texture. Note that some textures are inherently flipped vertically from OpenGL's standard coordinate system. This class takes care of @@ -79,22 +77,6 @@ public class TextureCoords { return d; } - /** Transfers {s * ss, t * ts} from this object into the given FloatBuffer in the following order: - *
-     *   left,  bottom
-     *   right, bottom
-     *   left,  top
-     *   right  top
-     * 
- */ - public FloatBuffer getST_LB_RB_LT_RT(FloatBuffer d, float ss, float ts) { - d.put( left *ss); d.put( bottom*ts); - d.put( right *ss); d.put( bottom*ts); - d.put( left *ss); d.put( top *ts); - d.put( right *ss); d.put( top *ts); - return d; - } - /** Returns the leftmost (x) texture coordinate of this rectangle. */ public float left() { return left; } @@ -110,4 +92,6 @@ public class TextureCoords { /** Returns the topmost (y) texture coordinate of this rectangle. */ public float top() { return top; } + + public String toString() { return "TexCoord[h: "+left+" - "+right+", v: "+bottom+" - "+top+"]"; } } diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureSequence.java b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureSequence.java new file mode 100644 index 000000000..e6d21c613 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureSequence.java @@ -0,0 +1,90 @@ +/** + * 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.util.texture; + +import javax.media.opengl.GL; + +public interface TextureSequence { + + public static class TextureFrame { + public TextureFrame(Texture t) { + texture = t; + // stMatrix = new float[4*4]; + // ProjectFloat.makeIdentityf(stMatrix, 0); + } + + public final Texture getTexture() { return texture; } + // public final float[] getSTMatrix() { return stMatrix; } + + public String toString() { + return "TextureFrame[" + texture + "]"; + } + protected final Texture texture; + // protected final float[] stMatrix; + } + + public interface TexSeqEventListener { + /** + * Signaling listeners that {@link TextureSequence#getNextTexture(GL, boolean)} is able to deliver a new frame. + * @param ts the event source + * @param when system time in msec. + **/ + public void newFrameAvailable(T ts, long when); + } + + public int getTextureTarget(); + + public int getTextureUnit(); + + public int[] getTextureMinMagFilter(); + + public int[] getTextureWrapST(); + + /** + * Returns the last updated texture. + *

+ * In case the instance is just initialized, it shall return a TextureFrame + * object with valid attributes. The texture content may be undefined + * until the first call of {@link #getNextTexture(GL, boolean)}.
+ *

+ * Not blocking. + */ + public TextureFrame getLastTexture(); + + /** + * Returns the next texture to be rendered. + *

+ * Implementation shall block until next frame is available if blocking is true, + * otherwise it shall return the last frame in case a new frame is not available. + *

+ *

+ * Shall return null in case no frame is available. + *

+ */ + public TextureFrame getNextTexture(GL gl, boolean blocking); +} \ No newline at end of file diff --git a/src/jogl/classes/jogamp/opengl/android/av/AndroidGLMediaPlayerAPI14.java b/src/jogl/classes/jogamp/opengl/android/av/AndroidGLMediaPlayerAPI14.java index ae45662db..a50f1507f 100644 --- a/src/jogl/classes/jogamp/opengl/android/av/AndroidGLMediaPlayerAPI14.java +++ b/src/jogl/classes/jogamp/opengl/android/av/AndroidGLMediaPlayerAPI14.java @@ -32,10 +32,10 @@ import java.io.IOException; import javax.media.opengl.GL; import javax.media.opengl.GLES2; -import com.jogamp.opengl.util.texture.TextureCoords; +import com.jogamp.opengl.util.texture.TextureSequence; import jogamp.common.os.android.StaticContext; -import jogamp.opengl.av.GLMediaPlayerImpl; +import jogamp.opengl.util.av.GLMediaPlayerImpl; import android.graphics.SurfaceTexture; import android.graphics.SurfaceTexture.OnFrameAvailableListener; @@ -51,7 +51,7 @@ public class AndroidGLMediaPlayerAPI14 extends GLMediaPlayerImpl { MediaPlayer mp; volatile boolean updateSurface = false; Object updateSurfaceLock = new Object(); - TextureFrame lastTexFrame = null; + TextureSequence.TextureFrame lastTexFrame = null; /** private static String toString(MediaPlayer m) { @@ -133,12 +133,12 @@ public class AndroidGLMediaPlayerAPI14 extends GLMediaPlayerImpl { } @Override - public TextureFrame getLastTexture() { + public TextureSequence.TextureFrame getLastTexture() { return lastTexFrame; } @Override - public TextureFrame getNextTexture(GL gl, boolean blocking) { + public TextureSequence.TextureFrame getNextTexture(GL gl, boolean blocking) { if(null != stex && null != mp) { // Only block once, no while-loop. // This relaxes locking code of non crucial resources/events. @@ -166,11 +166,6 @@ public class AndroidGLMediaPlayerAPI14 extends GLMediaPlayerImpl { return lastTexFrame; } - @Override - public TextureCoords getTextureCoords() { - return texFrames[0].getTexture().getImageTexCoords(); - } - private void wakeUp(boolean newFrame) { synchronized(updateSurfaceLock) { if(newFrame) { @@ -226,12 +221,19 @@ public class AndroidGLMediaPlayerAPI14 extends GLMediaPlayerImpl { totalFrames = 0; duration = mp.getDuration(); acodec = "unknown"; - vcodec = "unknown"; + vcodec = "unknown"; } } @Override - protected void destroyTexImage(GL gl, TextureFrame imgTex) { + protected TextureSequence.TextureFrame createTexImage(GL gl, int idx, int[] tex) { + lastTexFrame = new TextureSequence.TextureFrame( createTexImageImpl(gl, idx, tex, true) ); + // lastTexFrame = super.createTexImage(gl, idx, tex); + return lastTexFrame; + } + + @Override + protected void destroyTexImage(GL gl, TextureSequence.TextureFrame imgTex) { if(null != stex) { stex.release(); stex = null; diff --git a/src/jogl/classes/jogamp/opengl/omx/OMXGLMediaPlayer.java b/src/jogl/classes/jogamp/opengl/omx/OMXGLMediaPlayer.java index 7c775dd9f..c005c2ea6 100644 --- a/src/jogl/classes/jogamp/opengl/omx/OMXGLMediaPlayer.java +++ b/src/jogl/classes/jogamp/opengl/omx/OMXGLMediaPlayer.java @@ -7,11 +7,10 @@ import java.net.URL; import javax.media.opengl.GL; import javax.media.opengl.GLException; -import com.jogamp.opengl.av.GLMediaEventListener; -import com.jogamp.opengl.util.texture.TextureCoords; +import com.jogamp.opengl.util.texture.TextureSequence; -import jogamp.opengl.av.EGLMediaPlayerImpl; import jogamp.opengl.egl.EGL; +import jogamp.opengl.util.av.EGLMediaPlayerImpl; public class OMXGLMediaPlayer extends EGLMediaPlayerImpl { protected long moviePtr = 0; @@ -26,7 +25,7 @@ public class OMXGLMediaPlayer extends EGLMediaPlayerImpl { protected long o_totalFrames = 0; protected long o_duration = 0; - protected TextureFrame lastTex = null; + protected TextureSequence.TextureFrame lastTex = null; public OMXGLMediaPlayer() { super(TextureType.KHRImage, true); @@ -41,7 +40,7 @@ public class OMXGLMediaPlayer extends EGLMediaPlayerImpl { } @Override - protected TextureFrame createTexImage(GL gl, int idx, int[] tex) { + protected TextureSequence.TextureFrame createTexImage(GL gl, int idx, int[] tex) { final EGLTextureFrame eglTex = (EGLTextureFrame) super.createTexImage(gl, idx, tex); _setStreamEGLImageTexture2D(moviePtr, idx, tex[idx], eglTex.getImage(), eglTex.getSync()); lastTex = eglTex; @@ -49,8 +48,9 @@ public class OMXGLMediaPlayer extends EGLMediaPlayerImpl { } @Override - protected void destroyTexImage(GL gl, TextureFrame imgTex) { - super.destroyTexImage(gl, imgTex); + protected void destroyTexImage(GL gl, TextureSequence.TextureFrame imgTex) { + lastTex = null; + super.destroyTexImage(gl, imgTex); } @Override @@ -76,7 +76,7 @@ public class OMXGLMediaPlayer extends EGLMediaPlayerImpl { System.out.println("setURL: p1 "+this); _setStream(moviePtr, textureCount, path); - System.out.println("setURL: p2 "+this); + System.out.println("setURL: p2 "+this); } @Override @@ -135,18 +135,18 @@ public class OMXGLMediaPlayer extends EGLMediaPlayerImpl { } @Override - public TextureFrame getLastTexture() { + public TextureSequence.TextureFrame getLastTexture() { return lastTex; } @Override - public synchronized TextureFrame getNextTexture(GL gl, boolean blocking) { + public synchronized TextureSequence.TextureFrame getNextTexture(GL gl, boolean blocking) { if(0==moviePtr) { throw new GLException("OMX native instance null"); } final int nextTex = _getNextTextureID(moviePtr, blocking); if(0 < nextTex) { - final TextureFrame eglImgTex = texFrameMap.get(new Integer(_getNextTextureID(moviePtr, blocking))); + final TextureSequence.TextureFrame eglImgTex = texFrameMap.get(new Integer(_getNextTextureID(moviePtr, blocking))); if(null!=eglImgTex) { lastTex = eglImgTex; } @@ -154,12 +154,6 @@ public class OMXGLMediaPlayer extends EGLMediaPlayerImpl { return lastTex; } - @Override - public TextureCoords getTextureCoords() { - return lastTex.getTexture().getImageTexCoords(); - } - - protected void attributesUpdated() { int event_mask = 0; if( o_width != width || o_height != height ) { diff --git a/src/jogl/classes/jogamp/opengl/util/av/EGLMediaPlayerImpl.java b/src/jogl/classes/jogamp/opengl/util/av/EGLMediaPlayerImpl.java index 2f6744fc5..52378d0fd 100644 --- a/src/jogl/classes/jogamp/opengl/util/av/EGLMediaPlayerImpl.java +++ b/src/jogl/classes/jogamp/opengl/util/av/EGLMediaPlayerImpl.java @@ -25,7 +25,7 @@ * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ -package jogamp.opengl.av; +package jogamp.opengl.util.av; import java.nio.IntBuffer; @@ -33,6 +33,7 @@ import javax.media.opengl.GL; import com.jogamp.common.nio.Buffers; import com.jogamp.opengl.util.texture.Texture; +import com.jogamp.opengl.util.texture.TextureSequence; import jogamp.opengl.egl.EGL; import jogamp.opengl.egl.EGLContext; @@ -53,7 +54,7 @@ public abstract class EGLMediaPlayerImpl extends GLMediaPlayerImpl { } } - public static class EGLTextureFrame extends TextureFrame { + public static class EGLTextureFrame extends TextureSequence.TextureFrame { public EGLTextureFrame(Texture t, long khrImage, long khrSync) { super(t); @@ -83,7 +84,7 @@ public abstract class EGLMediaPlayerImpl extends GLMediaPlayerImpl { } @Override - protected TextureFrame createTexImage(GL gl, int idx, int[] tex) { + protected TextureSequence.TextureFrame createTexImage(GL gl, int idx, int[] tex) { final Texture texture = super.createTexImageImpl(gl, idx, tex, true); final long image; final long sync; @@ -123,7 +124,7 @@ public abstract class EGLMediaPlayerImpl extends GLMediaPlayerImpl { } @Override - protected void destroyTexImage(GL gl, TextureFrame imgTex) { + protected void destroyTexImage(GL gl, TextureSequence.TextureFrame imgTex) { final EGLContext eglCtx = (EGLContext) gl.getContext(); final EGLExt eglExt = eglCtx.getEGLExt(); final EGLDrawable eglDrawable = (EGLDrawable) eglCtx.getGLDrawable(); diff --git a/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java b/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java index acd707288..bc3fa0919 100644 --- a/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java +++ b/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java @@ -25,7 +25,7 @@ * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ -package jogamp.opengl.av; +package jogamp.opengl.util.av; import java.io.IOException; import java.net.URLConnection; @@ -37,9 +37,9 @@ import javax.media.opengl.GL; import javax.media.opengl.GLES2; import javax.media.opengl.GLException; -import com.jogamp.opengl.av.GLMediaPlayer; -import com.jogamp.opengl.av.GLMediaEventListener; +import com.jogamp.opengl.util.av.GLMediaPlayer; import com.jogamp.opengl.util.texture.Texture; +import com.jogamp.opengl.util.texture.TextureSequence; /** * After object creation an implementation may customize the behavior: @@ -86,8 +86,8 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { protected long frameNumber = 0; - protected TextureFrame[] texFrames = null; - protected HashMap texFrameMap = new HashMap(); + protected TextureSequence.TextureFrame[] texFrames = null; + protected HashMap texFrameMap = new HashMap(); private ArrayList eventListeners = new ArrayList(); protected GLMediaPlayerImpl() { @@ -172,27 +172,29 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { } this.urlConn = urlConn; if (this.urlConn != null) { - try { - if(null!=texFrames) { - removeAllImageTextures(gl); - } else { - texFrames = new TextureFrame[textureCount]; - } - - final int[] tex = new int[textureCount]; - { - gl.glGenTextures(textureCount, tex, 0); - final int err = gl.glGetError(); - if( GL.GL_NO_ERROR != err ) { - throw new RuntimeException("TextureNames creation failed (num: "+textureCount+"): err "+toHexString(err)); + try { + if(null != gl) { + if(null!=texFrames) { + // re-init .. + removeAllImageTextures(gl); + } else { + texFrames = new TextureSequence.TextureFrame[textureCount]; + } + final int[] tex = new int[textureCount]; + { + gl.glGenTextures(textureCount, tex, 0); + final int err = gl.glGetError(); + if( GL.GL_NO_ERROR != err ) { + throw new RuntimeException("TextureNames creation failed (num: "+textureCount+"): err "+toHexString(err)); + } + } + initGLStreamImpl(gl, tex); + + for(int i=0; i pos_ms) { 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 && i0) { + 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 getPackages() { + return Arrays.asList(pkgs); + } +} diff --git a/src/test/com/jogamp/opengl/test/android/MovieSimpleActivity.java b/src/test/com/jogamp/opengl/test/android/MovieSimpleActivity.java deleted file mode 100644 index 86b3ffb48..000000000 --- a/src/test/com/jogamp/opengl/test/android/MovieSimpleActivity.java +++ /dev/null @@ -1,204 +0,0 @@ -/** - * 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.GLAutoDrawable; -import javax.media.opengl.GLCapabilities; -import javax.media.opengl.GLProfile; -import javax.media.opengl.GLRunnable; - -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.av.GLMediaPlayer; -import com.jogamp.opengl.test.junit.jogl.demos.es2.av.MovieSimple; -import com.jogamp.opengl.util.Animator; - -import android.os.Bundle; -import android.util.Log; -import android.view.Gravity; - -public class MovieSimpleActivity extends NewtBaseActivity { - static String TAG = "NEWTGearsES2Activity"; - - 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); - - final boolean mPlayerLocal = Boolean.valueOf(System.getProperty("jnlp.mplayer.local")); - final boolean mPlayerNoZoom = Boolean.valueOf(System.getProperty("jnlp.mplayer.nozoom")); - final boolean mPlayerHUD = Boolean.valueOf(System.getProperty("jnlp.mplayer.hud")); - final boolean mPlayerSharedHUD = mPlayerHUD && Boolean.valueOf(System.getProperty("jnlp.mplayer.hud.shared")); - Log.d(TAG, "onCreate - 0 - mPlayerLocal "+mPlayerLocal+", mPlayerNoScale "+mPlayerNoZoom+", mPlayerHUD "+mPlayerHUD+", mPlayerSharedHUD "+mPlayerSharedHUD); - - String[] urls0 = new String[] { - System.getProperty("jnlp.media0_url2"), - System.getProperty("jnlp.media0_url1"), - System.getProperty("jnlp.media0_url0") }; - final URLConnection urlConnection0 = getResource(urls0, mPlayerLocal ? 2 : 0); - if(null == urlConnection0) { throw new RuntimeException("no media reachable: "+Arrays.asList(urls0)); } - - final URLConnection urlConnection1; - { - URLConnection _urlConnection1 = null; - if(mPlayerHUD && !mPlayerSharedHUD) { - String[] urls1 = new String[] { System.getProperty("jnlp.media1_url0") }; - _urlConnection1 = getResource(urls1, 0); - } - if(null == _urlConnection1) { _urlConnection1 = urlConnection0; } - urlConnection1 = _urlConnection1; - } - - setTransparencyTheme(); - setFullscreenFeature(getWindow(), true); - - final android.view.ViewGroup viewGroup = new android.widget.FrameLayout(getActivity().getApplicationContext()); - getWindow().setContentView(viewGroup); - - // also initializes JOGL - final GLCapabilities capsMain = new GLCapabilities(GLProfile.getGL2ES2()); - capsMain.setBackgroundOpaque(!mPlayerHUD); - - // 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 MovieSimple demoMain = new MovieSimple(urlConnection0); - if(mPlayerHUD) { - demoMain.setEffects(MovieSimple.EFFECT_GRADIENT_BOTTOM2TOP); - demoMain.setTransparency(0.9f); - } - demoMain.setScaleOrig(mPlayerNoZoom); - final GLWindow glWindowMain = GLWindow.create(scrn, capsMain); - { - final int padding = mPlayerHUD ? 32 : 0; - final android.view.View androidView = ((AndroidWindow)glWindowMain.getDelegatedWindow()).getAndroidView(); - glWindowMain.setSize(scrn.getWidth()-padding, scrn.getHeight()-padding); - glWindowMain.setUndecorated(true); - // setContentView(getWindow(), glWindowMain); - viewGroup.addView(androidView, new android.widget.FrameLayout.LayoutParams(glWindowMain.getWidth(), glWindowMain.getHeight(), Gravity.BOTTOM|Gravity.RIGHT)); - registerNEWTWindow(glWindowMain); - } - - glWindowMain.addGLEventListener(demoMain); - animator.add(glWindowMain); - glWindowMain.setVisible(true); - - if(mPlayerHUD) { - final GLMediaPlayer sharedPlayer = mPlayerSharedHUD ? demoMain.getGLMediaPlayer() : null; - final GLCapabilities capsHUD = new GLCapabilities(GLProfile.getGL2ES2()); - capsHUD.setBackgroundOpaque(false); - final GLWindow glWindowHUD = GLWindow.create(scrn, capsHUD); - glWindowMain.invoke(false, new GLRunnable() { - @Override - public boolean run(GLAutoDrawable drawable) { - int x2 = scrn.getX(); - int y2 = scrn.getY(); - int w2 = scrn.getWidth()/3; - int h2 = scrn.getHeight()/3; - if(null != sharedPlayer) { - if(0 < sharedPlayer.getWidth() && sharedPlayer.getWidth()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/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/MovieSimpleActivity1.java b/src/test/com/jogamp/opengl/test/android/MovieSimpleActivity1.java new file mode 100644 index 000000000..a5e5f4ccb --- /dev/null +++ b/src/test/com/jogamp/opengl/test/android/MovieSimpleActivity1.java @@ -0,0 +1,204 @@ +/** + * 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.GLAutoDrawable; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; +import javax.media.opengl.GLRunnable; + +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.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 MovieSimpleActivity1 extends NewtBaseActivity { + static String TAG = "MovieSimpleActivity1"; + + 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); + + final boolean mPlayerLocal = Boolean.valueOf(System.getProperty("jnlp.mplayer.local")); + final boolean mPlayerNoZoom = Boolean.valueOf(System.getProperty("jnlp.mplayer.nozoom")); + final boolean mPlayerHUD = Boolean.valueOf(System.getProperty("jnlp.mplayer.hud")); + final boolean mPlayerSharedHUD = mPlayerHUD && Boolean.valueOf(System.getProperty("jnlp.mplayer.hud.shared")); + Log.d(TAG, "onCreate - 0 - mPlayerLocal "+mPlayerLocal+", mPlayerNoScale "+mPlayerNoZoom+", mPlayerHUD "+mPlayerHUD+", mPlayerSharedHUD "+mPlayerSharedHUD); + + String[] urls0 = new String[] { + System.getProperty("jnlp.media0_url2"), + System.getProperty("jnlp.media0_url1"), + System.getProperty("jnlp.media0_url0") }; + final URLConnection urlConnection0 = getResource(urls0, mPlayerLocal ? 2 : 0); + if(null == urlConnection0) { throw new RuntimeException("no media reachable: "+Arrays.asList(urls0)); } + + final URLConnection urlConnection1; + { + URLConnection _urlConnection1 = null; + if(mPlayerHUD && !mPlayerSharedHUD) { + String[] urls1 = new String[] { System.getProperty("jnlp.media1_url0") }; + _urlConnection1 = getResource(urls1, 0); + } + if(null == _urlConnection1) { _urlConnection1 = urlConnection0; } + urlConnection1 = _urlConnection1; + } + + setTransparencyTheme(); + setFullscreenFeature(getWindow(), true); + + final android.view.ViewGroup viewGroup = new android.widget.FrameLayout(getActivity().getApplicationContext()); + getWindow().setContentView(viewGroup); + + // also initializes JOGL + final GLCapabilities capsMain = new GLCapabilities(GLProfile.getGL2ES2()); + capsMain.setBackgroundOpaque(!mPlayerHUD); + + // 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 MovieSimple demoMain = new MovieSimple(urlConnection0); + if(mPlayerHUD) { + demoMain.setEffects(MovieSimple.EFFECT_GRADIENT_BOTTOM2TOP); + demoMain.setTransparency(0.9f); + } + demoMain.setScaleOrig(mPlayerNoZoom); + final GLWindow glWindowMain = GLWindow.create(scrn, capsMain); + { + final int padding = mPlayerHUD ? 32 : 0; + final android.view.View androidView = ((AndroidWindow)glWindowMain.getDelegatedWindow()).getAndroidView(); + glWindowMain.setSize(scrn.getWidth()-padding, scrn.getHeight()-padding); + glWindowMain.setUndecorated(true); + // setContentView(getWindow(), glWindowMain); + viewGroup.addView(androidView, new android.widget.FrameLayout.LayoutParams(glWindowMain.getWidth(), glWindowMain.getHeight(), Gravity.BOTTOM|Gravity.RIGHT)); + registerNEWTWindow(glWindowMain); + } + + glWindowMain.addGLEventListener(demoMain); + animator.add(glWindowMain); + glWindowMain.setVisible(true); + + if(mPlayerHUD) { + final GLMediaPlayer sharedPlayer = mPlayerSharedHUD ? demoMain.getGLMediaPlayer() : null; + final GLCapabilities capsHUD = new GLCapabilities(GLProfile.getGL2ES2()); + capsHUD.setBackgroundOpaque(false); + final GLWindow glWindowHUD = GLWindow.create(scrn, capsHUD); + glWindowMain.invoke(false, new GLRunnable() { + @Override + public boolean run(GLAutoDrawable drawable) { + int x2 = scrn.getX(); + int y2 = scrn.getY(); + int w2 = scrn.getWidth()/3; + int h2 = scrn.getHeight()/3; + if(null != sharedPlayer) { + if(0 < sharedPlayer.getWidth() && sharedPlayer.getWidth()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/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; i0) { - 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