diff options
author | Sven Gothel <[email protected]> | 2014-05-20 01:02:27 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-05-20 01:02:27 +0200 |
commit | cca2782818bec79f63a5da1719b11e15244dbea2 (patch) | |
tree | 880a492c63dbf1a75f36c4f0e39c75bf0a2e0976 /src/jogl/classes | |
parent | d73a4a37bd4a376fc712ecc03332b8cf8821d134 (diff) |
Bug 801: Refine commit 9a15aad0e5388a4b927e44d3d2ce136f32474bc2 cache TextureSequence's fragment shader hash-code
Adding TextureSequence.getTextureFragmentShaderHashCode() allowing to use a cached hash-code (performance, interface usability).
Implemented in GLMediaPlayerImpl and ImageSequence.
Diffstat (limited to 'src/jogl/classes')
4 files changed, 52 insertions, 4 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java index 438895d8e..bb191e651 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java @@ -394,9 +394,7 @@ public class RegionRenderer { final boolean pass1, final int quality, final int sampleCount, final TextureSequence colorTexSeq) { final int colorTexSeqHash; if( null != colorTexSeq ) { - int hash = 31 + colorTexSeq.getTextureLookupFragmentShaderImpl().hashCode(); - hash = ((hash << 5) - hash) + colorTexSeq.getTextureSampler2DType().hashCode(); - colorTexSeqHash = hash; + colorTexSeqHash = colorTexSeq.getTextureFragmentShaderHashCode(); } else { colorTexSeqHash = 0; } 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 4622d6975..a2d202d11 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/ImageSequence.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/ImageSequence.java @@ -52,6 +52,7 @@ public class ImageSequence implements TextureSequence { private final int[] texWrapST = { GL.GL_CLAMP_TO_EDGE, GL.GL_CLAMP_TO_EDGE }; private volatile int frameIdx = 0; private volatile boolean manualStepping = false; + private int textureFragmentShaderHashCode = 0; public ImageSequence(final int textureUnit, final boolean useBuildInTexLookup) { this.textureUnit = textureUnit; @@ -173,4 +174,17 @@ public class ImageSequence implements TextureSequence { " return texture2D(image, texCoord);\n"+ "}\n\n"; } + + @Override + public int getTextureFragmentShaderHashCode() { + if( !isTextureAvailable() ) { + textureFragmentShaderHashCode = 0; + return 0; + } else if( 0 == textureFragmentShaderHashCode ) { + int hash = 31 + getTextureLookupFragmentShaderImpl().hashCode(); + hash = ((hash << 5) - hash) + getTextureSampler2DType().hashCode(); + textureFragmentShaderHashCode = hash; + } + return textureFragmentShaderHashCode; + } } 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 88f40e927..ee3b600a5 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureSequence.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureSequence.java @@ -257,5 +257,24 @@ public interface TextureSequence { * * @throws IllegalStateException if instance is not initialized */ - public String getTextureLookupFragmentShaderImpl() throws IllegalStateException ; + public String getTextureLookupFragmentShaderImpl() throws IllegalStateException; + + /** + * Returns the hash code of the strings: + * <ul> + * <li>{@link #getTextureLookupFragmentShaderImpl()}</li> + * <li>{@link #getTextureSampler2DType()}</li> + * </ul> + * <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, + * which must be reset to zero if {@link #isTextureAvailable() texture is not available}. + * </p> + */ + 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 49c3c2a13..a6d5e8e2a 100644 --- a/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java +++ b/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java @@ -86,6 +86,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { protected int textureType; protected int texUnit; + private int textureFragmentShaderHashCode; protected int[] texMinMagFilter = { GL.GL_NEAREST, GL.GL_NEAREST }; protected int[] texWrapST = { GL.GL_CLAMP_TO_EDGE, GL.GL_CLAMP_TO_EDGE }; @@ -281,6 +282,19 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { } @Override + public final int getTextureFragmentShaderHashCode() { + if( !isTextureAvailable() ) { + textureFragmentShaderHashCode = 0; + return 0; + } else if( 0 == textureFragmentShaderHashCode ) { + int hash = 31 + getTextureLookupFragmentShaderImpl().hashCode(); + hash = ((hash << 5) - hash) + getTextureSampler2DType().hashCode(); + textureFragmentShaderHashCode = hash; + } + return textureFragmentShaderHashCode; + } + + @Override public final int getDecodedFrameCount() { return decodedFrameCount; } @Override @@ -1354,6 +1368,9 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { event_mask = addStateEventMask(event_mask, newState); if( 0 != event_mask ) { state = newState; + if( !isTextureAvailable() ) { + textureFragmentShaderHashCode = 0; + } attributesUpdated( event_mask ); } } |