WebGLRenderingContext.getParameter()
====================================

WebGL API 的 **`WebGLRenderingContext.getParameter()`** 方法为传入的参数名称返回一个值。

语法
--
```

any gl.getParameter(pname);
```

### 参数

`pname`

一个指定要返回哪个参数值的 `GLenum` (en-US)。请参阅下文的可能值。

### 返回值

取决于参数。

参数名称
----

### WebGL 1

使用 `WebGLRenderingContext` 时，你可以查询以下 `pname` 参数。

| 常量 | 返回类型 | 描述 |
| --- | --- | --- |
| `gl.ACTIVE_TEXTURE` | `GLenum` (en-US) |  |
| `gl.ALIASED_LINE_WIDTH_RANGE` | `Float32Array` (with 2 elements) |  |
| `gl.ALIASED_POINT_SIZE_RANGE` | `Float32Array` (with 2 elements) |  |
| `gl.ALPHA_BITS` | `GLint` (en-US) |  |
| `gl.ARRAY_BUFFER_BINDING` | `WebGLBuffer` |  |
| `gl.BLEND` | `GLboolean` (en-US) |  |
| `gl.BLEND_COLOR` | `Float32Array` (with 4 values) |  |
| `gl.BLEND_DST_ALPHA` | `GLenum` (en-US) |  |
| `gl.BLEND_DST_RGB` | `GLenum` (en-US) |  |
| `gl.BLEND_EQUATION` | `GLenum` (en-US) |  |
| `gl.BLEND_EQUATION_ALPHA` | `GLenum` (en-US) |  |
| `gl.BLEND_EQUATION_RGB` | `GLenum` (en-US) |  |
| `gl.BLEND_SRC_ALPHA` | `GLenum` (en-US) |  |
| `gl.BLEND_SRC_RGB` | `GLenum` (en-US) |  |
| `gl.BLUE_BITS` | `GLint` (en-US) |  |
| `gl.COLOR_CLEAR_VALUE` | `Float32Array` (with 4 values) |  |
| `gl.COLOR_WRITEMASK` | sequence<`GLboolean` (en-US)> (with 4 values) |  |
| `gl.COMPRESSED_TEXTURE_FORMATS` | `Uint32Array` | 
 返回压缩的纹理格式。当使用
 `WEBGL_compressed_texture_s3tc` (en-US) 扩展时：
 * `ext.COMPRESSED_RGB_S3TC_DXT1_EXT`
* `ext.COMPRESSED_RGBA_S3TC_DXT1_EXT`
* `ext.COMPRESSED_RGBA_S3TC_DXT3_EXT`
* `ext.COMPRESSED_RGBA_S3TC_DXT5_EXT`

 当使用
 `WEBGL_compressed_texture_s3tc_srgb` (en-US)
 扩展时：
 * `ext.COMPRESSED_SRGB_S3TC_DXT1_EXT`
* `ext.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT`
* `ext.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT`
* `ext.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT`

当使用 `WEBGL_compressed_texture_es3` (en-US) 扩展时：
 * `ext.COMPRESSED_R11_EAC`
* `ext.COMPRESSED_SIGNED_R11_EAC`
* `ext.COMPRESSED_RG11_EAC`
* `ext.COMPRESSED_SIGNED_RG11_EAC`
* `ext.COMPRESSED_RGB8_ETC2`
* `ext.COMPRESSED_RGBA8_ETC2_EAC`
* `ext.COMPRESSED_SRGB8_ETC2`
* `ext.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC`
* `ext.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2`
* `ext.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2`

当使用 `WEBGL_compressed_texture_pvrtc` (en-US)
 扩展时：
 * `ext.COMPRESSED_RGB_PVRTC_4BPPV1_IMG`
* `ext.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG`
* `ext.COMPRESSED_RGB_PVRTC_2BPPV1_IMG`
* `ext.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG`

当使用 `WEBGL_compressed_texture_etc1` (en-US)
 扩展时：
 * `ext.COMPRESSED_RGB_ETC1_WEBGL`

当使用 `WEBGL_compressed_texture_atc` 扩展时：
 * `ext.COMPRESSED_RGB_ATC_WEBGL`
* `ext.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL`
* `ext.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL`

