现在的位置: 首页 > 综合 > 正文

WebGL Specification

2014年09月05日 ⁄ 综合 ⁄ 共 70694字 ⁄ 字号 评论关闭

Khronos

WebGL

WebGL Specification

Working Draft 10 December 2009

This version:
https://cvs.khronos.org/svn/repos/registry/trunk/public/webgl/doc/spec/WebGL-spec.html
Latest version:
https://cvs.khronos.org/svn/repos/registry/trunk/public/webgl/doc/spec/WebGL-spec.html
Previous version:
none
Editor:
Chris Marrin (Apple Inc)

Abstract

This specification describes an additional rendering context and support objects for the HTML 5 canvas element. This context allows rendering using an API that conforms closely to the OpenGL ES 2.0 API.

Status of this document

This is a working draft document and may be updated, replaced or obsoleted by other documents at any time. Do not cite this document as other than work in progress. Public discussion of this draft specification is welcome on the (archived) WebGL mailing list public_webgl@khronos.org (seeinstructions).

Table of contents

1 Introduction

This section is not normative.

The HTMLCanvasElement places an element on the page into which graphic images can be rendered using a programmatic interface. Currently the only such interface described is the CanvasRenderingContext2D. This document describes another such interface, WebGLRenderingContext, which presents and API derived from the OpenGL ES 2.0 specification. This API provides a rich set of functions allowing realistic 3D graphics to be rendered.

More details needed here...

This is where issues would go

2 Context Creation and Drawing Buffer Presentation

Before using the WebGL API, the author must obtain a WebGLRenderingContext object for a given HTMLCanvasElement as described below. This object is used to manage OpenGL state and render to the drawing context, which must also be created at the time of context creation.. The author may supply configuration options for this drawing buffer, otherwise default values shall be used as specified elsewhere in this document. This drawing buffer is presented to the HTML page compositor immediately before an HTML page compositing operation, but only if the drawing buffer has been modified since the last compositing operation.

2.1 The canvas Element

A WebGLRenderingContext object shall be created by calling the getContext() method of a given HTMLCanvasElement object with the exact string ‘webgl’. This string is case sensitive. When called for the first time, a WebGLRenderingContext object is created and returned. Also at this time a drawing buffer shall be created. Subsequent calls to getContext() with the same string shall return the same object. If getContext() is subsequently called with any other string, the WebGLRenderingContext shall be detached from its Canvas object (the canvas attribute will be null). API calls may still be made on the WebGLRenderingContext object and readPixels() may be used to obtain the contents of the drawing buffer. But the contents shall no longer be shown on the page.

A second parameter may be passed to the getContext() function. If passed, this parameter shall be a WebGLContextAttributes object containing configuration parameters to be used in creating the drawing buffer. See section 5.2 for more details. On subsequent calls to getContext() with the ‘webgl’ string, the passed WebGLContextAttributes object, if any, shall be ignored.

 

2.2 The Drawing Buffer

The drawing buffer into which the API calls are rendered shall be defined upon creation of the WebGLRenderingContext object. The size of this drawing buffer shall be determined by the width and height attributes of the HTMLCanvasElement. Changing either of these attributes shall cause the drawing buffer to resize and its contents to be cleared to (0,0,0,0).

By default, the drawing buffer has an RGBA color buffer of at least 8 bits per component and an integer depth buffer of at least 16 bits. The optional WebGLContextAttributes object may be used to change these defaults. This object is only used on the first call to getContext. No facility is provided to change the attributes of the drawing buffer after its creation.

WebGL presents its drawing buffer to the HTML page compositor immediately before a compositing operation, but only if the drawing buffer has been modified since the last compositing operation. Before the drawing buffer is presented for compositing the implementation shall ensure that all rendering operations have been flushed to the drawing buffer. After compositing the contents of the drawing buffer shall be undefined but must not contain uninitialized pixels.

3 WebGL Resources

OpenGL manages several type of resources as part of its state. These are identified by integer object names and are obtained from OpenGL by various creation calls. In contrast WebGL represents these resources as DOM objects. Each object is derived from the WebGLObject interface. Currently supported resources are: textures, buffers (i.e., VBOs) framebuffers, renderbuffers, shaders and programs. The WebGLRenderingContext interface has a method to create a WebGLObject subclass for each type. Data from the underlying graphics library are stored in these objects and are fully managed by them. The resources represented by these objects are guaranteed to exist as long as the object exists. Furthermore, the DOM object is guaranteed to exist as long as the author has an explicit valid reference to it OR as long as it is bound by the underlying graphics library. When none of these conditions exist the user agent can, at any point, delete the object using the equivalent of a delete call (e.g., deleteTexture). If authors wishes to control when the underlying resource is released then the delete call can be made explicitly.

4 Security

 

4.1 WebGLArrayBuffer and Uninitialized Data

Data present in a WebGLArrayBuffer can be read by the application directly by creating a WebGLArray view of the data or indirectly by via rendering and using a method such as readPixels. At creation time, a WebGLArrayBuffer must be initialized from existing user data or must be cleared to 0. Additionally, the WebGL implementation must ensure that no data outside of the valid byte range for a WebGLArrayBuffer can be accessed. If a caller attempts to access any data outside of that range, an implementation may choose to raise an exception, use the closest valid index, use 0, or any other approach that prevents it from providing access to uninitialized data.

4.2 Resource Restrictions

WebGL resources such as textures and vertex buffer objects (VBOs) must always contain initialized data, even if they were created without initial user data values. Creating a resource without initial values is commonly used to reserve space for a texture or VBO, which is then modified usingtexSubImage or bufferSubData calls. If initial data is not provided to these calls, the WebGL implementation must initialize their contents to 0. For example, this may require creating a temporary buffer of 0 values the size of a requested VBO, so that it can be initialized correctly. All other forms of loading data into a texture or VBO involve either WebGLArrayBuffers or DOM objects such as images, and are therefore already required to be initialized.

When WebGL resources are accessed by shaders through a call such as drawElements or drawArrays, the WebGL implementation must ensure that the shader cannot access either out of bounds or uninitialized data. For drawArrays, each bound VBO must be at least as large as needed to satisfy the given mode, offset, and count. For drawElements, the bound index buffer must be at least large enough to satisfy the requested mode, count, type, and offset, and the highest index in the index buffer range must be a valid index for every bound VBO.

4.3 Origin Restrictions

In order to prevent information leakage, the HTML5 canvas element has a origin-clean flag. (See HTML5, section 4.8.11.3, "Security with canvas elements".) For a WebGL context, the origin-clean flag must be set to false if any of the following actions occur:

  • The texImage2D method is called with an HTMLImageElement or HTMLVideoElement whose origin is not the same as that of the Document object that owns the canvas element.
  • The texImage2D method is called with an HTMLCanvasElement whose origin-clean flag is set to false.

Whenever the readPixels method of the 2D context of a canvas element whose origin-clean flag is set to false is called with otherwise correct arguments, the method must raise a SECURITY_ERR exception.

4.4 Supported GLSL Constructs

A WebGL implementation must only accept shaders which conform to The OpenGL ES Shading Language, Version 1.00 [GLES20GLSL], and which do not exceed the minimum functionality mandated in Sections 4 and 5 of Appendix A. In particular, a shader referencing state variables or functions that are available in other versions of GLSL (such as that found in versions of OpenGL for the desktop), must not be allowed to load.

4.5 Defense Against Denial of Service

This section is non-normative.

It is possible to create, either intentionally or unintentionally, combinations of shaders and geometry that take an undesirably long time to render. This issue is analogous to that of long-running scripts, for which user agents already have safeguards. However, long-running draw calls can cause loss of interactivity for the entire window system, not just the user agent.

In the general case it is not possible to impose limits on the structure of incoming shaders to guard against this problem. Experimentation has shown that even very strict structural limits are insufficient to prevent long rendering times, and such limits would prevent shader authors from implementing common algorithms.

User agents should implement safeguards to prevent excessively long rendering times and associated loss of interactivity. Suggested safeguards include:

  • Splitting up draw calls with large numbers of elements into smaller draw calls.
  • Timing individual draw calls and forbidding further rendering from a page if a certain timeout is exceeded.
  • Using any watchdog facilities available at the user level, graphics API level, or operating system level to limit the duration of draw calls.
  • Separating the graphics rendering of the user agent into a distinct operating system process which can be terminated and restarted without losing application state.

The supporting infrastructure at the OS and graphics API layer is expected to improve over time, which is why the exact nature of these safeguards is not specified.

5 DOM Interfaces

This section describes the interfaces and functionality added to the DOM to support runtime access to the functionality described above.

5.1 WebGLContextAttributes

The WebGLContextAttributes interface contains drawing surface attributes and is passed as the second parameter to getContext. This interface holds key/value pairs, where each key and value is a string. The keys identify the feature being set to the given value, which is typically a boolean ("true" or "false") or numeric value.

interface WebGLContextAttributes {
    [NameGetter] DOMString get(in DOMString name);
    [NameSetter, NameCreator] void set(in DOMString name, in DOMString value);
    [NameDeleter] void remove(in DOMString name);
};

5.1.1 Context creation parameters

The following list describes each key/value pair in the WebGLContextAttributes object and its use. For each key the default value is shown. If a key is present, the value is a DOMString. For keys expecting a numerica value, the string is converted to a number. For keys expecting a boolean value, the string "true" (case-insensitive) or any string which converts to a number other than 0 is considered to be true. All other values are considered false.

alpha
Default: true. If the value is true, the drawing buffer has an alpha channel for the purposes of performing OpenGL destination alpha operations and compositing with the page. If the value is false, no alpha buffer is available.
depth
Default: true. If the value is true, the drawing buffer has a depth buffer of at least 16 bits. If the value is false, no depth buffer is available.
stencil
Default: true. If the value is true, the drawing buffer has a stencil buffer of at least 8 bits. If the value is false, no stencil buffer is available.
antialias
Default: true. If the value is true and the implementation supports antialiasing the drawing buffer will perform antialiasing using its choice of technique (multisample/supersample) and quality. If the value is false or the implementation does not support antialiasing, no antialiasing is performed.
premultipliedAlpha
Default: true. If the value is true the page compositor will assume the drawing buffer contains colors with premultiplied alpha. If the value is false the page compositor will assume that colors in the drawing buffer are not premultiplied. This flag is ignored if the alpha flag is false.

5.2 WebGLObject

The WebGLObject interface is the parent interface for all GL objects.

interface WebGLObject {
};

5.3 WebGLBuffer

The WebGLBuffer interface represents an OpenGL Buffer Object. The underlying object is created as if by calling glGenBuffers , bound as if by callingglBindBuffer and destroyed as if by calling glDeleteBuffers.

interface WebGLBuffer : WebGLObject {
};

5.4 WebGLFramebuffer

The WebGLFramebuffer interface represents an OpenGL Framebuffer Object. The underlying object is created as if by calling glGenFramebuffers , bound as if by calling glBindFramebuffer and destroyed as if by calling glDeleteFramebuffers.

interface WebGLFramebuffer : WebGLObject {
};

5.5 WebGLProgram

The WebGLProgram interface represents an OpenGL Program Object. The underlying object is created as if by calling glCreateProgram , used as if by calling glUseProgram and destroyed as if by calling glDeleteProgram.

interface WebGLProgram : WebGLObject {
};

5.6 WebGLRenderbuffer

The WebGLRenderbuffer interface represents an OpenGL Renderbuffer Object. The underlying object is created as if by calling glGenRenderbuffers , bound as if by calling glBindRenderbuffer and destroyed as if by calling glDeleteRenderbuffers.

