OpenGL ES 3.1 

on Android
non-OpenGL part
Terms
OpenGL Family
• OpenGL

• A very common GPU accelerated Graphics Library for most desktop environment, such as in
Windows, Mac, and Linux.

• OpenGL ES

• OpenGL for Embedded Systems, a refined subset of OpenGL for embedded environment, such as
in iOS, Android, BlackBerry, bada, Linux, Windows, and Raspberry Pi, .

• OpenGL ES 1.1 / 2.0 / 3.0 / 3.1 / 3.2

• Different in API and functionality. The newer the more powerful.

• WebGL

• OpenGL ES 2.0 in Browser

• Vulkan

• Newer, Cooler, and thiner version of OpenGL / ES.
Non-OpenGL Part
https://github.com/aosp-mirror/platform_frameworks_base/blob/master/core/java/com/android/internal/policy/PhoneWindow.java
SurfaceView
View
sub class
TextView ImageView ViewGroup
(Standard OOP technique 

for tree structure)
Activity
has a
PhoneWindow

(Android-specific Window)
DecorView

(top-level view of the window)
has a
ViewGroup

(window contents are placed)
has a
has * View
View
View

Surface
(raw buffer for display)
has a
SurfaceView
GLSurfaceViewVideoView
sub class
bridged to
OpenGL ES
draw on ?
GLSurfaceView Handy and usual way.
SurfaceView For experienced.
TextureView Skip.
SurfaceTexture Skip.
Other way with OpenGL
GLSurfaceView / Renderer
GLSurfaceView GLSurfaceView.Renderer
draw on
has a /
notify change
Surface
(raw buffer for display)
has a
Minimal Example for
GLSurfaceView
Activity
https://developer.android.com/training/graphics/opengl/environment
GLSurfaceView
https://developer.android.com/training/graphics/opengl/environment
GLSurfaceView.Renderer
Manifest
https://developer.android.com/training/graphics/opengl/environment
OpenGL ES 3.1 need API 21+
use OpenGL ES 3.1
also compressed textures
_
Available in all
OpenGL ES 3.1 Devices
"GL_COMPRESSED_RGB8_ETC2_texture"
gl31.h
use OpenGL ES 3.X
Renderer base clase
Optional Property
Run > Run 'app'
color(0.2, 0.3, 0.4)
EGL 1.4
OpenGL ES 3.1
because of using host GPU in emulator, ignore
Graphics Part
Rasterization
https://commons.wikimedia.org/wiki/File:Rasterisation-triangle_example.svg
Depth
Texture
https://www.pexels.com/photo/bark-nature-texture-trees-819672/
Blender Projection Painting tutorial

https://vimeo.com/5093588
OpenGL Part
EGL 1.4
OpenGL ES 1.1
OpenGL ES 2.0
OpenGL ES 3.0
OpenGL ES 3.1
Draw on SurfaceInteract with Android Window system
Query GL capacities.
Manage framebuffer / Surface creation
API
eglCreateContext()

eglMakeCurrent()

eglSwapBuffers()

eglGetDisplay()

eglCreateWindowSurface()

eglCreatePbufferSurface()
glFinish()

glGenBuffers()

glBindBuffer()