当使用 `WEBGL_compressed_texture_astc` (en-US)
 扩展时：
 * `ext.COMPRESSED_RGBA_ASTC_4x4_KHRext.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR`
* `ext.COMPRESSED_RGBA_ASTC_5x4_KHRext.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR`
* `ext.COMPRESSED_RGBA_ASTC_5x5_KHRext.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR`
* `ext.COMPRESSED_RGBA_ASTC_6x5_KHRext.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR`
* `ext.COMPRESSED_RGBA_ASTC_6x6_KHRext.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR`
* `ext.COMPRESSED_RGBA_ASTC_8x5_KHRext.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR`
* `ext.COMPRESSED_RGBA_ASTC_8x6_KHRext.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR`
* `ext.COMPRESSED_RGBA_ASTC_8x8_KHRext.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR`
* `ext.COMPRESSED_RGBA_ASTC_10x5_KHRext.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR`
* `ext.COMPRESSED_RGBA_ASTC_10x6_KHRext.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR`
* `ext.COMPRESSED_RGBA_ASTC_10x6_KHRext.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR`
* `ext.COMPRESSED_RGBA_ASTC_10x10_KHRext.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR`
* `ext.COMPRESSED_RGBA_ASTC_12x10_KHRext.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR`
* `ext.COMPRESSED_RGBA_ASTC_12x12_KHRext.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR`
 |