interface WebGLRenderbuffer : WebGLObject {
};

5.7 WebGLShader

The WebGLShader interface represents an OpenGL Shader Object. The underlying object is created as if by calling glCreateShader , attached to a Program as if by calling glAttachShader and destroyed as if by calling glDeleteShader.

interface WebGLShader : WebGLObject {
};

5.8 WebGLTexture

The WebGLTexture interface represents an OpenGL Texture Object. The underlying object is created as if by calling glGenTextures , bound as if by calling glBindTexture and destroyed as if by calling glDeleteTextures.

interface WebGLTexture : WebGLObject {
};

5.9 WebGLObjectArray

The WebGLObjectArray interface represents an array of WebGLObject objects.

interface WebGLObjectArray {
    readonly attribute unsigned long length;
    [IndexGetter] WebGLObject get(in unsigned long index);
};

5.10 WebGLUniformLocation

The WebGLUniformLocation interface represents the location of a uniform variable in a shader program.

interface WebGLUniformLocation {
};

5.11 WebGLActiveInfo

The WebGLActiveInfo interface represents the information returned from the getActiveAttrib and getActiveUniform calls.

interface WebGLActiveInfo {
    readonly attribute GLint size;
    readonly attribute GLenum type;
    readonly attribute DOMString name;
};

5.11.1 Attributes

The following attributes are available:

size of type GLint
The size of the requested variable.
type of type GLenum
The data type of the requested variable.
name of type DOMString
The name of the requested variable.

5.12 WebGLArrayBuffer

The WebGLArrayBuffer interface describes the buffer used to store data for the WebGLArray interface and its subclasses.

[ Constructor(in unsigned long length) ]
interface WebGLArrayBuffer {
    readonly attribute unsigned long byteLength;
};

5.12.1 Constructors

Constructor(length)
Create a new WebGLArrayBuffer of the passed length in bytes. Data in the buffer is initialized to 0.

5.12.2 Attributes

The following attributes are available:

byteLength of type unsigned long
The length of the buffer in bytes. The length is fixed when the WebGLArrayBuffer is created.

5.13 WebGLArray

The WebGLArray interface is the abstract base interface for all the typed array interfaces. Every WebGLArray subclass presents a typed view of aWebGLArrayBuffer region. Multiple WebGLArrays can reference the same or overlapping regions of a WebGLArrayBuffer.

interface WebGLArray {
    readonly attribute WebGLArrayBuffer buffer;
    readonly attribute unsigned long byteOffset;
    readonly attribute unsigned long byteLength;
    readonly attribute unsigned long length;

    WebGLArray slice(in unsigned long offset, in unsigned long length);
};

5.13.1 Attributes

The following attributes are available:

buffer of type WebGLArrayBuffer
The WebGLArrayBuffer holding the data for this array.
byteOffset of type unsigned long
The offset of this data, in bytes, from the start of this WebGLArray's WebGLArrayBuffer.
byteLength of type unsigned long
The length of this data in bytes.
length of type unsigned long
The length of this data in elements.

5.13.2 slice method

slice(offset, length)

Returns a new WebGLArray view of the WebGLArrayBuffer store for this WebGLArray, referencing the element at offset in the current view, and containing length elements.

The returned WebGLArray will be of the same underlying type as the original WebGLArray.

5.13.3 Typed WebGLArray Interfaces

WebGLArray is intended to be an abstract base interface for WebGLArrays of a specific type. There is no way to create a WebGLArray, but there are constructors defined for each of the typed interfaces. The following sections define the shared constructors and methods that each typed interface implements.

The typed WebGLArray views provide access to data using indexing, and also provide a bulk set method for replacing a sequence of data from another array. A summary of all the typed WebGLArray views is given in the following table.

TypeName Element Size
(bytes)
Type Equivalent C Type
Byte 1 8-bit signed integer signed char
UnsignedByte 1 8-bit unsigned integer unsigned char
Short 2 16-bit signed integer short
UnsignedShort 2 16-bit unsigned integer unsigned short
Int 4 32-bit signed integer int
UnsignedInt 4 32-bit unsigned integer unsigned int
Float 4 32-bit floating point float

All of the typed WebGLArray views have the following IDL template:

[
    Constructor(in unsigned long length),
    Constructor(in WebGLTypeNameArray array),
    Constructor(in sequence<type> array),
    Constructor(in WebGLArrayBuffer buffer, 
                [Optional] in unsigned long byteOffset, [Optional] in unsigned long length)
]
interface WebGLTypeNameArray : WebGLArray {
    [IndexGetter] type get(in unsigned long index);
    [IndexSetter] void set(in unsigned long index, in type value);
    void set(in WebGLTypeNameArray array, [Optional] in unsigned long offset);
    void set(in sequence<type> array, [Optional] in unsigned long offset);
};
5.13.3.1 Shared Constructors
Constructor(length)
Create a new WebGLTypeNameArray object of the given length with a new underlying WebGLArrayBuffer large enough to hold length elements of the specific type. Data in the buffer is initialized to 0.
Constructor(array)
Create a new WebGLTypeNameArray object with a new underlying WebGLArrayBuffer large enough to hold the given data, then copy the passed data into the buffer.
Constructor(buffer, byteOffset, length)

Create a new WebGLTypeNameArray object using the passed WebGLArrayBuffer for its storage. Optional byteOffset and length can be used to limit the section of the buffer referenced. The byteOffset indicates the offset in bytes from the start of the WebGLArrayBuffer, and the length is the count of elements from the offset that this WebGLByteArray will reference. If both byteOffset and length are omitted, the WebGLTypeNameArray spans the entire WebGLArrayBuffer range. If the length is omitted, the WebGLTypeNameArray extends from the given byteOffset until the end of the WebGLArrayBuffer.

The given byteOffset must be a multiple of the element size of the specific type, otherwise an exception is raised.

If a given byteOffset and length references an area beyond the end of the WebGLArrayBuffer an exception is raised.

5.13.3.2 Shared Getters and Setters
get(index)
Return the element at the given index. If the index is out of range, an exception is raised. This is an index getter function, and may be invoked via array index syntax where applicable.
set(index, value)

Sets the element at the given index to the given value. If the index is out of range, an exception is raised. This is an index setter function, and may be invoked via array index syntax where applicable.

If the given value is out of range for the type of the array, a C-style cast operation is performed to coerce the value to the valid range. No clamping or rounding is performed.

set(array, offset)

Set multiple values, reading input values from the array. The optional offset value indicates the index in the current array where values are written. If omitted, it is assumed to be 0.

If the offset plus the length of the given array is out of range for the current WebGLArray, an exception is raised.

5.13.3.3 WebGLByteArray

WebGLByteArray represents an array of 8-bit signed integer values.

WebGLByteArray has an element size of 1 byte.

[
    Constructor(in unsigned long length),
    Constructor(in WebGLByteArray array),
    Constructor(in sequence<long> array),
    Constructor(in WebGLArrayBuffer buffer, 
                [Optional] in unsigned long byteOffset, [Optional] in unsigned long length)
]
interface WebGLByteArray : WebGLArray {
    [IndexGetter] long get(in unsigned long index);
    [IndexSetter] void set(in unsigned long index, in long value);
    void set(in WebGLByteArray array, [Optional] in unsigned long offset);
    void set(in sequence<long> array, [Optional] in unsigned long offset);
};
5.13.3.4 WebGLUnsignedByteArray

WebGLUnsignedByteArray represents an array of 8-bit unsigned integer values.

WebGLUnsignedByteArray has an element size of 1 byte.

[
    Constructor(in unsigned long length),
    Constructor(in WebGLUnsignedByteArray array),
    Constructor(in sequence<unsigned long> array),
    Constructor(in WebGLArrayBuffer buffer, 
                [Optional] in unsigned long byteOffset, [Optional] in unsigned long length)
]
interface WebGLUnsignedByteArray : WebGLArray {
    [IndexGetter] unsigned long get(in unsigned long index);
    [IndexSetter] void set(in unsigned long index, in unsigned long value);
    void set(in WebGLUnsignedByteArray array, [Optional] in unsigned long offset);
    void set(in sequence<unsigned long> array, [Optional] in unsigned long offset);
};
5.13.3.5 WebGLShortArray

WebGLShortArray represents an array of 16-bit signed integer values.

WebGLShortArray has an element size of 2 bytes.

[
    Constructor(in unsigned long length),
    Constructor(in WebGLShortArray array),
    Constructor(in sequence<long> array),
    Constructor(in WebGLArrayBuffer buffer, 
                [Optional] in unsigned long byteOffset, [Optional] in unsigned long length)
]
interface WebGLShortArray : WebGLArray {
    [IndexGetter] long get(in unsigned long index);
    [IndexSetter] void set(in unsigned long index, in long value);
    void set(in WebGLShortArray array, [Optional] in unsigned long offset);
    void set(in sequence<long> array, [Optional] in unsigned long offset);
};
5.13.3.6 WebGLUnsignedShortArray

WebGLUnsignedShortArray represents an array of 16-bit unsigned integer values.

WebGLUnsignedShortArray has an element size of 2 bytes.

[
    Constructor(in unsigned long length),
    Constructor(in WebGLUnsignedShortArray array),
    Constructor(in sequence<unsigned long> array),
    Constructor(in WebGLArrayBuffer buffer, 
                [Optional] in unsigned long byteOffset, [Optional] in unsigned long length)
]
interface WebGLUnsignedShortArray : WebGLArray {
    [IndexGetter] unsigned long get(in unsigned long index);
    [IndexSetter] void set(in unsigned long index, in unsigned long value);
    void set(in WebGLUnsignedShortArray array, [Optional] in unsigned long offset);
    void set(in sequence<unsigned long> array, [Optional] in unsigned long offset);
};
5.13.3.7 WebGLIntArray

WebGLIntArray represents an array of 32-bit signed integer values.

WebGLIntArray has an element size of 4 bytes.

[
    Constructor(in unsigned long length),
    Constructor(in WebGLIntArray array),
    Constructor(in sequence<long> array),
    Constructor(in WebGLArrayBuffer buffer, 
                [Optional] in unsigned long byteOffset, [Optional] in unsigned long length)
]
interface WebGLIntArray : WebGLArray {
    [IndexGetter] long get(in unsigned long index);
    [IndexSetter] void set(in unsigned long index, in long value);
    void set(in WebGLIntArray array, [Optional] in unsigned long offset);
    void set(in sequence<long> array, [Optional] in unsigned long offset);
};
5.13.3.8 WebGLUnsignedIntArray

WebGLUnsignedIntArray represents an array of 32-bit unsigned integer values.

WebGLUnsignedIntArray has an element size of 4 bytes.

[
    Constructor(in unsigned long length),
    Constructor(in WebGLUnsignedIntArray array),
    Constructor(in sequence<unsigned long> array),
    Constructor(in WebGLArrayBuffer buffer, 
                [Optional] in unsigned long byteOffset, [Optional] in unsigned long length)
]
interface WebGLUnsignedIntArray : WebGLArray {
    [IndexGetter] unsigned long get(in unsigned long index);
    [IndexSetter] void set(in unsigned long index, in unsigned long value);
    void set(in WebGLUnsignedIntArray array, [Optional] in unsigned long offset);
    void set(in sequence<unsigned long> array, [Optional] in unsigned long offset);
};
5.13.3.9 WebGLFloatArray

WebGLFloatArray represents an array of 32-bit floating point values.

WebGLFloatArray has an element size of 4 bytes.

