FileDocCategorySizeDatePackage
ShaderProgram.javaAPI DocAndroid 5.1 API10779Thu Mar 12 22:22:30 GMT 2015android.filterfw.core

ShaderProgram

public class ShaderProgram extends android.filterfw.core.Program
hide

Fields Summary
private int
shaderProgramId
private int
mMaxTileSize
private GLEnvironment
mGLEnvironment
private android.filterfw.core.StopWatchMap
mTimer
Constructors Summary
private ShaderProgram()

    
private ShaderProgram(android.filterfw.core.NativeAllocatorTag tag)

    
public ShaderProgram(FilterContext context, String fragmentShader)

        mGLEnvironment = getGLEnvironment(context);
        allocate(mGLEnvironment, null, fragmentShader);
        if (!compileAndLink()) {
            throw new RuntimeException("Could not compile and link shader!");
        }
        this.setTimer();
    
public ShaderProgram(FilterContext context, String vertexShader, String fragmentShader)

        mGLEnvironment = getGLEnvironment(context);
        allocate(mGLEnvironment, vertexShader, fragmentShader);
        if (!compileAndLink()) {
            throw new RuntimeException("Could not compile and link shader!");
        }
        this.setTimer();
    
Methods Summary
private native booleanallocate(GLEnvironment glEnv, java.lang.String vertexShader, java.lang.String fragmentShader)

public voidbeginDrawing()

        if (!beginShaderDrawing()) {
            throw new RuntimeException("Could not prepare shader-program for drawing!");
        }
    
private native booleanbeginShaderDrawing()

private native booleancompileAndLink()

public static android.filterfw.core.ShaderProgramcreateIdentity(FilterContext context)

        ShaderProgram program = nativeCreateIdentity(getGLEnvironment(context));
        program.setTimer();
        return program;
    
private native booleandeallocate()

protected voidfinalize()

        deallocate();
    
private static GLEnvironmentgetGLEnvironment(FilterContext context)

        GLEnvironment result = context != null ? context.getGLEnvironment() : null;
        if (result == null) {
            throw new NullPointerException("Attempting to create ShaderProgram with no GL "
                + "environment in place!");
        }
        return result;
    
public GLEnvironmentgetGLEnvironment()

        return mGLEnvironment;
    
public java.lang.ObjectgetHostValue(java.lang.String variableName)

        return getUniformValue(variableName);
    
private native java.lang.ObjectgetUniformValue(java.lang.String name)

private static native android.filterfw.core.ShaderProgramnativeCreateIdentity(GLEnvironment glEnv)

public voidprocess(android.filterfw.core.Frame[] inputs, android.filterfw.core.Frame output)

        if (mTimer.LOG_MFF_RUNNING_TIMES) {
          mTimer.start("glFinish");
          GLES20.glFinish();
          mTimer.stop("glFinish");
        }

        // Get the GL input frames
        // TODO: We do the same in the NativeProgram... can we find a better way?!
        GLFrame[] glInputs = new GLFrame[inputs.length];
        for (int i = 0; i < inputs.length; ++i) {
            if (inputs[i] instanceof GLFrame) {
                glInputs[i] = (GLFrame)inputs[i];
            } else {
                throw new RuntimeException("ShaderProgram got non-GL frame as input " + i + "!");
            }
        }

        // Get the GL output frame
        GLFrame glOutput = null;
        if (output instanceof GLFrame) {
            glOutput = (GLFrame)output;
        } else {
            throw new RuntimeException("ShaderProgram got non-GL output frame!");
        }

        // Adjust tiles to meet maximum tile size requirement
        if (mMaxTileSize > 0) {
            int xTiles = (output.getFormat().getWidth() + mMaxTileSize - 1) / mMaxTileSize;
            int yTiles = (output.getFormat().getHeight() + mMaxTileSize - 1) / mMaxTileSize;
            setShaderTileCounts(xTiles, yTiles);
        }

        // Process!
        if (!shaderProcess(glInputs, glOutput)) {
            throw new RuntimeException("Error executing ShaderProgram!");
        }

        if (mTimer.LOG_MFF_RUNNING_TIMES) {
          GLES20.glFinish();
        }
    