| `gl.CULL_FACE` | `GLboolean` (en-US) |  |
| `gl.CULL_FACE_MODE` | `GLenum` (en-US) |  |
| `gl.CURRENT_PROGRAM` | `WebGLProgram` |  |
| `gl.DEPTH_BITS` | `GLint` (en-US) |  |
| `gl.DEPTH_CLEAR_VALUE` | `GLfloat` (en-US) |  |
| `gl.DEPTH_FUNC` | `GLenum` (en-US) |  |
| `gl.DEPTH_RANGE` | `Float32Array` (with 2 elements) |  |
| `gl.DEPTH_TEST` | `GLboolean` (en-US) |  |
| `gl.DEPTH_WRITEMASK` | `GLboolean` (en-US) |  |
| `gl.DITHER` | `GLboolean` (en-US) |  |
| `gl.ELEMENT_ARRAY_BUFFER_BINDING` | `WebGLBuffer` |  |
| `gl.FRAMEBUFFER_BINDING` | `WebGLFramebuffer` |  |
| `gl.FRONT_FACE` | `GLenum` (en-US) |  |
| `gl.GENERATE_MIPMAP_HINT` | `GLenum` (en-US) |  |
| `gl.GREEN_BITS` | `GLint` (en-US) |  |
| `gl.IMPLEMENTATION_COLOR_READ_FORMAT` | `GLenum` (en-US) |  |
| `gl.IMPLEMENTATION_COLOR_READ_TYPE` | `GLenum` (en-US) |  |
| `gl.LINE_WIDTH` | `GLfloat` (en-US) |  |
| `gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS` | `GLint` (en-US) |  |
| `gl.MAX_CUBE_MAP_TEXTURE_SIZE` | `GLint` (en-US) |  |
| `gl.MAX_FRAGMENT_UNIFORM_VECTORS` | `GLint` (en-US) |  |
| `gl.MAX_RENDERBUFFER_SIZE` | `GLint` (en-US) |  |
| `gl.MAX_TEXTURE_IMAGE_UNITS` | `GLint` (en-US) |  |
| `gl.MAX_TEXTURE_SIZE` | `GLint` (en-US) |  |
| `gl.MAX_VARYING_VECTORS` | `GLint` (en-US) |  |
| `gl.MAX_VERTEX_ATTRIBS` | `GLint` (en-US) |  |
| `gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS` | `GLint` (en-US) |  |
| `gl.MAX_VERTEX_UNIFORM_VECTORS` | `GLint` (en-US) |  |
| `gl.MAX_VIEWPORT_DIMS` | `Int32Array` (with 2 elements) |  |
| `gl.PACK_ALIGNMENT` | `GLint` (en-US) |  |
| `gl.POLYGON_OFFSET_FACTOR` | `GLfloat` (en-US) |  |
| `gl.POLYGON_OFFSET_FILL` | `GLboolean` (en-US) |  |
| `gl.POLYGON_OFFSET_UNITS` | `GLfloat` (en-US) |  |
| `gl.RED_BITS` | `GLint` (en-US) |  |
| `gl.RENDERBUFFER_BINDING` | `WebGLRenderbuffer` |  |
| `gl.RENDERER` | `DOMString` |  |
| `gl.SAMPLE_BUFFERS` | `GLint` (en-US) |  |
| `gl.SAMPLE_COVERAGE_INVERT` | `GLboolean` (en-US) |  |
| `gl.SAMPLE_COVERAGE_VALUE` | `GLfloat` (en-US) |  |
| `gl.SAMPLES` | `GLint` (en-US) |  |
| `gl.SCISSOR_BOX` | `Int32Array` (with 4 elements) |  |
| `gl.SCISSOR_TEST` | `GLboolean` (en-US) |  |
| `gl.SHADING_LANGUAGE_VERSION` | `DOMString` |  |
| `gl.STENCIL_BACK_FAIL` | `GLenum` (en-US) |  |
| `gl.STENCIL_BACK_FUNC` | `GLenum` (en-US) |  |
| `gl.STENCIL_BACK_PASS_DEPTH_FAIL` | `GLenum` (en-US) |  |
| `gl.STENCIL_BACK_PASS_DEPTH_PASS` | `GLenum` (en-US) |  |
| `gl.STENCIL_BACK_REF` | `GLint` (en-US) |  |
| `gl.STENCIL_BACK_VALUE_MASK` | `GLuint` (en-US) |  |
| `gl.STENCIL_BACK_WRITEMASK` | `GLuint` (en-US) |  |
| `gl.STENCIL_BITS` | `GLint` (en-US) |  |
| `gl.STENCIL_CLEAR_VALUE` | `GLint` (en-US) |  |
| `gl.STENCIL_FAIL` | `GLenum` (en-US) |  |
| `gl.STENCIL_FUNC` | `GLenum` (en-US) |  |
| `gl.STENCIL_PASS_DEPTH_FAIL` | `GLenum` (en-US) |  |
| `gl.STENCIL_PASS_DEPTH_PASS` | `GLenum` (en-US) |  |
| `gl.STENCIL_REF` | `GLint` (en-US) |  |
| `gl.STENCIL_TEST` | `GLboolean` (en-US) |  |
| `gl.STENCIL_VALUE_MASK` | `GLuint` (en-US) |  |
| `gl.STENCIL_WRITEMASK` | `GLuint` (en-US) |  |
| `gl.SUBPIXEL_BITS` | `GLint` (en-US) |  |
| `gl.TEXTURE_BINDING_2D` | `WebGLTexture` |  |
| `gl.TEXTURE_BINDING_CUBE_MAP` | `WebGLTexture` |  |
| `gl.UNPACK_ALIGNMENT` | `GLint` (en-US) |  |
| `gl.UNPACK_COLORSPACE_CONVERSION_WEBGL` | `GLenum` (en-US) |  |
| `gl.UNPACK_FLIP_Y_WEBGL` | `GLboolean` (en-US) |  |
| `gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL` | `GLboolean` (en-US) |  |
| `gl.VENDOR` | `DOMString` |  |
| `gl.VERSION` | `DOMString` |  |
| `gl.VIEWPORT` | `Int32Array` (with 4 elements) |  |

### WebGL 2

使用 `WebGL2RenderingContext` 时，你可以查询以下 `pname` 参数。

