Opengl和Webgl:从附加到当前帧缓冲区的纹理采样 [英] Opengl and Webgl: sampling from a texture attached to current framebuffer

查看:239
本文介绍了Opengl和Webgl:从附加到当前帧缓冲区的纹理采样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有两个纹理 t0 t1 的帧缓冲区。

I have a framebuffer with two textures t0 and t1 attached.

在第一遍中,我使用多个片段着色器输出渲染它们两者。

On the first pass I render to both of them with multiple fragment shader output.

在第二遍之前,我要执行以下操作:

Before the second pass I do thew following:


  • 打开仅具有一个输出的着色器

  • 绑定 t1 到纹理单元

  • 调用glDrawBuffers以禁止写入 t1 的附件

  • Turn on a shader with one output only
  • Bind t1 to a texture unit
  • call glDrawBuffers to disable writing to t1's attachment

请注意, t1 用于采样,但仍绑定到当前帧缓冲区。据我了解,这种配置没有环回。

Note that t1 is used for sampling, but it's still bound to current framebuffer. As I understand, there are no loopbacks in such configuration.

在OpenGL和WebGL中合法吗?

Is it legal in both OpenGL and WebGL?

我制作了一个示例,它可以在Linux下的Chrome和Firefox中完美运行,但是呈现了一个Windows的两个浏览器中都出现黑屏。是此处?

I made an 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)中,反馈循环。如果您现在不写信,都没关系。您现在不能写信都没关系。只要将它附加到帧缓冲区,就可以通过对其进行读取来获得未定义的行为(除非它们是从未附加的mipmap级别读取的)。

In pre-GL 4.5 (which includes WebGL), feedback loops happen any time you read from a texture which is currently attached to the framebuffer. It doesn't matter if you don't write to it at the moment. It doesn't matter that you can't write to it at the moment. As long as it is attached to the framebuffer, you get undefined behavior from reads to it (unless they are reads from mipmap levels that aren't attached).

In < a href = https://www.khronos.org/opengl/wiki/Memory_Model#Texture_barrier rel = nofollow noreferrer> post-GL 4.5 (包括WebGL)或带有纹理障碍扩展名,这很轻松。但是还不足以解决您的问题。当您尝试从仍连接到帧缓冲区的图像中读取上次调用中写入的像素时,仍会触发UB。

In post-GL 4.5 (which doesn't include WebGL) or with the texture barrier extension, this is relaxed. But not enough to solve your problem. UB is still triggered when you try to read from pixels written in a previous call from an image that is still attached to the framebuffer.

因此,您必须更改FBO以便图像不再被附加,或者您必须发出纹理屏障(如果您可以访问4.5 / ARB / NV_texture_barrier,您可能会在桌面GL上执行此操作)。

So you have to either change FBOs so that the image is no longer attached, or you have to issue a texture barrier (if you have access to 4.5/ARB/NV_texture_barrier, which on desktop GL you probably do).

这篇关于Opengl和Webgl:从附加到当前帧缓冲区的纹理采样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