// Path: vrlib/src/main/java/com/martin/ads/vrlib/utils/ShaderUtils.java
// public class ShaderUtils {
// 
//     private static final String TAG = "ShaderUtils";
// 
//     public static void checkGlError(String label) {
//         int error;
//         while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) {
//             Log.e(TAG, label + ": glError " + error);
//             throw new RuntimeException(label + ": glError " + error);
//         }
//     }
// 
//     public static int createProgram(String vertexSource, String fragmentSource) {
//         int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource);
//         if (vertexShader == 0) {
//             return 0;
//         }
//         int pixelShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
//         if (pixelShader == 0) {
//             return 0;
//         }
// 
//         int program = GLES20.glCreateProgram();
//         if (program != 0) {
//             GLES20.glAttachShader(program, vertexShader);
//             checkGlError("glAttachShader");
//             GLES20.glAttachShader(program, pixelShader);
//             checkGlError("glAttachShader");
//             GLES20.glLinkProgram(program);
//             int[] linkStatus = new int[1];
//             GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
//             if (linkStatus[0] != GLES20.GL_TRUE) {
//                 Log.e(TAG, "Could not link program: ");
//                 Log.e(TAG, GLES20.glGetProgramInfoLog(program));
//                 GLES20.glDeleteProgram(program);
//                 program = 0;
//             }
//         }
//         return program;
//     }
// 
// 
//     public static int loadShader(int shaderType, String source) {
//         int shader = GLES20.glCreateShader(shaderType);
//         if (shader != 0) {
//             GLES20.glShaderSource(shader, source);
//             GLES20.glCompileShader(shader);
//             int[] compiled = new int[1];
//             GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compiled, 0);
//             if (compiled[0] == 0) {
//                 Log.e(TAG, "Could not compile shader " + shaderType + ":");
//                 Log.e(TAG, GLES20.glGetShaderInfoLog(shader));
//                 GLES20.glDeleteShader(shader);
//                 shader = 0;
//             }
//         }
//         return shader;
//     }
// 
// 
//     public static String readRawTextFile(Context context, int resId) {
//         InputStream inputStream = context.getResources().openRawResource(resId);
//         return getStringFromStream(inputStream);
//     }
// 
//     public static String readAssetsTextFile(Context context, String filePath) {
//         InputStream inputStream = null;
//         try {
//             inputStream = context.getResources().getAssets().open(filePath);
//         } catch (IOException e) {
//             e.printStackTrace();
//         }
//         return getStringFromStream(inputStream);
//     }
// 
//     private static String getStringFromStream(InputStream inputStream){
//         if(inputStream==null) return null;
//         try {
//             BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
//             StringBuilder sb = new StringBuilder();
//             String line;
//             while ((line = reader.readLine()) != null) {
//                 sb.append(line).append("\n");
//             }
//             reader.close();
//             return sb.toString();
//         } catch (IOException e) {
//             e.printStackTrace();
//         }
//         return null;
//     }
// 
// }


import android.content.Context;
import android.opengl.GLES20;
import com.martin.ads.vrlib.utils.ShaderUtils;
package com.martin.ads.vrlib.programs;




/**
 * Created by Ads on 2016/11/19.
 * with Sampler2D and MVPMatrix
 */

public class GLPassThroughProgram extends GLAbsProgram {

    private int uMVPMatrixHandle;
    private int uTextureSamplerHandle;

    public GLPassThroughProgram(Context context) {
        super(context, "filter/vsh/pass_through.glsl","filter/fsh/pass_through.glsl");
    }

