2. Agenda
●
Introduction : Graphics terms
●
Graphics on GPU
●
OpenGL Android Graphics
●
Graphics Pipeline
●
Shaders
●
High Performance Compute on GPU
●
RenderScript
3. Graphics Terms
●
●
●
OpenGLES : Graphics API for doing 3D operations on GPU /
CPU
Primitives : lines, point, triangles
Texture : make the image
realistic by adding bitmap
4. CPU versus GPU
●
CPU
–
good at executing sequential code
–
●
Handles branches well
–
Same code, multiple data
GPU
–
Parallelism (ideal for image rendering)
10. GLSurfaceView.Renderer
●
The renderer is responsible for making OpenGL calls to
render a frame.
–
onDrawFrame() responsible for drawing the
current frame
–
OnSurfaceChanged() called when surface size
changes
–
OnSurfaceCreated() called when surface is
created
11. GLSurfaceView.Renderer
public class SquareRenderer implements GLSurfaceView.Renderer {
public void onSurfaceCreated(GL10 unused, EGLConfig config) {
Code when surface is created
}
public void onDrawFrame(GL10 unused) {
Code for drawing the frame ( Square )
}
public void onSurfaceChanged(GL10 unused, int width, int height) {
When surface is changed (rotated etc)
}
}
12. Drawing a Square
draw() {
float coords[] = { .... };
vertex 'buffer' created with the coords
glVertexPointer(buffer) :
}
glDrawArrays(TRIANGLE_STRIP ...);
,
16. Shader Programs
• Vertex Shader – operates on each vertex
• Fragment Shader – operates on each pixel
• Shaders are compiled and linked ( like any program )
• Executable is sent to the GPU
21. GPU for General Programs
●
Graphics is accelerated by the GPU
●
Can GPU accelerate other programs ?
–
●
e.g. Matrix multiply, encryption
OpenCL, CUDA, Renderscript are API
–
used for general purpose GPU
22. RenderScript
●
A high level API to access GPU
●
Provides high performance Compute
●
Provides uniform API across multiple SoC
●
Alternative is NDK (but NDK is platform
specific)
23. RenderScript – Use cases
●
What functions can be accelerated
–
Graphics
–
Image Processing
–
Encryption
–
Signal processing
–
Mathematical functions
27. RenderScript
●
●
Advantages : Compared to NDK, provides an easy device
agnostic way to accelerate performance on GPU
Disadvantages : C99 standard, debugging is restricted
28. Renderscipt - Summary
●
Renderscript is an API to access GPU
●
Used for High Performance
●
High Performance Compute / Graphics
●
Compute, Math , FFT, convolution, Signal processing
●
Support Graphics – but not a replacement for OpenGL
●
Works on all GPUs ( if supported by SoC ) otherwise on CPU
●
●