WebGL 中使用的 STENCIL_INDEX 常量在哪里?
Where is the STENCIL_INDEX constant used in WebGL?
在 WebGL 1 specification 中,我注意到有一个常量 const GLenum STENCIL_INDEX = 0x1901;
并且想知道它是如何使用的。我一直在尝试将它与纹理或渲染缓冲区一起使用,尽管 none 我尝试过的组合已经奏效。例如,我尝试在下面的示例中使用 STENCIL_INDEX
而不是 STENCIL_INDEX8
作为渲染缓冲区,或者使用 STENCIL_INDEX8
作为内部格式和 STENCIL_INDEX
调用 texImage2D
作为格式。
在 WebGL 1 或 2 中(如果需要启用任何扩展),我想知道常量 STENCIL_INDEX
可以在纹理、渲染缓冲区或某些附件配置中的何处使用。即使这是特定于硬件的,我仍然有兴趣知道它是如何使用的。
例如,我很好奇如何修改下面的代码以使用 STENCIL_INDEX
(不是 STENCIL_INDEX8
——注意这个常量已经在渲染缓冲区中使用):
const pixel = new Uint8Array([0, 0, 0, 0]);
for (const version of ['webgl', 'webgl2']) {
const canvas = document.createElement('canvas'),
gl = canvas.getContext(version, {stencil: true}),
framebuffer = gl.createFramebuffer(),
stencilbuffer = gl.createRenderbuffer(),
texture = gl.createTexture();
canvas.width = 1;
canvas.height = 1;
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
gl.bindRenderbuffer(gl.RENDERBUFFER, stencilbuffer);
gl.renderbufferStorage(gl.RENDERBUFFER, gl.STENCIL_INDEX8, 1, 1);
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.RENDERBUFFER, stencilbuffer);
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, pixel);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
const status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
if (status !== gl.FRAMEBUFFER_COMPLETE) {
console.error(status, version);
}
gl.deleteTexture(texture);
gl.deleteRenderbuffer(stencilbuffer);
gl.deleteFramebuffer(framebuffer);
}
我确实看到了 OES_texture_stencil8
extension in OpenGL ES 3.1,尽管即使在那里它也声明 STENCIL_INDEX
常量已经存在。那么常量在 OpenGL ES 中的用途是什么?这与 WebGL 中的使用有何关系?
我还发现 this line of commented code referencing STENCIL_INDEX
in Chromium, which is why I thought I'd raise it here in case this behavior is known. Likewise Firefox doesn't seem to list STENCIL_INDEX
in its formats enum 并且似乎没有引用 STENCIL_INDEX
除了一致性测试确保常量存在并且具有值 0x1901
.
这是个好问题。我认为这可能是 WebGL 规范中的错误
检查 OpenGL ES 2.0 spec there appears to be no mention of STENCIL_INDEX
and STENCIL_INDEX
is also not in the OpenGL ES 2.0 headers
出现的OpenGL ES 3.0 spec nor the ES 3.0 headers. It's not until ES 3.1也没有提到
在 WebGL 1 specification 中,我注意到有一个常量 const GLenum STENCIL_INDEX = 0x1901;
并且想知道它是如何使用的。我一直在尝试将它与纹理或渲染缓冲区一起使用,尽管 none 我尝试过的组合已经奏效。例如,我尝试在下面的示例中使用 STENCIL_INDEX
而不是 STENCIL_INDEX8
作为渲染缓冲区,或者使用 STENCIL_INDEX8
作为内部格式和 STENCIL_INDEX
调用 texImage2D
作为格式。
在 WebGL 1 或 2 中(如果需要启用任何扩展),我想知道常量 STENCIL_INDEX
可以在纹理、渲染缓冲区或某些附件配置中的何处使用。即使这是特定于硬件的,我仍然有兴趣知道它是如何使用的。
例如,我很好奇如何修改下面的代码以使用 STENCIL_INDEX
(不是 STENCIL_INDEX8
——注意这个常量已经在渲染缓冲区中使用):
const pixel = new Uint8Array([0, 0, 0, 0]);
for (const version of ['webgl', 'webgl2']) {
const canvas = document.createElement('canvas'),
gl = canvas.getContext(version, {stencil: true}),
framebuffer = gl.createFramebuffer(),
stencilbuffer = gl.createRenderbuffer(),
texture = gl.createTexture();
canvas.width = 1;
canvas.height = 1;
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
gl.bindRenderbuffer(gl.RENDERBUFFER, stencilbuffer);
gl.renderbufferStorage(gl.RENDERBUFFER, gl.STENCIL_INDEX8, 1, 1);
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.RENDERBUFFER, stencilbuffer);
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, pixel);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
const status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
if (status !== gl.FRAMEBUFFER_COMPLETE) {
console.error(status, version);
}
gl.deleteTexture(texture);
gl.deleteRenderbuffer(stencilbuffer);
gl.deleteFramebuffer(framebuffer);
}
我确实看到了 OES_texture_stencil8
extension in OpenGL ES 3.1,尽管即使在那里它也声明 STENCIL_INDEX
常量已经存在。那么常量在 OpenGL ES 中的用途是什么?这与 WebGL 中的使用有何关系?
我还发现 this line of commented code referencing STENCIL_INDEX
in Chromium, which is why I thought I'd raise it here in case this behavior is known. Likewise Firefox doesn't seem to list STENCIL_INDEX
in its formats enum 并且似乎没有引用 STENCIL_INDEX
除了一致性测试确保常量存在并且具有值 0x1901
.
这是个好问题。我认为这可能是 WebGL 规范中的错误
检查 OpenGL ES 2.0 spec there appears to be no mention of STENCIL_INDEX
and STENCIL_INDEX
is also not in the OpenGL ES 2.0 headers
出现的OpenGL ES 3.0 spec nor the ES 3.0 headers. It's not until ES 3.1也没有提到