    @Override
    public void create() {
        super.create();
        uTextureSamplerHandle= GLES20.glGetUniformLocation(getProgramId(),"sTexture");
        ShaderUtils.checkGlError("glGetUniformLocation uniform sTexture");
        uMVPMatrixHandle=GLES20.glGetUniformLocation(getProgramId(),"uMVPMatrix");
// Path: vrlib/src/main/java/com/martin/ads/vrlib/utils/ShaderUtils.java
// public class ShaderUtils {
// 
//     private static final String TAG = "ShaderUtils";
// 
//     public static void checkGlError(String label) {
//         int error;
//         while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) {
//             Log.e(TAG, label + ": glError " + error);
//             throw new RuntimeException(label + ": glError " + error);
//         }
//     }
// 
//     public static int createProgram(String vertexSource, String fragmentSource) {
//         int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource);
//         if (vertexShader == 0) {
//             return 0;
//         }
//         int pixelShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
//         if (pixelShader == 0) {
//             return 0;
//         }
// 
//         int program = GLES20.glCreateProgram();
//         if (program != 0) {
//             GLES20.glAttachShader(program, vertexShader);
//             checkGlError("glAttachShader");
//             GLES20.glAttachShader(program, pixelShader);
//             checkGlError("glAttachShader");
//             GLES20.glLinkProgram(program);
//             int[] linkStatus = new int[1];
//             GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
//             if (linkStatus[0] != GLES20.GL_TRUE) {
//                 Log.e(TAG, "Could not link program: ");
//                 Log.e(TAG, GLES20.glGetProgramInfoLog(program));
//                 GLES20.glDeleteProgram(program);
//                 program = 0;
//             }
//         }
//         return program;
//     }
// 
// 
//     public static int loadShader(int shaderType, String source) {
//         int shader = GLES20.glCreateShader(shaderType);
//         if (shader != 0) {
//             GLES20.glShaderSource(shader, source);
//             GLES20.glCompileShader(shader);
//             int[] compiled = new int[1];
//             GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compiled, 0);
//             if (compiled[0] == 0) {
//                 Log.e(TAG, "Could not compile shader " + shaderType + ":");
//                 Log.e(TAG, GLES20.glGetShaderInfoLog(shader));
//                 GLES20.glDeleteShader(shader);
//                 shader = 0;
//             }
//         }
//         return shader;
//     }
// 
// 
//     public static String readRawTextFile(Context context, int resId) {
//         InputStream inputStream = context.getResources().openRawResource(resId);
//         return getStringFromStream(inputStream);
//     }
// 
//     public static String readAssetsTextFile(Context context, String filePath) {
//         InputStream inputStream = null;
//         try {
//             inputStream = context.getResources().getAssets().open(filePath);
//         } catch (IOException e) {
//             e.printStackTrace();
//         }
//         return getStringFromStream(inputStream);
//     }
// 
//     private static String getStringFromStream(InputStream inputStream){
//         if(inputStream==null) return null;
//         try {
//             BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
//             StringBuilder sb = new StringBuilder();
//             String line;
//             while ((line = reader.readLine()) != null) {
//                 sb.append(line).append("\n");
//             }
//             reader.close();
//             return sb.toString();
//         } catch (IOException e) {
//             e.printStackTrace();
//         }
//         return null;
//     }
// 
// }


// Path: vrlib/src/main/java/com/martin/ads/vrlib/programs/GLPassThroughProgram.java
import android.content.Context;
import android.opengl.GLES20;
import com.martin.ads.vrlib.utils.ShaderUtils;

package com.martin.ads.vrlib.programs;




/**
 * Created by Ads on 2016/11/19.
 * with Sampler2D and MVPMatrix
 */

public class GLPassThroughProgram extends GLAbsProgram {

    private int uMVPMatrixHandle;
    private int uTextureSamplerHandle;

    public GLPassThroughProgram(Context context) {
        super(context, "filter/vsh/pass_through.glsl","filter/fsh/pass_through.glsl");
    }

    @Override
    public void create() {
        super.create();
        uTextureSamplerHandle= GLES20.glGetUniformLocation(getProgramId(),"sTexture");
        ShaderUtils.checkGlError("glGetUniformLocation uniform sTexture");
        uMVPMatrixHandle=GLES20.glGetUniformLocation(getProgramId(),"uMVPMatrix");
        ShaderUtils.checkGlError("glGetUniformLocation uMVPMatrix");