[
    Constructor(in unsigned long length),
    Constructor(in WebGLFloatArray array),
    Constructor(in sequence<float> array),
    Constructor(in WebGLArrayBuffer buffer, 
                [Optional] in unsigned long byteOffset, [Optional] in unsigned long length)
]
interface WebGLFloatArray : WebGLArray {
    [IndexGetter] float get(in unsigned long index);
    [IndexSetter] void set(in unsigned long index, in float value);
    void set(in WebGLFloatArray array, [Optional] in unsigned long offset);
    void set(in sequence<float> array, [Optional] in unsigned long offset);
};

5.14 The WebGL context

The WebGLRenderingContext represents the API allowing OpenGL ES 2.0 style rendering into the canvas element.

interface WebGLRenderingContext {

    typedef unsigned long  GLenum;
    typedef boolean        GLboolean;
    typedef unsigned long  GLbitfield;
    typedef long           GLint;
    typedef long           GLsizei;
    typedef long           GLsizeiptr;
    typedef unsigned long  GLuint;
    typedef float          GLfloat;
    typedef float          GLclampf;
    
    /* ClearBufferMask */
    const GLenum DEPTH_BUFFER_BIT               = 0x00000100;
    const GLenum STENCIL_BUFFER_BIT             = 0x00000400;
    const GLenum COLOR_BUFFER_BIT               = 0x00004000;
    
    /* BeginMode */
    const GLenum POINTS                         = 0x0000;
    const GLenum LINES                          = 0x0001;
    const GLenum LINE_LOOP                      = 0x0002;
    const GLenum LINE_STRIP                     = 0x0003;
    const GLenum TRIANGLES                      = 0x0004;
    const GLenum TRIANGLE_STRIP                 = 0x0005;
    const GLenum TRIANGLE_FAN                   = 0x0006;
    
    /* AlphaFunction (not supported in ES20) */
    /*      NEVER */
    /*      LESS */
    /*      EQUAL */
    /*      LEQUAL */
    /*      GREATER */
    /*      NOTEQUAL */
    /*      GEQUAL */
    /*      ALWAYS */
    
    /* BlendingFactorDest */
    const GLenum ZERO                           = 0;
    const GLenum ONE                            = 1;
    const GLenum SRC_COLOR                      = 0x0300;
    const GLenum ONE_MINUS_SRC_COLOR            = 0x0301;
    const GLenum SRC_ALPHA                      = 0x0302;
    const GLenum ONE_MINUS_SRC_ALPHA            = 0x0303;
    const GLenum DST_ALPHA                      = 0x0304;
    const GLenum ONE_MINUS_DST_ALPHA            = 0x0305;
    
    /* BlendingFactorSrc */
    /*      ZERO */
    /*      ONE */
    const GLenum DST_COLOR                      = 0x0306;
    const GLenum ONE_MINUS_DST_COLOR            = 0x0307;
    const GLenum SRC_ALPHA_SATURATE             = 0x0308;
    /*      SRC_ALPHA */
    /*      ONE_MINUS_SRC_ALPHA */
    /*      DST_ALPHA */
    /*      ONE_MINUS_DST_ALPHA */
    
    /* BlendEquationSeparate */
    const GLenum FUNC_ADD                       = 0x8006;
    const GLenum BLEND_EQUATION                 = 0x8009;
    const GLenum BLEND_EQUATION_RGB             = 0x8009;   /* same as BLEND_EQUATION */
    const GLenum BLEND_EQUATION_ALPHA           = 0x883D;
    
    /* BlendSubtract */
    const GLenum FUNC_SUBTRACT                  = 0x800A;
    const GLenum FUNC_REVERSE_SUBTRACT          = 0x800B;
    
    /* Separate Blend Functions */
    const GLenum BLEND_DST_RGB                  = 0x80C8;
    const GLenum BLEND_SRC_RGB                  = 0x80C9;
    const GLenum BLEND_DST_ALPHA                = 0x80CA;
    const GLenum BLEND_SRC_ALPHA                = 0x80CB;
    const GLenum CONSTANT_COLOR                 = 0x8001;
    const GLenum ONE_MINUS_CONSTANT_COLOR       = 0x8002;
    const GLenum CONSTANT_ALPHA                 = 0x8003;
    const GLenum ONE_MINUS_CONSTANT_ALPHA       = 0x8004;
    const GLenum BLEND_COLOR                    = 0x8005;
    
    /* Buffer Objects */
    const GLenum ARRAY_BUFFER                   = 0x8892;
    const GLenum ELEMENT_ARRAY_BUFFER           = 0x8893;
    const GLenum ARRAY_BUFFER_BINDING           = 0x8894;
    const GLenum ELEMENT_ARRAY_BUFFER_BINDING   = 0x8895;
    
    const GLenum STREAM_DRAW                    = 0x88E0;
    const GLenum STATIC_DRAW                    = 0x88E4;
    const GLenum DYNAMIC_DRAW                   = 0x88E8;
    
    const GLenum BUFFER_SIZE                    = 0x8764;
    const GLenum BUFFER_USAGE                   = 0x8765;
    
    const GLenum CURRENT_VERTEX_ATTRIB          = 0x8626;
    
    /* CullFaceMode */
    const GLenum FRONT                          = 0x0404;
    const GLenum BACK                           = 0x0405;
    const GLenum FRONT_AND_BACK                 = 0x0408;
    
    /* DepthFunction */
    /*      NEVER */
    /*      LESS */
    /*      EQUAL */
    /*      LEQUAL */
    /*      GREATER */
    /*      NOTEQUAL */
    /*      GEQUAL */
    /*      ALWAYS */
    
    /* EnableCap */
    const GLenum TEXTURE_2D                     = 0x0DE1;
    const GLenum CULL_FACE                      = 0x0B44;
    const GLenum BLEND                          = 0x0BE2;
    const GLenum DITHER                         = 0x0BD0;
    const GLenum STENCIL_TEST                   = 0x0B90;
    const GLenum DEPTH_TEST                     = 0x0B71;
    const GLenum SCISSOR_TEST                   = 0x0C11;
    const GLenum POLYGON_OFFSET_FILL            = 0x8037;
    const GLenum SAMPLE_ALPHA_TO_COVERAGE       = 0x809E;
    const GLenum SAMPLE_COVERAGE                = 0x80A0;
    
    /* ErrorCode */
    const GLenum NO_ERROR                       = 0;
    const GLenum INVALID_ENUM                   = 0x0500;
    const GLenum INVALID_VALUE                  = 0x0501;
    const GLenum INVALID_OPERATION              = 0x0502;
    const GLenum OUT_OF_MEMORY                  = 0x0505;
    
    /* FrontFaceDirection */
    const GLenum CW                             = 0x0900;
    const GLenum CCW                            = 0x0901;
    
    /* GetPName */
    const GLenum LINE_WIDTH                     = 0x0B21;
    const GLenum ALIASED_POINT_SIZE_RANGE       = 0x846D;
    const GLenum ALIASED_LINE_WIDTH_RANGE       = 0x846E;
    const GLenum CULL_FACE_MODE                 = 0x0B45;
    const GLenum FRONT_FACE                     = 0x0B46;
    const GLenum DEPTH_RANGE                    = 0x0B70;
    const GLenum DEPTH_WRITEMASK                = 0x0B72;
    const GLenum DEPTH_CLEAR_VALUE              = 0x0B73;
    const GLenum DEPTH_FUNC                     = 0x0B74;
    const GLenum STENCIL_CLEAR_VALUE            = 0x0B91;
    const GLenum STENCIL_FUNC                   = 0x0B92;
    const GLenum STENCIL_FAIL                   = 0x0B94;
    const GLenum STENCIL_PASS_DEPTH_FAIL        = 0x0B95;
    const GLenum STENCIL_PASS_DEPTH_PASS        = 0x0B96;
    const GLenum STENCIL_REF                    = 0x0B97;
    const GLenum STENCIL_VALUE_MASK             = 0x0B93;
    const GLenum STENCIL_WRITEMASK              = 0x0B98;
    const GLenum STENCIL_BACK_FUNC              = 0x8800;
    const GLenum STENCIL_BACK_FAIL              = 0x8801;
    const GLenum STENCIL_BACK_PASS_DEPTH_FAIL   = 0x8802;
    const GLenum STENCIL_BACK_PASS_DEPTH_PASS   = 0x8803;
    const GLenum STENCIL_BACK_REF               = 0x8CA3;
    const GLenum STENCIL_BACK_VALUE_MASK        = 0x8CA4;
    const GLenum STENCIL_BACK_WRITEMASK         = 0x8CA5;
    const GLenum VIEWPORT                       = 0x0BA2;
    const GLenum SCISSOR_BOX                    = 0x0C10;
    /*      SCISSOR_TEST */
    const GLenum COLOR_CLEAR_VALUE              = 0x0C22;
    const GLenum COLOR_WRITEMASK                = 0x0C23;
    const GLenum UNPACK_ALIGNMENT               = 0x0CF5;
    const GLenum PACK_ALIGNMENT                 = 0x0D05;
    const GLenum MAX_TEXTURE_SIZE               = 0x0D33;
    const GLenum MAX_VIEWPORT_DIMS              = 0x0D3A;
    const GLenum SUBPIXEL_BITS                  = 0x0D50;
    const GLenum RED_BITS                       = 0x0D52;
    const GLenum GREEN_BITS                     = 0x0D53;
    const GLenum BLUE_BITS                      = 0x0D54;
    const GLenum ALPHA_BITS                     = 0x0D55;
    const GLenum DEPTH_BITS                     = 0x0D56;
    const GLenum STENCIL_BITS                   = 0x0D57;
    const GLenum POLYGON_OFFSET_UNITS           = 0x2A00;
    /*      POLYGON_OFFSET_FILL */
    const GLenum POLYGON_OFFSET_FACTOR          = 0x8038;
    const GLenum TEXTURE_BINDING_2D             = 0x8069;
    const GLenum SAMPLE_BUFFERS                 = 0x80A8;
    const GLenum SAMPLES                        = 0x80A9;
    const GLenum SAMPLE_COVERAGE_VALUE          = 0x80AA;
    const GLenum SAMPLE_COVERAGE_INVERT         = 0x80AB;
    
    /* GetTextureParameter */
    /*      TEXTURE_MAG_FILTER */
    /*      TEXTURE_MIN_FILTER */
    /*      TEXTURE_WRAP_S */
    /*      TEXTURE_WRAP_T */
    
    const GLenum NUM_COMPRESSED_TEXTURE_FORMATS = 0x86A2;
    const GLenum COMPRESSED_TEXTURE_FORMATS     = 0x86A3;
    
    /* HintMode */
    const GLenum DONT_CARE                      = 0x1100;
    const GLenum FASTEST                        = 0x1101;
    const GLenum NICEST                         = 0x1102;
    
    /* HintTarget */
    const GLenum GENERATE_MIPMAP_HINT            = 0x8192;
    
    /* DataType */
    const GLenum BYTE                           = 0x1400;
    const GLenum UNSIGNED_BYTE                  = 0x1401;
    const GLenum SHORT                          = 0x1402;
    const GLenum UNSIGNED_SHORT                 = 0x1403;
    const GLenum INT                            = 0x1404;
    const GLenum UNSIGNED_INT                   = 0x1405;
    const GLenum FLOAT                          = 0x1406;
    
    /* PixelFormat */
    const GLenum DEPTH_COMPONENT                = 0x1902;
    const GLenum ALPHA                          = 0x1906;
    const GLenum RGB                            = 0x1907;
    const GLenum RGBA                           = 0x1908;
    const GLenum LUMINANCE                      = 0x1909;
    const GLenum LUMINANCE_ALPHA                = 0x190A;
    