glCreateShader(()

glBindTexture()

glTexImage2D()
glClear()

glDrawArrays()

glDrawElements()
No shader
texture unit
framebuffer
(for display)
pbuffer
(as texture)
textures
vertices /
indexes /
per vertex data
(like colors)
drawing commends
GPU
Simplified Diagram
vertex
shader
build
point /
line /
triangle
rasterization
fragment
shader
vertex shader
fragment shader
program
fragment pixel
shader special processor
texture bitmap
rasterization point/line/triangle to pixel
framebuffer a memory block for display
pbuffer like framebuffer but not for display
In Detail
OpenGL ES 3.0 Programming Guide
OpenGL ES 3.0 Programming Guide
Constants Texture access
output for one vertex
coordinates
for points only
input for one vertex
vertex shader
program runs here
transform matrix,
OpenGL ES 3.0 Programming Guide
OpenGL ES 3.0 Programming Guide
fragment shader
program runs here
input for one pixel
output for one pixel
Constants Texture access
Per fragment operations
OpenGL ES 3.0 Programming Guide
if this area in framebuffer
owned by OpenGL ES
https://www.khronos.org/registry/OpenGL/specs/es/3.1/es_spec_3.1.pdf
OpenGL ES 3.1 Spec
More Android
JNI/NDK
class AJava / Kotlin
C function definition
Java_com_example_blah_A_y()
{
......
}
namespace com.example.blah
load
C/C++
library x
Activity
external fun y(width: Int)method y
implemented by
extern "C" JNIEXPORT void JNICALL
Java_com_example_blah_A_y(
JNIEnv *env, jobject this, jint width)
{
.......
}
More on
OpenGL ES 3.1
glCreateProgram()
attached into
glCreateShader(GL_VERTEX_SHADER) glCreateShader(GL_FRAGMENT_SHADER)
vertex shader object
fragment shader
object
glShaderSource(vertex shader code)
glCompileShader()
glShaderSource(fragment shader code)
glCompileShader()
compiled shader
object
compiled shader
object
glLinkProgram()
program object
glValidateProgram()
done
linked program
#version 300 es
in vec2 p;
in vec4 color;
uniform mat2 matTransform;
out vec4 vColor;
void main()
{
vec2 p2 = matTransform * p;
gl_Position = vec4(p2.x, p2.y, 0.0, 1.0);
vColor = color;
}
#version 300 es
precision mediump float;
in vec4 vColor;
out vec4 outColor;
void main()
{
outColor = vColor;
}
Linked Program
Vertex Shader
gl_Position
Fragment Shader
primitive assembly /
clipping / culling /
rasterization / ....
rasterized
in a
in b
uniform u
frambuffer, etc
gl_PointSize
out x
out y
gl_FragCoord
gl_FrontFacing
gl_PointCoord
in x'
in y'
uniform q
uniform sampler2D s
gl_FragDepth
out color_0
out color_1
out color_2
out color_3
out color_N
out : Output colors are
by orders, no special
names here.
gl_xxx variables are
special names.
in/out : per vertex data
uniform : global data,
shared by all vertices
in : per fragment data
uniform sampler2D : a
texture map
uniform : global data,
shared by all fragments
Vertex Shader
gl_Position
in a
in b
uniform u
gl_PointSize
out x
out y
in/out : per vertex data
uniform : global data,
shared by all vertices
ID_a = glGetAttribLocation(program, "a")
glVertexAttribPointer(ID_a, .....,offsetof(..., adata))
glEnableVertexAttribArray(ID_a)
ID_u = glGetUniformLocation(program, "u")
glUniformMatrix2fv(ID_u, 1, false, udata);
#version 300 es
in vec2 a;
in vec4 b;
uniform mat2 u;
out vec4 x;
void main() {
vec2 p2 = u * a;
gl_Position = vec4(p2.x, p2.y, 0.0, 1.0);
x = b;
y = b;
}
Minimal Example for
GL ES 3.1
Auto-generated 

JNI Code
Currently....
Auto generated but
removed by us
function declaration
class MainActivity
native-lib.cpp
function body
(convention in color box)
libname
cpp files
Change into
Shader
Vertex Data
Draw
Misc
Result
ES 3.0 Features
Instancing (Vulkan)
PowerVR Rogue GPUs running Gnome Horde demo (Vulkan prototype)
Reference - Android
• PhoneWindow.java

• SurfaceView.java

• GLSurfaceView.java

• Build an OpenGL ES environment

• OpenGL ES

• SurfaceView and GLSurfaceView

• GLSurfaceView.Renderer

• Graphics architecture

• Android NDK Native APIs

• Activity View Window 

• Activity Window View 

• GLSurfaceView
Reference - Graphics
• Interactive Computer Graphics

• 	OpenGL ES 3.0 Programming Guide: Edition 2
FAQ
FAQ
• Q : So, where is the animation?

• A : For mostly graphics subsystem, images display frame
by frame. Since each frame differs slightly, we think it as
animation.
Memo
• Beginning in Android 4.0, hardware-accelerated Canvas is
enabled by default. Consequently, a hardware GPU that
supports OpenGL ES 2.0 is mandatory for Android 4.0
and later devices. 

• SurfaceFlinger is the only service that can modify the
content of the display
• Bandwidth optimization 

• Framebuffer invalidation

Open GL ES Android