introduction to TextureView + OpenGL ES

introduction to TextureView + OpenGL ES

6dd0483f1353a4a359e92633cfd65c64?s=128

Daichi Furiya (Wasabeef)

November 06, 2015
Tweet

Transcript

  1. TextureView OpenGL ES Wasabeef

  2. About Me @wasabeef_jp AbemaTV, Inc. (CyberAgent, Inc.)

  3. What would you like to do?

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

    Unreal Engine, Cocos2d-x) ・Filter (Camera, Image, Movie)
  5. OpenGL ES by Khronos Group

  6. OpenGL ES “Android includes support for high performance 2D and

    3D graphics with the Open Graphics Library (OpenGL®), specifically, the OpenGL ES API.”
  7. 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+
  8. Vulkan by Khronos Group

  9. Vulkan

  10. Surface

  11. SurfaceView

  12. SurfaceHolder

  13. SurfaceHolder public class MySurfaceView extends SurfaceView { public MySurfaceView(Context context)

    { super(context); SurfaceHolder holder = this.getHolder(); } }
  14. 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) { /***/ } }
  15. GLSurfaceView

  16. TextureView

  17. SurfaceTexture

  18. SurfaceTextureListener

  19. 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) { /***/ }
 }
  20. GLTextureView http://bit.ly/1RAnLrw

  21. Shader

  22. Shader public static final String SAMPLE_SHADER = "" + "void

    main()\n" + "{\n" + " gl_FragColor =vec4(1.0, 0.0, 0.0, 1.0)\n” + "}";
  23. 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" + "}";
  24. 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; }
  25. Summary ・OpenGL ES2 (API level 8+) ・TextureView (API level 14+)

    ・SurfaceTexture ・SurfaceTextureListener ・GLTextureView (Custom) ・Shader (GLSL)
  26. Thanks.