public class BlackWhiteFilter extends SimpleFragmentShaderFilter {
    public BlackWhiteFilter(Context context) {
        super(context, "filter/fsh/mx_black_white.glsl");
    }
} public class GreenHouseFilter extends SimpleFragmentShaderFilter {
    public GreenHouseFilter(Context context) {
        super(context, "filter/fsh/mx_green_house.glsl");
    }
} public class MoonLightFilter extends SimpleFragmentShaderFilter {
    public MoonLightFilter(Context context) {
        super(context, "filter/fsh/mx_moon_light.glsl");
    }
} public class MxFaceBeautyFilter extends SimpleFragmentShaderFilter {
    public MxFaceBeautyFilter(Context context) {
        super(context, "filter/fsh/mx_face_beauty.glsl");
    }

    @Override
    public void onDrawFrame(int textureId) {
        onPreDrawElements();
        setUniform1f(glSimpleProgram.getProgramId(),"stepSizeX",1.0f/surfaceWidth);
        setUniform1f(glSimpleProgram.getProgramId(),"stepSizeY",1.0f/surfaceHeight);
        TextureUtils.bindTexture2D(textureId, GLES20.GL_TEXTURE0,glSimpleProgram.getTextureSamplerHandle(),0);
        GLES20.glViewport(0,0,surfaceWidth,surfaceHeight);
        plane.draw();
    }
} public class MxLomoFilter extends SimpleFragmentShaderFilter {
    public MxLomoFilter(Context context) {
        super(context, "filter/fsh/mx_lomo.glsl");
    }

    @Override
    public void onDrawFrame(int textureId) {
        onPreDrawElements();
        setUniform1f(glSimpleProgram.getProgramId(),"rOffset",1.0f);
        setUniform1f(glSimpleProgram.getProgramId(),"gOffset",1.0f);
        setUniform1f(glSimpleProgram.getProgramId(),"bOffset",1.0f);
        TextureUtils.bindTexture2D(textureId, GLES20.GL_TEXTURE0,glSimpleProgram.getTextureSamplerHandle(),0);
        GLES20.glViewport(0,0,surfaceWidth,surfaceHeight);
        plane.draw();
    }
} public class ReminiscenceFilter extends SimpleFragmentShaderFilter {
    public ReminiscenceFilter(Context context) {
        super(context, "filter/fsh/mx_reminiscence.glsl");
    }
} public class ShiftColorFilter extends SimpleFragmentShaderFilter {
    public ShiftColorFilter(Context context) {
        super(context, "filter/fsh/mx_shift_color.glsl");
    }
} public class VignetteFilter extends SimpleFragmentShaderFilter {
    public VignetteFilter(Context context) {
        super(context, "filter/fsh/mx_vignette.glsl");
    }
} public abstract class AbsFilter {
    protected static final String TAG = "AbsFilter";
    private final LinkedList<Runnable> mPreDrawTaskList;
    protected int surfaceWidth,surfaceHeight;

    public AbsFilter() {
        mPreDrawTaskList = new LinkedList<Runnable>();
    }

    abstract public void init();

    public void onPreDrawElements(){
        GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
        GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
    }

    abstract public void destroy();

    public void onFilterChanged(int surfaceWidth, int surfaceHeight){
        this.surfaceWidth=surfaceWidth;
        this.surfaceHeight=surfaceHeight;
    }

    void setViewport(){
        GLES20.glViewport(0, 0, surfaceWidth, surfaceHeight);
    }

    public FBO createFBO(){
        return FBO.newInstance().create(surfaceWidth,surfaceHeight);
    }

    abstract public void onDrawFrame(final int textureId);


    public void runPreDrawTasks() {
        while (!mPreDrawTaskList.isEmpty()) {
            mPreDrawTaskList.removeFirst().run();
        }
    }

    public void addPreDrawTask(final Runnable runnable) {
        synchronized (mPreDrawTaskList) {
            mPreDrawTaskList.addLast(runnable);
        }
    }

    public void setUniform1f(final int programId, final String name , final float floatValue) {
        int location=GLES20.glGetUniformLocation(programId,name);
        GLES20.glUniform1f(location,floatValue);
    }
} public class PassThroughFilter extends AbsFilter {

    protected GLPassThroughProgram glPassThroughProgram;
    private Plane plane;

    protected Context context;
    protected float[] projectionMatrix = new float[16];

    public PassThroughFilter(Context context) {
        this.context=context;
        glPassThroughProgram=new GLPassThroughProgram(context);
        plane =new Plane(true);
    }

    @Override
    public void init() {
        glPassThroughProgram.create();
    }

    @Override
    public void destroy() {
        glPassThroughProgram.onDestroy();
    }

    @Override
    public void onDrawFrame(int textureId) {
        onPreDrawElements();
        glPassThroughProgram.use();
        Matrix.setIdentityM(projectionMatrix,0);
        plane.uploadTexCoordinateBuffer(glPassThroughProgram.getTextureCoordinateHandle());
        plane.uploadVerticesBuffer(glPassThroughProgram.getPositionHandle());
        GLES20.glUniformMatrix4fv(glPassThroughProgram.getMVPMatrixHandle(), 1, false, projectionMatrix, 0);
        TextureUtils.bindTexture2D(textureId, GLES20.GL_TEXTURE0,glPassThroughProgram.getTextureSamplerHandle(),0);
        GLES20.glViewport(0,0,surfaceWidth,surfaceHeight);
        plane.draw();
    }

}
import android.content.Context;
import com.martin.ads.vrlib.filters.advanced.mx.BlackWhiteFilter;
import com.martin.ads.vrlib.filters.advanced.mx.BrightnessFilter;
import com.martin.ads.vrlib.filters.advanced.mx.FillLightFilter;
import com.martin.ads.vrlib.filters.advanced.mx.GreenHouseFilter;
import com.martin.ads.vrlib.filters.advanced.mx.MoonLightFilter;
import com.martin.ads.vrlib.filters.advanced.mx.MultiplyFilter;
import com.martin.ads.vrlib.filters.advanced.mx.MxFaceBeautyFilter;
import com.martin.ads.vrlib.filters.advanced.mx.MxLomoFilter;
import com.martin.ads.vrlib.filters.advanced.mx.MxProFilter;
import com.martin.ads.vrlib.filters.advanced.mx.PastTimeFilter;
import com.martin.ads.vrlib.filters.advanced.mx.PrintingFilter;
import com.martin.ads.vrlib.filters.advanced.mx.ReminiscenceFilter;
import com.martin.ads.vrlib.filters.advanced.mx.ShiftColorFilter;
import com.martin.ads.vrlib.filters.advanced.mx.SunnyFilter;
import com.martin.ads.vrlib.filters.advanced.mx.ToyFilter;
import com.martin.ads.vrlib.filters.advanced.mx.VignetteFilter;
import com.martin.ads.vrlib.filters.base.AbsFilter;
import com.martin.ads.vrlib.filters.base.PassThroughFilter;
package com.martin.ads.vrlib.filters.advanced;



/**
 * Created by Ads on 2017/2/13.
 */

public class FilterFactory {
    public static AbsFilter createFilter(FilterType filterType, Context context){
        switch (filterType){
            //Effects
            case FILL_LIGHT_FILTER:
                return new FillLightFilter(context);
            case GREEN_HOUSE_FILTER:
                return new GreenHouseFilter(context);
            case BLACK_WHITE_FILTER:
                return new BlackWhiteFilter(context);
            case PAST_TIME_FILTER:
                return new PastTimeFilter(context);
            case MOON_LIGHT_FILTER:
                return new MoonLightFilter(context);
            case PRINTING_FILTER:
                return new PrintingFilter(context);
            case TOY_FILTER:
                return new ToyFilter(context);
            case BRIGHTNESS_FILTER:
                return new BrightnessFilter(context);
            case VIGNETTE_FILTER:
                return new VignetteFilter(context);