public voidsetAttributeValues(java.lang.String attributeName, float[] data, int componentCount)

        if (!setShaderAttributeValues(attributeName, data, componentCount)) {
            throw new RuntimeException("Error setting attribute value for attribute '" +
                                       attributeName + "'!");
        }
    
public voidsetAttributeValues(java.lang.String attributeName, android.filterfw.core.VertexFrame vertexData, int type, int componentCount, int strideInBytes, int offsetInBytes, boolean normalize)

        if (!setShaderAttributeVertexFrame(attributeName,
                                           vertexData,
                                           type,
                                           componentCount,
                                           strideInBytes,
                                           offsetInBytes,
                                           normalize)) {
            throw new RuntimeException("Error setting attribute value for attribute '" +
                                       attributeName + "'!");
        }
    
public voidsetBlendEnabled(boolean enable)

        if (!setShaderBlendEnabled(enable)) {
            throw new RuntimeException("Could not set Blending " + enable + "!");
        }
    
public voidsetBlendFunc(int sfactor, int dfactor)

        if (!setShaderBlendFunc(sfactor, dfactor)) {
            throw new RuntimeException("Could not set BlendFunc " + sfactor +","+ dfactor + "!");
        }
    
public voidsetClearColor(float r, float g, float b)

        if (!setShaderClearColor(r, g, b)) {
            throw new RuntimeException("Could not set clear color to " + r + "," + g + "," + b + "!");
        }
    
public voidsetClearsOutput(boolean clears)

        if (!setShaderClearsOutput(clears)) {
            throw new RuntimeException("Could not set clears-output flag to " + clears + "!");
        }
    
public voidsetDrawMode(int drawMode)

        if (!setShaderDrawMode(drawMode)) {
            throw new RuntimeException("Could not set GL draw-mode to " + drawMode + "!");
        }
    
public voidsetHostValue(java.lang.String variableName, java.lang.Object value)

        if (!setUniformValue(variableName, value)) {
            throw new RuntimeException("Error setting uniform value for variable '" +
                                       variableName + "'!");
        }
    
public voidsetMaximumTileSize(int size)

        mMaxTileSize = size;
    
private native booleansetShaderAttributeValues(java.lang.String attributeName, float[] data, int componentCount)

private native booleansetShaderAttributeVertexFrame(java.lang.String attributeName, android.filterfw.core.VertexFrame vertexData, int type, int componentCount, int strideInBytes, int offsetInBytes, boolean normalize)

private native booleansetShaderBlendEnabled(boolean enable)

private native booleansetShaderBlendFunc(int sfactor, int dfactor)

private native booleansetShaderClearColor(float r, float g, float b)

private native booleansetShaderClearsOutput(boolean clears)

private native booleansetShaderDrawMode(int drawMode)

private native booleansetShaderTileCounts(int xCount, int yCount)

private native booleansetShaderVertexCount(int vertexCount)

public voidsetSourceRect(float x, float y, float width, float height)

        setSourceRegion(x, y, x + width, y, x, y + height, x + width, y + height);
    
public voidsetSourceRegion(android.filterfw.geometry.Quad region)

        setSourceRegion(region.p0.x, region.p0.y,
                        region.p1.x, region.p1.y,
                        region.p2.x, region.p2.y,
                        region.p3.x, region.p3.y);
    
public native booleansetSourceRegion(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3)

public voidsetTargetRect(float x, float y, float width, float height)

        setTargetRegion(x, y, x + width, y, x, y + height, x + width, y + height);
    
public voidsetTargetRegion(android.filterfw.geometry.Quad region)

        setTargetRegion(region.p0.x, region.p0.y,
                        region.p1.x, region.p1.y,
                        region.p2.x, region.p2.y,
                        region.p3.x, region.p3.y);
    
private native booleansetTargetRegion(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3)

private voidsetTimer()


       
        mTimer = new StopWatchMap();
    
private native booleansetUniformValue(java.lang.String name, java.lang.Object value)

public voidsetVertexCount(int count)

        if (!setShaderVertexCount(count)) {
            throw new RuntimeException("Could not set GL vertex count to " + count + "!");
        }
    
private native booleanshaderProcess(GLFrame[] inputs, GLFrame output)