WebGLRenderingContext: getActiveAttrib() 方法

Baseline 已廣泛支援

此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 ⁨2015 年 7 月⁩以來,各瀏覽器均已提供此特性。

注意:此功能在 Web Workers 中可用。

WebGLRenderingContext.getActiveAttrib() 方法是 WebGL API 的一部分,用於返回一個 WebGLActiveInfo 物件,其中包含頂點屬性的 size(大小)、type(型別)和 name(名稱)。它通常用於在除錯或建立通用庫時查詢未知屬性。

語法

js
getActiveAttrib(program, index)

引數

program

包含頂點屬性的 WebGLProgram

index

一個 GLuint,指定要獲取的頂點屬性的索引。該值是從 0 到 N-1 的索引,由 gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES) 返回。

返回值

一個 WebGLActiveInfo 物件。

示例

js
const numAttribs = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
for (let i = 0; i < numAttribs; ++i) {
  const info = gl.getActiveAttrib(program, i);
  console.log("name:", info.name, "type:", info.type, "size:", info.size);
}

規範

規範
WebGL 規範
# 5.14.10

瀏覽器相容性

另見