diff options
author | Sven Gothel <[email protected]> | 2012-04-05 02:47:35 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-04-05 02:47:35 +0200 |
commit | 9f8e09e57813628215c41887d3bdf6fd11472cc1 (patch) | |
tree | 9f4dbbb2ee5f8ba0488750c9f57cea3f1ae1394a /src/test | |
parent | a19db300a22c2c5b30330ee685e16213e6050d41 (diff) |
Enhance MovieSimple Demo: Split shader to es2/gl2, check for GL_OES_EGL_image_external extension if requested, use proper texture unit
Diffstat (limited to 'src/test')
11 files changed, 92 insertions, 74 deletions
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 f2237484e..d5538c537 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 @@ -55,6 +55,7 @@ import com.jogamp.newt.Window; import com.jogamp.newt.event.MouseEvent; import com.jogamp.newt.event.MouseListener; 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.GLMediaPlayer.TextureFrame; @@ -78,11 +79,15 @@ public class MovieSimple implements MouseListener, GLEventListener, GLMediaEvent private long curTime; private int effects = EFFECT_NORMAL; private float alpha = 1.0f; + private int texUnit = 0; public static final int EFFECT_NORMAL = 0; public static final int EFFECT_GRADIENT_BOTTOM2TOP = 1<<1; public static final int EFFECT_TRANSPARENT = 1<<3; + public void setTextureUnit(int u) { texUnit = u; } + public int getTextureUnit() { return texUnit; } + public boolean hasEffect(int e) { return 0 != ( effects & e ) ; } public void setEffects(int e) { effects = e; }; public void setTransparency(float alpha) { @@ -207,8 +212,8 @@ public class MovieSimple implements MouseListener, GLEventListener, GLMediaEvent private void initShader(GL2ES2 gl, boolean useExternalTexture) { // Create & Compile the shader objects - final String vShaderBasename = "moviesimple" ; - final String fShaderBasename = useExternalTexture ? "moviesimple_exttex" : "moviesimple" ; + final String vShaderBasename = gl.isGLES2() ? "moviesimple_es2" : "moviesimple_gl2" ; + final String fShaderBasename = gl.isGLES2() ? ( useExternalTexture ? "moviesimple_es2_exttex" : "moviesimple_es2" ) : "moviesimple_gl2"; ShaderCode rsVp = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, 1, MovieSimple.class, "../shader", "../shader/bin", vShaderBasename); @@ -230,10 +235,7 @@ public class MovieSimple implements MouseListener, GLEventListener, GLMediaEvent public void init(GLAutoDrawable drawable) { GL2ES2 gl = drawable.getGL().getGL2ES2(); - System.err.println("Entering initialization"); - System.err.println("GL_VERSION=" + gl.glGetString(GL.GL_VERSION)); - System.err.println("GL_EXTENSIONS:"); - System.err.println(" " + gl.glGetString(GL.GL_EXTENSIONS)); + System.err.println(JoglVersion.getGLInfo(gl, null)); System.err.println("Alpha: "+alpha+", opaque "+drawable.getChosenGLCapabilities().isBackgroundOpaque()+ ", "+drawable.getClass().getName()+", "+drawable); @@ -244,11 +246,14 @@ public class MovieSimple implements MouseListener, GLEventListener, GLMediaEvent } System.out.println("p1 "+mPlayer); useExternalTexture = GLES2.GL_TEXTURE_EXTERNAL_OES == mPlayer.getTextureTarget(); + if(useExternalTexture && !gl.isExtensionAvailable("GL_OES_EGL_image_external")) { + throw new GLException("GL_OES_EGL_image_external requested but not available"); + } if(!mPlayerShared) { mPlayer.setTextureMinMagFilter( new int[] { GL.GL_NEAREST, GL.GL_LINEAR } ); } } catch (GLException glex) { - if(null != mPlayer) { + if(!mPlayerShared && null != mPlayer) { mPlayer.destroy(gl); mPlayer = null; } @@ -272,10 +277,9 @@ public class MovieSimple implements MouseListener, GLEventListener, GLMediaEvent throw new GLException("Error setting PMVMatrix in shader: "+st); } final GLMediaPlayer.TextureFrame texFrame = mPlayer.getLastTexture(); - if(!st.uniform(gl, new GLUniformData("mgl_ActiveTexture", 0))) { + if(!st.uniform(gl, new GLUniformData("mgl_ActiveTexture", texUnit))) { throw new GLException("Error setting mgl_ActiveTexture in shader: "+st); } - gl.glActiveTexture(GL.GL_TEXTURE0); float dWidth = drawable.getWidth(); float dHeight = drawable.getHeight(); @@ -455,7 +459,7 @@ public class MovieSimple implements MouseListener, GLEventListener, GLMediaEvent } } - Texture tex = null; + final Texture tex; if(null!=mPlayer) { final GLMediaPlayer.TextureFrame texFrame; if(mPlayerShared) { @@ -463,9 +467,12 @@ public class MovieSimple implements MouseListener, GLEventListener, GLMediaEvent } else { texFrame=mPlayer.getNextTexture(); } - tex = texFrame.getTexture(); + tex = texFrame.getTexture(); + gl.glActiveTexture(GL.GL_TEXTURE0+texUnit); tex.enable(gl); tex.bind(gl); + } else { + tex = null; } // Draw a square diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/moviesimple.fp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/moviesimple.fp deleted file mode 100644 index d1ae39428..000000000 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/moviesimple.fp +++ /dev/null @@ -1,21 +0,0 @@ - -#ifdef GL_ES - #define MEDIUMP mediump - #define HIGHP highp -#else - #define MEDIUMP - #define HIGHP -#endif - -uniform sampler2D mgl_ActiveTexture; -varying MEDIUMP vec2 mgl_texCoord; -varying MEDIUMP vec4 frontColor; - -void main (void) -{ - HIGHP vec4 texColor = texture2D(mgl_ActiveTexture, mgl_texCoord); - - // mix frontColor with texture .. - gl_FragColor = vec4(frontColor*texColor); -} - diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/moviesimple.vp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/moviesimple.vp deleted file mode 100644 index 9d609ab87..000000000 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/moviesimple.vp +++ /dev/null @@ -1,24 +0,0 @@ - -#ifdef GL_ES - #define MEDIUMP mediump - #define HIGHP highp -#else - #define MEDIUMP - #define HIGHP -#endif - -uniform MEDIUMP mat4 mgl_PMVMatrix[2]; -// uniform MEDIUMP mat4 mgl_STMatrix; -attribute MEDIUMP vec4 mgl_Vertex; -attribute MEDIUMP vec4 mgl_Color; -attribute MEDIUMP vec4 mgl_MultiTexCoord; -varying MEDIUMP vec4 frontColor; -varying MEDIUMP vec2 mgl_texCoord; - -void main(void) -{ - frontColor=mgl_Color; - // mgl_texCoord = (mgl_STMatrix * mgl_MultiTexCoord).st; - mgl_texCoord = mgl_MultiTexCoord.st; - gl_Position = mgl_PMVMatrix[0] * mgl_PMVMatrix[1] * mgl_Vertex; -} 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/moviesimple_es2.fp new file mode 100644 index 000000000..466d9ecd7 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/moviesimple_es2.fp @@ -0,0 +1,12 @@ +//Copyright 2010 JogAmp Community. All rights reserved. + +#version 100 + +#extension GL_OES_EGL_image_external : enable + +precision mediump float; +precision mediump int; + +uniform sampler2D mgl_ActiveTexture; + +#include moviesimple_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/moviesimple_es2.vp new file mode 100644 index 000000000..ca5d69ebb --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/moviesimple_es2.vp @@ -0,0 +1,8 @@ +//Copyright 2010 JogAmp Community. All rights reserved. + +#version 100 + +precision mediump float; +precision mediump int; + +#include moviesimple_xxx.vp
\ No newline at end of file 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/moviesimple_es2_exttex.fp new file mode 100644 index 000000000..96efaf357 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/moviesimple_es2_exttex.fp @@ -0,0 +1,12 @@ +//Copyright 2010 JogAmp Community. All rights reserved. + +#version 100 + +#extension GL_OES_EGL_image_external : require + +precision mediump float; +precision mediump int; + +uniform samplerExternalOES mgl_ActiveTexture; + +#include moviesimple_xxx.fp diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/moviesimple_exttex.fp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/moviesimple_exttex.fp deleted file mode 100644 index 8d1d60b1f..000000000 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/moviesimple_exttex.fp +++ /dev/null @@ -1,18 +0,0 @@ - -#extension GL_OES_EGL_image_external : require - -#define MEDIUMP mediump -#define HIGHP highp - -uniform samplerExternalOES mgl_ActiveTexture; -varying MEDIUMP vec2 mgl_texCoord; -varying MEDIUMP vec4 frontColor; - -void main (void) -{ - HIGHP vec4 texColor = texture2D(mgl_ActiveTexture, mgl_texCoord); - - // mix frontColor with texture .. - gl_FragColor = vec4(frontColor*texColor); -} - 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/moviesimple_gl2.fp new file mode 100644 index 000000000..6e0e7063c --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/moviesimple_gl2.fp @@ -0,0 +1,7 @@ +//Copyright 2010 JogAmp Community. All rights reserved. + +#version 110 + +uniform sampler2D mgl_ActiveTexture; + +#include moviesimple_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/moviesimple_gl2.vp new file mode 100644 index 000000000..f8675eea4 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/moviesimple_gl2.vp @@ -0,0 +1,5 @@ +//Copyright 2010 JogAmp Community. All rights reserved. + +#version 110 + +#include moviesimple_xxx.vp
\ No newline at end of file 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/moviesimple_xxx.fp new file mode 100644 index 000000000..d32c1d293 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/moviesimple_xxx.fp @@ -0,0 +1,13 @@ +//Copyright 2010 JogAmp Community. All rights reserved. + +varying vec2 mgl_texCoord; +varying vec4 frontColor; + +void main (void) +{ + vec4 texColor = texture2D(mgl_ActiveTexture, mgl_texCoord); + + // 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/moviesimple_xxx.vp new file mode 100644 index 000000000..dea57ca9e --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/moviesimple_xxx.vp @@ -0,0 +1,17 @@ +//Copyright 2010 JogAmp Community. All rights reserved. + +uniform mat4 mgl_PMVMatrix[2]; +// uniform mat4 mgl_STMatrix; +attribute vec4 mgl_Vertex; +attribute vec4 mgl_Color; +attribute vec4 mgl_MultiTexCoord; +varying vec4 frontColor; +varying vec2 mgl_texCoord; + +void main(void) +{ + frontColor=mgl_Color; + // mgl_texCoord = (mgl_STMatrix * mgl_MultiTexCoord).st; + mgl_texCoord = mgl_MultiTexCoord.st; + gl_Position = mgl_PMVMatrix[0] * mgl_PMVMatrix[1] * mgl_Vertex; +} |