WebGL2RenderingContext: phương thức vertexAttribIPointer()
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2021.
Note: This feature is available in Web Workers.
Phương thức WebGL2RenderingContext.vertexAttribIPointer() của WebGL 2 API chỉ định định dạng dữ liệu số nguyên và vị trí của các thuộc tính đỉnh trong một mảng thuộc tính đỉnh.
Cú pháp
vertexAttribIPointer(index, size, type, stride, offset)
Tham số
index-
Một
GLuintchỉ định chỉ mục của thuộc tính đỉnh sẽ được sửa đổi. size-
Một
GLintchỉ định số lượng thành phần trên mỗi thuộc tính đỉnh. Phải là 1, 2, 3 hoặc 4. type-
Một
GLenumchỉ định loại dữ liệu của mỗi thành phần trong mảng. Phải là một trong:gl.BYTE,gl.UNSIGNED_BYTE,gl.SHORT,gl.UNSIGNED_SHORT,gl.INThoặcgl.UNSIGNED_INT. stride-
Một
GLsizeichỉ định offset tính bằng byte giữa phần bắt đầu của các thuộc tính đỉnh liên tiếp. offset-
Một
GLintptrchỉ định offset tính bằng byte của thành phần đầu tiên trong mảng thuộc tính đỉnh. Phải là bội số củatype.
Giá trị trả về
None (undefined).
Mô tả
Rất giống với WebGLRenderingContext.vertexAttribPointer(). Sự khác biệt chính là trong khi các giá trị được chỉ định bởi vertexAttribPointer luôn được hiểu là giá trị float trong shader (ngay cả khi chúng ban đầu được chỉ định là số nguyên trong bộ đệm), phương thức này cho phép chỉ định các giá trị được hiểu là số nguyên trong shader.
Ví dụ
>Linear Blend Skinning
// Mô tả bố cục của bộ đệm:
// 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);
// Kết nối với các thuộc tính từ 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>
Đặc tả kỹ thuật
| Thông số kỹ thuật |
|---|
| WebGL 2.0 Specification> # 3.7.8> |