WebGLRenderingContext.getActiveUniform()
方法在
WebGL API
返回
WebGLActiveInfo
object containing size, type, and name of a uniform attribute. It is generally used when querying unknown uniforms either for debugging or generic library creation.
WebGLActiveInfo WebGLRenderingContext.getActiveUniform(program, index);
program
WebGLProgram
specifying the WebGL shader program from which to obtain the uniform variable's information.
index
GLuint
specifying the index of the uniform attribute to get. This value is an index 0 to N - 1 as returned by
gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS)
.
A
WebGLActiveInfo
object describing the uniform.
type
attribute of the return value will be one of the following:
gl.FLOAT
gl.FLOAT_VEC2
gl.FLOAT_VEC3
gl.FLOAT_VEC4
gl.INT
gl.INT_VEC2
gl.INT_VEC3
gl.INT_VEC4
gl.BOOL
gl.BOOL_VEC2
gl.BOOL_VEC3
gl.BOOL_VEC4
gl.FLOAT_MAT2
gl.FLOAT_MAT3
gl.FLOAT_MAT4
gl.SAMPLER_2D
gl.SAMPLER_CUBE
gl.UNSIGNED_INT
gl.UNSIGNED_INT_VEC2
gl.UNSIGNED_INT_VEC3
gl.UNSIGNED_INT_VEC4
gl.FLOAT_MAT2x3
gl.FLOAT_MAT2x4
gl.FLOAT_MAT3x2
gl.FLOAT_MAT3x4
gl.FLOAT_MAT4x2
gl.FLOAT_MAT4x3
gl.SAMPLER_2D
gl.SAMPLER_3D
gl.SAMPLER_CUBE
gl.SAMPLER_2D_SHADOW
gl.SAMPLER_2D_ARRAY
gl.SAMPLER_2D_ARRAY_SHADOW
gl.SAMPLER_CUBE_SHADOW
gl.INT_SAMPLER_2D
gl.INT_SAMPLER_3D
gl.INT_SAMPLER_CUBE
gl.INT_SAMPLER_2D_ARRAY
gl.UNSIGNED_INT_SAMPLER_2D
gl.UNSIGNED_INT_SAMPLER_3D
gl.UNSIGNED_INT_SAMPLER_CUBE
gl.UNSIGNED_INT_SAMPLER_2D_ARRAY
当
gl.linkProgram
is called, WebGL creates a list of active uniforms. These are possible values of the
名称
attribute of return values of
getActiveUniform
. WebGL generates one or more entries in the list depending on the declared type of the uniform in the shader:
uniform vec4 a;
will result in
a
.
[0]
. E.g.
uniform vec4 b[];
will result in
b[0]
.
uniform struct { float foo; vec4 bar; } c;
will result in
c.foo
and
c.bar
.
uniform struct { float foo; vec4 bar; } d[2];
will result in:
d[0].foo
d[0].bar
d[1].foo
d[1].bar
uniform Block { float foo; };
will result in
foo
,和
uniform Block { float bar; } e;
will result in
Block.bar
.
size
attribute of the return value corresponds to the length of the array for uniforms declared as arrays. Otherwise, it is 1 (this includes interface blocks instanced with arrays).
gl.INVALID_VALUE
is generated if the program
WebGLProgram
is invalid (not linked, deleted, etc.).
gl.INVALID_VALUE
is generated if index is not in the range [0,
gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS)
- 1].
const numUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
for (let i = 0; i < numUniforms; ++i) {
const info = gl.getActiveUniform(program, i);
console.log('name:', info.name, 'type:', info.type, 'size:', info.size);
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
WebGL 1.0
The definition of 'getActiveUniform' in that specification. |
推荐 | 初始定义。 |
|
OpenGL ES 2.0
The definition of 'glGetActiveUniform' in that specification. |
标准 | Man page of the OpenGL API. |
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
更新 GitHub 上的兼容性数据| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
getActiveUniform
|
Chrome 9 | Edge 12 | Firefox 4 | IE 11 | Opera 12 | Safari 5.1 | WebView Android Yes | Chrome Android 25 | Firefox Android Yes | Opera Android 12 | Safari iOS 8 | Samsung Internet Android 1.5 |
完整支持
WebGLRenderingContext
activeTexture()
attachShader()
bindAttribLocation()
bindBuffer()
bindFramebuffer()
bindRenderbuffer()
bindTexture()
blendColor()
blendEquation()
blendEquationSeparate()
blendFunc()
blendFuncSeparate()
bufferData()
bufferSubData()
checkFramebufferStatus()
clear()
clearColor()
clearDepth()
clearStencil()
colorMask()
commit()
compileShader()
compressedTexImage[23]D()
compressedTexSubImage2D()
copyTexImage2D()
copyTexSubImage2D()
createBuffer()
createFramebuffer()
createProgram()
createRenderbuffer()
createShader()
createTexture()
cullFace()
deleteBuffer()
deleteFramebuffer()
deleteProgram()
deleteRenderbuffer()
deleteShader()
deleteTexture()
depthFunc()
depthMask()
depthRange()
detachShader()
disable()
disableVertexAttribArray()
drawArrays()
drawElements()
enable()
enableVertexAttribArray()
finish()
flush()
framebufferRenderbuffer()
framebufferTexture2D()
frontFace()
generateMipmap()
getActiveAttrib()
getActiveUniform()
getAttachedShaders()
getAttribLocation()
getBufferParameter()
getContextAttributes()
getError()
getExtension()
getFramebufferAttachmentParameter()
getParameter()
getProgramInfoLog()
getProgramParameter()
getRenderbufferParameter()
getShaderInfoLog()
getShaderParameter()
getShaderPrecisionFormat()
getShaderSource()
getSupportedExtensions()
getTexParameter()
getUniform()
getUniformLocation()
getVertexAttrib()
getVertexAttribOffset()
hint()
isBuffer()
isContextLost()
isEnabled()
isFramebuffer()
isProgram()
isRenderbuffer()
isShader()
isTexture()
lineWidth()
linkProgram()
pixelStorei()
polygonOffset()
readPixels()
renderbufferStorage()
sampleCoverage()
scissor()
shaderSource()
stencilFunc()
stencilFuncSeparate()
stencilMask()
stencilMaskSeparate()
stencilOp()
stencilOpSeparate()
texImage2D()
texParameter[fi]()
texSubImage2D()
uniform[1234][fi][v]()
uniformMatrix[234]fv()
useProgram()
validateProgram()
vertexAttrib[1234]f[v]()
vertexAttribPointer()
viewport()
ANGLE_instanced_arrays
EXT_blend_minmax
EXT_color_buffer_half_float
EXT_disjoint_timer_query
EXT_frag_depth
EXT_sRGB
EXT_shader_texture_lod
EXT_texture_filter_anisotropic
OES_element_index_uint
OES_standard_derivatives
OES_texture_float
OES_texture_float_linear
OES_texture_half_float
OES_texture_half_float_linear
OES_vertex_array_object
WEBGL_color_buffer_float
WEBGL_compressed_texture_atc
WEBGL_compressed_texture_etc1
WEBGL_compressed_texture_pvrtc
WEBGL_compressed_texture_s3tc
WEBGL_compressed_texture_s3tc_srgb
WEBGL_debug_renderer_info
WEBGL_debug_shaders
WEBGL_depth_texture
WEBGL_draw_buffers
WEBGL_lose_context
WebGL2RenderingContext
WebGLActiveInfo
WebGLBuffer
WebGLContextEvent
WebGLFramebuffer
WebGLObject
WebGLProgram
WebGLQuery
WebGLRenderbuffer
WebGLSampler
WebGLShader
WebGLShaderPrecisionFormat
WebGLSync
WebGLTexture
WebGLTransformFeedback
WebGLUniformLocation
WebGLVertexArrayObject