Opengl 和 Webgl:从附加到当前帧缓冲区的纹理中采样
Opengl and Webgl: sampling from a texture attached to current framebuffer
我有一个带有两个纹理 t0
和 t1
的帧缓冲区。
在第一遍中,我使用多个片段着色器输出渲染它们。
在第二遍之前我做了以下事情:
- 打开一个只有一个输出的着色器
- 绑定
t1
到纹理单元
- 调用 glDrawBuffers 以禁止写入
t1
的附件
请注意,t1
用于采样,但它仍绑定到当前帧缓冲区。据我了解,这种配置没有回环。
在 OpenGL 和 WebGL 中都合法吗?
我做了一个example which works perfectly in Chrome and Firefox under Linux, but renders a black screen in both browsers for Windows. Is the reason in D3D-backed Webgl implementation, and it's aggressive texture unbinding as pointed here?
As I understand, there are no loopbacks in such configuration.
但是有一个。
在 GL 4.5 之前的版本(包括 WebGL)中,只要您从当前附加到帧缓冲区的纹理读取数据,就会发生 feedback loops。此刻不给它写信也没关系。您现在不能写信给它也没关系。只要它附加到帧缓冲区,您就会从读取到它得到未定义的行为(除非它们是从未附加的 mipmap 级别读取的)。
在 post-GL 4.5(不 包括 WebGL)或纹理屏障扩展中,这是放宽的。但还不足以解决你的问题。当您尝试从仍然附加到帧缓冲区的图像中读取在先前调用中写入的像素时,UB 仍然会被触发。
因此您必须更改 FBO 以便不再附加图像,或者您必须发布纹理屏障(如果您可以访问 4.5/ARB/NV_texture_barrier,在桌面 GL 上您可能会这样做).
这在 WebGL1 和 WebGL2 中都是非法的。如果存在反馈循环,WebGL 需要生成 INVALID_OPERATION
错误。
6.25 Feedback Loops Between Textures and the Framebuffer
In the OpenGL ES 2.0 API, it's possible to make calls that both write to and read from the same texture, creating a feedback loop. It specifies that where these feedback loops exist, undefined behavior results.
In the WebGL API, such operations that would cause such feedback loops (by the definitions in the OpenGL ES 2.0 spec) will instead generate an INVALID_OPERATION error.
正如您在那里指出的那样,听起来您的情况可能没有实际的反馈回路,但正如 Nicol 根据规范指出的那样,仍然存在。 This appears to be a bug both Chrome and Firefox.
我有一个带有两个纹理 t0
和 t1
的帧缓冲区。
在第一遍中,我使用多个片段着色器输出渲染它们。
在第二遍之前我做了以下事情:
- 打开一个只有一个输出的着色器
- 绑定
t1
到纹理单元 - 调用 glDrawBuffers 以禁止写入
t1
的附件
请注意,t1
用于采样,但它仍绑定到当前帧缓冲区。据我了解,这种配置没有回环。
在 OpenGL 和 WebGL 中都合法吗?
我做了一个example which works perfectly in Chrome and Firefox under Linux, but renders a black screen in both browsers for Windows. Is the reason in D3D-backed Webgl implementation, and it's aggressive texture unbinding as pointed here?
As I understand, there are no loopbacks in such configuration.
但是有一个。
在 GL 4.5 之前的版本(包括 WebGL)中,只要您从当前附加到帧缓冲区的纹理读取数据,就会发生 feedback loops。此刻不给它写信也没关系。您现在不能写信给它也没关系。只要它附加到帧缓冲区,您就会从读取到它得到未定义的行为(除非它们是从未附加的 mipmap 级别读取的)。
在 post-GL 4.5(不 包括 WebGL)或纹理屏障扩展中,这是放宽的。但还不足以解决你的问题。当您尝试从仍然附加到帧缓冲区的图像中读取在先前调用中写入的像素时,UB 仍然会被触发。
因此您必须更改 FBO 以便不再附加图像,或者您必须发布纹理屏障(如果您可以访问 4.5/ARB/NV_texture_barrier,在桌面 GL 上您可能会这样做).
这在 WebGL1 和 WebGL2 中都是非法的。如果存在反馈循环,WebGL 需要生成 INVALID_OPERATION
错误。
6.25 Feedback Loops Between Textures and the Framebuffer
In the OpenGL ES 2.0 API, it's possible to make calls that both write to and read from the same texture, creating a feedback loop. It specifies that where these feedback loops exist, undefined behavior results.
In the WebGL API, such operations that would cause such feedback loops (by the definitions in the OpenGL ES 2.0 spec) will instead generate an INVALID_OPERATION error.
正如您在那里指出的那样,听起来您的情况可能没有实际的反馈回路,但正如 Nicol 根据规范指出的那样,仍然存在。 This appears to be a bug both Chrome and Firefox.