    /* PixelType */
    /*      UNSIGNED_BYTE */
    const GLenum UNSIGNED_SHORT_4_4_4_4         = 0x8033;
    const GLenum UNSIGNED_SHORT_5_5_5_1         = 0x8034;
    const GLenum UNSIGNED_SHORT_5_6_5           = 0x8363;
    
    /* Shaders */
    const GLenum FRAGMENT_SHADER                  = 0x8B30;
    const GLenum VERTEX_SHADER                    = 0x8B31;
    const GLenum MAX_VERTEX_ATTRIBS               = 0x8869;
    const GLenum MAX_VERTEX_UNIFORM_VECTORS       = 0x8DFB;
    const GLenum MAX_VARYING_VECTORS              = 0x8DFC;
    const GLenum MAX_COMBINED_TEXTURE_IMAGE_UNITS = 0x8B4D;
    const GLenum MAX_VERTEX_TEXTURE_IMAGE_UNITS   = 0x8B4C;
    const GLenum MAX_TEXTURE_IMAGE_UNITS          = 0x8872;
    const GLenum MAX_FRAGMENT_UNIFORM_VECTORS     = 0x8DFD;
    const GLenum SHADER_TYPE                      = 0x8B4F;
    const GLenum DELETE_STATUS                    = 0x8B80;
    const GLenum LINK_STATUS                      = 0x8B82;
    const GLenum VALIDATE_STATUS                  = 0x8B83;
    const GLenum ATTACHED_SHADERS                 = 0x8B85;
    const GLenum ACTIVE_UNIFORMS                  = 0x8B86;
    const GLenum ACTIVE_UNIFORM_MAX_LENGTH        = 0x8B87;
    const GLenum ACTIVE_ATTRIBUTES                = 0x8B89;
    const GLenum ACTIVE_ATTRIBUTE_MAX_LENGTH      = 0x8B8A;
    const GLenum SHADING_LANGUAGE_VERSION         = 0x8B8C;
    const GLenum CURRENT_PROGRAM                  = 0x8B8D;
    
    /* StencilFunction */
    const GLenum NEVER                          = 0x0200;
    const GLenum LESS                           = 0x0201;
    const GLenum EQUAL                          = 0x0202;
    const GLenum LEQUAL                         = 0x0203;
    const GLenum GREATER                        = 0x0204;
    const GLenum NOTEQUAL                       = 0x0205;
    const GLenum GEQUAL                         = 0x0206;
    const GLenum ALWAYS                         = 0x0207;
    
    /* StencilOp */
    /*      ZERO */
    const GLenum KEEP                           = 0x1E00;
    const GLenum REPLACE                        = 0x1E01;
    const GLenum INCR                           = 0x1E02;
    const GLenum DECR                           = 0x1E03;
    const GLenum INVERT                         = 0x150A;
    const GLenum INCR_WRAP                      = 0x8507;
    const GLenum DECR_WRAP                      = 0x8508;
    
    /* StringName */
    const GLenum VENDOR                         = 0x1F00;
    const GLenum RENDERER                       = 0x1F01;
    const GLenum VERSION                        = 0x1F02;
    const GLenum EXTENSIONS                     = 0x1F03;
    
    /* TextureMagFilter */
    const GLenum NEAREST                        = 0x2600;
    const GLenum LINEAR                         = 0x2601;
    
    /* TextureMinFilter */
    /*      NEAREST */
    /*      LINEAR */
    const GLenum NEAREST_MIPMAP_NEAREST         = 0x2700;
    const GLenum LINEAR_MIPMAP_NEAREST          = 0x2701;
    const GLenum NEAREST_MIPMAP_LINEAR          = 0x2702;
    const GLenum LINEAR_MIPMAP_LINEAR           = 0x2703;
    
    /* TextureParameterName */
    const GLenum TEXTURE_MAG_FILTER             = 0x2800;
    const GLenum TEXTURE_MIN_FILTER             = 0x2801;
    const GLenum TEXTURE_WRAP_S                 = 0x2802;
    const GLenum TEXTURE_WRAP_T                 = 0x2803;
    
    /* TextureTarget */
    /*      TEXTURE_2D */
    const GLenum TEXTURE                        = 0x1702;
    
    const GLenum TEXTURE_CUBE_MAP               = 0x8513;
    const GLenum TEXTURE_BINDING_CUBE_MAP       = 0x8514;
    const GLenum TEXTURE_CUBE_MAP_POSITIVE_X    = 0x8515;
    const GLenum TEXTURE_CUBE_MAP_NEGATIVE_X    = 0x8516;
    const GLenum TEXTURE_CUBE_MAP_POSITIVE_Y    = 0x8517;
    const GLenum TEXTURE_CUBE_MAP_NEGATIVE_Y    = 0x8518;
    const GLenum TEXTURE_CUBE_MAP_POSITIVE_Z    = 0x8519;
    const GLenum TEXTURE_CUBE_MAP_NEGATIVE_Z    = 0x851A;
    const GLenum MAX_CUBE_MAP_TEXTURE_SIZE      = 0x851C;
    
    /* TextureUnit */
    const GLenum TEXTURE0                       = 0x84C0;
    const GLenum TEXTURE1                       = 0x84C1;
    const GLenum TEXTURE2                       = 0x84C2;
    const GLenum TEXTURE3                       = 0x84C3;
    const GLenum TEXTURE4                       = 0x84C4;
    const GLenum TEXTURE5                       = 0x84C5;
    const GLenum TEXTURE6                       = 0x84C6;
    const GLenum TEXTURE7                       = 0x84C7;
    const GLenum TEXTURE8                       = 0x84C8;
    const GLenum TEXTURE9                       = 0x84C9;
    const GLenum TEXTURE10                      = 0x84CA;
    const GLenum TEXTURE11                      = 0x84CB;
    const GLenum TEXTURE12                      = 0x84CC;
    const GLenum TEXTURE13                      = 0x84CD;
    const GLenum TEXTURE14                      = 0x84CE;
    const GLenum TEXTURE15                      = 0x84CF;
    const GLenum TEXTURE16                      = 0x84D0;
    const GLenum TEXTURE17                      = 0x84D1;
    const GLenum TEXTURE18                      = 0x84D2;
    const GLenum TEXTURE19                      = 0x84D3;
    const GLenum TEXTURE20                      = 0x84D4;
    const GLenum TEXTURE21                      = 0x84D5;
    const GLenum TEXTURE22                      = 0x84D6;
    const GLenum TEXTURE23                      = 0x84D7;
    const GLenum TEXTURE24                      = 0x84D8;
    const GLenum TEXTURE25                      = 0x84D9;
    const GLenum TEXTURE26                      = 0x84DA;
    const GLenum TEXTURE27                      = 0x84DB;
    const GLenum TEXTURE28                      = 0x84DC;
    const GLenum TEXTURE29                      = 0x84DD;
    const GLenum TEXTURE30                      = 0x84DE;
    const GLenum TEXTURE31                      = 0x84DF;
    const GLenum ACTIVE_TEXTURE                 = 0x84E0;
    
    /* TextureWrapMode */
    const GLenum REPEAT                         = 0x2901;
    const GLenum CLAMP_TO_EDGE                  = 0x812F;
    const GLenum MIRRORED_REPEAT                = 0x8370;
    
    /* Uniform Types */
    const GLenum FLOAT_VEC2                     = 0x8B50;
    const GLenum FLOAT_VEC3                     = 0x8B51;
    const GLenum FLOAT_VEC4                     = 0x8B52;
    const GLenum INT_VEC2                       = 0x8B53;
    const GLenum INT_VEC3                       = 0x8B54;
    const GLenum INT_VEC4                       = 0x8B55;
    const GLenum BOOL                           = 0x8B56;
    const GLenum BOOL_VEC2                      = 0x8B57;
    const GLenum BOOL_VEC3                      = 0x8B58;
    const GLenum BOOL_VEC4                      = 0x8B59;
    const GLenum FLOAT_MAT2                     = 0x8B5A;
    const GLenum FLOAT_MAT3                     = 0x8B5B;
    const GLenum FLOAT_MAT4                     = 0x8B5C;
    const GLenum SAMPLER_2D                     = 0x8B5E;
    const GLenum SAMPLER_CUBE                   = 0x8B60;
    
    /* Vertex Arrays */
    const GLenum VERTEX_ATTRIB_ARRAY_ENABLED        = 0x8622;
    const GLenum VERTEX_ATTRIB_ARRAY_SIZE           = 0x8623;
    const GLenum VERTEX_ATTRIB_ARRAY_STRIDE         = 0x8624;
    const GLenum VERTEX_ATTRIB_ARRAY_TYPE           = 0x8625;
    const GLenum VERTEX_ATTRIB_ARRAY_NORMALIZED     = 0x886A;
    const GLenum VERTEX_ATTRIB_ARRAY_POINTER        = 0x8645;
    const GLenum VERTEX_ATTRIB_ARRAY_BUFFER_BINDING = 0x889F;
    
    /* Read Format */
    const GLenum IMPLEMENTATION_COLOR_READ_TYPE   = 0x8B9A;
    const GLenum IMPLEMENTATION_COLOR_READ_FORMAT = 0x8B9B;
    
    /* Shader Source */
    const GLenum COMPILE_STATUS                 = 0x8B81;
    const GLenum INFO_LOG_LENGTH                = 0x8B84;
    const GLenum SHADER_SOURCE_LENGTH           = 0x8B88;
    const GLenum SHADER_COMPILER                = 0x8DFA;
    
    /* Shader Precision-Specified Types */
    const GLenum LOW_FLOAT                      = 0x8DF0;
    const GLenum MEDIUM_FLOAT                   = 0x8DF1;
    const GLenum HIGH_FLOAT                     = 0x8DF2;
    const GLenum LOW_INT                        = 0x8DF3;
    const GLenum MEDIUM_INT                     = 0x8DF4;
    const GLenum HIGH_INT                       = 0x8DF5;
    
    /* Framebuffer Object. */
    const GLenum FRAMEBUFFER                    = 0x8D40;
    const GLenum RENDERBUFFER                   = 0x8D41;
    
    const GLenum RGBA4                          = 0x8056;
    const GLenum RGB5_A1                        = 0x8057;
    const GLenum RGB565                         = 0x8D62;
    const GLenum DEPTH_COMPONENT16              = 0x81A5;
    const GLenum STENCIL_INDEX                  = 0x1901;
    const GLenum STENCIL_INDEX8                 = 0x8D48;
    
    const GLenum RENDERBUFFER_WIDTH             = 0x8D42;
    const GLenum RENDERBUFFER_HEIGHT            = 0x8D43;
    const GLenum RENDERBUFFER_INTERNAL_FORMAT   = 0x8D44;
    const GLenum RENDERBUFFER_RED_SIZE          = 0x8D50;
    const GLenum RENDERBUFFER_GREEN_SIZE        = 0x8D51;
    const GLenum RENDERBUFFER_BLUE_SIZE         = 0x8D52;
    const GLenum RENDERBUFFER_ALPHA_SIZE        = 0x8D53;
    const GLenum RENDERBUFFER_DEPTH_SIZE        = 0x8D54;
    const GLenum RENDERBUFFER_STENCIL_SIZE      = 0x8D55;
    
    const GLenum FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE           = 0x8CD0;
    const GLenum FRAMEBUFFER_ATTACHMENT_OBJECT_NAME           = 0x8CD1;
    const GLenum FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL         = 0x8CD2;
    const GLenum FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE = 0x8CD3;
    
    const GLenum COLOR_ATTACHMENT0              = 0x8CE0;
    const GLenum DEPTH_ATTACHMENT               = 0x8D00;
    const GLenum STENCIL_ATTACHMENT             = 0x8D20;
    
