Interface TextureSequence
-
- All Known Subinterfaces:
GLMediaPlayer
- All Known Implementing Classes:
ImageSequence
public interface TextureSequenceProtocol for texture sequences, like animations, movies, etc.Ensure to respect the texture coordinates provided by
The user's shader shall be fitted for this implementation. Assuming we use a base shader code w/o headers using ShaderCode. (Code copied from unit test / demoTextureSequence.TextureFrame.getTexture().getImageTexCoords().TexCubeES2)static final String[] es2_prelude = { "#version 100\n", "precision mediump float;\n" }; static final String gl2_prelude = "#version 110\n"; static final String shaderBasename = "texsequence_xxx"; // the base shader code w/o headers static final String myTextureLookupName = "myTexture2D"; // the desired texture lookup function private void initShader(GL2ES2 gl, TextureSequence texSeq) { // Create & Compile the shader objects ShaderCode rsVp = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, TexCubeES2.class, "shader", "shader/bin", shaderBasename, true); ShaderCode rsFp = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, TexCubeES2.class, "shader", "shader/bin", shaderBasename, true); // Prelude shader code w/ GLSL profile specifics [ 1. pre-proc, 2. other ] int rsFpPos; if(gl.isGLES2()) { // insert ES2 version string in beginning rsVp.insertShaderSource(0, 0, es2_prelude[0]); rsFpPos = rsFp.insertShaderSource(0, 0, es2_prelude[0]); } else { // insert GL2 version string in beginning rsVp.insertShaderSource(0, 0, gl2_prelude); rsFpPos = rsFp.insertShaderSource(0, 0, gl2_prelude); } // insert required extensions as determined by TextureSequence implementation. rsFpPos = rsFp.insertShaderSource(0, rsFpPos, texSeq.getRequiredExtensionsShaderStub()); if(gl.isGLES2()) { // insert ES2 default precision declaration rsFpPos = rsFp.insertShaderSource(0, rsFpPos, es2_prelude[1]); } // negotiate the texture lookup function name final String texLookupFuncName = texSeq.getTextureLookupFunctionName(myTextureLookupName); // in case a fixed lookup function is being chosen, replace the name in our code rsFp.replaceInShaderSource(myTextureLookupName, texLookupFuncName); // Cache the TextureSequence shader details in StringBuilder: final StringBuilder sFpIns = new StringBuilder(); // .. declaration of the texture sampler using the implementation specific type sFpIns.append("uniform ").append(texSeq.getTextureSampler2DType()).append(" mgl_ActiveTexture;\n"); // .. the actual texture lookup function, maybe null in case a built-in function is being used sFpIns.append(texSeq.getTextureLookupFragmentShaderImpl()); // Now insert the TextureShader details in our shader after the given tag: rsFp.insertShaderSource(0, "TEXTURE-SEQUENCE-CODE-BEGIN", 0, sFpIns); // 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); } ...The above procedure might look complicated, however, it allows most flexibility and workarounds to also deal with GLSL bugs.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceTextureSequence.TexSeqEventListener<T extends TextureSequence>Event listener to notify users of updates regarding theTextureSequence.static classTextureSequence.TextureFrameTexture holder interface, maybe specialized by implementation to associated related data.
-
Field Summary
Fields Modifier and Type Field Description static Stringsampler2Dstatic StringsamplerExternalOES
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description com.jogamp.math.Vec4fgetARatioLetterboxBackColor()ReturnsuseARatioLetterbox()background color for added letter-box space, defaults to transparent zero.TextureSequence.TextureFramegetLastTexture()Returns the last updated texture.TextureSequence.TextureFramegetNextTexture(GL gl)Returns the next texture to be rendered.StringgetRequiredExtensionsShaderStub()In case a shader extension is required, based on the implementation and the runtime GL profile, this method returns the preprocessor macros, e.g.:intgetTextureFragmentShaderHashCode()Returns the hash code of the stringgetTextureFragmentShaderHashID().StringgetTextureFragmentShaderHashID()Returns the concatenated string representing the following values utilized forgetTextureFragmentShaderHashCode().StringgetTextureLookupFragmentShaderImpl()Returns the complete texture2D lookup function code of typeStringgetTextureLookupFunctionName()Returns the chosen lookup function name, which can be set viasetTextureLookupFunctionName(String).int[]getTextureMinMagFilter()StringgetTextureSampler2DType()Returns eithersampler2DorsamplerExternalOESdepending ongetLastTexture().getTexture().getTarget().intgetTextureTarget()Returns the texture target used by implementation.intgetTextureUnit()Return the texture unit used to render the current frame.int[]getTextureWrapST()booleanisTextureAvailable()Returns true if texture source is ready and a texture is available viagetNextTexture(GL)andgetLastTexture().voidsetARatioAdjustment(boolean v)TogglesuseARatioLetterbox().voidsetARatioLetterbox(boolean v, com.jogamp.math.Vec4f backColor)TogglesuseARatioLetterbox().static voidsetTexCoordBBox(Texture tex, com.jogamp.math.geom.AABBox box, boolean letterBox, float[] colorTexBBox, boolean verbose)Calculates the texture coordinates bounding box while correcting for aspect-ratio.static voidsetTexCoordBBoxSimple(Texture tex, com.jogamp.math.geom.AABBox box, float[] colorTexBBox, boolean verbose)Calculates the texture coordinates bounding box w/o correcting aspect-ratio.StringsetTextureLookupFunctionName(String texLookupFuncName)Set the desired shader code's texture lookup function name.booleanuseARatioAdjustment()Returningtrueindicates texture correction for aspect-ratio in the shader.booleanuseARatioLetterbox()Returns whetheruseARatioAdjustment()shall add letter-box space to match aspect-ratio, otherwise it will be zoomed in.
-
-
-
Field Detail
-
samplerExternalOES
static final String samplerExternalOES
- See Also:
- Constant Field Values
-
sampler2D
static final String sampler2D
- See Also:
- Constant Field Values
-
-
Method Detail
-
getTextureTarget
int getTextureTarget()
Returns the texture target used by implementation.
-
getTextureUnit
int getTextureUnit()
Return the texture unit used to render the current frame.
-
getTextureMinMagFilter
int[] getTextureMinMagFilter()
-
getTextureWrapST
int[] getTextureWrapST()
-
useARatioAdjustment
boolean useARatioAdjustment()
Returningtrueindicates texture correction for aspect-ratio in the shader. Graph'sRegionshader will utilizesetTexCoordBBox(Texture, AABBox, boolean, float[], boolean)for texture-coordinate bounding-box calculation.Returning
falseindicates no correction for aspect-ratio in the shader. Graph'sRegionshader will utilizesetTexCoordBBoxSimple(Texture, AABBox, float[], boolean)for texture-coordinate bounding-box calculation.Default value is implementation specific and toggling is optional.
-
setARatioAdjustment
void setARatioAdjustment(boolean v)
TogglesuseARatioLetterbox().Default value is implementation specific and toggling is optional.
- See Also:
useARatioLetterbox(),useARatioAdjustment()
-
useARatioLetterbox
boolean useARatioLetterbox()
Returns whetheruseARatioAdjustment()shall add letter-box space to match aspect-ratio, otherwise it will be zoomed in.Default value is implementation specific and toggling is optional.
-
getARatioLetterboxBackColor
com.jogamp.math.Vec4f getARatioLetterboxBackColor()
ReturnsuseARatioLetterbox()background color for added letter-box space, defaults to transparent zero.
-
setARatioLetterbox
void setARatioLetterbox(boolean v, com.jogamp.math.Vec4f backColor)TogglesuseARatioLetterbox().Default value is implementation specific and toggling is optional.
Impacts only if
useARatioAdjustment()returnstrue.- Parameters:
v- new value foruseARatioLetterbox()backColor- optional background color for added letter-box space, defaults to transparent zero- See Also:
useARatioLetterbox(),useARatioAdjustment()
-
isTextureAvailable
boolean isTextureAvailable()
Returns true if texture source is ready and a texture is available viagetNextTexture(GL)andgetLastTexture().
-
getLastTexture
TextureSequence.TextureFrame getLastTexture() throws IllegalStateException
Returns the last updated texture.In case the instance is just initialized, it shall return a
Not blocking.TextureFrameobject with valid attributes. The texture content may be undefined until the first call ofgetNextTexture(GL).
- Throws:
IllegalStateException- if instance is not initialized
-
getNextTexture
TextureSequence.TextureFrame getNextTexture(GL gl) throws IllegalStateException
Returns the next texture to be rendered.Implementation shall return the next frame if available, may block if a next frame may arrive soon. Otherwise implementation shall return the last frame.
Shall return
nullin case no next or last frame is available.- Throws:
IllegalStateException- if instance is not initialized
-
getRequiredExtensionsShaderStub
String getRequiredExtensionsShaderStub() throws IllegalStateException
In case a shader extension is required, based on the implementation and the runtime GL profile, this method returns the preprocessor macros, e.g.:#extension GL_OES_EGL_image_external : enable
- Throws:
IllegalStateException- if instance is not initialized
-
getTextureSampler2DType
String getTextureSampler2DType() throws IllegalStateException
Returns eithersampler2DorsamplerExternalOESdepending ongetLastTexture().getTexture().getTarget().- Throws:
IllegalStateException- if instance is not initialized
-
setTextureLookupFunctionName
String setTextureLookupFunctionName(String texLookupFuncName) throws IllegalStateException
Set the desired shader code's texture lookup function name.- Parameters:
texLookupFuncName- desired lookup function name. Ifnullor ignored by the implementation, a build-in name is returned.- Returns:
- the chosen lookup function name
- Throws:
IllegalStateException- if instance is not initialized- See Also:
getTextureLookupFunctionName(),getTextureFragmentShaderHashCode(),getTextureLookupFragmentShaderImpl()
-
getTextureLookupFunctionName
String getTextureLookupFunctionName() throws IllegalStateException
Returns the chosen lookup function name, which can be set viasetTextureLookupFunctionName(String).- Throws:
IllegalStateException- if instance is not initialized- See Also:
setTextureLookupFunctionName(String),getTextureFragmentShaderHashCode(),getTextureLookupFragmentShaderImpl()
-
getTextureLookupFragmentShaderImpl
String getTextureLookupFragmentShaderImpl() throws IllegalStateException
Returns the complete texture2D lookup function code of typevec4 funcName(in getTextureSampler2DType() image, in vec2 texCoord) { vec4 texColor = do_something_with(image, texCoord); return texColor; }funcName is set via
setTextureLookupFunctionName(String)and queried viagetTextureLookupFunctionName().User shall call
setTextureLookupFunctionName(String)first if intended.Note: This function may return an empty string in case a build-in lookup function is being chosen. If the implementation desires so,
getTextureLookupFunctionName()will ignore the desired function name and returns the build-in lookup function name.- Throws:
IllegalStateException- if instance is not initialized- See Also:
getTextureLookupFunctionName(),setTextureLookupFunctionName(String),getTextureFragmentShaderHashID(),getTextureFragmentShaderHashCode(),getTextureSampler2DType()
-
getTextureFragmentShaderHashID
String getTextureFragmentShaderHashID()
Returns the concatenated string representing the following values utilized forgetTextureFragmentShaderHashCode().To reduce string concatenating, implementation may simply return
getTextureLookupFragmentShaderImpl(), if it coversgetTextureSampler2DType()andgetTextureLookupFunctionName().- See Also:
getTextureFragmentShaderHashCode()
-
getTextureFragmentShaderHashCode
int getTextureFragmentShaderHashCode()
Returns the hash code of the stringgetTextureFragmentShaderHashID().User shall call
setTextureLookupFunctionName(String)first if intended.Returns zero if
The returned hash code allows selection of a matching shader program for thistexture is not available.TextureSequenceinstance.Implementation caches the resulting hash code, which is reset by
setTextureLookupFunctionName(String)and this method iftexture is not available.
-
setTexCoordBBoxSimple
static void setTexCoordBBoxSimple(Texture tex, com.jogamp.math.geom.AABBox box, float[] colorTexBBox, boolean verbose)
Calculates the texture coordinates bounding box w/o correcting aspect-ratio.- Parameters:
tex- theTexturebox- the of the destinationcolorTexBBox- destination float[6] array for the following three texture-coordinate tuples: minX/minY, maxX/maxY, texW/texHverbose- TODO- See Also:
useARatioAdjustment()
-
setTexCoordBBox
static void setTexCoordBBox(Texture tex, com.jogamp.math.geom.AABBox box, boolean letterBox, float[] colorTexBBox, boolean verbose)
Calculates the texture coordinates bounding box while correcting for aspect-ratio.- Parameters:
tex- theTexturebox- the of the destinationletterBox- true to produce letter-box space to match aspect-ratio, otherwise will zoom incolorTexBBox- destination float[6] array for the following three texture-coordinate tuples: minX/minY, maxX/maxY, texW/texHverbose- TODO- See Also:
useARatioAdjustment()
-
-