这是 实验性技术
检查 浏览器兼容性表格 要小心谨慎在生产中使用这之前。

WebGL2RenderingContext.vertexAttribIPointer() 方法在 WebGL 2 API specifies integer data formats and locations of vertex attributes in a vertex attributes array.

句法

void gl.vertexAttribIPointer(index, size, type, stride, offset);
					

参数

index
GLuint specifying the index of the vertex attribute that is to be modified.
size
GLint specifying the number of components per vertex attribute. Must be 1, 2, 3, or 4.
type
A GLenum specifying the data type of each component in the array. Must be one of: gl.BYTE , gl.UNSIGNED_BYTE , gl.SHORT , gl.UNSIGNED_SHORT , gl.INT ,或 gl.UNSIGNED_INT .
stride
GLsizei specifying the offset in bytes between the beginning of consecutive vertex attributes.
offset
GLintptr specifying an offset in bytes of the first component in the vertex attribute array. Must be a multiple of type .

返回值

None.

描述

Very similar to WebGLRenderingContext.vertexAttribPointer() . The main difference is that while values specified by vertexAttribPointer are always  interpreted as floating-point values in the shader (even if they were originally specified as integers in the buffer), this method allows specifying values which are interpreted as integers in the shader.

范例

Linear Blend Skinning

//Describe the layout of the buffer:
//1. position
gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 20, 0);
gl.enableVertexAttribArray(0);
//2. bone weights, normalized to [0, 1]
gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, true, 20, 12);
gl.enableVertexAttribArray(1);
//3. bone indices, interpreted as integer
gl.vertexAttribIPointer(2, 4, gl.UNSIGNED_BYTE, 20, 16);
gl.enableVertexAttribArray(2);
//Connect to attributes from the vertex shader
gl.bindAttribLocation(shaderProgram, 0, "position");
gl.bindAttribLocation(shaderProgram, 1, "boneWeights");
gl.bindAttribLocation(shaderProgram, 2, "boneIndices");
					
<script id="shader-vs" type="x-shader/x-vertex">#version 300 es
uniform mat4 mvMatrix;
uniform mat4 bones[120];
in vec3 position;
in vec4 boneWeights;
in uvec4 boneIndices;//read as 4-component unsigned integer
void main() {
    vec4 skinnedPosition =
        bones[boneIndices.s] * vec4(position, 1.0) * boneWeights.s +
        bones[boneIndices.t] * vec4(position, 1.0) * boneWeights.t +
        bones[boneIndices.p] * vec4(position, 1.0) * boneWeights.p +
        bones[boneIndices.q] * vec4(position, 1.0) * boneWeights.q;
    gl_Position = mvMatrix * skinnedPosition;
}
</script>
					

规范

规范 状态 注释
WebGL 2.0
The definition of 'vertexAttribIPointer' in that specification.
编者草案 Initial definition for WebGL.
OpenGL ES 3.0
The definition of 'glVertexAttribPointer' in that specification.
标准 Man page of the (similar) OpenGL API.

浏览器兼容性

更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
vertexAttribIPointer Chrome 56 Edge 79 Firefox 51 IE No Opera 43 Safari No WebView Android 58 Chrome Android 58 Firefox Android 51 Opera Android 43 Safari iOS No Samsung Internet Android 7.0

图例

完整支持

完整支持

不支持

不支持

另请参阅

元数据

  • 最后修改:
  1. WebGL API
  2. WebGL2RenderingContext
  3. 方法
    1. beginQuery()
    2. beginTransformFeedback()
    3. bindBufferBase()
    4. bindBufferRange()
    5. bindSampler()
    6. bindTransformFeedback()
    7. bindVertexArray()
    8. blitFramebuffer()
    9. clearBuffer[fiuv]()
    10. clientWaitSync()
    11. compressedTexSubImage3D()
    12. copyBufferSubData()
    13. copyTexSubImage3D()
    14. createQuery()
    15. createSampler()
    16. createTransformFeedback()
    17. createVertexArray()
    18. deleteQuery()
    19. deleteSampler()
    20. deleteSync()
    21. deleteTransformFeedback()
    22. deleteVertexArray()
    23. drawArraysInstanced()
    24. drawBuffers()
    25. drawElementsInstanced()
    26. drawRangeElements()
    27. endQuery()
    28. endTransformFeedback()
    29. fenceSync()
    30. framebufferTextureLayer()
    31. getActiveUniformBlockName()
    32. getActiveUniformBlockParameter()
    33. getActiveUniforms()
    34. getBufferSubData()
    35. getFragDataLocation()
    36. getIndexedParameter()
    37. getInternalformatParameter()
    38. getQuery()
    39. getQueryParameter()
    40. getSamplerParameter()
    41. getSyncParameter()
    42. getTransformFeedbackVarying()
    43. getUniformBlockIndex()
    44. getUniformIndices()
    45. invalidateFramebuffer()
    46. invalidateSubFramebuffer()
    47. isQuery()
    48. isSampler()
    49. isSync()
    50. isTransformFeedback()
    51. isVertexArray()
    52. pauseTransformFeedback()
    53. readBuffer()
    54. renderbufferStorageMultisample()
    55. resumeTransformFeedback()
    56. samplerParameter[if]()
    57. texImage3D()
    58. texStorage2D()
    59. texStorage3D()
    60. texSubImage3D()
    61. transformFeedbackVaryings()
    62. uniform[1234][uif][v]()
    63. uniformBlockBinding()
    64. uniformMatrix[234]x[234]fv()
    65. vertexAttribDivisor()
    66. vertexAttribI4[u]i[v]()
    67. vertexAttribIPointer()
    68. waitSync()
  4. 继承:
    1. WebGLRenderingContext
  5. WebGL 相关页面
    1. ANGLE_instanced_arrays
    2. EXT_blend_minmax
    3. EXT_color_buffer_half_float
    4. EXT_disjoint_timer_query
    5. EXT_frag_depth
    6. EXT_sRGB
    7. EXT_shader_texture_lod
    8. EXT_texture_filter_anisotropic
    9. OES_element_index_uint
    10. OES_standard_derivatives
    11. OES_texture_float
    12. OES_texture_float_linear
    13. OES_texture_half_float
    14. OES_texture_half_float_linear
    15. OES_vertex_array_object
    16. WEBGL_color_buffer_float
    17. WEBGL_compressed_texture_atc
    18. WEBGL_compressed_texture_etc1
    19. WEBGL_compressed_texture_pvrtc
    20. WEBGL_compressed_texture_s3tc
    21. WEBGL_compressed_texture_s3tc_srgb
    22. WEBGL_debug_renderer_info
    23. WEBGL_debug_shaders
    24. WEBGL_depth_texture
    25. WEBGL_draw_buffers
    26. WEBGL_lose_context
    27. WebGLActiveInfo
    28. WebGLBuffer
    29. WebGLContextEvent
    30. WebGLFramebuffer
    31. WebGLObject
    32. WebGLProgram
    33. WebGLQuery
    34. WebGLRenderbuffer
    35. WebGLRenderingContext
    36. WebGLSampler
    37. WebGLShader
    38. WebGLShaderPrecisionFormat
    39. WebGLSync
    40. WebGLTexture
    41. WebGLTransformFeedback
    42. WebGLUniformLocation
    43. WebGLVertexArrayObject