Transcript PPTX - Intel Software Academic Program
Lecture 8 - OpenGL on Android
This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
OpenGL ES
Cut down version of OpenGL Fixed point support Found in many mobile platforms (Android, iOS, Blackberry, Symbian, 3DS, etc.) Designed for slower GPUs and CPUs Laura Gheorghe, Petre Eftime 2
Version 1.x
OpenGL ES 1.0 based on OpenGL 1.3 and OpenGL ES 1.1 based on OpenGL 1.5
Common and Common-Lite (only fixed point) profile Fixed-function rendering pipeline Reduced features: no quad and polygon primitives, no stippling, only multisample AA, reduced drawing modes, no display lists, etc.
OpenGL ES 1.1 adds better multitexture support, VBOs, clip planes, mipmap generation Android 1.0 and higher Laura Gheorghe, Petre Eftime 3
Version 2.0
Based on OpenGL 2.0, but reduced fixed-function pipeline support Not compatible with OpenGL ES 1.x
OpenGL ES Shading Language ESSL only has forward branches and fixed iteration loops Transforming and Lighting functions replaced by shaders Better performance than OpenGL ES 1.x in many cases Android 2.2 and higher Laura Gheorghe, Petre Eftime 4
Version 3.0
Compatible with OpenGL ES 2.0 and OpenGL 4.3
Standardized texture compression Better texturing support New Shading Language version with full support for integer and floating point Improved flow control Easier portability Android 4.3 and higher Laura Gheorghe, Petre Eftime 5
GL Surface
Manages a surface (a region of memory which can be displayed on screen) Manages an EGL display (an OpenGL rendering context) Dedicated rendering thread Can provide debug information Laura Gheorghe, Petre Eftime 6
EGL
Virtual display which contains a rendering context 2D and 3D rendering Allows having multiple smaller surfaces on the actual screen or drawing to offscreen buffer Used by SurfaceFlinger and other compositors (Wayland, Mir) or libraries (SDL) Laura Gheorghe, Petre Eftime 7
Demo
Create GL2JNIView and set it as a view for the activity Constructor initializes the view private void init(boolean translucent, int depth, int stencil) { setEGLContextFactory(new ContextFactory()); setEGLConfigChooser( translucent ?
new ConfigChooser(8, 8, 8, 8, depth, stencil) : new ConfigChooser(5, 6, 5, 0, depth, stencil) ); setRenderer(new Renderer()); } Laura Gheorghe, Petre Eftime 8
}
Demo
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) { /* Get the number of minimally matching EGL configurations */ int[] num_config = new int[1]; egl.eglChooseConfig(display, s_configAttribs2, null, 0, num_config); int numConfigs = num_config[0]; /* Allocate then read the array of minimally matching EGL configs */ EGLConfig[] configs = new EGLConfig[numConfigs]; egl.eglChooseConfig(display, s_configAttribs2, configs, numConfigs, num_config); /* Now return the "best" one (matches rgba specifications) */ return chooseConfig(egl, display, configs); Laura Gheorghe, Petre Eftime 9
Demo
private static class Renderer implements GLSurfaceView.Renderer { public void onDrawFrame(GL10 gl) { GL2JNILib.step(); } public void onSurfaceChanged(GL10 gl, int width, int height) { GL2JNILib.init(width, height); } public void onSurfaceCreated(GL10 gl, EGLConfig config) { // Do nothing.
} } Laura Gheorghe, Petre Eftime 10
Demo
setupGraphics Compiles vertex and pixel shaders into a program Defines Uniforms, Attributes, etc.
Sets initial camera position and viewport Laura Gheorghe, Petre Eftime 11
Demo
renderFrame Updates camera Sets shader program Sets Uniforms and Attributes for current frame Draws triangles Laura Gheorghe, Petre Eftime 12
Android Tools for Debugging and Profiling
Logging Debugging Developer Options: Overdraw, Clipping Profiling Developer Options: Performance metrics on screen or through ADB, Traces Tracer for OpenGL ES: Visualize traces Laura Gheorghe, Petre Eftime 13
Intel GPA
Intel Atom processors More information: GPU, CPU, Battery usage More detailed analysis Identifies possible bottlenecks Realtime Works over Wifi Laura Gheorghe, Petre Eftime 14
Vendor specific tools
Low level information Different interface and capabilities for each vendor Optimizations not always portable PowerVR, Tegra, Adreno, etc.
Laura Gheorghe, Petre Eftime 15
Bibliography
https://www.khronos.org/opengles/ http://developer.android.com/guide/topics/graphics/ope ngl.html
http://developer.android.com/training/graphics/opengl/i ndex.html
Laura Gheorghe, Petre Eftime 16
Keywords
OpenGL EGL Fixed function pipeline Shaders GLSurfaceView Profiling Tracer Laura Gheorghe, Petre Eftime 17