    const GLenum NONE                           = 0;
    
    const GLenum FRAMEBUFFER_COMPLETE                      = 0x8CD5;
    const GLenum FRAMEBUFFER_INCOMPLETE_ATTACHMENT         = 0x8CD6;
    const GLenum FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = 0x8CD7;
    const GLenum FRAMEBUFFER_INCOMPLETE_DIMENSIONS         = 0x8CD9;
    const GLenum FRAMEBUFFER_UNSUPPORTED                   = 0x8CDD;
    
    const GLenum FRAMEBUFFER_BINDING            = 0x8CA6;
    const GLenum RENDERBUFFER_BINDING           = 0x8CA7;
    const GLenum MAX_RENDERBUFFER_SIZE          = 0x84E8;
    
    const GLenum INVALID_FRAMEBUFFER_OPERATION  = 0x0506;
    
    readonly attribute HTMLCanvasElement canvas;

    long sizeInBytes(in GLenum type);
    WebGLContextAttributes getContextAttributes();

    void activeTexture(in GLenum texture) raises(DOMException);
    void attachShader(in WebGLProgram program, in WebGLShader shader) raises(DOMException);
    void bindAttribLocation(in WebGLProgram program, in GLuint index, in DOMString name) 
                                                                        raises(DOMException);
    void bindBuffer(in GLenum target, in WebGLBuffer buffer) raises(DOMException);
    void bindFramebuffer(in GLenum target, in WebGLFramebuffer framebuffer) 
                                                                        raises(DOMException);
    void bindRenderbuffer(in GLenum target, in WebGLRenderbuffer renderbuffer) 
                                                                        raises(DOMException);
    void bindTexture(in GLenum target, in WebGLTexture texture) raises(DOMException);
    void blendColor(in GLclampf red, in GLclampf green, in GLclampf blue, in GLclampf alpha) 
                                                                        raises(DOMException);
    void blendEquation(in GLenum mode) raises(DOMException);
    void blendEquationSeparate(in GLenum modeRGB, in GLenum modeAlpha) raises(DOMException);
    void blendFunc(in GLenum sfactor, in GLenum dfactor) raises(DOMException);
    void blendFuncSeparate(in GLenum srcRGB, in GLenum dstRGB, 
                           in GLenum srcAlpha, in GLenum dstAlpha) raises(DOMException);

    void bufferData(in GLenum target, in GLsizei size, in GLenum usage) raises(DOMException);
    void bufferData(in GLenum target, in WebGLArray data, in GLenum usage) 
                                                                        raises(DOMException);
    void bufferData(in GLenum target, in WebGLArrayBuffer data, in GLenum usage) 
                                                                        raises(DOMException);
    void bufferSubData(in GLenum target, in GLsizeiptr offset, in WebGLArray data) 
                                                                        raises(DOMException);
    void bufferSubData(in GLenum target, in GLsizeiptr offset, in WebGLArrayBuffer data) 
                                                                        raises(DOMException);

    GLenum checkFramebufferStatus(in GLenum target) raises(DOMException);
    void clear(in GLbitfield mask) raises(DOMException);
    void clearColor(in GLclampf red, in GLclampf green, in GLclampf blue, in GLclampf alpha) 
                                                                        raises(DOMException);
    void clearDepth(in GLclampf depth) raises(DOMException);
    void clearStencil(in GLint s) raises(DOMException);
    void colorMask(in GLboolean red, in GLboolean green, in GLboolean blue, in GLboolean alpha) 
                                                                        raises(DOMException);
    void compileShader(in WebGLShader shader) raises(DOMException);

    void copyTexImage2D(in GLenum target, in GLint level, in GLenum internalformat, 
                        in GLint x, in GLint y, in GLsizei width, in GLsizei height, 
                        in GLint border) raises(DOMException);
    void copyTexSubImage2D(in GLenum target, in GLint level, in GLint xoffset, in GLint yoffset, 
                           in GLint x, in GLint y, in GLsizei width, in GLsizei height) 
                                                                        raises(DOMException);

    WebGLBuffer createBuffer() raises(DOMException);
    WebGLFramebuffer createFramebuffer() raises(DOMException);
    WebGLProgram createProgram() raises(DOMException);
    WebGLRenderbuffer createRenderbuffer() raises(DOMException);
    WebGLShader createShader(in GLenum type) raises(DOMException);
    WebGLTexture createTexture() raises(DOMException);

    void cullFace(in GLenum mode) raises(DOMException);

    void deleteBuffer(in WebGLBuffer buffer) raises(DOMException);
    void deleteFramebuffer(in WebGLFramebuffer framebuffer) raises(DOMException);
    void deleteProgram(in WebGLProgram program) raises(DOMException);
    void deleteRenderbuffer(in WebGLRenderbuffer renderbuffer) raises(DOMException);
    void deleteShader(in WebGLShader shader) raises(DOMException);
    void deleteTexture(in WebGLTexture texture) raises(DOMException);

    void depthFunc(in GLenum func) raises(DOMException);
    void depthMask(in GLboolean flag) raises(DOMException);
    void depthRange(in GLclampf zNear, in GLclampf zFar) raises(DOMException);
    void detachShader(in WebGLProgram program, in WebGLShader shader) raises(DOMException);
    void disable(in GLenum cap) raises(DOMException);
    void disableVertexAttribArray(in GLuint index) raises(DOMException);
    void drawArrays(in GLenum mode, in GLint first, in GLsizei count) raises(DOMException);
    void drawElements(in GLenum mode, in GLsizei count, in GLenum type, in GLsizeiptr offset) 
                                                                        raises(DOMException);

    void enable(in GLenum cap) raises(DOMException);
    void enableVertexAttribArray(in GLuint index) raises(DOMException);
    void finish() raises(DOMException);
    void flush() raises(DOMException);
    void framebufferRenderbuffer(in GLenum target, in GLenum attachment, 
                                 in GLenum renderbuffertarget, 
                                 in WebGLRenderbuffer renderbuffer) raises(DOMException);
    void framebufferTexture2D(in GLenum target, in GLenum attachment, in GLenum textarget, 
                              in WebGLTexture texture, in GLint level) raises(DOMException);
    void frontFace(in GLenum mode) raises(DOMException);

    void generateMipmap(in GLenum target) raises(DOMException);

    WebGLActiveInfo getActiveAttrib(GLuint program, GLuint index) raises(DOMException);
    WebGLActiveInfo getActiveUniform(GLuint program, GLuint index) raises(DOMException);
    WebGLObjectArray getAttachedShaders(GLuint program) raises(DOMException);

    GLint getAttribLocation(in WebGLProgram program, DOMString name) raises(DOMException);

    any getParameter(in GLenum pname) raises(DOMException);
    any getBufferParameter(in GLenum target, in GLenum pname) raises(DOMException);

    GLenum getError() raises(DOMException);

    any getFramebufferAttachmentParameter(in GLenum target, in GLenum attachment, 
                                          in GLenum pname) raises(DOMException);
    any getProgramParameter(in WebGLProgram program, in GLenum pname) raises(DOMException);
    DOMString getProgramInfoLog(in WebGLProgram program) raises(DOMException);
    any getRenderbufferParameter(in GLenum target, in GLenum pname) raises(DOMException);
    any getShaderParameter(in WebGLShader shader, in GLenum pname) raises(DOMException);
    DOMString getShaderInfoLog(in WebGLShader shader) raises(DOMException);

    DOMString getShaderSource(in WebGLShader shader) raises(DOMException);
    DOMString getString(in GLenum name) raises(DOMException);

    any getTexParameter(in GLenum target, in GLenum pname) raises(DOMException);

    any getUniform(in WebGLProgram program, in WebGLUniformLocation location) raises(DOMException);

    WebGLUniformLocation getUniformLocation(in WebGLProgram program, DOMString name) raises(DOMException);

    any getVertexAttrib(in GLuint index, in GLenum pname) raises(DOMException);

    GLsizeiptr getVertexAttribOffset(GLuint index, GLenum pname) raises(DOMException);

    void hint(in GLenum target, in GLenum mode) raises(DOMException);
    GLboolean isBuffer(in WebGLObject buffer) raises(DOMException);
    GLboolean isEnabled(in GLenum cap) raises(DOMException);
    GLboolean isFramebuffer(in WebGLObject framebuffer) raises(DOMException);
    GLboolean isProgram(in WebGLObject program) raises(DOMException);
    GLboolean isRenderbuffer(in WebGLObject renderbuffer) raises(DOMException);
    GLboolean isShader(in WebGLObject shader) raises(DOMException);
    GLboolean isTexture(in WebGLObject texture) raises(DOMException);
    void lineWidth(in GLfloat width) raises(DOMException);
    void linkProgram(in WebGLProgram program) raises(DOMException);
    void pixelStorei(in GLenum pname, in GLint param) raises(DOMException);
    void polygonOffset(in GLfloat factor, in GLfloat units) raises(DOMException);

    WebGLArray readPixels(GLint x, GLint y, GLsizei width, GLsizei height, 
                           GLenum format, GLenum type) raises(DOMException);

    void renderbufferStorage(in GLenum target, in GLenum internalformat, 
                             in GLsizei width, in GLsizei height) raises(DOMException);
    void sampleCoverage(in GLclampf value, in GLboolean invert) raises(DOMException);
    void scissor(in GLint x, in GLint y, in GLsizei width, in GLsizei height) 
                                                                        raises(DOMException);

    void shaderSource(in WebGLShader shader, in DOMString source) raises(DOMException);

    void stencilFunc(in GLenum func, in GLint ref, in GLuint mask) raises(DOMException);
    void stencilFuncSeparate(in GLenum face, in GLenum func, in GLint ref, in GLuint mask) 
                                                                        raises(DOMException);
    void stencilMask(in GLuint mask) raises(DOMException);
    void stencilMaskSeparate(in GLenum face, in GLuint mask) raises(DOMException);
    void stencilOp(in GLenum fail, in GLenum zfail, in GLenum zpass) raises(DOMException);
    void stencilOpSeparate(in GLenum face, in GLenum fail, in GLenum zfail, in GLenum zpass) 
                                                                        raises(DOMException);

    void texImage2D(in GLenum target, in GLint level, in GLenum internalformat, 
                    in GLsizei width, in GLsizei height, in GLint border, in GLenum format, 
                    in GLenum type, in WebGLArray pixels) raises(DOMException);
    void texImage2D(in GLenum target, in GLint level, in ImageData pixels,
                    [Optional] in GLboolean flipY, [Optional] in GLboolean asPremultipliedAlpha) 
                                                                        raises(DOMException);
    void texImage2D(in GLenum target, in GLint level, in HTMLImageElement image,
                    [Optional] in GLboolean flipY, [Optional] in GLboolean asPremultipliedAlpha) 
                                                                        raises(DOMException);
    void texImage2D(in GLenum target, in GLint level, in HTMLCanvasElement image,
                    [Optional] in GLboolean flipY, [Optional] in GLboolean asPremultipliedAlpha) 
                                                                        raises(DOMException);
    void texImage2D(in GLenum target, in GLint level, in HTMLVideoElement image,
                    [Optional] in GLboolean flipY, [Optional] in GLboolean asPremultipliedAlpha) 
                                                                        raises(DOMException);

    void texParameterf(in GLenum target, in GLenum pname, in GLfloat param) 
                                                                        raises(DOMException);
    void texParameteri(in GLenum target, in GLenum pname, in GLint param) raises(DOMException);

