1. Introduction
WebGL™ is an immediate mode 3D rendering API designed for the web. This is the WebGL 2.0 compute specification. It is derived from OpenGL® ES 3.1, and provides similar rendering functionality, but in an HTML context.
WebGL 2.0 compute extends WebGL 2.0 and expose features in OpenGL ES 3.1. It is not entirely backwards compatible with WebGL 2.0. Existing error-free content written against the core WebGL 2.0 specification without extensions will often run in WebGL 2.0 compute without modification, but this is not always the case. All exceptions to backwards compatibility are recorded in the [Backwards Incompatibility] section. To access the new behavior provided in this specification, the content explicitly requests a new context below.
2. Context Creation and Drawing Buffer Presentation
Each WebGLRenderingContext and WebGL2RenderingContext and WebGL2ComputeRenderingContext has an associated canvas, set upon creation, which is a canvas [Canvas].
Each WebGLRenderingContext and WebGL2RenderingContext and WebGL2ComputeRenderingContext has context creation parameters, set upon creation, in a WebGLContextAttributes object.
Each WebGLRenderingContext and WebGL2RenderingContext and WebGL2ComputeRenderingContext has actual context parameters, set each time the drawing buffer is created, in a WebGLContextAttributes object.
Each WebGLRenderingContext and WebGL2RenderingContext and WebGL2ComputeRenderingContext has a webgl context lost flag, which is initially unset.
When the getContext() method of a canvas element is to return a new object for the contextId webgl2Compute [\CANVASCONTEXTS], the user agent must perform the following steps:
Create a new WebGL2ComputeRenderingContext object, context.
Let context’s canvas be the canvas the getContext() method is associated with.
Create a new WebGLContextAttributes object, contextAttributes.
If getContext() was invoked with a second argument, options, set the attributes of contextAttributes from those specified in options.
Create a drawing buffer using the settings specified in contextAttributes, and associate the drawing buffer with context.
If drawing buffer creation failed, perform the following steps: Fire a WebGL context creation error at canvas. Return null and terminate these steps. Create a new WebGLContextAttributes object, actualAttributes. Set the attributes of actualAttributes based on the properties of the newly created drawing buffer. Set context’s context creation parameters to contextAttributes. Set context’s actual context parameters to actualAttributes. Return context.
3. DOM Interfaces
This section describes the interfaces and functionality added to the DOM to support runtime access to the functionality described above.
3.1. The WebGL 2 Compute Rendering Context
The WebGL2ComputeRenderingContext represents the API allowing OpenGL ES 3.1 style rendering into the canvas element.
interface {
WebGL2ComputeRenderingContextBase const GLenum = 0x91B9;
COMPUTE_SHADER const GLenum = 0x91BB;
MAX_COMPUTE_UNIFORM_BLOCKS const GLenum = 0x91BC;
MAX_COMPUTE_TEXTURE_IMAGE_UNITS const GLenum = 0x91BD;
MAX_COMPUTE_IMAGE_UNIFORMS const GLenum = 0x8262;
MAX_COMPUTE_SHARED_MEMORY_SIZE const GLenum = 0x8263;
MAX_COMPUTE_UNIFORM_COMPONENTS const GLenum = 0x8264;
MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS const GLenum = 0x8265;
MAX_COMPUTE_ATOMIC_COUNTERS const GLenum = 0x8266;
MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS const GLenum = 0x90EB;
MAX_COMPUTE_WORK_GROUP_INVOCATIONS const GLenum = 0x91BE;
MAX_COMPUTE_WORK_GROUP_COUNT const GLenum = 0x91BF;
MAX_COMPUTE_WORK_GROUP_SIZE const GLenum = 0x8267;
COMPUTE_WORK_GROUP_SIZE const GLenum = 0x90EE;
DISPATCH_INDIRECT_BUFFER const GLenum = 0x90EF;
DISPATCH_INDIRECT_BUFFER_BINDING const GLenum = 0x00000020;
COMPUTE_SHADER_BIT const GLenum = 0x8F3F;
DRAW_INDIRECT_BUFFER const GLenum = 0x8F43;
DRAW_INDIRECT_BUFFER_BINDING const GLenum = 0x826E;
MAX_UNIFORM_LOCATIONS const GLenum = 0x9310;
FRAMEBUFFER_DEFAULT_WIDTH const GLenum = 0x9311;
FRAMEBUFFER_DEFAULT_HEIGHT const GLenum = 0x9313;
FRAMEBUFFER_DEFAULT_SAMPLES const GLenum = 0x9314;
FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS const GLenum = 0x9315;
MAX_FRAMEBUFFER_WIDTH const GLenum = 0x9316;
MAX_FRAMEBUFFER_HEIGHT const GLenum = 0x9318;
MAX_FRAMEBUFFER_SAMPLES const GLenum = 0x92E1;
UNIFORM const GLenum = 0x92E2;
UNIFORM_BLOCK const GLenum = 0x92E3;
PROGRAM_INPUT const GLenum = 0x92E4;
PROGRAM_OUTPUT const GLenum = 0x92E5;
BUFFER_VARIABLE const GLenum = 0x92E6;
SHADER_STORAGE_BLOCK const GLenum = 0x92C0;
ATOMIC_COUNTER_BUFFER const GLenum = 0x92F4;
TRANSFORM_FEEDBACK_VARYING const GLenum = 0x92F5;
ACTIVE_RESOURCES const GLenum = 0x92F6;
MAX_NAME_LENGTH const GLenum = 0x92F7;
MAX_NUM_ACTIVE_VARIABLES const GLenum = 0x92F9;
NAME_LENGTH const GLenum = 0x92FA;
TYPE const GLenum = 0x92FB;
ARRAY_SIZE const GLenum = 0x92FC;
OFFSET const GLenum = 0x92FD;
BLOCK_INDEX const GLenum = 0x92FE;
ARRAY_STRIDE const GLenum = 0x92FF;
MATRIX_STRIDE const GLenum = 0x9300;
IS_ROW_MAJOR const GLenum = 0x9301;
ATOMIC_COUNTER_BUFFER_INDEX const GLenum = 0x9302;
BUFFER_BINDING const GLenum = 0x9303;
BUFFER_DATA_SIZE const GLenum = 0x9304;
NUM_ACTIVE_VARIABLES const GLenum = 0x9305;
ACTIVE_VARIABLES const GLenum = 0x9306;
REFERENCED_BY_VERTEX_SHADER const GLenum = 0x930A;
REFERENCED_BY_FRAGMENT_SHADER const GLenum = 0x930B;
REFERENCED_BY_COMPUTE_SHADER const GLenum = 0x930C;
TOP_LEVEL_ARRAY_SIZE const GLenum = 0x930D;
TOP_LEVEL_ARRAY_STRIDE const GLenum = 0x930E;
LOCATION const GLenum = 0x00000001;
VERTEX_SHADER_BIT const GLenum = 0x00000002;
FRAGMENT_SHADER_BIT const GLenum = 0xFFFFFFFF;
ALL_SHADER_BITS const GLenum = 0x92C1;
ATOMIC_COUNTER_BUFFER_BINDING const GLenum = 0x92C2;
ATOMIC_COUNTER_BUFFER_START const GLenum = 0x92C3;
ATOMIC_COUNTER_BUFFER_SIZE const GLenum = 0x92CC;
MAX_VERTEX_ATOMIC_COUNTER_BUFFERS const GLenum = 0x92D0;
MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS const GLenum = 0x92D1;
MAX_COMBINED_ATOMIC_COUNTER_BUFFERS const GLenum = 0x92D2;
MAX_VERTEX_ATOMIC_COUNTERS const GLenum = 0x92D6;
MAX_FRAGMENT_ATOMIC_COUNTERS const GLenum = 0x92D7;
MAX_COMBINED_ATOMIC_COUNTERS const GLenum = 0x92D8;
MAX_ATOMIC_COUNTER_BUFFER_SIZE const GLenum = 0x92DC;
MAX_ATOMIC_COUNTER_BUFFER_BINDINGS const GLenum = 0x92D9;
ACTIVE_ATOMIC_COUNTER_BUFFERS const GLenum = 0x92DB;
UNSIGNED_INT_ATOMIC_COUNTER const GLenum = 0x8F38;
MAX_IMAGE_UNITS const GLenum = 0x90CA;
MAX_VERTEX_IMAGE_UNIFORMS const GLenum = 0x90CE;
MAX_FRAGMENT_IMAGE_UNIFORMS const GLenum = 0x90CF;
MAX_COMBINED_IMAGE_UNIFORMS const GLenum = 0x8F3A;
IMAGE_BINDING_NAME const GLenum = 0x8F3B;
IMAGE_BINDING_LEVEL const GLenum = 0x8F3C;
IMAGE_BINDING_LAYERED const GLenum = 0x8F3D;
IMAGE_BINDING_LAYER const GLenum = 0x8F3E;
IMAGE_BINDING_ACCESS const GLenum = 0x906E;
IMAGE_BINDING_FORMAT const GLenum = 0x00000001;
VERTEX_ATTRIB_ARRAY_BARRIER_BIT const GLenum = 0x00000002;
ELEMENT_ARRAY_BARRIER_BIT const GLenum = 0x00000004;
UNIFORM_BARRIER_BIT const GLenum = 0x00000008;
TEXTURE_FETCH_BARRIER_BIT const GLenum = 0x00000020;
SHADER_IMAGE_ACCESS_BARRIER_BIT const GLenum = 0x00000040;
COMMAND_BARRIER_BIT const GLenum = 0x00000080;
PIXEL_BUFFER_BARRIER_BIT const GLenum = 0x00000100;
TEXTURE_UPDATE_BARRIER_BIT const GLenum = 0x00000200;
BUFFER_UPDATE_BARRIER_BIT const GLenum = 0x00000400;
FRAMEBUFFER_BARRIER_BIT const GLenum = 0x00000800;
TRANSFORM_FEEDBACK_BARRIER_BIT const GLenum = 0x00001000;
ATOMIC_COUNTER_BARRIER_BIT const GLenum = 0x00002000;
SHADER_STORAGE_BARRIER_BIT const GLenum = 0xFFFFFFFF;
ALL_BARRIER_BITS const GLenum = 0x904D;
IMAGE_2D const GLenum = 0x904E;
IMAGE_3D const GLenum = 0x9050;
IMAGE_CUBE const GLenum = 0x9053;
IMAGE_2D_ARRAY const GLenum = 0x9058;
INT_IMAGE_2D const GLenum = 0x9059;
INT_IMAGE_3D const GLenum = 0x905B;
INT_IMAGE_CUBE const GLenum = 0x905E;
INT_IMAGE_2D_ARRAY const GLenum = 0x9063;
UNSIGNED_INT_IMAGE_2D const GLenum = 0x9064;
UNSIGNED_INT_IMAGE_3D const GLenum = 0x9066;
UNSIGNED_INT_IMAGE_CUBE const GLenum = 0x9069;
UNSIGNED_INT_IMAGE_2D_ARRAY const GLenum = 0x90C7;
IMAGE_FORMAT_COMPATIBILITY_TYPE const GLenum = 0x90C8;
IMAGE_FORMAT_COMPATIBILITY_BY_SIZE const GLenum = 0x90C9;
IMAGE_FORMAT_COMPATIBILITY_BY_CLASS const GLenum = 0x88B8;
READ_ONLY const GLenum = 0x88B9;
WRITE_ONLY const GLenum = 0x88BA;
READ_WRITE const GLenum = 0x90D2;
SHADER_STORAGE_BUFFER const GLenum = 0x90D3;
SHADER_STORAGE_BUFFER_BINDING const GLenum = 0x90D4;
SHADER_STORAGE_BUFFER_START const GLenum = 0x90D5;
SHADER_STORAGE_BUFFER_SIZE const GLenum = 0x90D6;
MAX_VERTEX_SHADER_STORAGE_BLOCKS const GLenum = 0x90DA;
MAX_FRAGMENT_SHADER_STORAGE_BLOCKS const GLenum = 0x90DB;
MAX_COMPUTE_SHADER_STORAGE_BLOCKS const GLenum = 0x90DC;
MAX_COMBINED_SHADER_STORAGE_BLOCKS const GLenum = 0x90DD;
MAX_SHADER_STORAGE_BUFFER_BINDINGS const GLenum = 0x90DE;
MAX_SHADER_STORAGE_BLOCK_SIZE const GLenum = 0x90DF;
SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT const GLenum = 0x8F39;
MAX_COMBINED_SHADER_OUTPUT_RESOURCES const GLenum = 0x90EA;
DEPTH_STENCIL_TEXTURE_MODE const GLenum = 0x1901;
STENCIL_INDEX const GLenum = 0x8E5E;
MIN_PROGRAM_TEXTURE_GATHER_OFFSET const GLenum = 0x8E5F;
MAX_PROGRAM_TEXTURE_GATHER_OFFSET const GLenum = 0x8E50;
SAMPLE_POSITION const GLenum = 0x8E51;
SAMPLE_MASK const GLenum = 0x8E52;
SAMPLE_MASK_VALUE const GLenum = 0x9100;
TEXTURE_2D_MULTISAMPLE const GLenum = 0x8E59;
MAX_SAMPLE_MASK_WORDS const GLenum = 0x910E;
MAX_COLOR_TEXTURE_SAMPLES const GLenum = 0x910F;
MAX_DEPTH_TEXTURE_SAMPLES const GLenum = 0x9110;
MAX_INTEGER_SAMPLES const GLenum = 0x9104;
TEXTURE_BINDING_2D_MULTISAMPLE const GLenum = 0x9106;
TEXTURE_SAMPLES const GLenum = 0x9107;
TEXTURE_FIXED_SAMPLE_LOCATIONS const GLenum = 0x1000;
TEXTURE_WIDTH const GLenum = 0x1001;
TEXTURE_HEIGHT const GLenum = 0x8071;
TEXTURE_DEPTH const GLenum = 0x1003;
TEXTURE_INTERNAL_FORMAT const GLenum = 0x805C;
TEXTURE_RED_SIZE const GLenum = 0x805D;
TEXTURE_GREEN_SIZE const GLenum = 0x805E;
TEXTURE_BLUE_SIZE const GLenum = 0x805F;
TEXTURE_ALPHA_SIZE const GLenum = 0x884A;
TEXTURE_DEPTH_SIZE const GLenum = 0x88F1;
TEXTURE_STENCIL_SIZE const GLenum = 0x8C3F;
TEXTURE_SHARED_SIZE const GLenum = 0x8C10;
TEXTURE_RED_TYPE const GLenum = 0x8C11;
TEXTURE_GREEN_TYPE const GLenum = 0x8C12;
TEXTURE_BLUE_TYPE const GLenum = 0x8C13;
TEXTURE_ALPHA_TYPE const GLenum = 0x8C16;
TEXTURE_DEPTH_TYPE const GLenum = 0x86A1;
TEXTURE_COMPRESSED const GLenum = 0x9108;
SAMPLER_2D_MULTISAMPLE const GLenum = 0x9109;
INT_SAMPLER_2D_MULTISAMPLE const GLenum = 0x910A;
UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE const GLenum = 0x82D4;
VERTEX_ATTRIB_BINDING const GLenum = 0x82D5;
VERTEX_ATTRIB_RELATIVE_OFFSET const GLenum = 0x82D6;
VERTEX_BINDING_DIVISOR const GLenum = 0x82D7;
VERTEX_BINDING_OFFSET const GLenum = 0x82D8;
VERTEX_BINDING_STRIDE const GLenum = 0x8F4F;
VERTEX_BINDING_BUFFER const GLenum = 0x82D9;
MAX_VERTEX_ATTRIB_RELATIVE_OFFSET const GLenum = 0x82DA;
MAX_VERTEX_ATTRIB_BINDINGS const GLenum = 0x82E5;
MAX_VERTEX_ATTRIB_STRIDE void (
dispatchCompute GLuint ,
num_groups_x GLuint ,
num_groups_y GLuint );
num_groups_z void (
dispatchComputeIndirect GLintptr );
offset void (
drawArraysIndirect GLenum ,
mode GLintptr );
offset void (
drawElementsIndirect GLenum ,
mode GLenum ,
type GLintptr );
offset void (
framebufferParameter GLenum ,
target GLenum ,
pname GLint );
param any (
getFramebufferParameter GLenum ,
target GLenum );
pname any (
getProgramInterfaceParameter WebGLProgram ,
program GLenum ,
programInterface GLenum );
pname any (
getProgramResource WebGLProgram ,
program GLenum ,
programInterface GLuint ,
index GLenum );
props GLuint (
getProgramResourceIndex WebGLProgram ,
program GLenum ,
programInterface DOMString );
name DOMString ?(
getProgramResourceName WebGLProgram ,
program GLenum ,
programInterface GLuint );
index any (
getProgramResourceLocation WebGLProgram ,
program GLenum ,
programInterface DOMString );
name void (
programUniform1i WebGLProgram ?,
program WebGLUniformLocation ?,
location GLint );
v0 void (
programUniform2i WebGLProgram ?,
program WebGLUniformLocation ?,
location GLint ,
v0 GLint );
v1 void (
programUniform3i WebGLProgram ?,
program WebGLUniformLocation ?,
location GLint ,
v0 GLint ,
v1 GLint );
v2 void (
programUniform4i WebGLProgram ?,
program WebGLUniformLocation ?,
location GLint ,
v0 GLint ,
v1 GLint ,
v2 GLint );
v3 void (
programUniform1ui WebGLProgram ?,
program WebGLUniformLocation ?,
location GLuint );
v0 void (
programUniform2ui WebGLProgram ?,
program WebGLUniformLocation ?,
location GLuint ,
v0 GLuint );
v1 void (
programUniform3ui WebGLProgram ?,
program WebGLUniformLocation ?,
location GLuint ,
v0 GLuint ,
v1 GLuint );
v2 void (
programUniform4ui WebGLProgram ?,
program WebGLUniformLocation ?,
location GLuint ,
v0 GLuint ,
v1 GLuint ,
v2 GLuint );
v3 void (
programUniform1f WebGLProgram ?,
program WebGLUniformLocation ?,
location GLfloat );
v0 void (
programUniform2f WebGLProgram ?,
program WebGLUniformLocation ?,
location GLfloat ,
v0 GLfloat );
v1 void (
programUniform3f WebGLProgram ?,
program WebGLUniformLocation ?,
location GLfloat ,
v0 GLfloat ,
v1 GLfloat );
v2 void (
programUniform4f WebGLProgram ?,
program WebGLUniformLocation ?,
location GLfloat ,
v0 GLfloat ,
v1 GLfloat ,
v2 GLfloat );
v3 void (
programUniform1iv WebGLProgram ?,
program WebGLUniformLocation ?,
location GLsizei ,
count Int32List );
data void (
programUniform2iv WebGLProgram ?,
program WebGLUniformLocation ?,
location GLsizei ,
count Int32List );
data void (
programUniform3iv WebGLProgram ?,
program WebGLUniformLocation ?,
location GLsizei ,
count Int32List );
data void (
programUniform4iv WebGLProgram ?,
program WebGLUniformLocation ?,
location GLsizei ,
count Int32List );
data void (
programUniform1uiv WebGLProgram ?,
program WebGLUniformLocation ?,
location GLsizei ,
count Uint32List );
data void (
programUniform2uiv WebGLProgram ?,
program WebGLUniformLocation ?,
location GLsizei ,
count Uint32List );
data void (
programUniform3uiv WebGLProgram ?,
program WebGLUniformLocation ?,
location GLsizei ,
count Uint32List );
data void (
programUniform4uiv WebGLProgram ?,
program WebGLUniformLocation ?,
location GLsizei ,
count Uint32List );
data void (
programUniform1fv WebGLProgram ?,
program WebGLUniformLocation ?,
location GLsizei ,
count Float32List );
data void (
programUniform2fv WebGLProgram ?,
program WebGLUniformLocation ?,
location GLsizei ,
count Float32List );
data void (
programUniform3fv WebGLProgram ?,
program WebGLUniformLocation ?,
location GLsizei ,
count Float32List );
data void (
programUniform4fv WebGLProgram ?,
program WebGLUniformLocation ?,
location GLsizei ,
count Float32List );
data void (
programUniformMatrix2fv WebGLProgram ?,
program WebGLUniformLocation ?,
location GLsizei ,
count GLboolean ,
transpose Float32List );
data void (
programUniformMatrix3fv WebGLProgram ?,
program WebGLUniformLocation ?,
location GLsizei ,
count GLboolean ,
transpose Float32List );
data void (
programUniformMatrix4fv WebGLProgram ?,
program WebGLUniformLocation ?,
location GLsizei ,
count GLboolean ,
transpose Float32List );
data void (
programUniformMatrix2x3fv WebGLProgram ?,
program WebGLUniformLocation ?,
location GLsizei ,
count GLboolean ,
transpose Float32List );
data void (
programUniformMatrix3x2fv WebGLProgram ?,
program WebGLUniformLocation ?,
location GLsizei ,
count GLboolean ,
transpose Float32List );
data void (
programUniformMatrix2x4fv WebGLProgram ?,
program WebGLUniformLocation ?,
location GLsizei ,
count GLboolean ,
transpose Float32List );
data void (
programUniformMatrix4x2fv WebGLProgram ?,
program WebGLUniformLocation ?,
location GLsizei ,
count GLboolean ,
transpose Float32List );
data void (
programUniformMatrix3x4fv WebGLProgram ?,
program WebGLUniformLocation ?,
location GLsizei ,
count GLboolean ,
transpose Float32List );
data void (
programUniformMatrix4x3fv WebGLProgram ?,
program WebGLUniformLocation ?,
location GLsizei ,
count GLboolean ,
transpose Float32List );
data void (
bindImageTexture GLuint ,
unit WebGLTexture ?,
texture GLint ,
level GLboolean ,
layered GLint ,
layer GLenum ,
access GLenum );
format void (
memoryBarrier GLbitfield );
barriers void (
memoryBarrierByRegion GLbitfield );
barriers void (
texStorage2DMultisample GLenum ,
target GLsizei ,
samples GLenum ,
internalformat GLsizei ,
width GLsizei ,
height GLboolean );
fixedsamplelocations any (
getTexLevelParameter GLenum ,
target GLint ,
level GLenum );
pname any (
getMultisample GLenum ,
pname GLuint );
index void (
sampleMask GLuint ,
index GLbitfield );
mask void (
bindVertexBuffer GLuint ,
bindingindex WebGLBuffer ?,
buffer GLintptr ,
offset GLsizei );
stride void (
vertexAttribFormat GLuint ,
attribindex GLint ,
size GLenum ,
type GLboolean ,
normalized GLuint );
relativeoffset void (
vertexAttribIFormat GLuint ,
attribindex GLint ,
size GLenum ,
type GLuint );
relativeoffset void (
vertexAttribBinding GLuint ,
attribindex GLuint );
bindingindex void (
vertexBindingDivisor GLuint ,
bindingindex GLuint ); };
divisor
3.1.1. Framebuffer Object
void framebufferParameter(GLenum target, GLenum pname, GLint param) ( OpenGL ES 3.1 Section 9.2.1, man page)
Set framebuffer default parameter.
See glFramebufferParameteri at OpenGL ES 3.1 Section 9.2.1,
and man page
any getFramebufferParameter(GLenum target, GLenum pname)
Set framebuffer default parameter.
See glFramebufferParameteri at OpenGL ES 3.1 Section 9.2.1,
and man page
3.1.2. Texture Object
void texStorage2DMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations)
Establish the data storage, format, dimensions, and number of samples of a multisample texture’s image.
See glTexStorage2DMultisample at OpenGL ES 3.1 Section 8.8,
and man page
any getTexLevelParameter(GLenum target, GLint level, GLenum valuepname)
Query the level-of-detail information of the given pname for the currently bound texture specified by target.
See glGetTexLevelParameter{if}v at OpenGL ES 3.1 Section 8.10.3,
and man page
The requested pname and its return type are given in the following table:
pname | returned type |
---|---|
TEXTURE_SAMPLES | GLuint |
TEXTURE_FIXED_SAMPLE_LOCATIONS | GLboolean |
TEXTURE_WIDTH | GLuint |
TEXTURE_HEIGHT | GLuint |
TEXTURE_DEPTH | GLuint |
TEXTURE_INTERNAL_FORMAT | GLenum |
TEXTURE_RED_SIZE | GLuint |
TEXTURE_GREEN_SIZE | GLuint |
TEXTURE_BLUE_SIZE | GLuint |
TEXTURE_ALPHA_SIZE | GLuint |
TEXTURE_DEPTH_SIZE | GLuint |
TEXTURE_STENCIL_SIZE | GLuint |
TEXTURE_SHARED_SIZE | GLuint |
TEXTURE_RED_TYPE | GLenum |
TEXTURE_GREEN_TYPE | GLenum |
TEXTURE_BLUE_TYPE | GLenum |
TEXTURE_ALPHA_TYPE | GLenum |
TEXTURE_DEPTH_TYPE | GLenum |
TEXTURE_COMPRESSED | GLboolean |
3.1.3. Sampler Object
any getMultisample(GLenum pname, GLuint index)
Query the location of a given sample within the pixel.
See glGetMultisamplefv at OpenGL ES 3.1 Section 13.2.1,
and man page
void sampleMask(GLuint index, GLbitfield mask)
Specify the sample mask value to mask for desired mask of index.
See glSampleMaski at OpenGL ES 3.1 Section 13.6.3,
and man page
3.1.4. Uniforms and Attributes
void programUniform[1234][if](WebGLProgram? program, WebGLUniformLocation? location, ...)
Set uniform value for a given program.
See glProgramUniform[1234][if] at OpenGL ES 3.1 Section 7.6.1,
and man page
void programUniform[1234][if]v(WebGLProgram? program, WebGLUniformLocation? location, ...)
Set uniform value for a given program.
See glProgramUniform[1234][if]v at OpenGL ES 3.1 Section 7.6.1,
and man page
void programUniform[1234]ui(WebGLProgram? program, WebGLUniformLocation? location, ...)
Set uniform value for a given program.
See glProgramUniform[1234]ui at OpenGL ES 3.1 Section 7.6.1,
and man page
void programUniform[1234]uiv(WebGLProgram? program, WebGLUniformLocation? location, ...)
Set uniform value for a given program.
See glProgramUniform[1234]uiv at OpenGL ES 3.1 Section 7.6.1,
and man page
void programUniformMatrix[234][f]v(WebGLProgram? program, WebGLUniformLocation? location, GLsizei count, GLboolean transpose, ...)
Set uniform value for a given program.
See glProgramUniform[234][f]v at OpenGL ES 3.1 Section 7.6.1,
and man page
void programUniformMatrix[2x3, 3x2, 2x4, 4x2, 3x4, 4x3][f]v(WebGLProgram? program, WebGLUniformLocation? location, GLsizei count, GLboolean transpose, ...)
Set uniform value for a given program.
See glProgramUniformMatirx[2x3, 3x2, 2x4, 4x2, 3x4, 4x3][f]v at OpenGL ES 3.1 Section 7.6.1,
and man page
void bindVertexBuffer(GLuint bindingindex, WebGLBuffer? buffer, GLintptr offset, GLsizei stride)
Bind vertex buffer to the binding point bindingindex.
See glBindVertexBuffer at OpenGL ES 3.1 Section 10.3.1,
and man page
void vertexAttribFormat(GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset)
Describe the orgnization of vertex arrays.
See glVertexAttribFormat at OpenGL ES 3.1 Section 10.3.1,
and man page
void vertexAttribIFormat(GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset)
Describe the orgnization of vertex arrays.
See glVertexAttribIFormat at OpenGL ES 3.1 Section 10.3.1,
and man page
void vertexAttribBinding(GLuint attribindex, GLuint bindingindex)
Set the association between a vertex attribute and the vertex buffer binding.
See glVertexAttribBinding at OpenGL ES 3.1 Section 10.3.1,
and man page
void vertexBindingDivisor(GLuint bindingindex, GLuint divisor)
Set the divisor value for attributes taken from the buffer bound to bindingindex between a vertex attribute and the vertex buffer binding.
See glVertexBindingDivisor at OpenGL ES 3.1 Section 10.3.2,
and man page
3.1.5. Writing to the Drawing Buffers
void drawArraysIndirect(GLenum mode, GLintptr offset)
Draw geometry with vertices by reading parameters via indirect buffer.
See glDrawArraysIndirect at OpenGL ES 3.1 Section 10.5,
and man page
void drawElementsIndirect(GLenum mode, GLenum type, GLintptr offset)
Draw geometry with indexed vertices by reading parameters via indirect buffer.
See glDrawElementsIndirect at OpenGL ES 3.1 Section 10.5,
and man page
3.1.6. Program Interface Query
any getProgramInterfaceParameter(WebGLProgram program, GLenum programInterface, GLenum pname)
Query a property of the interface programInterface in program program.
See glGetProgramInterfaceiv at OpenGL ES 3.1 Section 7.3.1.1,
and man page
sequence
Query multiple properties of the interface programInterface in program program.
See glGetProgramResourceiv at OpenGL ES 3.1 Section 7.3.1.1,
and man page
DOMString? getProgramResourceName(WebGLProgram program, GLenum programInterface, GLuint index)
Query the name string assigned to the single active resource with an index of index in the interface programInterface in program program.
See glGetProgramResourceName at OpenGL ES 3.1 Section 7.3.1.1,
and man page
GLuint getProgramResourceIndex(WebGLProgram program, GLenum programInterface, DOMString name)
Query the unsigned integer index assigned to a resource named name in the interface programInterface in program program.
See glGetProgramResourceIndex at OpenGL ES 3.1 Section 7.3.1.1,
and man page
any getProgramResourceLocation(WebGLProgram program, GLenum programInterface, DOMString name)
Query the location assigned to a resource named name in the interface programInterface in program program.
See glGetProgramResourceLocation at OpenGL ES 3.1 Section 7.3.1.1,
and man page
3.1.7. Image Binding
void bindImageTexture(GLuint unit, WebGLTexture? texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format)
Bind a texture to a image unit for image load and store.
See glBindImageTexture at OpenGL ES 3.1 Section 8.22,
and man page
3.1.8. Memory Barrior
void memoryBarrior(GLbitfield barriers)
Define a barrier ordering the memory transactions issued prior to the command relative to those issued after the barrier.
See glMemoryBarrier at OpenGL ES 3.1 Section 7.11.2,
and man page
void memoryBarriorByRegion(GLbitfield barriers)
With restrictions, define a barrier ordering the memory transactions issued prior to the command relative to those issued after the barrier.
See glMemoryBarrier at OpenGL ES 3.1 Section 7.11.2,
and man page
3.1.9. Dispatch Compute
void dispatchCompute(GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z)
Launch one or more work groups and start compute pipeline.
See glDispatchCompute at OpenGL ES 3.1 Section 17,
and man page
void dispatchComputeIndirect(GLintptr offset)
Launch one or more work groups and start compute pipeline, with parameter stored in a buffer from offset offset.
See glDispatchComputeIndirect at OpenGL ES 3.1 Section 17,
and man page
3.1.10. More Shader Types
WebGLShader? createShader(GLenum type)
type accept the following parameters:
type |
---|
COMPUTE_SHADER |
COMPUTE_SHADER
is also supported by corresponding APIs like createShaderProgram
, among other APIs.
3.1.11. More Binding Point
void bindBuffer(GLenum target, WebGLBuffer buffer)
target accept the following parameters:
target |
---|
ATOMIC_COUNTER_BUFFER |
DISPATCH_INDIRECT_BUFFER |
DRAW_INDIRECT_BUFFER |
SHADER_STORAGE_BUFFER |
bindBufferRange
and bindBufferBase
, only ATOMIC_COUNTER_BUFFER
and SHADER_STORAGE_BUFFER
are supported.
3.1.12. Setting and Getting States
any getParameter(GLenum pname)
pname accept the following parameters. The return type of this method now depends on the parameter queried:
pname | returned type |
---|---|
MAX_SAMPLE_MASK_WORDS | GLuint |
MAX_COLOR_TEXTURE_SAMPLES | GLuint |
MAX_DEPTH_TEXTURE_SAMPLES | GLuint |
MAX_INTEGER_SAMPLES | GLuint |
TEXTURE_BINDING_2D_MULTISAMPLE | WebGLTexture |
MAX_VERTEX_ATOMIC_COUNTER_BUFFERS | GLuint |
MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS | GLuint |
MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS | GLuint |
MAX_COMBINED_ATOMIC_COUNTER_BUFFERS | GLuint |
MAX_ATOMIC_COUNTER_BUFFER_BINDINGS | GLuint |
MAX_VERTEX_ATOMIC_COUNTERS | GLuint |
MAX_FRAGMENT_ATOMIC_COUNTERS | GLuint |
MAX_COMPUTE_ATOMIC_COUNTERS | GLuint |
MAX_COMBINED_ATOMIC_COUNTERS | GLuint |
ATOMIC_COUNTER_BUFFER_BINDING | WebGLBuffer |
MAX_COMBINED_SHADER_STORAGE_BLOCKS | GLuint |
MAX_COMPUTE_SHADER_STORAGE_BLOCKS | GLuint |
MAX_FRAGMENT_SHADER_STORAGE_BLOCKS | GLuint |
MAX_VERTEX_SHADER_STORAGE_BLOCKS | GLuint |
MAX_SHADER_STORAGE_BLOCK_SIZE | GLuint |
MAX_SHADER_STORAGE_BUFFER_BINDINGS | GLuint |
SHADER_STORAGE_BUFFER_BINDING | WebGLBuffer |
any getIndexedParameter(GLenum target, GLuint index)
target accept the following parameters. The return type of this method now depends on the parameter queried:
target | returned type |
---|---|
VERTEX_BINDING_OFFSET | GLintptr |
VERTEX_BINDING_STRIDE | GLint |
VERTEX_BINDING_DIVISOR | GLint |
VERTEX_BINDING_BUFFER | WebGLBuffer |
SAMPLE_MASK_VALUE | GLbitfield |
ATOMIC_COUNTER_BUFFER_BINDING | WebGLBuffer |
ATOMIC_COUNTER_BUFFER_START | GLintptr |
ATOMIC_COUNTER_BUFFER_SIZE | GLsizeiptr |
IMAGE_BINDING_NAME | WebGLTexture |
IMAGE_BINDING_LEVEL | GLint |
IMAGE_BINDING_LAYERED | GLboolean |
IMAGE_BINDING_LAYER | GLint |
IMAGE_BINDING_ACCESS | GLenum |
IMAGE_BINDING_FORMAT | GLenum |
SHADER_STORAGE_BUFFER_BINDING | WebGLBuffer |
SHADER_STORAGE_BUFFER_START | GLintptr |
SHADER_STORAGE_BUFFER_SIZE | GLsizeiptr |
MAX_COMPUTE_WORK_GROUP_COUNT | GLint |
MAX_COMPUTE_WORK_GROUP_SIZE | GLint |
any getProgramParameter(WebGLProgram? program, GLenum pname)
Query program parameter pname give program.
See glGetProgramiv at OpenGL ES 3.1 Section 7.12,
and man page The requested pname and its return type are given in the following table:
pname | returned type |
---|---|
COMPUTE_WORK_GROUP_SIZE | GLint |
ACTIVE_ATOMIC_COUNTER_BUFFERS | GLint |
4. Other Differences Between WebGL 2.0 compute and WebGL 2.0
4.1. WebGL 2.0 compute can support GLSL ES 310
local size, group size, group ID, invocation ID and so on for compute shader
image
shared memory
barriers
shader storage buffer
atomics
multisample texture
new qualifier like coherent, volatile, restrict, readonly, writeonly, std430, early_fragment_test, etc
new math built-ins
array of arrays
texture gather
4.2. Integer Format Renderbuffer
Renderbuffer can support integer format via RenderbufferStorage()
4.3. Framebuffer without attachment can be complete
In WebGL 2.0, it is a must that there is at least one attached image in framebuffer. Otherwise, it is framebuffer incomplete. In WebGL 2.0 compute, this requirement is removed.
4.4. Extra restrictions for vertexAttrib*Pointer
In WebGL 2.0 compute, vertexAttrib*Pointer has an extra restriction on the maximum stride: MAX_VERTEX_ATTRIB_STRIDE.
5. Differences between WebGL 2.0 compute and OpenGL ES 3.1
5.1. Program pipeline is not supported in WebGL 2.0 compute
Program pipeline in OpenGL ES 3.1 is not supported in WebGL 2.0 compute. Program pipeline is irrelevant to compute shader and it is not very useful.
5.2. The same layer and level of texture cannot be bound to multiple image units
In OpenGL ES 3.1, the same layer and level of texture can be bound to multiple image units. But this feature is not allowed in D3D11, and it is not very useful. So this feature is disabled. It generates INVALID_OPERATION otherwise.
5.3. Multiple image variables can’t be used to access the same image unit
In OpenGL ES 3.1, Multiple image variables can be used to access the same image unit. But this feature is not allowed in D3D11, and it is not very useful. So this feature is disabled. It generates INVALID_OPERATION otherwise.
5.4. Multiple shader storage blocks are not allowed to bind to a single buffer
dispatchCompute generates an INVALID_OPERATION error if more than one shader storage block that are bound to a single buffer are statically used in that dispatch call.
This is a restriction from D3D11, where the same resource bound to different UAVs is not allowed.
5.5. gl_HelperInvocation is not supported
gl_HelperInvocation is a built-in input variable of fragment shader introduced in ESSL 310 (Chapter 7.1.2 Page 106). It needs at least GLSL 450 on desktop OpenGL, and it has no equivalent in HLSL system values in D3D11. So it is not supported in WebGL.
5.6. Presenting particular value in compute shader
Define the const and non-const behavior for some corner case like NaN, Inf, 0.0 in compute shader
5.7. std430 layout is requred for shared memory
OpenGL ES 3.1 SPEC does not define which memory layout we should follow to calculate the total memory consumption of shared variables.
This extension calculates the usage of shared memory in std430 layout. The total size of active shared variables may not exceed the largest block size that would be obtained if all active variables declared as shared were instead declared as arbitrarily ordered members of a shader storage block qualified with std430.
5.8. Clarify undefined behaviors
5.8.1. Rendering against compute program is not allowed
Rendering against compute program is not allowed
5.8.2. Shadow sampler in texture lookup function
Shadow sampler in texture lookup function has a lot of limitation, which will lead to undefined behavior. Find “shadow sam” in GLES spec.
5.8.3. Sampling from incomplete texture with integer or unsigned integer format
Sampling from incomplete texture with integer or unsigned integer format, it will return undefined value. See GLES spec 3.1 on page 275 (the 1st paragraph).
5.8.4. Sampling from stencil texture via non-unsigned integer sampler
Sampling from stencil texture should use a unsigned integer sampler (say usampler2D tex in shader). Otherwise, the result are undefined, see GLES spec 3.1 on page 274. (the last but one paragraph).
5.8.5. Out-of-bounds access to ssbo or atomic counter in shader
Out-of-bounds access to shader storage buffers or atomic counter buffers in shader cannot read from or write to data not owned by the application. See KHR_robust_buffer_access_behavior.
5.8.6. Uninitialized shared variables in shader
Variables declared as shared may not have initializers and their contents are all zero at the beginning of shader execution.
5.8.7. Image load or store
Read from an image unit with a texture bound as GL_WRITE_ONLY, or write to an image unit with a texture bound as GL_READ_ONLY, the results of that shader operation are undefined and may lead to application termination in OpenGL ES 3.1. It generates INVALID_OPERATION instead when dispatch compute in this spec.
If the individual texel identified for an image load or store operation doesn’t exist, the access is treated as invalid. An access is considered invalid if
-
no texture is bound to the selected image unit;
-
the texture bound to the selected image unit is incomplete;
-
the texture level bound to the image unit is less than the base level or greater than the maximum level of the texture;
-
the internal format of the texture bound to the image unit is not RGBA32F, RGBA16F, R32F, RGBA32UI, RGBA16UI, RGBA8UI, R32UI, RGBA32I, RGBA16I, RGBA8I, R32I, RGBA8, RGBA8_SNORM.
-
the internal format of the texture bound to the image unit is incompatible with the specified format according to ES 3.1 spec table 8.28.
-
the texture bound to the image unit has layers, and the selected layer or cube map face doesn’t exist.
It generates INVALID_OPERATION when dispatch compute in the cases above for both load and store in this spec.
If image load or store operations are considered to involve a format mismatch, undefined values will be returned by image load operations and undefined values will be written by stores in OpenGL ES 3.1 spec. A format mismatch will occur if:
-
The type of image variable used to access the image unit does not match the target of a texture bound to the image unit with layered set to TRUE.
-
The type of image variable used to access the image unit does not match the target corresponding to a single layer of a multi-layer texture target bound to the image unit with layered set to FALSE.
-
The type of image variable used to access the image unit has a component data type(floating-point, signed integer, unsigned integer) incompatible with the format of the image unit.
-
The format layout qualifier for an image variable used for an image load or atomic operation does not match the format for the image unit, according to ES 3.1 spec table 8.27.
-
The image variable used for an image store has a format layout qualifier, and that qualifier does not match the format of the image unit, according to table ES 3.1 spec table 8.27.
It generates INVALID_OPERATION when dispatch compute in this spec;