200 likes | 380 Views
Lecture 8 - OpenGL on Android. 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. Version 1.x.
E N D
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
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
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
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
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
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)
Demo private void init(boolean translucent, int depth, int stencil) { setEGLContextFactory(newContextFactory()); setEGLConfigChooser( translucent ? newConfigChooser(8, 8, 8, 8, depth, stencil) : newConfigChooser(5, 6, 5, 0, depth, stencil) ); setRenderer(new Renderer()); } Create GL2JNIView and set it as a view for the activity Constructor initializes the view
Demo publicEGLConfigchooseConfig(EGL10 egl, EGLDisplay display) { /* Get the number of minimally matching EGL configurations */ int[] num_config = newint[1]; egl.eglChooseConfig(display, s_configAttribs2, null, 0, num_config); intnumConfigs = num_config[0]; /* Allocate then read the array of minimally matching EGL configs */ EGLConfig[] configs = newEGLConfig[numConfigs]; egl.eglChooseConfig(display, s_configAttribs2, configs, numConfigs, num_config); /* Now return the "best" one (matches rgba specifications) */ returnchooseConfig(egl, display, configs); }
Demo private static class Renderer implementsGLSurfaceView.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, EGLConfigconfig) { // Do nothing. } }
Demo • setupGraphics • Compiles vertex and pixel shaders into a program • Defines Uniforms, Attributes, etc. • Sets initial camera position and viewport
Demo • renderFrame • Updates camera • Sets shader program • Sets Uniforms and Attributes for current frame • Draws triangles
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
Intel GPA Intel Atom processors More information: GPU, CPU, Battery usage More detailed analysis Identifies possible bottlenecks Realtime Works over Wifi
Vendor specific tools Low level information Different interface and capabilities for each vendor Optimizations not always portable PowerVR, Tegra, Adreno, etc.
Bibliography https://www.khronos.org/opengles/ http://developer.android.com/guide/topics/graphics/opengl.html http://developer.android.com/training/graphics/opengl/index.html
Keywords OpenGL EGL Fixed function pipeline Shaders GLSurfaceView Profiling Tracer