3. 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.
34. 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
35. 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
37. 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,
46. 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;
}
47. 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
48. 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;
}
79. 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.
81. • 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