    void texSubImage2D(in GLenum target, in GLint level, in GLint xoffset, in GLint yoffset, 
                       in GLsizei width, in GLsizei height, 
                       in GLenum format, in GLenum type, in WebGLArray pixels) 
                                                                        raises(DOMException);
    void texSubImage2D(in GLenum target, in GLint level, in GLint xoffset, in GLint yoffset, 
                       in ImageData pixels,
                       [Optional] in GLboolean flipY, [Optional] in GLboolean asPremultipliedAlpha)
                                                                        raises(DOMException);
    void texSubImage2D(in GLenum target, in GLint level, in GLint xoffset, in GLint yoffset, 
                       in HTMLImageElement image,
                       [Optional] in GLboolean flipY, [Optional] in GLboolean asPremultipliedAlpha) 
                                                                        raises(DOMException);
    void texSubImage2D(in GLenum target, in GLint level, in GLint xoffset, in GLint yoffset, 
                       in HTMLCanvasElement image,
                       [Optional] in GLboolean flipY, [Optional] in GLboolean asPremultipliedAlpha) 
                                                                        raises(DOMException);
    void texSubImage2D(in GLenum target, in GLint level, in GLint xoffset, in GLint yoffset, 
                       in HTMLVideoElement image,
                       [Optional] in GLboolean flipY, [Optional] in GLboolean asPremultipliedAlpha) 
                                                                        raises(DOMException);

    void uniform1f(in WebGLUniformLocation location, in GLfloat x) raises(DOMException);
    void uniform1fv(in WebGLUniformLocation location, in WebGLFloatArray v) raises(DOMException);
    void uniform1fv(in WebGLUniformLocation location, in sequence<float> v) raises(DOMException);
    void uniform1i(in WebGLUniformLocation location, in GLint x) raises(DOMException);
    void uniform1iv(in WebGLUniformLocation location, in WebGLIntArray v) raises(DOMException);
    void uniform1iv(in WebGLUniformLocation location, in sequence<long> v) raises(DOMException);
    void uniform2f(in WebGLUniformLocation location, in GLfloat x, in GLfloat y) raises(DOMException);
    void uniform2fv(in WebGLUniformLocation location, in WebGLFloatArray v) raises(DOMException);
    void uniform2fv(in WebGLUniformLocation location, in sequence<float> v) raises(DOMException);
    void uniform2i(in WebGLUniformLocation location, in GLint x, in GLint y) raises(DOMException);
    void uniform2iv(in WebGLUniformLocation location, in WebGLIntArray v) raises(DOMException);
    void uniform2iv(in WebGLUniformLocation location, in sequence<long> v) raises(DOMException);
    void uniform3f(in WebGLUniformLocation location, in GLfloat x, in GLfloat y, in GLfloat z) 
                                                                        raises(DOMException);
    void uniform3fv(in WebGLUniformLocation location, in WebGLFloatArray v) raises(DOMException);
    void uniform3fv(in WebGLUniformLocation location, in sequence<float> v) raises(DOMException);
    void uniform3i(in WebGLUniformLocation location, in GLint x, in GLint y, in GLint z) raises(DOMException);
    void uniform3iv(in WebGLUniformLocation location, in WebGLIntArray v) raises(DOMException);
    void uniform3iv(in WebGLUniformLocation location, in sequence<long> v) raises(DOMException);
    void uniform4f(in WebGLUniformLocation location, in GLfloat x, in GLfloat y, in GLfloat z, in GLfloat w) 
                                                                        raises(DOMException);
    void uniform4fv(in WebGLUniformLocation location, in WebGLFloatArray v) raises(DOMException);
    void uniform4fv(in WebGLUniformLocation location, in sequence<float> v) raises(DOMException);
    void uniform4i(in WebGLUniformLocation location, in GLint x, in GLint y, in GLint z, in GLint w) 
                                                                        raises(DOMException);
    void uniform4iv(in WebGLUniformLocation location, in WebGLIntArray v) raises(DOMException);
    void uniform4iv(in WebGLUniformLocation location, in sequence<long> v) raises(DOMException);

    void uniformMatrix2fv(in WebGLUniformLocation location, in GLboolean transpose, 
                          in WebGLFloatArray value) raises(DOMException);
    void uniformMatrix2fv(in WebGLUniformLocation location, in GLboolean transpose, 
                          in sequence<float> value) raises(DOMException);
    void uniformMatrix3fv(in WebGLUniformLocation location, in GLboolean transpose, 
                          in WebGLFloatArray value) raises(DOMException);
    void uniformMatrix3fv(in WebGLUniformLocation location, in GLboolean transpose, 
                          in sequence<float> value) raises(DOMException);
    void uniformMatrix4fv(in WebGLUniformLocation location, in GLboolean transpose, 
                          in WebGLFloatArray value) raises(DOMException);
    void uniformMatrix4fv(in WebGLUniformLocation location, in GLboolean transpose, 
                          in sequence<float> value) raises(DOMException);

    void useProgram(in WebGLProgram program) raises(DOMException);
    void validateProgram(in WebGLProgram program) raises(DOMException);

    void vertexAttrib1f(in GLuint indx, in GLfloat x) raises(DOMException);
    void vertexAttrib1fv(in GLuint indx, in WebGLFloatArray values) raises(DOMException);
    void vertexAttrib1fv(in GLuint indx, in sequence<float> values) raises(DOMException);
    void vertexAttrib2f(in GLuint indx, in GLfloat x, in GLfloat y) raises(DOMException);
    void vertexAttrib2fv(in GLuint indx, in WebGLFloatArray values) raises(DOMException);
    void vertexAttrib2fv(in GLuint indx, in sequence<float> values) raises(DOMException);
    void vertexAttrib3f(in GLuint indx, in GLfloat x, in GLfloat y, in GLfloat z) 
                                                                        raises(DOMException);
    void vertexAttrib3fv(in GLuint indx, in WebGLFloatArray values) raises(DOMException);
    void vertexAttrib3fv(in GLuint indx, in sequence<float> values) raises(DOMException);
    void vertexAttrib4f(in GLuint indx, in GLfloat x, in GLfloat y, in GLfloat z, in GLfloat w) 
                                                                        raises(DOMException);
    void vertexAttrib4fv(in GLuint indx, in WebGLFloatArray values) raises(DOMException);
    void vertexAttrib4fv(in GLuint indx, in sequence<float> values) raises(DOMException);
    void vertexAttribPointer(in GLuint indx, in GLint size, in GLenum type, 
                             in GLboolean normalized, GLsizei stride, GLsizeiptr offset) 
                                                                        raises(DOMException);

    void viewport(in GLint x, in GLint y, in GLsizei width, in GLsizei height) 
                                                                        raises(DOMException);
};

5.14.1 Attributes

The following attributes are available:

canvas of type HTMLCanvasElement
A reference to the canvas element which created this context.

5.14.2 The sizeInBytes method

sizeInBytes()
Returns the number of bytes used to represent the passed GL data type on the current platform.

5.14.3 The getContextAttributes method

getContextAttributes()
Returns the WebGLContextAttributes desribing the current drawing buffer.

5.14.4 Setting and getting state

OpenGL ES 2.0 maintains state values for use in rendering. All the calls in this group behave identically to their OpenGL counterparts unless otherwise noted.

activeTexture(texture) (OpenGL ES 2.0 man page)
blendColor(red, green, blue, alpha) (OpenGL ES 2.0 man page)
blendEquation(mode) (OpenGL ES 2.0 man page)
blendEquationSeparate(modeRGB, modeAlpha) (OpenGL ES 2.0 man page)
blendFunc(sfactor, dfactor) (OpenGL ES 2.0 man page)
blendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha) (OpenGL ES 2.0 man page)
clearColor(red, green, blue, alpha) (OpenGL ES 2.0 man page)
clearDepth(depth) (OpenGL ES 2.0 man page)
depth value is clamped to the range 0 to 1.
clearStencil(s) (OpenGL ES 2.0 man page)
colorMask(red, green, blue, alpha) (OpenGL ES 2.0 man page)
cullFace(mode) (OpenGL ES 2.0 man page)
depthFunc(func) (OpenGL ES 2.0 man page)
depthMask(flag) (OpenGL ES 2.0 man page)
depthRange(zNear, zFar) (OpenGL ES 2.0 man page)
zNear and zFar values are clamped to the range 0 to 1.
disable(cap) (OpenGL ES 2.0 man page)
enable(cap) (OpenGL ES 2.0 man page)
frontFace(mode) (OpenGL ES 2.0 man page)
getParameter(pname) (OpenGL ES 2.0 man page)
Return the value for the passed pname. The type returned is the natural type for the requested pname, as given in the following table:

pname returned type
ACTIVE_TEXTURE unsigned long
ALIASED_LINE_WIDTH_RANGE WebGLFloatArray (with 2 elements)
ALIASED_POINT_SIZE_RANGE WebGLFloatArray (with 2 elements)
ALPHA_BITS long
ARRAY_BUFFER_BINDING WebGLBuffer
BLEND boolean
BLEND_COLOR WebGLFloatArray (with 4 values)
BLEND_DST_ALPHA unsigned long
BLEND_DST_RGB unsigned long
BLEND_EQUATION_ALPHA unsigned long
BLEND_EQUATION_RGB unsigned long
BLEND_SRC_ALPHA unsigned long
BLEND_SRC_RGB unsigned long
BLUE_BITS long
COLOR_CLEAR_VALUE WebGLFloatArray (with 4 values)
COLOR_WRITEMASK WebGLUnsignedByteArray (with 4 values)
COMPRESSED_TEXTURE_FORMATS null
CULL_FACE boolean
CULL_FACE_MODE unsigned long
CURRENT_PROGRAM WebGLProgram
DEPTH_BITS long
DEPTH_CLEAR_VALUE float
DEPTH_FUNC unsigned long
DEPTH_RANGE WebGLFloatArray (with 2 elements)
DEPTH_TEST boolean
DEPTH_WRITEMASK boolean
DITHER boolean
ELEMENT_ARRAY_BUFFER_BINDING WebGLBuffer
FRAMEBUFFER_BINDING WebGLFramebuffer
FRONT_FACE unsigned long
GENERATE_MIPMAP_HINT unsigned long
GREEN_BITS long
LINE_WIDTH float
MAX_COMBINED_TEXTURE_IMAGE_UNITS long
MAX_CUBE_MAP_TEXTURE_SIZE long
MAX_FRAGMENT_UNIFORM_VECTORS long
MAX_RENDERBUFFER_SIZE long
MAX_TEXTURE_IMAGE_UNITS long
MAX_TEXTURE_SIZE long
MAX_VARYING_VECTORS long
MAX_VERTEX_ATTRIBS long
MAX_VERTEX_TEXTURE_IMAGE_UNITS long
MAX_VERTEX_UNIFORM_VECTORS long
MAX_VIEWPORT_DIMS WebGLIntArray (with 2 elements)
NUM_COMPRESSED_TEXTURE_FORMATS long
PACK_ALIGNMENT long
POLYGON_OFFSET_FACTOR float
POLYGON_OFFSET_FILL boolean
POLYGON_OFFSET_UNITS float
RED_BITS long
RENDERBUFFER_BINDING WebGLRenderbuffer
SAMPLE_BUFFERS long
SAMPLE_COVERAGE_INVERT boolean
SAMPLE_COVERAGE_VALUE float
SAMPLES long
SCISSOR_BOX WebGLIntArray (with 4 elements)
SCISSOR_TEST boolean
STENCIL_BACK_FAIL unsigned long
STENCIL_BACK_FUNC unsigned long
STENCIL_BACK_PASS_DEPTH_FAIL unsigned long
STENCIL_BACK_PASS_DEPTH_PASS unsigned long
STENCIL_BACK_REF long
STENCIL_BACK_VALUE_MASK unsigned long
STENCIL_BACK_WRITEMASK unsigned long
STENCIL_BITS long
STENCIL_CLEAR_VALUE long
STENCIL_FAIL unsigned long
STENCIL_FUNC unsigned long
STENCIL_PASS_DEPTH_FAIL unsigned long
STENCIL_PASS_DEPTH_PASS unsigned long
STENCIL_REF long
STENCIL_TEST boolean
STENCIL_VALUE_MASK unsigned long
STENCIL_WRITEMASK unsigned long
SUBPIXEL_BITS long
TEXTURE_BINDING_2D WebGLTexture
TEXTURE_BINDING_CUBE_MAP WebGLTexture
UNPACK_ALIGNMENT int
VIEWPORT WebGLIntArray (with 4 elements)
getError() (OpenGL ES 2.0 man page)
getString(name) (OpenGL ES 2.0 man page)
hint(target, mode) (OpenGL ES 2.0 man page)
isEnabled(cap) (OpenGL ES 2.0 man page)
lineWidth(width) (OpenGL ES 2.0 man page)
pixelStorei(pname, param) (OpenGL ES 2.0 man page)
polygonOffset(factor, units) (OpenGL ES 2.0 man page)
sampleCoverage(value, invert) (OpenGL ES 2.0 man page)
stencilFunc(func, ref, mask) (OpenGL ES 2.0 man page)
stencilFuncSeparate(face, func, ref, mask) (OpenGL ES 2.0 man page)
stencilMask(mask) (OpenGL ES 2.0 man page)
stencilMaskSeparate(face, mask) (OpenGL ES 2.0 man page)
stencilOp(fail, zfail, zpass) (OpenGL ES 2.0 man page)
stencilOpSeparate(face, fail, zfail, zpass) (OpenGL ES 2.0 man page)

