Interface TextureSequence

  • All Known Subinterfaces:
    GLMediaPlayer
    All Known Implementing Classes:
    ImageSequence

    public interface TextureSequence
    Protocol for texture sequences, like animations, movies, etc.

    Ensure to respect the texture coordinates provided by TextureSequence.TextureFrame.getTexture().getImageTexCoords().

    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 / demo 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.