summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-03-14 14:17:53 +0100
committerSven Gothel <[email protected]>2023-03-14 14:17:53 +0100
commit6faab9ada2a7e2b99bb20ce828915a07fdcbea27 (patch)
treecf55401d676e8b31ba55eca93cde8d4fdb99984d /src
parent67a723477ecd818fbc5859fe20ee536a3b4efae5 (diff)
TextureSequence (API Change): Use setTextureLookupFunctionName(..) explicitly to set the name upfront, clarifying workflow. Impl: ImageSequence + GLMediaPlayerImpl
Diffstat (limited to 'src')
-rw-r--r--src/demos/com/jogamp/opengl/demos/av/MovieSBSStereo.java2
-rw-r--r--src/demos/com/jogamp/opengl/demos/es2/TextureSequenceCubeES2.java2
-rw-r--r--src/demos/com/jogamp/opengl/demos/es2/TextureSequenceES2.java2
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/texture/ImageSequence.java14
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/texture/TextureSequence.java48
-rw-r--r--src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java23
-rw-r--r--src/jogl/classes/jogamp/opengl/util/av/impl/FFMPEGMediaPlayer.java23
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TextureSequenceCubeES2.java8
8 files changed, 87 insertions, 35 deletions
diff --git a/src/demos/com/jogamp/opengl/demos/av/MovieSBSStereo.java b/src/demos/com/jogamp/opengl/demos/av/MovieSBSStereo.java
index 519a51a87..3a59216d5 100644
--- a/src/demos/com/jogamp/opengl/demos/av/MovieSBSStereo.java
+++ b/src/demos/com/jogamp/opengl/demos/av/MovieSBSStereo.java
@@ -382,7 +382,7 @@ public class MovieSBSStereo implements StereoGLEventListener {
rsFpPos = rsFp.insertShaderSource(0, rsFpPos, mPlayer.getRequiredExtensionsShaderStub());
rsFp.addDefaultShaderPrecision(gl, rsFpPos);
- final String texLookupFuncName = mPlayer.getTextureLookupFunctionName(myTextureLookupName);
+ final String texLookupFuncName = mPlayer.setTextureLookupFunctionName(myTextureLookupName);
rsFp.replaceInShaderSource(myTextureLookupName, texLookupFuncName);
// Inject TextureSequence shader details
diff --git a/src/demos/com/jogamp/opengl/demos/es2/TextureSequenceCubeES2.java b/src/demos/com/jogamp/opengl/demos/es2/TextureSequenceCubeES2.java
index 26a26e3e1..211ac8cbf 100644
--- a/src/demos/com/jogamp/opengl/demos/es2/TextureSequenceCubeES2.java
+++ b/src/demos/com/jogamp/opengl/demos/es2/TextureSequenceCubeES2.java
@@ -185,7 +185,7 @@ public class TextureSequenceCubeES2 implements GLEventListener {
rsFpPos = rsFp.insertShaderSource(0, rsFpPos, texSeq.getRequiredExtensionsShaderStub());
rsFp.addDefaultShaderPrecision(gl, rsFpPos);
- final String texLookupFuncName = texSeq.getTextureLookupFunctionName(myTextureLookupName);
+ final String texLookupFuncName = texSeq.setTextureLookupFunctionName(myTextureLookupName);
rsFp.replaceInShaderSource(myTextureLookupName, texLookupFuncName);
// Inject TextureSequence shader details
diff --git a/src/demos/com/jogamp/opengl/demos/es2/TextureSequenceES2.java b/src/demos/com/jogamp/opengl/demos/es2/TextureSequenceES2.java
index fd934cb1e..95b4df8d6 100644
--- a/src/demos/com/jogamp/opengl/demos/es2/TextureSequenceES2.java
+++ b/src/demos/com/jogamp/opengl/demos/es2/TextureSequenceES2.java
@@ -121,7 +121,7 @@ public class TextureSequenceES2 implements GLEventListener {
rsFpPos = rsFp.insertShaderSource(0, rsFpPos, texSeq.getRequiredExtensionsShaderStub());
rsFp.addDefaultShaderPrecision(gl, rsFpPos);
- final String texLookupFuncName = texSeq.getTextureLookupFunctionName(myTextureLookupName);
+ final String texLookupFuncName = texSeq.setTextureLookupFunctionName(myTextureLookupName);
rsFp.replaceInShaderSource(myTextureLookupName, texLookupFuncName);
// Inject TextureSequence shader details
diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/ImageSequence.java b/src/jogl/classes/com/jogamp/opengl/util/texture/ImageSequence.java
index e485e5452..2da2dcbfc 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/texture/ImageSequence.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/texture/ImageSequence.java
@@ -153,17 +153,21 @@ public class ImageSequence implements TextureSequence {
private String textureLookupFunctionName = "myTexture2D";
@Override
- public String getTextureLookupFunctionName(final String desiredFuncName) throws IllegalStateException {
+ public String setTextureLookupFunctionName(final String texLookupFuncName) throws IllegalStateException {
if(useBuildInTexLookup) {
- return "texture2D";
- }
- if(null != desiredFuncName && desiredFuncName.length()>0) {
- textureLookupFunctionName = desiredFuncName;
+ textureLookupFunctionName = "texture2D";
+ } else if(null != texLookupFuncName && texLookupFuncName.length()>0) {
+ textureLookupFunctionName = texLookupFuncName;
}
return textureLookupFunctionName;
}
@Override
+ public String getTextureLookupFunctionName() throws IllegalStateException {
+ return textureLookupFunctionName;
+ }
+
+ @Override
public String getTextureLookupFragmentShaderImpl() throws IllegalStateException {
if(useBuildInTexLookup) {
return "";
diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureSequence.java b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureSequence.java
index 7147fd61b..2b91f3b1f 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureSequence.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureSequence.java
@@ -226,15 +226,28 @@ public interface TextureSequence {
public String getTextureSampler2DType() throws IllegalStateException ;
/**
- * @param desiredFuncName desired lookup function name. If <code>null</code> or ignored by the implementation,
- * a build-in name is returned.
- * @return the final lookup function name
+ * Set the desired shader code's texture lookup function name.
*
- * @see {@link #getTextureLookupFragmentShaderImpl()}
+ * @param texLookupFuncName desired lookup function name. If <code>null</code> or ignored by the implementation,
+ * a build-in name is returned.
+ * @return the chosen lookup function name
*
* @throws IllegalStateException if instance is not initialized
+ * @see #getTextureLookupFunctionName()
+ * @see #getTextureFragmentShaderHashCode()
+ * @see #getTextureLookupFragmentShaderImpl()
*/
- public String getTextureLookupFunctionName(String desiredFuncName) throws IllegalStateException ;
+ public String setTextureLookupFunctionName(String texLookupFuncName) throws IllegalStateException ;
+
+ /**
+ * Returns the chosen lookup function name, which can be set via {@link #setTextureLookupFunctionName(String)}.
+ *
+ * @throws IllegalStateException if instance is not initialized
+ * @see #setTextureLookupFunctionName(String)
+ * @see #getTextureFragmentShaderHashCode()
+ * @see #getTextureLookupFragmentShaderImpl()
+ */
+ public String getTextureLookupFunctionName() throws IllegalStateException ;
/**
* Returns the complete texture2D lookup function code of type
@@ -245,36 +258,49 @@ public interface TextureSequence {
* }
* </pre>
* <p>
- * <i>funcName</i> can be negotiated and queried via {@link #getTextureLookupFunctionName(String)}.
+ * <i>funcName</i> is set via {@link #setTextureLookupFunctionName(String)}
+ * and queried via {@link #getTextureLookupFunctionName()}.
+ * </p>
+ * <p>
+ * User shall call {@link #setTextureLookupFunctionName(String)} first if intended.
* </p>
+ * <p>
* Note: This function may return an empty string in case a build-in lookup
* function is being chosen. If the implementation desires so,
- * {@link #getTextureLookupFunctionName(String)} will ignore the desired function name
+ * {@link #getTextureLookupFunctionName()} will ignore the desired function name
* and returns the build-in lookup function name.
* </p>
- * @see #getTextureLookupFunctionName(String)
- * @see #getTextureSampler2DType()
- *
* @throws IllegalStateException if instance is not initialized
+ * @see #getTextureLookupFunctionName()
+ * @see #setTextureLookupFunctionName(String)
+ * @see #getTextureFragmentShaderHashCode()
+ * @see #getTextureSampler2DType()
*/
public String getTextureLookupFragmentShaderImpl() throws IllegalStateException;
/**
* Returns the hash code of the strings:
* <ul>
+ * <li>{@link #getTextureLookupFunctionName()}</li>
* <li>{@link #getTextureLookupFragmentShaderImpl()}</li>
* <li>{@link #getTextureSampler2DType()}</li>
* </ul>
* <p>
+ * User shall call {@link #setTextureLookupFunctionName(String)} first if intended.
+ * </p>
+ * <p>
* Returns zero if {@link #isTextureAvailable() texture is not available}.
* </p>
* The returned hash code allows selection of a matching shader program for this {@link TextureSequence} instance.
* <p>
* </p>
* <p>
- * Implementation shall cache the resulting hash code,
+ * Implementation caches the resulting hash code,
* which must be reset to zero if {@link #isTextureAvailable() texture is not available}.
* </p>
+ * @see #setTextureLookupFunctionName(String)
+ * @see #getTextureLookupFunctionName()
+ * @see #getTextureLookupFragmentShaderImpl()
*/
public int getTextureFragmentShaderHashCode();
}
diff --git a/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java b/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java
index a9e4b5bc3..d94fbb1a7 100644
--- a/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java
+++ b/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java
@@ -268,15 +268,29 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer {
}
}
+ protected String textureLookupFunctionName = "texture2D";
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation simply sets and returns the build-in function name of <code>texture2D</code>,
+ * if not overridden by specialization, e.g. using the ffmpeg implementation.
+ */
+ @Override
+ public String setTextureLookupFunctionName(final String texLookupFuncName) throws IllegalStateException {
+ textureLookupFunctionName = "texture2D";
+ return textureLookupFunctionName;
+ }
+
/**
* {@inheritDoc}
*
* This implementation simply returns the build-in function name of <code>texture2D</code>,
- * if not overridden by specialization.
+ * if not overridden by specialization, e.g. using the ffmpeg implementation.
*/
@Override
- public String getTextureLookupFunctionName(final String desiredFuncName) {
- return "texture2D";
+ public final String getTextureLookupFunctionName() {
+ return textureLookupFunctionName;
}
/**
@@ -297,7 +311,8 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer {
textureFragmentShaderHashCode = 0;
return 0;
} else if( 0 == textureFragmentShaderHashCode ) {
- int hash = 31 + getTextureLookupFragmentShaderImpl().hashCode();
+ int hash = 31 + getTextureLookupFunctionName().hashCode();
+ hash = ((hash << 5) - hash) + getTextureLookupFragmentShaderImpl().hashCode();
hash = ((hash << 5) - hash) + getTextureSampler2DType().hashCode();
textureFragmentShaderHashCode = hash;
}
diff --git a/src/jogl/classes/jogamp/opengl/util/av/impl/FFMPEGMediaPlayer.java b/src/jogl/classes/jogamp/opengl/util/av/impl/FFMPEGMediaPlayer.java
index 91bef005a..fb3e8e4d3 100644
--- a/src/jogl/classes/jogamp/opengl/util/av/impl/FFMPEGMediaPlayer.java
+++ b/src/jogl/classes/jogamp/opengl/util/av/impl/FFMPEGMediaPlayer.java
@@ -276,7 +276,6 @@ public class FFMPEGMediaPlayer extends GLMediaPlayerImpl {
// Video
//
- private String texLookupFuncName = "ffmpegTexture2D";
private boolean usesTexLookupShader = false;
private VideoPixelFormat vPixelFmt = null;
private int vPlanes = 0;
@@ -703,14 +702,16 @@ public class FFMPEGMediaPlayer extends GLMediaPlayerImpl {
* Otherwise the call is delegated to it's super class.
*/
@Override
- public final String getTextureLookupFunctionName(final String desiredFuncName) {
+ public String setTextureLookupFunctionName(final String texLookupFuncName) throws IllegalStateException {
if( usesTexLookupShader ) {
- if(null != desiredFuncName && desiredFuncName.length()>0) {
- texLookupFuncName = desiredFuncName;
+ if(null != texLookupFuncName && texLookupFuncName.length()>0) {
+ textureLookupFunctionName = texLookupFuncName;
+ } else {
+ textureLookupFunctionName = "ffmpegTexture2D";
}
- return texLookupFuncName;
+ return textureLookupFunctionName;
}
- return super.getTextureLookupFunctionName(desiredFuncName);
+ return super.getTextureLookupFunctionName();
}
/**
@@ -729,7 +730,7 @@ public class FFMPEGMediaPlayer extends GLMediaPlayerImpl {
case YUVJ420P:
case YUV420P: // < planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
return
- "vec4 "+texLookupFuncName+"(in "+getTextureSampler2DType()+" image, in vec2 texCoord) {\n"+
+ "vec4 "+getTextureLookupFunctionName()+"(in "+getTextureSampler2DType()+" image, in vec2 texCoord) {\n"+
" const vec2 u_off = vec2("+tc_w_1+", 0.0);\n"+
" const vec2 v_off = vec2("+tc_w_1+", 0.5);\n"+
" vec2 tc_half = texCoord*0.5;\n"+
@@ -750,7 +751,7 @@ public class FFMPEGMediaPlayer extends GLMediaPlayerImpl {
case YUVJ422P:
case YUV422P: ///< planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
return
- "vec4 "+texLookupFuncName+"(in "+getTextureSampler2DType()+" image, in vec2 texCoord) {\n"+
+ "vec4 "+getTextureLookupFunctionName()+"(in "+getTextureSampler2DType()+" image, in vec2 texCoord) {\n"+
" const vec2 u_off = vec2("+tc_w_1+" , 0.0);\n"+
" const vec2 v_off = vec2("+tc_w_1+" * 1.5, 0.0);\n"+
" vec2 tc_halfw = vec2(texCoord.x*0.5, texCoord.y);\n"+
@@ -771,7 +772,7 @@ public class FFMPEGMediaPlayer extends GLMediaPlayerImpl {
case YUYV422: // < packed YUV 4:2:2, 2 x 16bpp, [Y0 Cb] [Y1 Cr]
// Stuffed into RGBA half width texture
return
- "vec4 "+texLookupFuncName+"(in "+getTextureSampler2DType()+" image, in vec2 texCoord) {\n"+
+ "vec4 "+getTextureLookupFunctionName()+"(in "+getTextureSampler2DType()+" image, in vec2 texCoord) {\n"+
" "+
" float y1,u,y2,v,y,r,g,b;\n"+
" vec2 tc_halfw = vec2(texCoord.x*0.5, texCoord.y);\n"+
@@ -793,7 +794,7 @@ public class FFMPEGMediaPlayer extends GLMediaPlayerImpl {
case UYVY422: // < packed YUV 4:2:2, 2 x 16bpp, Cb Y0 Cr Y1
// Stuffed into RGBA half width texture
return
- "vec4 "+texLookupFuncName+"(in "+getTextureSampler2DType()+" image, in vec2 texCoord) {\n"+
+ "vec4 "+getTextureLookupFunctionName()+"(in "+getTextureSampler2DType()+" image, in vec2 texCoord) {\n"+
" "+
" float y1,u,y2,v,y,r,g,b;\n"+
" vec2 tc_halfw = vec2(texCoord.x*0.5, texCoord.y);\n"+
@@ -815,7 +816,7 @@ public class FFMPEGMediaPlayer extends GLMediaPlayerImpl {
case BGR24:
return
- "vec4 "+texLookupFuncName+"(in "+getTextureSampler2DType()+" image, in vec2 texCoord) {\n"+
+ "vec4 "+getTextureLookupFunctionName()+"(in "+getTextureSampler2DType()+" image, in vec2 texCoord) {\n"+
" "+
" vec3 bgr = texture2D(image, texCoord).rgb;\n"+
" return vec4(bgr.b, bgr.g, bgr.r, 1);\n"+ /* just swizzle */
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TextureSequenceCubeES2.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TextureSequenceCubeES2.java
index aade02efa..540fb8eb3 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TextureSequenceCubeES2.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TextureSequenceCubeES2.java
@@ -84,12 +84,15 @@ public class TextureSequenceCubeES2 implements GLEventListener {
int ly = 0;
boolean first = false;
+ @Override
public void mousePressed(final MouseEvent e) {
first = true;
}
+ @Override
public void mouseMoved(final MouseEvent e) {
first = false;
}
+ @Override
public void mouseDragged(final MouseEvent e) {
int width, height;
final Object source = e.getSource();
@@ -143,6 +146,7 @@ public class TextureSequenceCubeES2 implements GLEventListener {
ly = ny;
}
}
+ @Override
public void mouseWheelMoved(final MouseEvent e) {
// System.err.println("XXX "+e);
if( !e.isShiftDown() ) {
@@ -182,7 +186,7 @@ public class TextureSequenceCubeES2 implements GLEventListener {
rsFpPos = rsFp.insertShaderSource(0, rsFpPos, texSeq.getRequiredExtensionsShaderStub());
rsFp.addDefaultShaderPrecision(gl, rsFpPos);
- final String texLookupFuncName = texSeq.getTextureLookupFunctionName(myTextureLookupName);
+ final String texLookupFuncName = texSeq.setTextureLookupFunctionName(myTextureLookupName);
rsFp.replaceInShaderSource(myTextureLookupName, texLookupFuncName);
// Inject TextureSequence shader details
@@ -206,6 +210,7 @@ public class TextureSequenceCubeES2 implements GLEventListener {
GLArrayDataServer interleavedVBO, cubeIndicesVBO;
+ @Override
public void init(final GLAutoDrawable drawable) {
final GL2ES2 gl = drawable.getGL().getGL2ES2();
System.err.println(JoglVersion.getGLInfo(gl, null));
@@ -304,6 +309,7 @@ public class TextureSequenceCubeES2 implements GLEventListener {
System.out.println(st);
}
+ @Override
public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) {
final GL2ES2 gl = drawable.getGL().getGL2ES2();