Opengl and EGL
Total Page:16
File Type:pdf, Size:1020Kb
2014, 13th Kandroid minmax GPU, Graphics and Networking OpenGL and EGL SK플래닛/모바일 플랫폼 개발팀 남정수 ([email protected]) http://www.linkedin.com/in/yegam400 목 차 OpenGL • What is OpenGL • OpenGL ES 2.0 Rendering Pipeline • GLSL(OpenGL Shading Language) • Android GLSL Usages EGL • OpenGL Utility Libraries • EGL Overview • EGL Operations • EGL Usages • Android GLSurfaceView OpenGL : What is OpenGL • OpenGL – OpenGL (Open Graphics Library)[2] is a cross-language, multi-platform application programming interface ( API) for rendering 2D and 3D vector graphics. The API is typically used to interact with a Graphics processin g unit (GPU), to achieve hardware-accelerated rendering. – OpenGL was developed by Silicon Graphics Inc. (SGI) from 1991 and released in January 1992[3] and is wid ely used in CAD, virtual reality, scientific visualization, information visualization, flight simulation, and video g ames. OpenGL is managed by the non-profit technology consortium Khronos Group. • OpenGL ES – OpenGL for Embedded Systems (OpenGL ES or GLES) is a subset of the OpenGL – It is designed for embedded systems like smartphones, computer tablets, video game consoles and PDAs. • OpenGL development – In addition to the features required by the core API, GPU vendors may provide additional functionality in the f orm of extensions. Extensions may introduce new functions and new constants, and may relax or remove re strictions on existing OpenGL functions. Vendors can use extensions to expose custom APIs without needin g support from other vendors or the Khronos Group as a whole, which greatly increases the flexibility of Ope nGL. All extensions are collected in, and defined by, the OpenGL Registry. 2014, 13th Kandroid minmax - www.kandroid.org 3 OpenGL : OpenGL ES 2.0 Rendering Pipeline • Fixed Function Pipeline removed at ES2.0 2014, 13th Kandroid minmax - www.kandroid.org 4 OpenGL : Shading and Shaders • Shading – Shading refers to depicting depth perception in 3D models or illustrations by varying levels of darkness. – In computer graphics, shading refers to the process of altering the color of an object/surface/ polygon in the 3D scene, based on its angle to lights and its distance from lights to create a p hotorealistic effect. Shading is performed during the rendering process by a program called a shader. 2014, 13th Kandroid minmax - www.kandroid.org 5 OpenGL : Transform and Lighting emissive = Ke ambient = Ka x globalAmbient diffuse = Kd x lightColor x max(N · L, 0) specular = Ks x lightColor x facing x (max(N · H, 0)) s hininess surfaceColor = emissive + ambient + diffuse + specular 2014, 13th Kandroid minmax - www.kandroid.org 6 OpenGL : Rasterization & Raster Operations(ROP) 2014, 13th Kandroid minmax - www.kandroid.org 7 OpenGL : What is GLSL • GLSL – OpenGL Shading Language (abbreviated: GLSL or GLslang), is a high-level shading langu age based on the syntax of the C programming language. It was created by the OpenGL AR B (OpenGL Architecture Review Board) to give developers more direct control of the graphic s pipeline without having to use ARB assembly language or hardware-specific languages. – Supports OpenGL ES(Android, iOS, and etc.) 2014, 13th Kandroid minmax - www.kandroid.org 8 OpenGL : GLSL – Simple Example ftransform() is used for fixed function pipeline. 2014, 13th Kandroid minmax - www.kandroid.org 9 OpenGL : GLSL keywords – attribute, uniform, varying • (Vertex) Attribute – Vertex attributes are used to communicate from outside to the vertex shader. • Unlike uniform variables, values are provided per vertex (and not globally for all vertices). • There are built-in vertex attributes like the normal or the position, or you can specify your own vertex at tribute like a tangent or another custom value. • Attributes can't be defined in the fragment shader. • Uniform – Uniform variables are used to communicate with your vertex or fragment shader from "outsid e". In your shader you use the uniform qualifier to declare the variable • Uniform variables are read-only and have the same value among all processed vertices. You can only change them within your C++ program. • Varying – Varying variables provide an interface between Vertex and Fragment Shader. • Vertex Shaders compute values per vertex and fragment shaders compute values per fragment. • If you define a varying variable in a vertex shader, its value will be interpolated (perspective-correct) ov er the primitive being rendered and you can access the interpolated value in the fragment shader. 2014, 13th Kandroid minmax - www.kandroid.org 10 OpenGL : GLSL - Build-in Variables(1/2) 2014, 13th Kandroid minmax - www.kandroid.org 11 OpenGL : GLSL - Build-in Variables(2/2) 2014, 13th Kandroid minmax - www.kandroid.org 12 OpenGL : GLSL APIs • GLSL flow APIs – Loading Shader • glCreateShaderObject() • glShaderSource() – Compiling Shader • glCompileShader() – Linking • glCreateProgramObject() • glAttachObject() • glLinkProgram() – Using Shaders • glUseProgramObject() • GLSL communication APIs – Attribute • glGetAttribLocation() • glEnableVertexAttribArray() • glVertexAttribPointer() – Uniform • glGetUniformLocation() • glUniform() 2014, 13th Kandroid minmax - www.kandroid.org 13 OpenGL : GLSL Vertex Shader Example – Directional Lighting 2014, 13th Kandroid minmax - www.kandroid.org 14 OpenGL : GLSL Fragment Shader Example – Per Pixel Directional Lighting http://www.lighthouse3d.com/tutorials/glsl-tutorial/directional-light-per-pixel/ 2014, 13th Kandroid minmax - www.kandroid.org 15 OpenGL : GLSL Fragment Shader Example – YUV to RGB Conversion http://helloworld.naver.com/helloworld/1207 2014, 13th Kandroid minmax - www.kandroid.org 16 OpenGL : GLSL Fragment Shader Example – Image Filter(Box Blur) 2014, 13th Kandroid minmax - www.kandroid.org 17 OpenGL : Android GLSL Usages(1/4) - Initializing 2014, 13th Kandroid minmax - www.kandroid.org 18 OpenGL : Android GLSL Usages(2/4) - Shaders 2014, 13th Kandroid minmax - www.kandroid.org 19 OpenGL : Android GLSL Usages(3/4) – Rendering environment setup 2014, 13th Kandroid minmax - www.kandroid.org 20 OpenGL : Android GLSL Usages(4/4) – Rendering a mesh 2014, 13th Kandroid minmax - www.kandroid.org 21 목 차 OpenGL • What is OpenGL • OpenGL ES 2.0 Rendering Pipeline • GLSL(OpenGL Shading Language) • Android GLSL Usages EGL • OpenGL Utility Libraries • EGL Overview • EGL Operations • EGL Usages • Android GLSurfaceView EGL : OpenGL ARB and Khronos Group • OpenGL ES – OpenGL ES is a lightweight graphics API which is designed for Embedded System from Ope nGL which is designed for Work Station. – OpenGL is maintained by OpenGL ARB(Architecture Review Board), OpenGL ES is maintained Khronos Group. 2014, 13th Kandroid minmax - www.kandroid.org 23 EGL : OpenGL Utility Libraries Prefix Name Functions gl OpenGL API glClear,glDrawArrays,… glu OpenGL Utility Library gluPerspective,gluLookAt glut OpenGL Utility Toolkit glutInitDisplayMode,glutSwapBuffers aux OpenGL Auxiliary Library auxDIBImageLoad,auxInitWindow glew OpenGL Extension Wrangler Library glewInit, glewIsSupported wgl/agl/cgl/glx/egl Native Interface for OpenGL wglCreateContext,wglMakeCurrent,e glCreateContext,eglMakeCurrent 2014, 13th Kandroid minmax - www.kandroid.org 24 EGL : WGL • OpenGL Native Interface for Windows – WGL or Wiggle is an API between OpenGL and the windowing system interface of Microsoft Windows. • http://nehe.gamedev.net/tutorial/creating_an_opengl_window_(win32)/13001/ ChoosePixelFormat() SetPixelFormat() wglCreateContext() wglMakeCurrent() 2014, 13th Kandroid minmax - www.kandroid.org 25 EGL : EGL Overview • Native Platform Interface – EGL™ is an interface between Khronos rendering APIs such as OpenGL ES or OpenVG and the underlying native platform window system. It handles graphics context management, surf ace/buffer binding, and rendering synchronization and enables high-performance, accelerate d, mixed-mode 2D and 3D rendering using other Khronos APIs. EGL also provides interop ca pability between Khronos to enable efficient transfer of data between APIs – for example bet ween a video subsystem running OpenMAX AL and a GPU running OpenGL ES. • Portable Layer for Graphics Resource Management – EGL can be implemented on multiple operating systems (such as Android and Linux) and native window systems (such as X and Microsoft Windows). Implementations may also choose to allow rendering into specific types of EGL surfaces via other supported native rendering APIs, such as Xlib or GDI. EGL provides: • Mechanisms for creating rendering surfaces (windows, pbuffers, pixmaps) onto which client APIs can d raw and share • Methods to create and manage graphics contexts for client APIs • Ways to synchronize drawing by client APIs as well as native platform rendering APIs 2014, 13th Kandroid minmax - www.kandroid.org 26 EGL : EGL Features • Specifically EGL is a wrapper over the following subsystems; – WGL: Windows GL-the Windows-OpenGL interface (pronounced wiggle) – CGL: the Mac OS X-OpenGL interface (the AGL layer sits on top of CGL) – GLX: the equivalent X11-OpenGL interface • EGL not only provides a convenient binding between the operating system resources and the OpenGL subsystem, but also provides the hooks to the operating system to i nform it when you require something, such as; 1. Iterating, selecting, and initializing an OpenGL context. 2. This can be the OGL API level, software vs. hardware rendering, etc. 3. Requesting a surface or memory resource. 4. The OS services requests for system or video memory. 5. Iterating through the available surface formats (to pick an optimal