diff options
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java | 65 | ||||
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java | 119 |
2 files changed, 129 insertions, 55 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java index 7647421a0..57da78131 100644 --- 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 @@ -67,6 +67,7 @@ public class MovieCube implements GLEventListener { private GLMediaPlayer mPlayer=null; private int swapInterval = 1; private long lastPerfPos = 0; + private volatile boolean resetGLState = false; /** Blender's Big Buck Bunny Trailer: 24f 640p VP8, Vorbis 44100Hz mono, WebM/Matroska Stream. */ public static final URI defURI; @@ -100,6 +101,10 @@ public class MovieCube implements GLEventListener { public GLMediaPlayer getGLMediaPlayer() { return mPlayer; } + public void resetGLState() { + resetGLState = true; + } + private final KeyListener keyAction = new KeyAdapter() { public void keyReleased(KeyEvent e) { if( e.isAutoRepeat() ) { @@ -172,12 +177,14 @@ public class MovieCube implements GLEventListener { if(null == mPlayer) { throw new InternalError("mPlayer null"); } - if( GLMediaPlayer.State.Initialized != mPlayer.getState() ) { - throw new IllegalStateException("mPlayer not in state initialized: "+mPlayer); + if( GLMediaPlayer.State.Uninitialized == mPlayer.getState() ) { + throw new IllegalStateException("mPlayer in uninitialized state: "+mPlayer); } if( GLMediaPlayer.STREAM_ID_NONE == mPlayer.getVID() ) { // throw new IllegalStateException("mPlayer has no VID/stream selected: "+mPlayer); } + resetGLState = false; + GL2ES2 gl = drawable.getGL().getGL2ES2(); System.err.println(JoglVersion.getGLInfo(gl, null)); @@ -186,16 +193,18 @@ public class MovieCube implements GLEventListener { if(waitForKey) { UITestCase.waitForKey("Init>"); } - - try { - mPlayer.initGL(gl); - } catch (Exception e) { - e.printStackTrace(); - if(null != mPlayer) { - mPlayer.destroy(gl); - mPlayer = null; + + if( GLMediaPlayer.State.Initialized == mPlayer.getState() ) { + try { + mPlayer.initGL(gl); + } catch (Exception e) { + e.printStackTrace(); + if(null != mPlayer) { + mPlayer.destroy(gl); + mPlayer = null; + } + throw new GLException(e); } - throw new GLException(e); } cube.init(drawable); mPlayer.play(); @@ -224,18 +233,38 @@ public class MovieCube implements GLEventListener { @Override public void dispose(GLAutoDrawable drawable) { System.err.println(Thread.currentThread()+" MovieCube.dispose ... "); + disposeImpl(drawable, true); + } + + private void disposeImpl(GLAutoDrawable drawable, boolean disposePlayer) { if(null == mPlayer) { return; } + final Object upstreamWidget = drawable.getUpstreamWidget(); + if (upstreamWidget instanceof Window) { + final Window window = (Window) upstreamWidget; + window.removeKeyListener(keyAction); + } final GL2ES2 gl = drawable.getGL().getGL2ES2(); - mPlayer.destroy(gl); - mPlayer=null; + if( disposePlayer ) { + mPlayer.destroy(gl); + mPlayer=null; + } cube.dispose(drawable); - cube=null; + cube=null; } + @Override public void display(GLAutoDrawable drawable) { if(null == mPlayer) { return; } + if( resetGLState ) { + resetGLState = false; + System.err.println("XXX resetGLState"); + disposeImpl(drawable, false); + init(drawable); + reshape(drawable, 0, 0, drawable.getWidth(), drawable.getHeight()); + } + final long currentPos = System.currentTimeMillis(); if( currentPos - lastPerfPos > 2000 ) { System.err.println( mPlayer.getPerfString() ); @@ -350,8 +379,12 @@ public class MovieCube implements GLEventListener { public void attributesChanged(final GLMediaPlayer mp, int event_mask, long when) { System.err.println("MovieCube AttributesChanges: events_mask 0x"+Integer.toHexString(event_mask)+", when "+when); System.err.println("MovieCube State: "+mp); - if( 0 != ( GLMediaEventListener.EVENT_CHANGE_SIZE & event_mask ) && origSize ) { - window.setSize(mp.getWidth(), mp.getHeight()); + if( 0 != ( GLMediaEventListener.EVENT_CHANGE_SIZE & event_mask ) ) { + if( origSize ) { + window.setSize(mp.getWidth(), mp.getHeight()); + } + // window.disposeGLEventListener(ms, false /* remove */ ); + mc.resetGLState(); } if( 0 != ( GLMediaEventListener.EVENT_CHANGE_INIT & event_mask ) ) { window.addGLEventListener(mc); 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 f0a11820e..b52e1fb21 100644 --- 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 @@ -98,7 +98,9 @@ public class MovieSimple implements GLEventListener { private boolean mPlayerExternal; private boolean mPlayerShared; private boolean mPlayerScaleOrig; + private float[] verts = null; private GLArrayDataServer interleavedVBO; + private volatile boolean resetGLState = false; private ShaderState st; private PMVMatrix pmvMatrix; @@ -270,6 +272,10 @@ public class MovieSimple implements GLEventListener { this.alpha = alpha; } + public void resetGLState() { + resetGLState = true; + } + private void initShader(GL2ES2 gl) { // Create & Compile the shader objects ShaderCode rsVp = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, MovieSimple.class, @@ -309,12 +315,14 @@ public class MovieSimple implements GLEventListener { if(null == mPlayer) { throw new InternalError("mPlayer null"); } - if( GLMediaPlayer.State.Initialized != mPlayer.getState() ) { - throw new IllegalStateException("mPlayer not in state initialized: "+mPlayer); + if( GLMediaPlayer.State.Uninitialized == mPlayer.getState() ) { + throw new IllegalStateException("mPlayer in uninitialized state: "+mPlayer); } if( GLMediaPlayer.STREAM_ID_NONE == mPlayer.getVID() ) { throw new IllegalStateException("mPlayer has no VID/stream selected: "+mPlayer); } + resetGLState = false; + zoom0 = orthoProjection ? 0f : -2.5f; zoom1 = orthoProjection ? 0f : -5f; zoom = zoom0; @@ -331,7 +339,7 @@ public class MovieSimple implements GLEventListener { boolean useExternalTexture = false; try { System.out.println("p0 "+mPlayer+", shared "+mPlayerShared); - if(!mPlayerShared) { + if(!mPlayerShared && GLMediaPlayer.State.Initialized == mPlayer.getState() ) { mPlayer.initGL(gl); } System.out.println("p1 "+mPlayer+", shared "+mPlayerShared); @@ -378,7 +386,6 @@ public class MovieSimple implements GLEventListener { float mHeight = mPlayer.getHeight(); float mAspect = mWidth/mHeight; System.err.println("XXX0: mov aspect: "+mAspect); - float[] verts; float xs, ys; if(orthoProjection) { if(mPlayerScaleOrig && mWidth < dWidth && mHeight < dHeight) { @@ -406,14 +413,48 @@ public class MovieSimple implements GLEventListener { System.err.println("XXX0: win LB: "+winLB[0]+", "+winLB[1]+", "+winLB[2]); System.err.println("XXX0: win RT: "+winRT[0]+", "+winRT[1]+", "+winRT[2]); } - final float ss = 1f, ts = 1f; // scale tex-coord interleavedVBO = GLArrayDataServer.createGLSLInterleaved(3+4+2, GL.GL_FLOAT, false, 3*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_MultiTexCoord", 2, GL.GL_ARRAY_BUFFER); - + interleavedVBO.addGLSLSubArray("mgl_MultiTexCoord", 2, GL.GL_ARRAY_BUFFER); + } + updateInterleavedVBO(gl, tex); + + st.ownAttribute(interleavedVBO, true); + gl.glClearColor(0.3f, 0.3f, 0.3f, 0.3f); + + gl.glEnable(GL2ES2.GL_DEPTH_TEST); + + st.useProgram(gl, false); + + // Let's show the completed shader state .. + System.out.println("iVBO: "+interleavedVBO); + System.out.println(st); + + if(!mPlayerShared) { + mPlayer.play(); + System.out.println("play.0 "+mPlayer); + } + startTime = System.currentTimeMillis(); + + final Object upstreamWidget = drawable.getUpstreamWidget(); + if (upstreamWidget instanceof Window) { + final Window window = (Window) upstreamWidget; + window.addMouseListener(mouseAction); + window.addKeyListener(keyAction); + winWidth = window.getWidth(); + winHeight = window.getHeight(); + } + } + + protected void updateInterleavedVBO(GL gl, Texture tex) { + final float ss = 1f, ts = 1f; // scale tex-coord + final boolean wasEnabled = interleavedVBO.enabled(); + interleavedVBO.seal(gl, false); + interleavedVBO.rewind(); + { final FloatBuffer ib = (FloatBuffer)interleavedVBO.getBuffer(); final TextureCoords tc = tex.getImageTexCoords(); System.err.println("XXX0: "+tc); @@ -457,31 +498,8 @@ public class MovieSimple implements GLEventListener { ib.put( tc.right() *ss); ib.put( tc.top() *ts); } 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); - - st.useProgram(gl, false); - - // Let's show the completed shader state .. - System.out.println("iVBO: "+interleavedVBO); - System.out.println(st); - - if(!mPlayerShared) { - mPlayer.play(); - System.out.println("play.0 "+mPlayer); - } - startTime = System.currentTimeMillis(); - - final Object upstreamWidget = drawable.getUpstreamWidget(); - if (upstreamWidget instanceof Window) { - final Window window = (Window) upstreamWidget; - window.addMouseListener(mouseAction); - window.addKeyListener(keyAction); - winWidth = window.getWidth(); - winHeight = window.getHeight(); + if( !wasEnabled ) { + interleavedVBO.enableBuffer(gl, false); } } @@ -526,17 +544,28 @@ public class MovieSimple implements GLEventListener { @Override public void dispose(GLAutoDrawable drawable) { + disposeImpl(drawable, true); + } + + private void disposeImpl(GLAutoDrawable drawable, boolean disposePlayer) { if(null == mPlayer) { return; } - System.out.println("pD.1 "+mPlayer); - GL2ES2 gl = drawable.getGL().getGL2ES2(); - if( null != mPlayer ) { + final Object upstreamWidget = drawable.getUpstreamWidget(); + if (upstreamWidget instanceof Window) { + final Window window = (Window) upstreamWidget; + window.removeMouseListener(mouseAction); + window.removeKeyListener(keyAction); + } + + System.out.println("pD.1 "+mPlayer+", disposePlayer "+disposePlayer); + GL2ES2 gl = drawable.getGL().getGL2ES2(); + if( disposePlayer ) { if(!mPlayerExternal) { mPlayer.destroy(gl); } + System.out.println("pD.X "+mPlayer); + mPlayer=null; } - System.out.println("pD.X "+mPlayer); - mPlayer=null; pmvMatrixUniform = null; if(null != pmvMatrix) { pmvMatrix.destroy(); @@ -554,6 +583,14 @@ public class MovieSimple implements GLEventListener { public void display(GLAutoDrawable drawable) { if(null == mPlayer) { return; } + if( resetGLState ) { + resetGLState = false; + System.err.println("XXX resetGLState"); + disposeImpl(drawable, false); + init(drawable); + reshape(drawable, 0, 0, drawable.getWidth(), drawable.getHeight()); + } + final long currentPos = System.currentTimeMillis(); if( currentPos - lastPerfPos > 2000 ) { System.err.println( mPlayer.getPerfString() ); @@ -727,8 +764,12 @@ public class MovieSimple implements GLEventListener { public void attributesChanged(final GLMediaPlayer mp, int event_mask, long when) { System.err.println("MovieSimple AttributesChanges: events_mask 0x"+Integer.toHexString(event_mask)+", when "+when); System.err.println("MovieSimple State: "+mp); - if( 0 != ( GLMediaEventListener.EVENT_CHANGE_SIZE & event_mask ) && origSize ) { - window.setSize(mp.getWidth(), mp.getHeight()); + if( 0 != ( GLMediaEventListener.EVENT_CHANGE_SIZE & event_mask ) ) { + if( origSize ) { + window.setSize(mp.getWidth(), mp.getHeight()); + } + // window.disposeGLEventListener(ms, false /* remove */ ); + ms.resetGLState(); } if( 0 != ( GLMediaEventListener.EVENT_CHANGE_INIT & event_mask ) ) { if( GLMediaPlayer.STREAM_ID_NONE != ms.mPlayer.getVID() ) { |