The document provides an overview of the OpenGL ES 2.0 API including commands for vertex specification, rendering, shaders, textures, and reading pixels. It describes the API syntax and data types as well as commands for buffer objects, programs, and shader variables.
The document provides an overview of the OpenGL ES 2.0 API including commands for vertex specification, rendering, shaders, textures, and reading pixels. It describes the API syntax and data types as well as commands for buffer objects, programs, and shader variables.
www.khronos.org/opengles 2010 Khronos Group - Rev.
0210 OpenGL ES 2.0 API Quick Reference Card OpenGL
ES is a sofware interface to graphics hardware. The interface
consists of a set of procedures and functons that allow a programmer to specify the objects and operatons involved in producing high-quality graphical images, specifcally color images of three-dimensional objects. [n.n.n] refers to sectons and tables in the OpenGL ES 2.0 specifcaton. [n.n.n] refers to sectons in the OpenGL ES Shading Language 1.0 specifcaton. Specifcatons are available at www.opengl.org/registry/gles Vertces Current Vertex State [2.7] void VertexAtrib{1234}{f}(uint index, T values); void VertexAtrib{1234}{f}v(uint index, T values); Vertex Arrays [2.8] Vertex data may be sourced from arrays that are stored in applicaton memory (via a pointer) or faster GPU memory (in a bufer object). void VertexAtribPointer(uint index, int size, enum type, boolean normalized, sizei stride, const void *pointer); type: BYTE, UNSIGNED_BYTE, SHORT, UNSIGNED_SHORT, FIXED, FLOAT index: [0, MAX_VERTEX_ATTRIBS - 1] If an ARRAY_BUFFER is bound, the atribute will be read from the bound bufer, and pointer is treated as an ofset within the bufer. void EnableVertexAtribArray(uint index); void DisableVertexAtribArray(uint index); index: [0, MAX_VERTEX_ATTRIBS - 1] void DrawArrays(enum mode, int frst, sizei count); void DrawElements(enum mode, sizei count, enum type, void *indices); mode: POINTS, LINE_STRIP, LINE_LOOP, LINES, TRIANGLE_STRIP, TRIANGLE_FAN, TRIANGLES type: UNSIGNED_BYTE, UNSIGNED_SHORT If an ELEMENT_ARRAY_BUFFER is bound, the indices will be read from the bound bufer, and indices is treated as an ofset within the bufer. OpenGL ES Command Syntax [2.3] Open GL ES commands are formed from a return type, a name, and optonally a type leter i for 32-bit int, or f for 32-bit foat, as shown by the prototype below: return-type Name{1234}{if}{v} ([args ,] T arg1 , . . . , T argN [, args]); The arguments enclosed in brackets ([args ,] and [, args]) may or may not be present. The argument type T and the number N of arguments may be indicated by the command name sufxes. N is 1, 2, 3, or 4 if present, or else corresponds to the type leters. If v is present, an array of N items is passed by a pointer. For brevity, the OpenGL documentaton and this reference may omit the standard prefxes. The actual names are of the forms: glFunctonName(), GL_CONSTANT, GLtype Errors [2.5] enum GetError( void ); //Returns one of the following: INVALID_ENUM Enum argument out of range INVALID_FRAMEBUFFER_OPERATION Framebufer is incomplete INVALID_VALUE Numeric argument out of range INVALID_OPERATION Operaton illegal in current state OUT_OF_MEMORY Not enough memory lef to execute command NO_ERROR No error encountered Bufer Objects [2.9] Bufer objects hold vertex array data or indices in high-performance server memory. void GenBufers(sizei n, uint *bufers); void DeleteBufers(sizei n, const uint *bufers); Creatng and Binding Bufer Objects void BindBufer(enum target, uint bufer); target: ARRAY_BUFFER, ELEMENT_ARRAY_BUFFER Creatng Bufer Object Data Stores void BuferData(enum target, sizeiptr size, const void *data, enum usage); usage: STATIC_DRAW, STREAM_DRAW, DYNAMIC_DRAW Updatng Bufer Object Data Stores void BuferSubData(enum target, intptr ofset, sizeiptr size, const void *data); target: ARRAY_BUFFER, ELEMENT_ARRAY_BUFFER Bufer Object Queries [6.1.6, 6.1.3] boolean IsBufer(uint bufer); void GetBuferParameteriv(enum target, enum value, T data); target: ARRAY_BUFFER, ELEMENT_ ARRAY_BUFFER value: BUFFER_SIZE, BUFFER_USAGE Viewport and Clipping Controlling the Viewport [2.12.1] void DepthRangef(clampf n, clampf f); void Viewport(int x, int y, sizei w, sizei h); Rasterizaton [3] Points [3.3] Point size is taken from the shader builtn gl_PointSize and clamped to the implementaton-dependent point size range. Line Segments [3.4] void LineWidth(foat width); Polygons [3.5] void FrontFace(enum dir); dir: CCW, CW void CullFace(enum mode); mode: FRONT, BACK, FRONT_AND_BACK Enable/Disable(CULL_FACE) void PolygonOfset(foat factor, foat units); Enable/Disable(POLYGON_OFFSET_FILL) Pixel Rectangles [3.6, 4.3] void PixelStorei(enum pname, int param); pname: UNPACK_ALIGNMENT, PACK_ALIGNMENT Texturing [3.7] Shaders support texturing using at least MAX_VERTEX_TEXTURE_IMAGE_UNITS images for vertex shaders and at least MAX_TEXTURE_IMAGE_UNITS images for fragment shaders. void ActveTexture(enum texture); texture: [TEXTURE0..TEXTUREi] where i = MAX_COMBINED_TEXTURE_IMAGE_UNITS-1 Texture Image Specifcaton [3.7.1] void TexImage2D(enum target, int level, int internalformat, sizei width, sizei height, int border, enum format, enum type, void *data); target: TEXTURE_2D, TEXTURE_CUBE_MAP_POSITIVE_{X,Y,Z} TEXTURE_CUBE_MAP_NEGATIVE_{X,Y,Z} internalformat: ALPHA, LUMINANCE, LUMINANCE_ALPHA, RGB, RGBA format: ALPHA, RGB, RGBA, LUMINANCE, LUMINANCE_ALPHA type: UNSIGNED_BYTE, UNSIGNED_SHORT_5_6_5, UNSIGNED_SHORT_4_4_4_4, UNSIGNED_SHORT_5_5_5_1 Conversion from RGBA pixel components to internal texture components: Base Internal Format RGBA Internal Components ALPHA A A LUMINANCE R L LUMINANCE _ALPHA R, A L, A RGB R, G, B R, G, B RGBA R, G, B, A R, G, B, A Alt. Texture Image Specifcaton Commands [3.7.2] Texture images may also be specifed using image data taken directly from the framebufer, and rectangular subregions of existng texture images may be respecifed. void CopyTexImage2D(enum target, int level, enum internalformat, int x, int y, sizei width, sizei height, int border); target: TEXTURE_2D, TEXTURE_CUBE_MAP_POSITIVE_{X, Y, Z}, TEXTURE_CUBE_MAP_NEGATIVE_{X, Y, Z} internalformat: See TexImage2D void TexSubImage2D(enum target, int level, int xofset, int yofset, sizei width, sizei height, enum format, enum type, void *data); target: TEXTURE_CUBE_MAP_POSITIVE_{X, Y, Z}, TEXTURE_CUBE_MAP_NEGATIVE_{X, Y, Z} format and type: See TexImage2D void CopyTexSubImage2D(enum target, int level, int xofset, int yofset, int x, int y, sizei width, sizei height); target: TEXTURE_2D, TEXTURE_CUBE_MAP_POSITIVE_{X, Y, Z}, TEXTURE_CUBE_MAP_NEGATIVE_{X, Y, Z} format and type: See TexImage2D Compressed Texture Images [3.7.3] void CompressedTexImage2D(enum target, int level, enum internalformat, sizei width, sizei height, int border, sizei imageSize, void *data); target and internalformat: See TexImage2D void CompressedTexSubImage2D(enum target, int level, int xofset, int yofset, sizei width, sizei height, enum format, sizei imageSize, void *data); target and internalformat: See TexImage2D Texture Parameters [3.7.4] void TexParameter{if}(enum target, enum pname, T param); void TexParameter{if}v(enum target, enum pname, T params); target: TEXTURE_2D, TEXTURE_CUBE_MAP pname: TEXTURE_WRAP_{S, T}, TEXTURE_{MIN, MAG}_FILTER Manual Mipmap Generaton [3.7.11] void GenerateMipmap(enum target); target: TEXTURE_2D, TEXTURE_CUBE_MAP Texture Objects [3.7.13] void BindTexture(enum target, uint texture); void DeleteTextures(sizei n, uint *textures); void GenTextures(sizei n, uint *textures); Enumerated Queries [6.1.3] void GetTexParameter{if}v(enum target, enum value, T data); target: TEXTURE_2D, TEXTURE_CUBE_MAP value: TEXTURE_WRAP_{S, T}, TEXTURE_{MIN, MAG}_FILTER Texture Queries [6.1.4] boolean IsTexture(uint texture); GL Data Types [2.3] GL types are not C types. GL Type Minimum Bit Width Descripton boolean 1 Boolean byte 8 Signed binary integer ubyte 8 Unsigned binary integer char 8 Characters making up strings short 16 Signed 2s complement binary integer ushort 16 Unsigned binary integer int 32 Signed 2s complement binary integer uint 32 Unsigned binary integer fxed 32 Signed 2s complement 16.16 scaled integer sizei 32 Non-negatve binary integer size enum 32 Enumerated binary integer value intptr ptrbits Signed 2s complement binary integer sizeiptr ptrbits Non-negatve binary integer size bitield 32 Bit feld foat 32 Floatng-point value clampf 32 Floatng-point value clamped to [0; 1] Reading Pixels [4.3.1] void ReadPixels(int x, int y, sizei width, sizei height, enum format, enum type, void *data); format: RGBA type: UNSIGNED_BYTE Note: ReadPixels() also accepts a queriable implementaton- defned format/type combinaton, see [4.3.1]. www.khronos.org/opengles 2010 Khronos Group - Rev. 0210 OpenGL ES 2.0 API Quick Reference Card OpenGL ES 2.0 API Quick Reference Card Shaders and Programs Shader Objects [2.10.1] uint CreateShader(enum type); type: VERTEX_SHADER, FRAGMENT_SHADER void ShaderSource(uint shader, sizei count, const char **string, const int *length); void CompileShader(uint shader); void ReleaseShaderCompiler(void); void DeleteShader(uint shader); Loading Shader Binaries [2.10.2] void ShaderBinary(sizei count, const uint *shaders, enum binaryformat, const void *binary, sizei length); Program Objects [2.10.3] uint CreateProgram(void); void AtachShader(uint program, uint shader); void DetachShader(uint program, uint shader); void LinkProgram(uint program); void UseProgram(uint program); void DeleteProgram(uint program); Shader Variables [2.10.4] Vertex Atributes void GetActveAtrib(uint program, uint index, sizei bufSize, sizei *length, int *size, enum *type, char *name); *type returns: FLOAT, FLOAT_VEC{2,3,4}, FLOAT_MAT{2,3,4} int GetAtribLocaton(uint program, const char *name); void BindAtribLocaton(uint program, uint index, const char *name); Uniform Variables int GetUniformLocaton(uint program, const char *name); void GetActveUniform(uint program, uint index, sizei bufSize, sizei *length, int *size, enum *type, char *name); *type: FLOAT, FLOAT_VEC{2,3,4}, INT, INT_VEC{2,3,4}, BOOL, BOOL_VEC{2,3,4}, FLOAT_MAT{2,3,4}, SAMPLER_2D, SAMPLER_CUBE void Uniform{1234}{if}(int locaton, T value); void Uniform{1234}{if}v(int locaton, sizei count, T value); void UniformMatrix{234}fv(int locaton, sizei count, boolean transpose, const foat *value); transpose: FALSE Shader Executon (Validaton) [2.10.5] void ValidateProgram(uint program); Shader Queries Shader Queries [6.1.8] boolean IsShader(uint shader); void GetShaderiv(uint shader, enum pname, int *params); pname: SHADER_TYPE, DELETE_STATUS, COMPILE_STATUS, INFO_LOG_LENGTH, SHADER_SOURCE_LENGTH void GetAtachedShaders(uint program, sizei maxCount, sizei *count, uint *shaders); void GetShaderInfoLog(uint shader, sizei bufSize, sizei *length, char *infoLog); void GetShaderSource(uint shader, sizei bufSize, sizei *length, char *source); void GetShaderPrecisionFormat(enum shadertype, enum precisiontype, int *range, int *precision); shadertype: VERTEX_SHADER, FRAGMENT_SHADER precision: LOW_FLOAT, MEDIUM_FLOAT, HIGH_FLOAT, LOW_INT, MEDIUM_INT, HIGH_INT void GetVertexAtribfv(uint index, enum pname, foat *params); pname: CURRENT_VERTEX_ATTRIB , VERTEX_ATTRIB_ARRAY_x (where x may be BUFFER_BINDING, ENABLED, SIZE, STRIDE, TYPE, NORMALIZED) void GetVertexAtribiv(uint index, enum pname, int *params); pname: CURRENT_VERTEX_ATTRIB , VERTEX_ATTRIB_ARRAY_x (where x may be BUFFER_BINDING, ENABLED, SIZE, STRIDE, TYPE, NORMALIZED) void GetVertexAtribPointerv(uint index, enum pname, void **pointer); pname: VERTEX_ATTRIB_ARRAY_POINTER void GetUniformfv(uint program, int locaton, foat *params) void GetUniformiv(uint program, int locaton, int *params) Program Queries [6.1.8] boolean IsProgram(uint program); void GetProgramiv(uint program, enum pname, int *params); pname: DELETE_STATUS, LINK_STATUS, VALIDATE_STATUS, INFO_LOG_LENGTH, ATTACHED_SHADERS, ACTIVE_ATTRIBUTES, ACTIVE_ATTRIBUTE_MAX_LENGTH, ACTIVE_UNIFORMS, ACTIVE_UNIFORM_MAX_LENGTH void GetProgramInfoLog(uint program, sizei bufSize, sizei *length, char *infoLog); Per-Fragment Operatons Scissor Test [4.1.2] Enable/Disable(SCISSOR_TEST) void Scissor(int lef, int botom, sizei width, sizei height ); Multsample Fragment Operatons [4.1.3] Enable/Disable(cap) cap: SAMPLE_ALPHA_TO_COVERAGE, SAMPLE_COVERAGE void SampleCoverage(clampf value, boolean invert); Stencil Test [4.1.4] Enable/Disable(STENCIL_TEST) void StencilFunc(enum func, int ref, uint mask); void StencilFuncSeparate(enum face, enum func, int ref, uint mask); void StencilOp(enum sfail, enum dpfail, enum dppass); void StencilOpSeparate(enum face, enum sfail, enum dpfail, enum dppass); face: FRONT, BACK, FRONT_AND_BACK sfail, dpfail, and dppass: KEEP, ZERO, REPLACE, INCR, DECR, INVERT, INCR_WRAP, DECR_WRAP func: NEVER, ALWAYS, LESS, LEQUAL, EQUAL, GREATER, GEQUAL, NOTEQUAL Depth Bufer Test [4.1.5] Enable/Disable(DEPTH_TEST) void DepthFunc(enum func); func: NEVER, ALWAYS, LESS, LEQUAL, EQUAL, GREATER, GEQUAL, NOTEQUAL Blending [4.1.6] Enable/Disable(BLEND) (applies to all draw bufers) void BlendEquaton(enum mode); void BlendEquatonSeparate(enum modeRGB, enum modeAlpha); mode, modeRGB, and modeAlpha: FUNC_ADD, FUNC_SUBTRACT, FUNC_REVERSE_SUBTRACT void BlendFuncSeparate(enum srcRGB, enum dstRGB, enum srcAlpha, enum dstAlpha); void BlendFunc(enum src, enum dst); dst, dstRGB, and dstAlpha: ZERO, ONE, [ONE_MINUS_]SRC_COLOR, [ONE_MINUS_]DST_COLOR, [ONE_MINUS_]SRC_ALPHA, [ONE_MINUS_]DST_ALPHA, [ONE_MINUS_]CONSTANT_COLOR, [ONE_MINUS_]CONSTANT_ALPHA src, srcRGB, srcAlpha: same for dst, plus SRC_ALPHA_SATURATE void BlendColor(clampf red, clampf green, clampf blue, clampf alpha); Dithering [4.1.7] Enable/Disable(DITHER) Whole Framebufer Operatons Fine Control of Bufer Updates [4.2.2] void ColorMask(boolean r, boolean g, boolean b, boolean a); void DepthMask(boolean mask); void StencilMask(uint mask); void StencilMaskSeparate(enum face, uint mask); face: FRONT, BACK, FRONT_AND_BACK Clearing the Bufers [4.2.3] void Clear(bitield buf); buf: Bitwise OR of COLOR_BUFFER_BIT, DEPTH_BUFFER_BIT, STENCIL_BUFFER_BIT void ClearColor(clampf r, clampf g, clampf b, clampf a); void ClearDepthf(clampf d); void ClearStencil(int s); State and State Requests A complete list of symbolic constants for states is shown in the tables in [6.2]. Simple Queries [6.1.1] void GetBooleanv(enum value, boolean *data); void GetIntegerv(enum value, int *data); void GetFloatv(enum value, foat *data); boolean IsEnabled(enum value); Pointer and String Queries [6.1.5] ubyte *GetString(enum name); name: VENDOR, RENDERER, VERSION, SHADING_LANGUAGE_VERSION, EXTENSIONS Special Functons Flush and Finish [5.1] Flush guarantees that commands issued so far will eventually complete. Finish blocks untl all commands issued so far have completed. void Flush(void); void Finish(void); Hints [5.2] Hint controls certain aspects of GL behavior. void Hint(enum target, enum hint); target: GENERATE_MIPMAP_HINT hint: FASTEST, NICEST, DONT_CARE Framebufer Objects Binding & Managing Framebufer Objects [4.4.1] void BindFramebufer(enum target, uint framebufer); target: FRAMEBUFFER void DeleteFramebufers(sizei n, uint *framebufers); void GenFramebufers(sizei n, uint *framebufers); Renderbufer Objects [4.4.2] void BindRenderbufer(enum target, uint renderbufer); target: RENDERBUFFER void DeleteRenderbufers(sizei n, const uint *renderbufers); void GenRenderbufers(sizei n, uint *renderbufers); void RenderbuferStorage(enum target, enum internalformat, sizei width, sizei height); target: RENDERBUFFER internalformat: DEPTH_COMPONENT16, RGBA4, RGB5_A1, RGB565, STENCIL_INDEX8 Ataching Renderbufer Images to Framebufer void FramebuferRenderbufer(enum target, enum atachment, enum renderbufertarget, uint renderbufer); target: FRAMEBUFFER atachment: COLOR_ATTACHMENT0, DEPTH_ATTACHMENT, STENCIL_ATTACHMENT renderbufertarget: RENDERBUFFER Ataching Texture Images to a Framebufer void FramebuferTexture2D(enum target, enum atachment, enum textarget, uint texture, int level); textarget: TEXTURE_2D, TEXTURE_CUBE_MAP_POSITIVE{X, Y, Z}, TEXTURE_CUBE_MAP_NEGATIVE{X, Y, Z}, target: FRAMEBUFFER atachment: COLOR_ATTACHMENT0, DEPTH_ATTACHMENT, STENCIL_ATTACHMENT Framebufer Completeness [4.4.5] enum CheckFramebuferStatus(enum target); target: FRAMEBUFFER returns: FRAMEBUFFER_COMPLETE or a constant indicatng which value violates framebufer completeness Framebufer Object Queries [6.1.3, 6.1.7] boolean IsFramebufer(uint framebufer); void GetFramebuferAtachmentParameteriv(enum target, enum atachment, enum pname, int *params); target: FRAMEBUFFER atachment: COLOR_ATTACHMENT0, DEPTH_ATTACHMENT, STENCIL_ATTACHMENT pname: FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL, FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE Renderbufer Object Queries [6.1.3, 6.1.7] boolean IsRenderbufer(uint renderbufer); void GetRenderbuferParameteriv(enum target, enum pname, int *params); target: RENDERBUFFER pname: RENDERBUFFER_x (where x may be WIDTH, HEIGHT, RED_SIZE, GREEN_SIZE, BLUE_SIZE, ALPHA_SIZE, DEPTH_SIZE, STENCIL_SIZE, INTERNAL_FORMAT) www.khronos.org/opengles 2010 Khronos Group - Rev. 0210 www.khronos.org/opengles 2010 Khronos Group - Rev. 0210 OpenGL ES Shading Language 1.0 Quick Reference Card Operators and Expressions Operators [5.1] Numbered in order of precedence. The relatonal and equality operators > < <= >= == != evaluate to a Boolean. To compare vectors component-wise, use functons such as lessThan(), equal(), etc. Operator Descripton Associatvity 1. ( ) parenthetcal grouping N/A 2. [ ] ( ) . ++ -- array subscript functon call & constructor structure feld or method selector, swizzler postix increment and decrement L - R 3. ++ -- + - ! prefx increment and decrement unary R - L 4. * / multplicatve L - R 5. + - additve L - R 7. < > <= >= relatonal L - R 8. == != equality L - R 12. && logical and L - R 13. ^^ logical exclusive or L - R 14. | | logical inclusive or L - R 15. ? : selecton (Selects one entre operand. Use mix() to select individual components of vectors.) L - R 16. = += -= *= /= assignment arithmetc assignments L - R 17. , sequence L - R Vector Components [5.5] In additon to array numeric subscript syntax, names of vector components are denoted by a single leter. Components can be swizzled and replicated, e.g.: pos.xx, pos.zy {x, y, z, w} Use when accessing vectors that represent points or normals {r, g, b, a} Use when accessing vectors that represent colors {s, t, p, q} Use when accessing vectors that represent texture coordinates Preprocessor [3.4] Preprocessor Directves The number sign (#) can be immediately preceded or followed in its line by spaces or horizontal tabs. # #defne #undef #if #ifdef #ifndef #else #elif #endif #error #pragma #extension #version #line Examples of Preprocessor Directves #version 100 in a shader program specifes that the program is writen in GLSL ES version 1.00. It is optonal. If used, it must occur before anything else in the program other than whitespace or comments. #extension extension_name : behavior, where behavior can be require, enable, warn, or disable; and where extension_name is the extension supported by the compiler Predefned Macros __LINE__ Decimal integer constant that is one more than the number of preceding new-lines in the current source string __FILE__ Decimal integer constant that says which source string number is currently being processed. __VERSION__ Decimal integer, e.g.: 100 GL_ES Defned and set to integer 1 if running on an OpenGL-ES Shading Language. GL_FRAGMENT_PRECISION_HIGH 1 if highp is supported in the fragment language, else undefned [4.5.4] The OpenGL
ES Shading Language is two closely-
related languages which are used to create shaders for the vertex and fragment processors contained in the OpenGL ES processing pipeline. [n.n.n] and [Table n.n] refer to sectons and tables in the OpenGL ES Shading Language 1.0 specifcaton at www.opengl.org/registry/gles Qualifers Storage Qualifers [4.3] Variable declaratons may be preceded by one storage qualifer. none (Default) local read/write memory, or input parameter const Compile-tme constant, or read-only functon parameter atribute Linkage between a vertex shader and OpenGL ES for per-vertex data uniform Value does not change across the primitve being processed, uniforms form the linkage between a shader, OpenGL ES, and the applicaton varying Linkage between a vertex shader and fragment shader for interpolated data Uniform [4.3.4] Use to declare global variables whose values are the same across the entre primitve being processed. All uniform variables are read-only. Use uniform qualifers with any basic data types, to declare a variable whose type is a structure, or an array of any of these. For example: uniform vec4 lightPositon; Varying [4.3.5] The varying qualifer can be used only with the data types foat, vec2, vec3, vec4, mat2, mat3, mat4, or arrays of these. Structures cannot be varying. Varying variables are required to have global scope. Declaraton is as follows: varying vec3 normal; Parameter Qualifers [4.4] Input values are copied in at functon call tme, output values are copied out at functon return tme. none (Default) same as in in For functon parameters passed into a functon out For functon parameters passed back out of a functon, but not initalized for use when passed in inout For functon parameters passed both into and out of a functon Precision and Precision Qualifers [4.5] Any foatng point, integer, or sampler declaraton can have the type preceded by one of these precision qualifers: highp Satsfes minimum requirements for the vertex language. Optonal in the fragment language. mediump Satsfes minimum requirements for the fragment language. Its range and precision is between that provided by lowp and highp. lowp Range and precision can be less than mediump, but stll represents all color values for any color channel. For example: lowp foat color; varying mediump vec2 Coord; lowp ivec2 foo(lowp mat3); highp mat4 m; Ranges & precisions for precision qualifers (FP=foatng point): FP Range FP Magnitude Range FP Precision Integer Range highp (2 62 , 2 62 ) (2 62 , 2 62 ) Relatve 2 16 (2 16 , 2 16 ) mediump (2 14 , 2 14 ) (2 14 , 2 14 ) Relatve 2 10 (2 10 , 2 10 ) lowp (2, 2) (2 8 , 2) Absolute 2 8 (2 8 , 2 8 ) A precision statement establishes a default precision qualifer for subsequent int, foat, and sampler declaratons, e.g.: precision highp int; Invariant Qualifers Examples [4.6] #pragma STDGL invariant(all) Force all output variables to be invariant invariant gl_Positon; Qualify a previously declared variable invariant varying mediump vec3 Color; Qualify as part of a variable declaraton Order of Qualifcaton [4.7] When multple qualifcatons are present, they must follow a strict order. This order is as follows. invariant, storage, precision storage, parameter, precision Types [4.1] A shader can aggregate these using arrays and structures to build more complex types. There are no pointer types. Basic Types void no functon return value or empty parameter list bool Boolean int signed integer foat foatng scalar vec2, vec3, vec4 n-component foatng point vector bvec2, bvec3, bvec4 Boolean vector ivec2, ivec3, ivec4 signed integer vector mat2, mat3, mat4 2x2, 3x3, 4x4 foat matrix sampler2D access a 2D texture samplerCube access cube mapped texture Structures and Arrays [4.1.8, 4.1.9] Structures struct type-name { members } struct-name[]; // optonal variable declaraton, // optonally an array Arrays foat foo[3]; * structures and blocks can be arrays * only 1-dimensional arrays supported * structure members can be arrays Aggregate Operatons and Constructors Matrix Constructor Examples [5.4] mat2(foat) // init diagonal mat2(vec2, vec2); // column-major order mat2(foat, foat, foat, foat); // column-major order Structure Constructor Example [5.4.3] struct light {foat intensity; vec3 pos; }; light lightVar = light(3.0, vec3(1.0, 2.0, 3.0)); Matrix Components [5.6] Access components of a matrix with array subscriptng syntax. For example: mat4 m; // m represents a matrix m[1] = vec4(2.0); // sets second column to all 2.0 m[0][0] = 1.0; // sets upper lef element to 1.0 m[2][3] = 2.0; // sets 4th element of 3rd column to 2.0 Examples of operatons on matrices and vectors: m = f * m; // scalar * matrix component-wise v = f * v; // scalar * vector component-wise v = v * v; // vector * vector component-wise m = m +/- m; // matrix component-wise additon/subtracton m = m * m; // linear algebraic multply m = v * m; // row vector * matrix linear algebraic multply m = m * v; // matrix * column vector linear algebraic multply f = dot(v, v); // vector dot product v = cross(v, v); // vector cross product m = matrixCompMult(m, m); // component-wise multply Structure Operatons [5.7] Select structure felds using the period (.) operator. Other operators include: . feld selector == != equality = assignment Array Operatons [4.1.9] Array elements are accessed using the array subscript operator [ ]. For example: difuseColor += lightIntensity[3] * NdotL; www.khronos.org/opengles 2010 Khronos Group - Rev. 0210 OpenGL ES Shading Language 1.0 Quick Reference Card Built-In Functons Angle & Trigonometry Functons [8.1] Component-wise operaton. Parameters specifed as angle are assumed to be in units of radians. T is foat, vec2, vec3, vec4. T radians(T degrees) degrees to radians T degrees(T radians) radians to degrees T sin(T angle) sine T cos(T angle) cosine T tan(T angle) tangent T asin(T x) arc sine T acos(T x) arc cosine T atan(T y, T x) T atan(T y_over_x) arc tangent Exponental Functons [8.2] Component-wise operaton. T is foat, vec2, vec3, vec4. T pow(T x, T y) x y T exp(T x) e x T log(T x) ln T exp2(T x) 2 x T log2(T x) log 2 T sqrt(T x) square root T inversesqrt(T x) inverse square root Common Functons [8.3] Component-wise operaton. T is foat, vec2, vec3, vec4. T abs(T x) absolute value T sign(T x) returns -1.0, 0.0, or 1.0 T foor(T x) nearest integer <= x T ceil(T x) nearest integer >= x T fract(T x) x - foor(x) T mod(T x, T y) T mod(T x, foat y) modulus T min(T x, T y) T min(T x, foat y) minimum value T max(T x, T y) T max(T x, foat y) maximum value T clamp(T x, T minVal, T maxVal) T clamp(T x, foat minVal, foat maxVal) min(max(x, minVal), maxVal) T mix(T x, T y, T a) T mix(T x, T y, foat a) linear blend of x and y T step(T edge, T x) T step(foat edge, T x) 0.0 if x < edge, else 1.0 T smoothstep(T edge0, T edge1, T x) T smoothstep(foat edge0, foat edge1, T x) clip and smooth Geometric Functons [8.4] These functons operate on vectors as vectors, not component-wise. T is foat, vec2, vec3, vec4. foat length(T x) length of vector foat distance(T p0, T p1) distance between points foat dot(T x, T y) dot product vec3 cross(vec3 x, vec3 y) cross product T normalize(T x) normalize vector to length 1 T faceforward(T N, T I, T Nref) returns N if dot(Nref, I) < 0, else -N T refect(T I, T N) refecton directon I - 2 * dot(N,I) * N T refract(T I, T N, foat eta) refracton vector Matrix Functons [8.5] Type mat is any matrix type. mat matrixCompMult(mat x, mat y) multply x by y component-wise Vector Relatonal Functons [8.6] Compare x and y component-wise. Sizes of input and return vectors for a partcular call must match. Type bvec is bvecn; vec is vecn; ivec is ivecn (where n is 2, 3, or 4). T is the union of vec and ivec. bvec lessThan(T x, T y) x < y bvec lessThanEqual(T x, T y) x <= y bvec greaterThan(T x, T y) x > y bvec greaterThanEqual(T x, T y) x >= y bvec equal(T x, T y) bvec equal(bvec x, bvec y) x == y bvec notEqual(T x, T y) bvec notEqual(bvec x, bvec y) x!= y bool any(bvec x) true if any component of x is true bool all(bvec x) true if all components of x are true bvec not(bvec x) logical complement of x Texture Lookup Functons [8.7] Available only in vertex shaders. vec4 texture2DLod(sampler2D sampler, vec2 coord, foat lod) vec4 texture2DProjLod(sampler2D sampler, vec3 coord, foat lod) vec4 texture2DProjLod(sampler2D sampler, vec4 coord, foat lod) vec4 textureCubeLod(samplerCube sampler, vec3 coord, foat lod) Available only in fragment shaders. vec4 texture2D(sampler2D sampler, vec2 coord, foat bias) vec4 texture2DProj(sampler2D sampler, vec3 coord, foat bias) vec4 texture2DProj(sampler2D sampler, vec4 coord, foat bias) vec4 textureCube(samplerCube sampler, vec3 coord, foat bias) Available in vertex and fragment shaders. vec4 texture2D(sampler2D sampler, vec2 coord) vec4 texture2DProj(sampler2D sampler, vec3 coord) vec4 texture2DProj(sampler2D sampler, vec4 coord) vec4 textureCube(samplerCube sampler, vec3 coord) Statements and Structure Iteraton and Jumps [6] Functon Call call by value-return Iteraton for (;;) { break, contnue } while ( ) { break, contnue } do { break, contnue } while ( ); Selecton if ( ) { } if ( ) { } else { } Jump break, contnue, return discard // Fragment shader only Entry void main() Built-In Inputs, Outputs, and Constants [7] Shader programs use Special Variables to communicate with fxed-functon parts of the pipeline. Output Special Variables may be read back afer writng. Input Special Variables are read-only. All Special Variables have global scope. Vertex Shader Special Variables [7.1] Outputs: Variable Descripton Units or coordinate system highp vec4 gl_Positon; transformed vertex positon clip coordinates mediump foat gl_PointSize; transformed point size (point rasterizaton only) pixels Fragment Shader Special Variables [7.2] Fragment shaders may write to gl_FragColor or to one or more elements of gl_FragData[], but not both. The size of the gl_FragData array is given by the built-in constant gl_MaxDrawBufers. Inputs: Variable Descripton Units or coordinate system mediump vec4 gl_FragCoord; fragment positon within frame bufer window coordinates bool gl_FrontFacing; fragment belongs to a front-facing primitve Boolean mediump int gl_PointCoord; fragment positon within a point (point rasterizaton only) 0.0 to 1.0 for each component Outputs: Variable Descripton Units or coordinate system mediump vec4 gl_FragColor; fragment color RGBA color mediump vec4 gl_FragData[n] fragment color for color atachment n RGBA color Built-In Constants With Minimum Values [7.4] Built-in Constant Minimum value const mediump int gl_MaxVertexAtribs 8 const mediump int gl_MaxVertexUniformVectors 128 const mediump int gl_MaxVaryingVectors 8 const mediump int gl_MaxVertexTextureImageUnits 0 const mediump int gl_MaxCombinedTextureImageUnits 8 const mediump int gl_MaxTextureImageUnits 8 const mediump int gl_MaxFragmentUniformVectors 16 const mediump int gl_MaxDrawBufers 1 Built-In Uniform State [7.5] Specifes depth range in window coordinates. If an implementaton does not support highp precision in the fragment language, and state is listed as highp, then that state will only be available as mediump in the fragment language. struct gl_DepthRangeParameters { highp foat near; // n highp foat far; // f highp foat dif; // f - n }; uniform gl_DepthRangeParameters gl_DepthRange; Reference card producton by Miller & Mattson www.millermatson.com OpenGL ES is a registered trademark of Silicon Graphics Internatonal, used under license by Khronos Group. The Khronos Group is an industry consortum creatng open standards for the authoring and acceleraton of parallel computng, graphics and dynamic media on a wide variety of platorms and devices. See www.khronos.org to learn more about the Khronos Group. See www.khronos.org/opengles to learn more about OpenGL ES. Sample Program A shader pair that applies difuse and ambient lightng to a textured object. Vertex Shader uniform mat4 mvp_matrix; // model-view-projecton matrix uniform mat3 normal_matrix; // normal matrix uniform vec3 ec_light_dir; // light directon in eye coords atribute vec4 a_vertex; // vertex positon atribute vec3 a_normal; // vertex normal atribute vec2 a_texcoord; // texture coordinates varying foat v_difuse; varying vec2 v_texcoord; void main(void) { // put vertex normal into eye coords vec3 ec_normal = normalize(normal_matrix * a_normal); // emit difuse scale factor, texcoord, and positon v_difuse = max(dot(ec_light_dir, ec_normal), 0.0); v_texcoord = a_texcoord; gl_Positon = mvp_matrix * a_vertex; } Fragment Shader precision mediump foat; uniform sampler2D t_refectance; uniform vec4 i_ambient; varying foat v_difuse; varying vec2 v_texcoord; void main (void) { vec4 color = texture2D(t_refectance, v_texcoord); gl_FragColor = color * (vec4(v_difuse) + i_ambient); }
Arrested Democracy - The Legality Under International Law of The 2012 Transfer of Power in The Maldives and Alleged Human Rights Violations Perpetrated by Maldivian Security Forces.