OpenGL ES 2.0: Go Mobile

Presented by Dan Ginsburg, Staff Engineer Agenda

 OpenGL ES  Overview and History  OpenGL ES 2.0  Shaders Overview  What’s changed in GLSL?  What’s changed from OpenGL 2.0?  Writing OpenGL ES 2.0 Games OpenGL ES: Overview and History What is OpenGL ES?

 OpenGL-based API for embedded systems  Removed redundant and expensive functionality  Kept as compatible with OpenGL as possible  Added features needed for embedded systems Who created OpenGL ES?

Over 100 companies creating media authoring and acceleration standards Why is OpenGL ES important?

 API of choice for 3D handheld games  OpenGL ES 2.0 is the path forward for 3D  Lean and clean  Allows for vendor-specific extensibility  Simplified driver implementation OpenGL ES History

 OpenGL ES 1.0  Basic 3D functionality  OpenGL ES 1.1+  Comprehensive set of fixed-function 3D  Backwards compatible  OpenGL ES 2.0  only  Not backwards compatible OpenGL ES 2.0: Shaders Overview OpenGL ES 2.0 Overview

 ES GLSL forms core of API  Shifts some burden to application  But puts more power in your hands  Convergence of desktop and handheld! OpenGL ES Pipeline

Vertex shaders replace Fixed Function Transform and Lighting Triangles/Lines/Points

Primitive TransformTransformVertex Primitive ProcessingPrimitive Vertices ShaderVertexandand AssemblyPrimitive RasterizerRasterizer Processing LightingLightingShader Assembly APIAPI

VertexVertex BufferBuffer ObjectsObjects TextureTexture FragmentFragmentColourColour Fog EnvironmentEnvironment ShaderShaderSumSum Fog Fragment shaders replace Fixed Function Texture, Color and Fog

Alpha Depth ColourColour TestAlpha StencilDepth BufferBuffer DitherDither FrameFrame Buffer Buffer Test Stencil BlendBlend OpenGL ES 2.0 – Vertex Shader

UniformsUniforms TexturesTextures

AttributeAttribute 0 0 VaryingVarying 0 0 AttributeAttribute 1 1 VaryingVarying 1 1 AttributeAttribute 2 2 VaryingVarying 2 2 AttributeAttribute 3 3 VaryingVarying 3 3 VertexVertex Shader Shader AttributeAttribute 4 4 VaryingVarying 4 4 AttributeAttribute 5 5 VaryingVarying 5 5 AttributeAttribute 6 6 VaryingVarying 6 6 AttributeAttribute 7 7 VaryingVarying 7 7

gl_Positiongl_Position gl_FrontFacinggl_PointSize OpenGL ES 2.0 – Example Vertex Shader

attribute vec4 Vertex; attribute vec2 VertexSt; uniform mat4 Transform; varying vec2 TexCoord; invariant gl_Position; void main() { gl_Position = Transform * Vertex; TexCoord = VertexSt; } OpenGL ES 2.0 – Fragment Shader

UniformsUniforms TexturesTextures

VaryingVarying 0 0 VaryingVarying 1 1 VaryingVarying 2 2 VaryingVarying 3 3 VaryingVarying 4 4 gl_FragColor FragmentFragment Shader Shader gl_FragColor VaryingVarying 5 5 VaryingVarying 6 6 VaryingVarying 7 7

gl_FrontFacinggl_FrontFacing gl_FragCoordgl_Position gl_PointCoord OpenGL ES 2.0 – Example Fragment Shader

uniform sampler2D Sampler; varying vec2 TexCoord; void main() { vec4 color = texture2D(Sampler, TexCoord); color *= 0.5; gl_FragColor = color; } OpenGL ES 2.0: What’s changed in GLSL? OpenGL ES 2.0 – GLSL Changes

 Binary Shaders  Allows for off-line shader compiler  Vendor-specific opaque format  Optional: on-line vs. off-line compiler

 Removed multiple vertex / fragment shaders

 Load a binary shader pair OpenGL ES 2.0 – GLSL Changes (continued)

 All built-in attribute variables removed  gl_Vertex, gl_Normal, etc.  Generic vertex attributes only

 All built-in varying variables removed  One new varying: gl_PointSize

 Most built-in uniform variables removed  Shifts burden to application OpenGL ES 2.0 – GLSL Changes (continued)

 Removed 1D and Shadow texture functions

 noise(), dFdx(), dFdy() optional

 ftransform() is removed  Replaced with invariance qualifier OpenGL ES 2.0 – GLSL Changes (continued)

 Precision qualifiers added  Low, medium, high  Vertex shader default: high float  Fragment shader default: none

 Fewer attributes (8) and uniforms (384)

 User-clipping removed OpenGL ES 2.0: What’s changed from OpenGL 2.0? OpenGL ES 2.0 – What’s new?

 Vertex and attribute data formats  Fixed (16.16)  Half float (optional)

 Compressed texture formats  Ericsson (ETC)

 Floating-point textures  16-bit and 32-bit OpenGL ES 2.0 – What’s new? (continued)

 Objects  Simplified version of EXT_framebuffer_object

 Shader precision query  glGetShaderPrecisionFormatOES

 Binary shaders  glShaderBinaryOES OpenGL ES 2.0 – What’s Gone?

 Enable/Disable(MULTISAMPLE)

 Anti-aliased lines

 Points and anti-aliased points  Only point sprites supported

 Coordinate transforms & matrix stack

 Occlusion queries OpenGL ES 2.0 – What’s Optional?

 MapBuffer/UnmapBuffer

 3D textures

 Non-power of 2 textures

 FP16 vertex attribute data

 FP16 and FP32 textures OpenGL ES 2.0: Writing OpenGL ES 2.0 Games Fixed-Function is Gone

 Your game engine must now manage:  Matrices: modelview, projection, etc.  Setup of frustum projection  Storage of constants:  Light properties  Fog properties  Etc. Managing constants

 One option: implement a fixed-function wrapper  Another option: create a custom solution  This is what ATI does in our new demo engine  Other such as D3D10 are removing fixed-function too Lighting

 All lighting computations and properties must be shader-based  Implement the GL or custom lighting equations  Great place to start:  ShaderGen – shows you how to generate GLSL shaders from any fixed-function state!  developer.3dlabs.com/downloads/shadergen/ Effect file formats

 Need a file format with more than just shaders  Render state  Material properties  Techniques and render passes  Constant bindings  Vertex attribute bindings  Texture information Effect File Solutions

 COLLADA FX  Extensible file format supporting multiple APIs  Custom solution  ATI demo team developed its own effect file format  Similar to D3D .FX, but cross-API friendly Developing shaders

 Use the tools that are out there:  RenderMonkey provides GLSL support  OpenGL ES 2.0 support is planned  Various other shader tools available Summary

 OpenGL ES overview and history  OpenGL ES 2.0 technical details  How to develop OpenGL ES 2.0 games Conclusions

 Convergence of desktop and handheld  Design shaders into your engine  Implement fixed-functionality you need  Leverage existing solutions Where to get more info

 www.khronos.org  OpenGL ES 2.0 and ES specs  Extensive of presentations  The latest OpenGL ES news Questions?