| 常量 | 返回类型 | 描述 |
| --- | --- | --- |
| `gl.COPY_READ_BUFFER_BINDING` | `WebGLBuffer` |  |
| `gl.COPY_WRITE_BUFFER_BINDING` | `WebGLBuffer` |  |
| `gl.DRAW_BUFFERi` | `GLenum` (en-US) |  |
| `gl.DRAW_FRAMEBUFFER_BINDING` | `WebGLFramebuffer` |  |
| `gl.FRAGMENT_SHADER_DERIVATIVE_HINT` | `GLenum` (en-US) |  |
| `gl.MAX_3D_TEXTURE_SIZE` | `GLint` (en-US) |  |
| `gl.MAX_ARRAY_TEXTURE_LAYERS` | `GLint` (en-US) |  |
| `gl.MAX_CLIENT_WAIT_TIMEOUT_WEBGL` | `GLint64` (en-US) |  |
| `gl.MAX_COLOR_ATTACHMENTS` | `GLint` (en-US) |  |
| `gl.MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS` | `GLint64` (en-US) |  |
| `gl.MAX_COMBINED_UNIFORM_BLOCKS` | `GLint` (en-US) |  |
| `gl.MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS` | `GLint64` (en-US) |  |
| `gl.MAX_DRAW_BUFFERS` | `GLint` (en-US) |  |
| `gl.MAX_ELEMENT_INDEX` | `GLint64` (en-US) |  |
| `gl.MAX_ELEMENTS_INDICES` | `GLint` (en-US) |  |
| `gl.MAX_ELEMENTS_VERTICES` | `GLint` (en-US) |  |
| `gl.MAX_FRAGMENT_INPUT_COMPONENTS` | `GLint` (en-US) |  |
| `gl.MAX_FRAGMENT_UNIFORM_BLOCKS` | `GLint` (en-US) |  |
| `gl.MAX_FRAGMENT_UNIFORM_COMPONENTS` | `GLint` (en-US) |  |
| `gl.MAX_PROGRAM_TEXEL_OFFSET` | `GLint` (en-US) |  |
| `gl.MAX_SAMPLES` | `GLint` (en-US) |  |
| `gl.MAX_SERVER_WAIT_TIMEOUT` | `GLint64` (en-US) |  |
| `gl.MAX_TEXTURE_LOD_BIAS` | `GLfloat` (en-US) |  |
| `gl.MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS` | `GLint` (en-US) |  |
| `gl.MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS` | `GLint` (en-US) |  |
| `gl.MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS` | `GLint` (en-US) |  |
| `gl.MAX_UNIFORM_BLOCK_SIZE` | `GLint64` (en-US) |  |
| `gl.MAX_UNIFORM_BUFFER_BINDINGS` | `GLint` (en-US) |  |
| `gl.MAX_VARYING_COMPONENTS` | `GLint` (en-US) |  |
| `gl.MAX_VERTEX_OUTPUT_COMPONENTS` | `GLint` (en-US) |  |
| `gl.MAX_VERTEX_UNIFORM_BLOCKS` | `GLint` (en-US) |  |
| `gl.MAX_VERTEX_UNIFORM_COMPONENTS` | `GLint` (en-US) |  |
| `gl.MIN_PROGRAM_TEXEL_OFFSET` | `GLint` (en-US) |  |
| `gl.PACK_ROW_LENGTH` | `GLint` (en-US) |  |
| `gl.PACK_SKIP_PIXELS` | `GLint` (en-US) |  |
| `gl.PACK_SKIP_ROWS` | `GLint` (en-US) |  |
| `gl.PIXEL_PACK_BUFFER_BINDING` | `WebGLBuffer` |  |
| `gl.PIXEL_UNPACK_BUFFER_BINDING` | `WebGLBuffer` |  |
| `gl.RASTERIZER_DISCARD` | `GLboolean` (en-US) |  |
| `gl.READ_BUFFER` | `GLenum` (en-US) |  |
| `gl.READ_FRAMEBUFFER_BINDING` | `WebGLFramebuffer` |  |
| `gl.SAMPLE_ALPHA_TO_COVERAGE` | `GLboolean` (en-US) |  |
| `gl.SAMPLE_COVERAGE` | `GLboolean` (en-US) |  |
| `gl.SAMPLER_BINDING` | `WebGLSampler` |  |
| `gl.TEXTURE_BINDING_2D_ARRAY` | `WebGLTexture` |  |
| `gl.TEXTURE_BINDING_3D` | `WebGLTexture` |  |
| `gl.TRANSFORM_FEEDBACK_ACTIVE` | `GLboolean` (en-US) |  |
| `gl.TRANSFORM_FEEDBACK_BINDING` | `WebGLTransformFeedback` (en-US) |  |
| `gl.TRANSFORM_FEEDBACK_BUFFER_BINDING` | `WebGLBuffer` |  |
| `gl.TRANSFORM_FEEDBACK_PAUSED` | `GLboolean` (en-US) |  |
| `gl.UNIFORM_BUFFER_BINDING` | `WebGLBuffer` |  |
| `gl.UNIFORM_BUFFER_OFFSET_ALIGNMENT` | `GLint` (en-US) |  |
| `gl.UNPACK_IMAGE_HEIGHT` | `GLint` (en-US) |  |
| `gl.UNPACK_ROW_LENGTH` | `GLint` (en-US) |  |
| `gl.UNPACK_SKIP_IMAGES` | `GLint` (en-US) |  |
| `gl.UNPACK_SKIP_PIXELS` | `GLint` (en-US) |  |
| `gl.UNPACK_SKIP_ROWS` | `GLint` (en-US) |  |
| `gl.VERTEX_ARRAY_BINDING` | `WebGLVertexArrayObject` |  |

