Upgrade to Pro — share decks privately, control downloads, hide ads and more …

introduction to TextureView + OpenGL ES

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on. →

introduction to TextureView + OpenGL ES

Daichi Furiya (Wasabeef)

November 06, 2015

Transcript

26 slides
  1. What would you like to do? ・3D Graphics  Game (Unity,

    Unreal Engine, Cocos2d-x) ・Filter (Camera, Image, Movie)
  2. OpenGL ES “Android includes support for high performance 2D and

    3D graphics with the Open Graphics Library (OpenGL®), specifically, the OpenGL ES API.”
  3. OpenGL ES ・OpenGL ES 1.0/1.1 - API level 1+ ・OpenGL

    ES 2.0 - API level 8+ ・OpenGL ES 3.0 - API level 18+ ・OpenGL ES 3.1 - API level 21+
  4. SurfaceHolder.Callback public class MySurfaceView extends SurfaceView implements SurfaceHolder.Callback { public

    MySurfaceView(Context context) { super(context); getHolder().addCallback(this); } @Override public void surfaceCreated(SurfaceHolder arg0) { /***/ } @Override public void surfaceChanged( SurfaceHolder arg0, int arg1, int arg2, int arg3) { /***/ } @Override public void surfaceDestroyed(SurfaceHolder arg0) { /***/ } }
  5. SurfaceTextureListener private class MySurfaceTextureListener implements SurfaceTextureListener { @Override public void

    onSurfaceTextureAvailable( SurfaceTexture surface, int width, int height) { /***/ } @Override public void onSurfaceTextureSizeChanged( SurfaceTexture surface, int width, int height) { /***/ } @Override public boolean onSurfaceTextureDestroyed( SurfaceTexture surface) { /***/ } @Override public void onSurfaceTextureUpdated( SurfaceTexture surface) { /***/ }
 }
  6. Shader public static final String SAMPLE_SHADER = "" + "void

    main()\n" + "{\n" + " gl_FragColor =vec4(1.0, 0.0, 0.0, 1.0)\n” + "}";
  7. Shader public static final String COLOR_SHADER = "" + "varying

    highp vec2 textureCoordinate;\n" + "uniform sampler2D inputImageTexture;\n" + "uniform lowp mat4 colorMatrix;\n" + "uniform lowp float intensity;\n" + "void main()\n" + "{\n" + " lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" + " lowp vec4 outputColor = textureColor * colorMatrix;\n" + " gl_FragColor = (intensity * outputColor) + ((1.0 - intensity) * textureColor);\n" + "}";
  8. Shader private static int loadShader(int type, String src) { int

    shader = GLES20.glCreateShader(type); if (shader != 0) { GLES20.glShaderSource(shader, src); GLES20.glCompileShader(shader); int[] compiled = new int[1]; GLES20.glGetShaderiv( shader, GLES20.GL_COMPILE_STATUS, compiled, 0); if (compiled[0] == 0) { GLES20.glDeleteShader(shader); shader = 0; } } return shader; }
  9. Summary ・OpenGL ES2 (API level 8+) ・TextureView (API level 14+)

    ・SurfaceTexture ・SurfaceTextureListener ・GLTextureView (Custom) ・Shader (GLSL)

More Decks by Daichi Furiya (Wasabeef)

Other Decks in Programming