package sbname.sbcamera.opengl;

import android.opengl.GLES11Ext;
import android.opengl.GLES20;

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

public class SbDrawer {
    private final String mVertexShader =
            "uniform mat4 uMVPMatrix;\n" +
                    "attribute vec4 aPosition;\n" +
                    "attribute vec2 aTextureCoord;\n" +
                    "varying vec2 vTextureCoord;\n" +
                    "void main() {\n" +
                    "  gl_Position = uMVPMatrix * aPosition;\n" +
                    "  vTextureCoord = aTextureCoord;\n" +
                    "}\n";

    private final String mFragmentShader =
            "precision mediump float;\n" +
                    "varying vec2 vTextureCoord;\n" +
                    "uniform sampler2D sTexture;\n" +
                    "void main() {\n" +
                    "  gl_FragColor = texture2D(sTexture, vTextureCoord);\n" +
                    "}\n";

    private static final float[] VERTICES ={
            1.0f , 1.0f,
            -1.0f, 1.0f,
            1.0f ,-1.0f,
            -1.0f,-1.0f
    };
    private static final float[] TEXCOORD = {
            1.0f, 1.0f,
            0.0f, 1.0f,
            1.0f, 0.0f,
            0.0f, 0.0f
    };

    /**
     * create external texture
     * @return texture ID
     */
    public static int initTex() {
        //初始化texture
        final int[] texId = new int[1];
        //拿到第一个Texure 并且存在texId 的texId[0]
        GLES20.glGenTextures(1, texId, 0);
        GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, texId[0]);
        //设置一堆参数  不卵他
        GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
                GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
        GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
                GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
        GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
                GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
        GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
                GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
        return texId[0];
    }
}

@@ -90,16 +90,101 @@
 LES20;%0A%0A
+import java.nio.ByteBuffer;%0Aimport java.nio.ByteOrder;%0Aimport java.nio.FloatBuffer;%0A%0A
 /**%0A * C
@@ -1068,16 +1068,17 @@
 RTICES =
+ 
 %7B%0A      
@@ -1087,17 +1087,16 @@
     1.0f
- 
 , 1.0f,%0A
@@ -1140,10 +1140,10 @@
 1.0f
- 
 ,
+ 
 -1.0
@@ -1163,16 +1163,17 @@
   -1.0f,
+ 
 -1.0f%0A  
@@ -1326,16 +1326,126 @@
     %7D;%0A%0A
+%0A    private final FloatBuffer mVerticesFloatBuffer;%0A    private static final int FLOAT_SZ = Float.SIZE / 8;%0A%0A
     /**%0A
@@ -1471,24 +1471,31 @@
 nal texture%0A
+     *%0A
      * @retu
@@ -1516,16 +1516,265 @@
      */%0A
+%0A    public SbDrawer() %7B%0A        mVerticesFloatBuffer = ByteBuffer.allocateDirect(8 * FLOAT_SZ)%0A                .order(ByteOrder.nativeOrder()).asFloatBuffer();%0A        mVerticesFloatBuffer.put(VERTICES);%0A        mVerticesFloatBuffer.flip();%0A    %7D%0A%0A
     publ

add vertex buffer