### WebGL 扩展

当使用 WebGL 扩展 时，你可以查询以下 `pname` 参数：

| 常量 | 返回类型 | 扩展 | 描述 |
| --- | --- | --- | --- |
| `ext.MAX_TEXTURE_MAX_ANISOTROPY_EXT` | `GLfloat` (en-US) | `EXT_texture_filter_anisotropic` (en-US) | 最大可用各向异性。 |
| `ext.FRAGMENT_SHADER_DERIVATIVE_HINT_OES` | `GLenum` (en-US) | `OES_standard_derivatives` (en-US) | GLSL 内置函数的导数计算精度：`dFdx`、 `dFdy` 和 `fwidth`。 |
| `ext.MAX_COLOR_ATTACHMENTS_WEBGL` | `GLint` (en-US) | `WEBGL_draw_buffers` (en-US) | 帧缓冲区颜色附着点的最大数量。 |
| `ext.MAX_DRAW_BUFFERS_WEBGL` | `GLint` (en-US) | `WEBGL_draw_buffers` (en-US) | 绘图缓冲区的最大数量。 |
| `ext.DRAW_BUFFER0_WEBGL ext.DRAW_BUFFER1_WEBGL ext.DRAW_BUFFER2_WEBGL ext.DRAW_BUFFER3_WEBGL ext.DRAW_BUFFER4_WEBGL ext.DRAW_BUFFER5_WEBGL ext.DRAW_BUFFER6_WEBGL ext.DRAW_BUFFER7_WEBGL ext.DRAW_BUFFER8_WEBGL ext.DRAW_BUFFER9_WEBGL ext.DRAW_BUFFER10_WEBGL ext.DRAW_BUFFER11_WEBGL ext.DRAW_BUFFER12_WEBGL ext.DRAW_BUFFER13_WEBGL ext.DRAW_BUFFER14_WEBGL ext.DRAW_BUFFER15_WEBGL` | `GLenum` (en-US) | `WEBGL_draw_buffers` (en-US) | 绘图缓冲区。 |
| `ext.VERTEX_ARRAY_BINDING_OES` | `WebGLVertexArrayObjectOES` (en-US) | `OES_vertex_array_object` | 绑定的顶点数组对象（VAO）。 |
| `ext.TIMESTAMP_EXT` | `GLuint64EXT` (en-US) | `EXT_disjoint_timer_query` (en-US) | 当前时间。 |
| `ext.GPU_DISJOINT_EXT` | `GLboolean` (en-US) | `EXT_disjoint_timer_query` (en-US) | 返回 GPU 是否执行了任何不相交的操作。 |

示例
--


```js
gl.getParameter(gl.DITHER);
gl.getParameter(gl.VERSION);
gl.getParameter(gl.VIEWPORT);
```

规范
--

| Specification |
| --- |
| WebGL Specification # 5.14.3 |
| WebGL 2.0 Specification # 3.7.2 |

浏览器兼容性
------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

参见
--

* `WebGLRenderingContext.enable()`
* `WebGLRenderingContext.disable()` (en-US)
* `EXT_texture_filter_anisotropic` (en-US)
* `OES_standard_derivatives` (en-US)
* `WEBGL_draw_buffers` (en-US)
* `EXT_disjoint_timer_query` (en-US)