opengl on androidelf.cs.pub.ro/ndk/wiki/_media/lecture-7.pdf · i not compatible with opengl es 1.x...
TRANSCRIPT
OpenGL on AndroidLecture 7
Android and Low-level Optimizations Summer School
27 July 2015
This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of thislicense, visit http://creativecommons.org/licenses/by/4.0/.
OpenGL on Android, Lecture 7 1/26
OpenGL ES
OpenGL ES on Android
Demo
Debugging and Profiling
Bibliography
Keywords
OpenGL on Android, Lecture 7 2/26
Outline
OpenGL ES
OpenGL ES on Android
Demo
Debugging and Profiling
Bibliography
Keywords
OpenGL on Android, Lecture 7 3/26
OpenGL ES
I Cut down version of OpenGL
I Fixed point support
I Found in many mobile platforms (Android, iOS, Blackberry,Symbian, 3DS, etc.)
I Designed for slower GPUs and CPUs
I Disclaimer: Learning OpenGL is outside the scope of thiscourse
OpenGL on Android, Lecture 7 4/26
Version 1.x
I OpenGL ES 1.0 based on OpenGL 1.3 and OpenGL ES 1.1based on OpenGL 1.5
I Common and Common-Lite (only fixed point) profile
I Fixed-function rendering pipeline
I Reduced features: no quad and polygon primitives, nostippling, only multisample AA, reduced drawing modes, nodisplay lists, etc.
I OpenGL ES 1.1 adds better multitexture support, VBOs, clipplanes, mipmap generation
I Android 1.0 and higher
OpenGL on Android, Lecture 7 5/26
Version 2.0
I Based on OpenGL 2.0, but reduced fixed-function pipelinesupport
I Not compatible with OpenGL ES 1.x
I OpenGL ES Shading Language
I ESSL only has forward branches and fixed iteration loops
I Transforming and Lighting functions replaced by shaders
I Better performance than OpenGL ES 1.x in many cases
I Android 2.2 and higher
OpenGL on Android, Lecture 7 6/26
Version 3.0
I Compatible with OpenGL ES 2.0 and OpenGL 4.3
I Standardized texture compression
I Better texturing support
I New Shading Language version with full support for integerand floating point
I Improved flow control
I Easier portability
I Android 4.3 and higher
OpenGL on Android, Lecture 7 7/26
Version 3.1
I Compatible with OpenGL ES 2.0 and 3.0
I Compute shaders
I Easier to combine shaders
I Shading language improvements
I Enhanced texturing
I Indirect draw commands
I Android 5.0 and higher
OpenGL on Android, Lecture 7 8/26
Outline
OpenGL ES
OpenGL ES on Android
Demo
Debugging and Profiling
Bibliography
Keywords
OpenGL on Android, Lecture 7 9/26
GL Surface
I Manages a surface (a region of memory which can bedisplayed on screen)
I Manages an EGL display (an OpenGL rendering context)
I Dedicated rendering thread
I Can provide debug information
OpenGL on Android, Lecture 7 10/26
EGL
I Virtual display which contains a rendering context
I 2D and 3D rendering
I Allows having multiple smaller surfaces on the actual screen ordrawing to offscreen buffer
I Used by SurfaceFlinger and other compositors (Wayland, Mir)or libraries (SDL)
OpenGL on Android, Lecture 7 11/26
Outline
OpenGL ES
OpenGL ES on Android
Demo
Debugging and Profiling
Bibliography
Keywords
OpenGL on Android, Lecture 7 12/26
Demo
I Turn on OpenGL in AndroidManifest.xml
I Create GL2JNIView and set it as a view for the activity
I Constructor initializes the view
p r i v a t e vo id i n i t ( boolean t r a n s l u c e n t , i n t depth , i n t s t e n c i l ) {
se tEGLContextFacto ry (new Contex tFac to r y ( ) ) ;
se tEGLConf igChoose r ( t r a n s l u c e n t ?new Conf i gChoose r (8 , 8 , 8 , 8 ,
depth , s t e n c i l ) :new Conf i gChoose r (5 , 6 , 5 , 0 ,
depth , s t e n c i l ) ) ;
s e tRend e r e r (new Rendere r ( ) ) ;}
OpenGL on Android, Lecture 7 13/26
Demo
pub l i c EGLConfig chooseCon f i g (EGL10 eg l , EGLDisplay d i s p l a y ) {/∗ Get the number o f m i n ima l l y matching EGL c o n f i g u r a t i o n s ∗/i n t [ ] num conf ig = new i n t [ 1 ] ;e g l . e g lChoo s eCon f i g ( d i s p l a y , s c o n f i g A t t r i b s 2 , nu l l ,
0 , num conf ig ) ;
i n t numConfigs = num conf ig [ 0 ] ;/∗ A l l o c a t e then read the a r r a y o f m in ima l l y
matching EGL c o n f i g s ∗/EGLConfig [ ] c o n f i g s = new EGLConfig [ numConfigs ] ;e g l . e g lChoo s eCon f i g ( d i s p l a y , s c o n f i g A t t r i b s 2 , c o n f i g s ,
numConfigs , num conf ig ) ;
/∗ Now r e t u r n the ” be s t ” one ( matches rgba s p e c i f i c a t i o n s ) ∗/r e t u r n chooseCon f i g ( eg l , d i s p l a y , c o n f i g s ) ;
}
OpenGL on Android, Lecture 7 14/26
Demo
p r i v a t e s t a t i c c l a s s Rendere r implements GLSurfaceView . Rendere r {pub l i c vo id onDrawFrame (GL10 g l ) {
GL2JNILib . s t e p ( ) ;}
pub l i c vo id onSurfaceChanged (GL10 g l , i n t width , i n t h e i g h t ) {GL2JNILib . i n i t ( width , h e i g h t ) ;
}
pub l i c vo id onSu r f a c eC rea t ed (GL10 g l , EGLConfig c o n f i g ) {// Do noth i ng .
}}
OpenGL on Android, Lecture 7 15/26
Demo
I setupGraphicsI Compiles vertex and pixel shaders into a programI Defines Uniforms, Attributes, etc.I Sets initial camera position and viewport
OpenGL on Android, Lecture 7 16/26
Demo
I renderFrameI Updates cameraI Sets shader programI Sets Uniforms and Attributes for current frameI Draws triangles
OpenGL on Android, Lecture 7 17/26
Outline
OpenGL ES
OpenGL ES on Android
Demo
Debugging and Profiling
Bibliography
Keywords
OpenGL on Android, Lecture 7 18/26
Android tools
I Logging
I Debugging Developer Options: Overdraw, Clipping
I Profiling Developer Options: Performance metrics on screenor through ADB, Traces
I Tracer for OpenGL ES: Visualize traces
OpenGL on Android, Lecture 7 19/26
Tracer for OpenGL ES
OpenGL on Android, Lecture 7 20/26
Intel GPA
I Intel Atom processors
I More information: GPU, CPU, Battery usage
I More detailed analysis
I Identifies possible bottlenecks
I Realtime
I Works over Wifi
OpenGL on Android, Lecture 7 21/26
Vendor specific tools
I Low level information
I Different interface and capabilities for each vendor
I Optimizations not always portable
I PowerVR, Tegra, Adreno, etc.
OpenGL on Android, Lecture 7 22/26
Outline
OpenGL ES
OpenGL ES on Android
Demo
Debugging and Profiling
Bibliography
Keywords
OpenGL on Android, Lecture 7 23/26
Bibliography
I https://www.khronos.org/opengles/
I http://developer.android.com/guide/topics/
graphics/opengl.html
I http://developer.android.com/training/graphics/
opengl/index.html
OpenGL on Android, Lecture 7 24/26
Outline
OpenGL ES
OpenGL ES on Android
Demo
Debugging and Profiling
Bibliography
Keywords
OpenGL on Android, Lecture 7 25/26
Keywords
I OpenGL
I EGL
I Fixed function pipeline
I Shaders
I GLSurfaceView
I Profiling
I Tracer
OpenGL on Android, Lecture 7 26/26