如何在 WebGL2 中创建内部格式为“RG8UI”的纹理?

How do I create a texture with internal format `RG8UI` in WebGL2?

下面的代码片段尝试创建一个纹理,然后检查 gl.getError()。当内部格式设置为RG8时创建成功。我想将内部格式设置为RG8UI,但这导致创建失败。在 Firefox 中,还会向控制台打印一条警告:Mismatched internalFormat and format/type: 0x8238 and 0x8227/0x1401 其中 0x8238=RG8UI0x8227=RG0x1401=UNSIGNED_BYTE.

据我所知,MDN's documentation on texImage2D 表示内部格式 RG8UI 与格式 RG 的配对是允许的,尽管它不是 "texture filterable" 是什么意思。我在这里做错了什么?

const gl = document.createElement('canvas').getContext('webgl2');
const GL = WebGL2RenderingContext;
const w = 8;
const h = 8;
let texture = gl.createTexture();
gl.bindTexture(GL.TEXTURE_2D, texture);
gl.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_MAG_FILTER, GL.NEAREST);
gl.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_MIN_FILTER, GL.NEAREST);
gl.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_S, GL.CLAMP_TO_EDGE);
gl.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_T, GL.CLAMP_TO_EDGE);

gl.texImage2D(GL.TEXTURE_2D, 0, GL.RG8UI, w, h, 0, GL.RG, GL.UNSIGNED_BYTE, null);

if (gl.getError() != GL.NO_ERROR) {
    throw new Error("Failed");
}
console.log("passed");

如果 imageformat 是一个完整的格式,那么 format 也必须是完整的。生成 INVALID_OPERATION 错误。
请注意,指定了 internalformatformattype 的允许组合:Valid combinations of format, type, and sized internalformat .有效组合为 RG8UIRG_INTEGERUNSIGNED_BYTE.

将格式参数从 GL.RG 更改为 GL.RG_INTEGER

gl.texImage2D(GL.TEXTURE_2D, 0, GL.RG8UI, w, h, 0, GL.RG, GL.UNSIGNED_BYTE, null);

gl.texImage2D(GL.TEXTURE_2D, 0, GL.RG8UI, w, h, 0, GL.RG_INTEGER, GL.UNSIGNED_BYTE, null);