5.14.5 Viewing and clipping

The viewport specifies the affine transformation of x and y from normalized device coordinates to window coordinates. The size of the drawing buffer is determined by the HTMLCanvasElement. The scissor box defines a rectangle which constrains drawing. When the scissor test is enabled only pixels that lie within the scissor box can be modified by drawing commands. When enabled drawing can only occur inside the intersection of the viewport, canvas area and the scissor box. When the scissor test is not enabled drawing can only occur inside the intersection of the viewport and canvas area.

scissor(x, y, width, height) (OpenGL ES 2.0 man page)
viewport(x, y, width, height) (OpenGL ES 2.0 man page)

5.14.6 Buffer objects

Buffer objects (sometimes referred to as VBOs) hold vertex attribute data for the GLSL shaders.

bindBuffer(target, buffer) (OpenGL ES 2.0 man page)
bufferData(target, size, usage) (OpenGL ES 2.0 man page)
Set the size of the currently bound WebGLBuffer object for the passed target. The buffer is initialized to 0.
bufferData(target, data, usage) (OpenGL ES 2.0 man page)
Set the size of the currently bound WebGLBuffer object for the passed target to the size of the passed data, then write the contents of data to the buffer object.
bufferSubData(target, offset, data) (OpenGL ES 2.0 man page)
For the WebGLBuffer object bound to the passed target write the passed data starting at the passed offset. If the data would be written past the end of the buffer object an INVALID_VALUE error is raised.
createBuffer() (OpenGL ES 2.0 man page)
Create a WebGLBuffer object and initialize it with a buffer object name as if by calling glGenBuffers.
deleteBuffer(buffer) (OpenGL ES 2.0 man page)
Delete the buffer object contained in the passed WebGLBuffer as if by calling glDeleteBuffers. If the buffer has already been deleted the call has no effect. Note that the buffer object will be deleted when the WebGLBuffer object is destroyed. This method merely gives the author greater control over when the buffer object is destroyed.
getBufferParameter(target, pname) (OpenGL ES 2.0 man page)
Return the value for the passed pname. The type returned is the natural type for the requested pname, as given in the following table:

pname returned type
BUFFER_SIZE long
BUFFER_USAGE unsigned long
isBuffer(buffer) (OpenGL ES 2.0 man page)

5.14.7 Framebuffer objects

Framebuffer objects provide an alternative rendering target to the drawing buffer. They are a collection of color, alpha, depth and stencil buffers and are often used to render an image that will later be used as a texture.

bindFramebuffer(target, buffer) (OpenGL ES 2.0 man page)
checkFramebufferStatus(target) (OpenGL ES 2.0 man page)
createFramebuffer() (OpenGL ES 2.0 man page)
Create a WebGLFramebuffer object and initialize it with a framebuffer object name as if by calling glGenFramebuffers.
deleteFramebuffer(buffer) (OpenGL ES 2.0 man page)
Delete the framebuffer object contained in the passed WebGLFramebuffer as if by calling glDeleteFramebuffers. If the framebuffer has already been deleted the call has no effect. Note that the framebuffer object will be deleted when the WebGLFramebuffer object is destroyed. This method merely gives the author greater control over when the framebuffer object is destroyed.
framebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer) (OpenGL ES 2.0 man page)
framebufferTexture2D(target, attachment, textarget, texture, level) (OpenGL ES 2.0 man page)
getFramebufferAttachmentParameter(target, attachment, pname) (OpenGL ES 2.0 man page)
Return the value for the passed pname given the passed target and attachment. The type returned is the natural type for the requested pname, as given in the following table:

pname returned type
FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE unsigned long
FRAMEBUFFER_ATTACHMENT_OBJECT_NAME WebGLRenderbuffer or WebGLTexture
FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL long
FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE long
isFramebuffer(buffer) (OpenGL ES 2.0 man page)
Return true if the passed WebGLObject is a WebGLFramebuffer and false otherwise.

5.14.8 Renderbuffer objects

Renderbuffer objects are used to provide storage for the individual buffers used in a framebuffer object.

bindRenderbuffer(target, buffer) (OpenGL ES 2.0 man page)
createRenderbuffer() (OpenGL ES 2.0 man page)
Create a WebGLRenderbuffer object and initialize it with a renderbuffer object name as if by calling glGenRenderbuffers.
deleteRenderbuffer(buffer) (OpenGL ES 2.0 man page)
Delete the renderbuffer object contained in the passed WebGLRenderbuffer as if by calling glDeleteRenderbuffers. If the renderbuffer has already been deleted the call has no effect. Note that the renderbuffer object will be deleted when the WebGLRenderbuffer object is destroyed. This method merely gives the author greater control over when the renderbuffer object is destroyed.
getRenderbufferParameter(target, pname) (OpenGL ES 2.0 man page)
Return the value for the passed pname given the passed target. The type returned is the natural type for the requested pname, as given in the following table:

pname returned type
RENDERBUFFER_WIDTH long
RENDERBUFFER_HEIGHT long
RENDERBUFFER_INTERNAL_FORMAT unsigned long
RENDERBUFFER_RED_SIZE long
RENDERBUFFER_GREEN_SIZE long
RENDERBUFFER_BLUE_SIZE long
RENDERBUFFER_ALPHA_SIZE long
RENDERBUFFER_DEPTH_SIZE long
RENDERBUFFER_STENCIL_SIZE long
isRenderbuffer(buffer) (OpenGL ES 2.0 man page)
Return true if the passed WebGLObject is a WebGLRenderbuffer and false otherwise.
renderbufferStorage(target, internalformat, width, height) (OpenGL ES 2.0 man page)

5.14.9 Texture objects

Texture objects provide storage and state for texturing operations. If no WebGLTexture is bound (e.g., passing null or 0 to bindTexture) then attempts to modify the texture object shall raise an INVALID_OPERATION error. This is indicated in the functions below.

bindTexture(target, texture) (OpenGL ES 2.0 man page)
copyTexImage2D(target, level, internalformat, x, y, width, height, border) (OpenGL ES 2.0 man page)
If an attempt is made to call this function with no WebGLTexture bound (see above), an INVALID_OPERATION error is raised.
copyTexSubImage2D(target, level, xoffset, yoffset, internalformat, x, y, width, height) (OpenGL ES 2.0 man page)
If an attempt is made to call this function with no WebGLTexture bound (see above), an INVALID_OPERATION error is raised.
createTexture() (OpenGL ES 2.0 man page)
Create a WebGLTexture object and initialize it with a texture object name as if by calling glGenTextures.
deleteTexture(texture) (OpenGL ES 2.0 man page)
Delete the texture object contained in the passed WebGLTexture as if by calling glDeleteTextures. If the texture has already been deleted the call has no effect. Note that the texture object will be deleted when the WebGLTexture object is destroyed. This method merely gives the author greater control over when the texture object is destroyed.
generateMipmap(target) (OpenGL ES 2.0 man page)
If an attempt is made to call this function with no WebGLTexture bound (see above), an INVALID_OPERATION error is raised.
getTexParameter(target, pname) (OpenGL ES 2.0 man page)
Return the value for the passed pname given the passed target. The type returned is the natural type for the requested pname, as given in the following table:

pname returned type
TEXTURE_MAG_FILTER unsigned long
TEXTURE_MIN_FILTER unsigned long
TEXTURE_WRAP_S unsigned long
TEXTURE_WRAP_T unsigned long
isTexture(buffer) (OpenGL ES 2.0 man page)
Return true if the passed WebGLObject is a WebGLTexture and false otherwise.
texImage2D(target, level, internalformat, width, height, border, format, type, pixels) (OpenGL ES 2.0 man page)
If the passed pixels value is null a buffer of sufficient size initialized to 0 is passed. If an attempt is made to call this function with no WebGLTexture bound (see above), an INVALID_OPERATION error is raised.
texImage2D(target, level, image, flipY, asPremultipliedAlpha) (OpenGL ES 2.0 man page)
If the flipY parameter is false, the upper left pixel of the passed image is sent first and then transfer proceeds across and then down the image. If the flipY parameter is true, the lower left pixel of the passed image is sent first and then transfer proceeds across and then up the image. If an attempt is made to call this function with no WebGLTexture bound (see above), an INVALID_OPERATION error is raised.
texParameterf(target, pname, param) (OpenGL ES 2.0 man page)
If an attempt is made to call this function with no WebGLTexture bound (see above), an INVALID_OPERATION error is raised.
texParameteri(target, pname, param) (OpenGL ES 2.0 man page)
If an attempt is made to call this function with no WebGLTexture bound (see above), an INVALID_OPERATION error is raised.
texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels) (OpenGL ES 2.0 man page)
If an attempt is made to call this function with no WebGLTexture bound (see above), an INVALID_OPERATION error is raised.
texSubImage2D(target, level, xoffset, yoffset, image, flipY, asPremultipliedAlpha) (OpenGL ES 2.0 man page)
If the flipY parameter is false, the upper left pixel of the passed image is sent first and then transfer proceeds across and then down the image. If the flipY parameter is true, the lower left pixel of the passed image is sent first and then transfer proceeds across and then up the image. If an attempt is made to call this function with no WebGLTexture bound (see above), an INVALID_OPERATION error is raised.

5.14.10 Programs and Shaders

Rendering with OpenGL ES 2.0 requires the use of shaders, written in OpenGL's shading language, GLSL. Shaders must be loaded with a source string (shaderSource), compiled (compileShader) and attached to a program (attachShader) which must be linked (linkProgram) and then used (useProgram).

