GLES Tutorial

download GLES Tutorial

of 48

  • date post

    27-Oct-2014
  • Category

    Documents

  • view

    971
  • download

    0

Embed Size (px)

Transcript of GLES Tutorial

OpenGL ES 1.1+ and ES 2.0

Presented by Aaftab Munshi

AgendaOpenGL ES 1.1 Specification OpenGL ES 1.1 Extension Pack OpenGL ES 2.0 Specification

OpenGL ES 1.1 - FeaturesBuffer Objects Texture Enhancements Matrix Palette User Clip Planes Point Sprites State Queries Draw Texture

Buffer ObjectsVertex ArraysUsed to render primitives in OpenGL ES 1.0 Vertex array data stored in client memory Need to allow vertex data to be cached in graphics memory

Vertex Buffer objectsAllow caching of vertex data Can be used to storevertex array and element index data

LimitationsVertex data cannot be read back Cannot map the vertex data into client memoryMapBuffer, UnmapBuffer

Using Buffer ObjectsVertex Array Examplevoid Draw_Arrays() { // Enable client states needed for our vertex format glEnableClientState( GL_VERTEX_ARRAY); glEnableClientState( GL_TEXTURE_COORD_ARRAY); glEnableClientState( GL_COLOR_ARRAY); // Set up glPointers glVertexPointer( 3, GL_SHORT, sizeof( tVertex), (void*) &my_vertex_data[0].x ); glTexCoordPointer( 2, GL_SHORT, sizeof( tVertex), (void*) &my_vertex_data[0].u ); glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof( tVertex), (void*) &my_vertex_data[0].color ); // Draw the vertex array as an indexed triangle list glDrawElements( GL_TRIANGLES, my_index_count, GL_UNSIGNED_SHORT, my_index_data ); }

Using Buffer ObjectsVertex Buffer Objects Examplevoid Draw_Buffers() { // Bind vertex + index buffers glBindBuffer( GL_ARRAY_BUFFER, vertex_buffer); glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, index_buffer); // Enable client states needed for our vertex format glEnableClientState( GL_VERTEX_ARRAY); glEnableClientState( GL_TEXTURE_COORD_ARRAY); glEnableClientState( GL_COLOR_ARRAY); // Set up glPointers glVertexPointer( 3, GL_SHORT, sizeof(tVertex), 0); glTexCoordPointer( 2, GL_SHORT, sizeof(tVertex), 8); glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof( tVertex), 12); // Draw the vertex buffer as an indexed triangle list glDrawElements( GL_TRIANGLES, my_index_count, GL_UNSIGNED_SHORT, 0, ); }

Texture EnhancementsMinimum of 2 texture units is required glTexImagesupports 2D textures only internal format must match format type used to indicate texel format

Addressing Modesrepeat, clamp to edge

Auto mip-map generation Texture CombineSupport following extensions as core featuresARB_texture_env_combineExtends combine functions by including support for ADD_SIGNED, SUBTRACT, and INTERPOLATE Application can program arguments passed in as inputs to combine units

ARB_texture_env_dot3Compute a per-pixel dot product Useful for per-pixel lighting & bump mapping

Texture CombineCOMBINE_RGB REPLACE MODULATE ADD ADD_SIGNED INTERPOLATE SUBTRACT DOT3_RGB Texture Function Arg0 Arg0 * Arg1 Arg0 + Arg1 Arg0 + Arg1 0.5 Arg0 * Arg2 + Arg1 * (1 Arg2) Arg0 Arg1 4 * ((Arg0r 0.5) * (Arg1 r 0.5) + (Arg0 g 0.5) * (Arg1g 0.5) + (Arg0 b 0.5) * (Arg1 b 0.5)) 4 * ((Arg0r 0.5) * (Arg1 r 0.5) + (Arg0 g 0.5) * (Arg1g 0.5) + (Arg0 b 0.5) * (Arg1 b 0.5))

DOT3_RGBA

COMBINE_ALPHA REPLACE MODULATE ADD ADD_SIGNED INTERPOLATE SUBTRACT

Texture Function Arg0 Arg0 * Arg1 Arg0 + Arg1 Arg0 + Arg1 0.5 Arg0 * Arg2 + Arg1 * (1 Arg2) Arg0 Arg1

Texture CombineSRCn_RGB TEXTURE OPERANDn_RGB Argument Cs 1 Cs As 1 As Cc 1 Cc Ac 1 Ac Cf 1 Cf Af 1 Af Cp 1 Cp Ap 1 Ap SRC_COLOR ONE_MINUS_SRC_COLOR SRC_ALPHA ONE_MINUS_SRC_ALPHA CONSTANT SRC_COLOR ONE_MINUS_SRC_COLOR SRC_ALPHA ONE_MINUS_SRC_ALPHA PRIMARY_COLOR SRC_COLOR ONE_MINUS_SRC_COLOR SRC_ALPHA ONE_MINUS_SRC_ALPHA PREVIOUS SRC_COLOR ONE_MINUS_SRC_COLOR SRC_ALPHA ONE_MINUS_SRC_ALPHA Table 5.2: Arguments for COMBINE_RGB functions. SRCn_ALPHA TEXTURE OPERANDn_ALPHA Argument As 1 As Ac 1 Ac Af 1 Af Ap 1 Ap

SRC_ALPHA ONE_MINUS_SRC_ALPHA CONSTANT SRC_ALPHA ONE_MINUS_SRC_ALPHA PRIMARY_COLOR SRC_ALPHA ONE_MINUS_SRC_ALPHA PREVIOUS SRC_ALPHA ONE_MINUS_SRC_ALPHA Table 5.3: Arguments for COMBINE_ALPHA functions.

OES_matrix_paletteUsed to do vertex skinning in OpenGL ES 1.1Modified version of ARB_matrix_palette A set of matrix indices & weights per vertex.# of matrices / vertex can be queried using glGetIntegerv Minimum # supported3 matrices / vertex

Matrix paletteMatrix indices specified per vertex into the palette Size of matrix palette can be queried using glGetIntegerv Minimum supportedPalette of 16 matrices.

User Clip PlanesUseful for portal culling algorithms Support a minimum of one user clip planeOpenGL supports a minimum of 6 user planes

How does it workClip plane in object coordinates specified by glClipPlane Compute dot product of clip plane & point in eye spaceIf dot product >= 0, point is inside plane

PointsOES_point_spriteAccelerate rendering of particle effects Render particles as points instead of quads Texture coordinates smoothly interpolated across point from 0.0 to 1.0Application can enable/disable this per texture

Point sprites enabled using GL_POINT_SPRITE

OES_point_size_arrayExtends how points & point sprites are rendered glPointSizePointerOESUsed to specify the point size array Point sizes can also be stored in a buffer object

Distance attenuation of pointsAttenuate point size based on distance from eye

StateOpenGL ES 1.0 supports static state queries OpenGL ES 1.1 allows dynamic state queriesWhy ?Implement state save/restore Middle-ware or application can implement state push and pop with an infinite stack depth

State FunctionsRefer to the OpenGL ES 1.1 spec

OES_draw_textureRender pixel rectangles using texture units Why ?Useful for fast rendering of sprites, bitmapped font glyphs, & 2D framing elements in games

glDrawPixels vs. OES_draw_textureBoth are similar in functionality OES_draw_texture uses texture pipe & texture objectsglDrawPixels inefficient because pixel data supplied by application cannot be cached.

OpenGL ES 1.1 Extension PackCollection of optional extensionsTexture Crossbar Texture Cubemap Texture Mirrored Repeat Blending Enhancements Stencil Enhancements Extended Matrix Palette Framebuffer ObjectsDiscussed in OpenGL 2.0 slides

OpenGL ES 1.1 Extension PackCT0 CT1

Texture CrossbarTexture Combine 0 Texture Combine 1Cprev Cf

Cf Cf Cf CTj Cprev = = = = fragment primary color input to texturing fragment color output from texturing texture color from texture lookup j color output from previous combine unit

Adds capability to use the texture color from other texture units as sources to the COMBINE unit.

OpenGL ES 1.1 Texture Combine

CT0

CT1

Texture Combine 0 Texture Combine 1

Cprev

Cf

Cf Cf Cf CTj Cprev = = = = fragment primary color input to texturing fragment color output from texturing texture color from texture lookup j color output from previous combine unit

Texture Environment Crossbar

OpenGL ES 1.1 Extension PackMirrored Texture Addressing Blending ExtensionsAdditional Blending EquationsGL_FUNC_SUBTRACT GL_FUNC_REVERSE_SUBTRACT

glBlendFuncSeparate, glBlendEquationSeparateSeparate blending functions and equations for RGB and alpha.

New StencilOp functionsGL_INCR_WRAP and GL_DECR_WRAP

OpenGL ES 1.1 Extension PackCube MapsAccurate real-time reflections in handheld 3D gamesGiven normal & position, compute reflection vector Use reflection vector as texture coordinate Per-pixel computed reflection vector is used to index one of 6 faces of cube

Generate per-pixel reflection value

Per-pixel specular lightingPer-vertex specular highlight requires very finely tessellated geometry With cube-maps you can compute specular color per pixel

And not require lots of geometry

OpenGL ES 1.1 Extension PackExtended Matrix PaletteOES_matrix_palette in OpenGL ES 1.1 recommendsa minimum matrix palette size of 9 matrices and up to 3 matrices / vertex

ProblemsRequires games to break geometry into smaller primitive listsnot efficient for HW

Many cases where 4 matrices / vertex is required

OES_extended_matrix_palette increases minimums toMatrix palette size = 32 # of matrices / vertex = 4

OpenGL ES 2.0

OpenGL ES 2.0 OverviewDerived from the OpenGL 2.0 specification No Fixed Function Pipeline Common Profile OnlyAPI entry points use single precision floating point or integer variants

Shifts some burden to applicationBut puts more power in your hands

Convergence of desktop and handheld!

OpenGL ES 2.0 Programmable PipelineVertex shaders replace Fixed Function Transform and Lighting Triangles/Lines/Points

API API

Primitive Primitive Processing Processing

Vertices

Transform Vertex Transform and Vertex Shader and Lighting Shader Lighting

Primitive Primitive Assembly Assembly

Rasterizer Rasterizer

Texture Texture Environment Environment Fragment shaders replace Fixed Function Texture, Color and Fog

Vertex Vertex Buffer Buffer Objects Objects

Fragment Color Colour Fragment Colour Shader Sum Shader Sum

Fog Fog

Alpha Alpha Test Test

Depth Depth Stencil Stencil

Color Colour Buffer Buffer Blend Blend

Dither Dither

Frame Buffer Frame Buffer

OpenGL ES 2.0 Vertex ShaderUniforms Uniforms Textures Textures

Attribute 00 Attribute Attribute 11 Attribute Attribute 22 Attribute Attribute 33 Attribute Attribute 44 Attribute Attribute 55 Attribute Attribute 66 Attribute Attribute 77 Attribute

Vertex Shader Vertex Shader

Varying 00 Varying Varying 11 Varying Varying 22 Varying Varying 33 Varying Varying 44 Varying Varying 55 Varying Varying 66 Varying Varying 77 Varying gl_Position gl_Position gl_PointSize gl_FrontFacing

Temporary Temporary variables variables

Ope