WebGL2RenderingContext
WebGL2RenderingContext 接口在底层使用了 OpenGL ES 3.0 为 HTML 的 <canvas> 元素提供了绘图上下文。
要获取该接口的实例对象需要调用一个 <canvas> 标签对象的 getContext() 函数,并将 "webgl2" 作为参数传递:
js
var canvas = document.getElementById('myCanvas');
var gl = canvas.getContext('webgl2');
备注: WebGL 2 是 WebGL 1 的扩展。 WebGL2RenderingContext 接口实现了 WebGLRenderingContext 接口的所有成员。有一些 WebGL 1 上下文中的方法在使用 WebGL 2 上下文的时候可以接受附加值。您可以通过 WebGL 1 的参考页了解这些信息。
这个 WebGL 教程 中提供了关于如何开始使用 WebGL 的更多信息、示例以及资源。
常量
请看 WebGL 常量 页面。
状态信息
缓冲区
WebGL2RenderingContext.copyBufferSubData()(en-US)-
将缓冲区的部分数据复制到另一个缓冲区。
WebGL2RenderingContext.getBufferSubData()(en-US)-
从缓冲区中读取数据,然后将其写入到
ArrayBuffer或SharedArrayBuffer中。
帧缓冲区
WebGL2RenderingContext.blitFramebuffer()(en-US)-
将一个像素块从读取帧缓冲区传输到绘制帧缓冲区。
WebGL2RenderingContext.framebufferTextureLayer()(en-US)-
附着一个单层的材质到帧缓冲区。
WebGL2RenderingContext.invalidateFramebuffer()(en-US)-
使附着到缓冲区的内容失效。
WebGL2RenderingContext.invalidateSubFramebuffer()(en-US)-
使附着到缓冲区的部分内容失效。
WebGL2RenderingContext.readBuffer()(en-US)-
选择一个颜色缓冲作为像素的 source。
渲染缓冲区
WebGL2RenderingContext.getInternalformatParameter()(en-US)-
Returns information about implementation-dependent support for internal formats.
WebGL2RenderingContext.renderbufferStorageMultisample()(en-US)-
Creates and initializes a renderbuffer object's data store and allows specifying the number of samples to be used.
纹理
WebGL2RenderingContext.texStorage2D()(en-US)-
Specifies all levels of two-dimensional texture storage.
WebGL2RenderingContext.texStorage3D()(en-US)-
Specifies all levels of a three-dimensional texture or two-dimensional array texture.
WebGL2RenderingContext.texImage3D()-
Specifies a three-dimensional texture image.
WebGL2RenderingContext.texSubImage3D()(en-US)-
Specifies a sub-rectangle of the current 3D texture.
WebGL2RenderingContext.copyTexSubImage3D()(en-US)-
Copies pixels from the current
WebGLFramebufferinto an existing 3D texture sub-image. WebGL2RenderingContext.compressedTexImage3D()(en-US)-
Specifies a three-dimensional texture image in a compressed format.
WebGL2RenderingContext.compressedTexSubImage3D()(en-US)-
Specifies a three-dimensional sub-rectangle for a texture image in a compressed format.
程序和着色器
WebGL2RenderingContext.getFragDataLocation()(en-US)-
Returns the binding of color numbers to user-defined varying out variables.
Uniforms 和 Attributes
WebGL2RenderingContext.uniform[1234][fiu][v]()-
指定一个 uniform 变量。
WebGL2RenderingContext.uniformMatrix[1234][fv]()-
指定一个 uniform 矩阵变量。
WebGL2RenderingContext.vertexAttribI[iuv]()(en-US)-
Methods specifying integer values for generic vertex attributes.
WebGL2RenderingContext.vertexAttribIPointer()(en-US)-
Specifies integer data formats and locations of vertex attributes in a vertex attributes array.
绘图缓冲区
WebGL2RenderingContext.vertexAttribDivisor()(en-US)-
Modifies the rate at which generic vertex attributes advance when rendering multiple instances of primitives with
gl.drawArraysInstanced()(en-US) andgl.drawElementsInstanced()(en-US). WebGL2RenderingContext.drawArraysInstanced()(en-US)-
Renders primitives from array data. In addition, it can execute multiple instances of the range of elements.
WebGL2RenderingContext.drawElementsInstanced()(en-US)-
Renders primitives from array data. In addition, it can execute multiple instances of a set of elements.
WebGL2RenderingContext.drawRangeElements()(en-US)-
Renders primitives from array data in a given range.
WebGL2RenderingContext.drawBuffers()-
Specifies a list of color buffers to be drawn into.
WebGL2RenderingContext.clearBuffer[fiuv]()(en-US)-
Clears buffers from the currently bound framebuffer.
查询对象
Methods for working with WebGLQuery objects.
WebGL2RenderingContext.createQuery()(en-US)-
创建一个新的
WebGLQuery对象。 WebGL2RenderingContext.deleteQuery()(en-US)-
删除一个指定的
WebGLQuery对象。 WebGL2RenderingContext.isQuery()(en-US)-
Returns
trueif a given object is a validWebGLQueryobject. WebGL2RenderingContext.beginQuery()-
开始一个异步查询。
WebGL2RenderingContext.endQuery()(en-US)-
Marks the end of an asynchronous query.
WebGL2RenderingContext.getQuery()(en-US)-
返回一个指定目标的
WebGLQuery对象。 WebGL2RenderingContext.getQueryParameter()(en-US)-
返回关于一个查询的信息。
采样对象
WebGL2RenderingContext.createSampler()-
Creates a new
WebGLSamplerobject. WebGL2RenderingContext.deleteSampler()(en-US)-
Deletes a given
WebGLSamplerobject. WebGL2RenderingContext.bindSampler()(en-US)-
Binds a given
WebGLSamplerto a texture unit. WebGL2RenderingContext.isSampler()(en-US)-
Returns
trueif a given object is a validWebGLSamplerobject. WebGL2RenderingContext.samplerParameter[if]()(en-US)-
Sets sampler parameters.
WebGL2RenderingContext.getSamplerParameter()(en-US)-
Returns sampler parameter information.
同步对象
WebGL2RenderingContext.fenceSync()(en-US)-
创建一个
WebGLSync对象并插入到 GL 命令流中。 WebGL2RenderingContext.isSync()(en-US)-
Returns
trueif the passed object is a validWebGLSyncobject. WebGL2RenderingContext.deleteSync()(en-US)-
删除一个指定的
WebGLSync对象。 WebGL2RenderingContext.clientWaitSync()(en-US)-
Blocks and waits for a
WebGLSyncobject to become signaled or a given timeout to be passed. WebGL2RenderingContext.waitSync()(en-US)-
Returns immediately, but waits on the GL server until the given
WebGLSyncobject is signaled. WebGL2RenderingContext.getSyncParameter()(en-US)-
根据一个
WebGLSync对象返回参数信息。
变换反馈
WebGL2RenderingContext.createTransformFeedback()(en-US)-
创建并初始化
WebGLTransformFeedback(en-US) 对象。 WebGL2RenderingContext.deleteTransformFeedback()(en-US)-
删除一个指定的
WebGLTransformFeedback(en-US) 对象。 WebGL2RenderingContext.isTransformFeedback()(en-US)-
Returns
trueif the passed object is a validWebGLTransformFeedback(en-US) object. WebGL2RenderingContext.bindTransformFeedback()(en-US)-
Binds a passed
WebGLTransformFeedback(en-US) object to the current GL state. WebGL2RenderingContext.beginTransformFeedback()-
Starts a transform feedback operation.
WebGL2RenderingContext.endTransformFeedback()(en-US)-
Ends a transform feedback operation.
WebGL2RenderingContext.transformFeedbackVaryings()(en-US)-
Specifies values to record in
WebGLTransformFeedback(en-US) buffers. WebGL2RenderingContext.getTransformFeedbackVarying()(en-US)-
Returns information about varying variables from
WebGLTransformFeedback(en-US) buffers. WebGL2RenderingContext.pauseTransformFeedback()(en-US)-
Pauses a transform feedback operation.
WebGL2RenderingContext.resumeTransformFeedback()(en-US)-
Resumes a transform feedback operation.
Uniform 缓冲对象
WebGL2RenderingContext.bindBufferBase()-
Binds a given
WebGLBufferto a given binding point (target) at a givenindex. WebGL2RenderingContext.bindBufferRange()(en-US)-
Binds a range of a given
WebGLBufferto a given binding point (target) at a givenindex. WebGL2RenderingContext.getUniformIndices()(en-US)-
Retrieves the indices of a number of uniforms within a
WebGLProgram. WebGL2RenderingContext.getActiveUniforms()(en-US)-
Retrieves information about active uniforms within a
WebGLProgram. WebGL2RenderingContext.getUniformBlockIndex()(en-US)-
Retrieves the index of a uniform block within a
WebGLProgram. WebGL2RenderingContext.getActiveUniformBlockParameter()(en-US)-
Retrieves information about an active uniform block within a
WebGLProgram. WebGL2RenderingContext.getActiveUniformBlockName()(en-US)-
Retrieves the name of the active uniform block at a given index within a
WebGLProgram. WebGL2RenderingContext.uniformBlockBinding()(en-US)-
Assigns binding points for active uniform blocks.
顶点数组对象
Methods for working with WebGLVertexArrayObject (VAO) objects.
WebGL2RenderingContext.createVertexArray()-
创建一个新的
WebGLVertexArrayObject。 WebGL2RenderingContext.deleteVertexArray()(en-US)-
删除一个指定的
WebGLVertexArrayObject。 WebGL2RenderingContext.isVertexArray()(en-US)-
如果一个指定的
WebGLVertexArrayObject对象有效则返回true。 WebGL2RenderingContext.bindVertexArray()(en-US)-
绑定一个指定的
WebGLVertexArrayObject到缓冲。
规范
| Specification |
|---|
| WebGL 2.0 Specification # 3.7 |
浏览器兼容性
BCD tables only load in the browser