attachShader(program, shader) (OpenGL ES 2.0 man page)
bindAttribLocation(program, index, name) (OpenGL ES 2.0 man page)
compileShader(shader) (OpenGL ES 2.0 man page)
createProgram() (OpenGL ES 2.0 man page)
Create a WebGLProgram object and initialize it with a program object name as if by calling glCreateProgram.
createShader(type) (OpenGL ES 2.0 man page)
Create a WebGLShader object and initialize it with a shader object name as if by calling glCreateShader.
deleteProgram(program) (OpenGL ES 2.0 man page)
Delete the program object contained in the passed WebGLProgram as if by calling glDeleteProgram. If the program has already been deleted the call has no effect. Note that the program object will be deleted when the WebGLProgram object is destroyed. This method merely gives the author greater control over when the program object is destroyed.
deleteShader(shader) (OpenGL ES 2.0 man page)
Delete the shader object contained in the passed WebGLShader as if by calling glDeleteShader. If the shader has already been deleted the call has no effect. Note that the shader object will be deleted when the WebGLShader object is destroyed. This method merely gives the author greater control over when the shader object is destroyed.
detachShader(program, shader) (OpenGL ES 2.0 man page)
getAttachedShaders(program) (OpenGL ES 2.0 man page)
Return the list of shaders attached to the passed program.
getProgramParameter(program, pname) (OpenGL ES 2.0 man page)
Return the value for the passed pname given the passed program. The type returned is the natural type for the requested pname, as given in the following table:

pname returned type
DELETE_STATUS boolean
LINK_STATUS boolean
VALIDATE_STATUS boolean
INFO_LOG_LENGTH long
ATTACHED_SHADERS long
ACTIVE_ATTRIBUTES long
ACTIVE_ATTRIBUTE_MAX_LENGTH long
ACTIVE_UNIFORMS long
ACTIVE_UNIFORM_MAX_LENGTH long
getProgramInfoLog(program) (OpenGL ES 2.0 man page)
getShaderParameter(shader, pname) (OpenGL ES 2.0 man page)
Return the value for the passed pname given the passed shader. The type returned is the natural type for the requested pname, as given in the following table:

pname returned type
SHADER_TYPE unsigned long
DELETE_STATUS boolean
COMPILE_STATUS boolean
INFO_LOG_LENGTH long
SHADER_SOURCE_LENGTH long
getShaderInfoLog(program) (OpenGL ES 2.0 man page)
getShaderSource(shader) (OpenGL ES 2.0 man page)
isProgram(program) (OpenGL ES 2.0 man page)
Return true if the passed WebGLObject is a WebGLProgram and false otherwise.
isShader(shader) (OpenGL ES 2.0 man page)
Return true if the passed WebGLObject is a WebGLShader and false otherwise.
linkProgram(program) (OpenGL ES 2.0 man page)
shaderSource(shader, source) (OpenGL ES 2.0 man page)
useProgram(program) (OpenGL ES 2.0 man page)
validateProgram(program) (OpenGL ES 2.0 man page)

5.14.11 Uniforms and attributes

Values used by the shaders are passed in as uniform of vertex attributes.

disableVertexAttribArray(index) (OpenGL ES 2.0 man page)
enableVertexAttribArray(index) (OpenGL ES 2.0 man page)
getActiveAttrib(program, index) (OpenGL ES 2.0 man page)
Returns information about the size, type and name of the vertex attribute at the passed index of the passed program object.
getActiveUniform(program, index) (OpenGL ES 2.0 man page)
Returns information about the size, type and name of the uniform at the passed index of the passed program object.
getAttribLocation(program, name) (OpenGL ES 2.0 man page)
getUniform(program, location) (OpenGL ES 2.0 man page)
Return the uniform value at the passed location in the passed program. The type returned is dependent on the uniform type, as shown in the following table:

uniform type returned type
boolean boolean
int long
float float
vec2 WebGLFloatArray (with 2 elements)
ivec2 WebGLIntArray (with 2 elements)
bvec2 WebGLUnsignedByteArray (with 2 elements)
vec3 WebGLFloatArray (with 3 elements)
ivec3 WebGLIntArray (with 3 elements)
bvec3 WebGLUnsignedByteArray (with 3 elements)
vec4 WebGLFloatArray (with 4 elements)
ivec4 WebGLIntArray (with 4 elements)
bvec4 WebGLUnsignedByteArray (with 4 elements)
mat2 WebGLFloatArray (with 4 elements)
mat3 WebGLFloatArray (with 9 elements)
mat4 WebGLFloatArray (with 16 elements)
getUniformLocation(program, name) (OpenGL ES 2.0 man page)
getVertexAttrib(index, pname) (OpenGL ES 2.0 man page)
Return the information requested in pname about the vertex attribute at the passed index. The type returned is dependent on the information requested, as shown in the following table:

pname returned type
VERTEX_ATTRIB_ARRAY_BUFFER_BINDING WebGLBuffer
VERTEX_ATTRIB_ARRAY_ENABLED boolean
VERTEX_ATTRIB_ARRAY_SIZE long
VERTEX_ATTRIB_ARRAY_STRIDE long
VERTEX_ATTRIB_ARRAY_TYPE unsigned long
VERTEX_ATTRIB_ARRAY_NORMALIZED boolean
CURRENT_VERTEX_ATTRIB WebGLFloatArray (with 4 elements)
getVertexAttribOffset(index, pname) (OpenGL ES 2.0 man page)
uniform1f(location, x) (OpenGL ES 2.0 man page)
uniform1fv(location, v) (OpenGL ES 2.0 man page)
uniform1i(location, x) (OpenGL ES 2.0 man page)
uniform1iv(location, v) (OpenGL ES 2.0 man page)
uniform2f(location, x, y) (OpenGL ES 2.0 man page)
uniform2fv(location, v) (OpenGL ES 2.0 man page)
uniform2i(location, x, y) (OpenGL ES 2.0 man page)
uniform2iv(location, v) (OpenGL ES 2.0 man page)
uniform3f(location, x, y, z) (OpenGL ES 2.0 man page)
uniform3fv(location, v) (OpenGL ES 2.0 man page)
uniform3i(location, x, y, z) (OpenGL ES 2.0 man page)
uniform3iv(location, v) (OpenGL ES 2.0 man page)
uniform4f(location, x, y, z, w) (OpenGL ES 2.0 man page)
uniform4fv(location, v) (OpenGL ES 2.0 man page)
uniform4i(location, x, y, z, w) (OpenGL ES 2.0 man page)
uniform4iv(location, v) (OpenGL ES 2.0 man page)
uniformMatrix2fv(location, transpose, value) (OpenGL ES 2.0 man page)
uniformMatrix3fv(location, transpose, value) (OpenGL ES 2.0 man page)
uniformMatrix4fv(location, transpose, value) (OpenGL ES 2.0 man page)
Each of the uniform* functions above sets the specified uniform or uniforms to the values provided. The passed location must have been obtained from the currently used program via an earlier call to getUniformLocation, or an INVALID_VALUE error will be raised.
vertexAttrib1f(index, x) (OpenGL ES 2.0 man page)
vertexAttrib1fv(index, v) (OpenGL ES 2.0 man page)
vertexAttrib2f(index, x) (OpenGL ES 2.0 man page)
vertexAttrib2fv(index, v) (OpenGL ES 2.0 man page)
vertexAttrib3f(index, x) (OpenGL ES 2.0 man page)
vertexAttrib3fv(index, v) (OpenGL ES 2.0 man page)
vertexAttrib4f(index, x) (OpenGL ES 2.0 man page)
vertexAttrib4fv(index, v) (OpenGL ES 2.0 man page)
vertexAttribPointer(index, size, type, normalized, stride, offset) (OpenGL ES 2.0 man page)
Assign the currently bound WebGLBuffer object to the passed vertex attrib index. Size is number of components per attribute. Stride and offset are in units of bytes. Passed stride and offset must be appropriate for the passed type and size or an INVALID_VALUE error will be raised.

5.14.12 Writing to the drawing buffer

OpenGL ES 2.0 has 3 calls which can render to the drawing buffer: cleardrawArrays and drawElements. Furthermore rendering can be directed to the drawing buffer or to a Framebuffer object. When rendering is directed to the drawing buffer, making any of the 3 rendering calls shall cause the drawing buffer to be presented to the HTML page compositor at the start of the next compositing operation.

clear(mask) (OpenGL ES 2.0 man page)
drawArrays(mode, first, count) (OpenGL ES 2.0 man page)
drawElements(mode, count, type, offset) (OpenGL ES 2.0 man page)
Draw using the currently bound index array. The given offset is in bytes, and must be a valid multiple of the size of the given type or an INVALID_VALUE error will be raised.
finish() (OpenGL ES 2.0 man page)
flush() (OpenGL ES 2.0 man page)

5.14.13 Reading back pixels

Pixels in the current framebuffer can be read back into a WebGLArray object.

readPixels(x, y, width, height, format, type) (OpenGL ES 2.0 man page)
Return a WebGLArray with pixels within the passed rectangle. The specific subclass of WebGLArray returned depends on the passed type. If it is GL_UNSIGNED_BYTE, a WebGLUnsignedByteArray is returned, otherwise a WebGLUnsignedShortArray is returned.

5.15 Events

WebGL generates events when certain system activity occurs affecting the context. These events are sent to the corresponding HTMLCanvasElement through the DOM Event System.

5.15.1 WebGLResourceLostEvent

This event occurs when some system activity external to WebGL occurs which causes one of more resources of the current context to be lost. Theresource attribute contains the resource that was lost, or null if all resources were lost. The context attribute contains the WebGLRenderingContext for which the resource was lost.

interface WebGLResourceLostEvent : Event {
    readonly attribute WebGLObject resource;
    readonly attribute WebGLRenderingContext context;
    
    void initWebGLResourceLostEvent(in DOMString type,
                                    in boolean canBubble,
                                    in boolean cancelable,
                                    in WebGLObject resource,
                                    in WebGLRenderingContext context);
};
5.15.1.1 Attributes

The following attributes are available:

resource
The resource that was lost, or null if all resources were lost.
context
The context for which the resource was lost.
5.15.1.2 5.15.1.2 Methods

The following methods are available:

initWebGLResourceLostEvent(type, canBubble, cancelable, resource, context)
Initialize the event created through the DocumentEvent interface. This method may only be called before the event has been dispatched via the dispatchEvent method, though it may be called multiple times during that phase if necessary. If called multiple times, the final invocation takes precedence.

6 References

6.1 Normative references

http://www.khronos.org/registry/gles/specs/2.0/es_full_spec_2.0.24.pdf
[GLES20]
OpenGL® ES Common Profile Specification Version 2.0.24, A. Munshi, J. Leech, April 2009.
[GLES20GLSL]
The OpenGL® ES Shading Language Version 1.00, R. Simpson, May 2009.
[RFC2119]
Key words for use in RFCs to Indicate Requirement Levels, S. Bradner. IETF, March 1997.

6.2 Other references

7 Acknowledgments

This specification is produced by the Khronos WebGL Working Group.

Special thanks to: Arun Ranganathan (Mozilla), Jon Leech, Kenneth Russell (Google), Kenneth Waters (Google), Mark Callow (HI), Mark Steele (Mozilla), Oliver Hunt (Apple), Tim Johansson (Opera), Vangelis Kokkevis (Google), Vladimir Vukicevic (Mozilla)

Additional thanks to: Alan Hudson (Yumetech), Bill Licea Kane (AMD), Dan Gessel (Apple), David Ligon (Qualcomm), Greg Ross (Nvidia), Jacob Strom (Ericsson), Kari Pulli (Nokia), Leddie Stenvie (ST-Ericsson), Neil Trevett (Nvidia), Per Wennersten (Ericsson), Per-Erik Brodin (Ericsson), Tom Olson (ARM), Zhengrong Yao (Ericsson), and the members of the Khronos WebGL Working Group.

抱歉!评论已关闭.