OpenGl read and write to the same texture

后端 未结 4 1152
既然无缘
既然无缘 2020-12-11 05:18

I have a RGBA16F texture with depth, normal.x, normal.y on it. I want to read r, g, b and write to a on the texture. I will hit every pixel exactly once.

Would there

4条回答
  •  无人及你
    2020-12-11 06:03

    There won't be a performance problem. There will be a functionality problem. As in, it won't work.

    You cannot read from an image that you are writing to via FBO and expect to get reasonable results. That's yields undefined behavior.

    If you were using shader_image_load_store to do your reading/writing, you might be able to get away with it. But even then, it's a read/modify/write operation; you have to write back the alpha that you read.

    That being said, if you are certain that you will "hit every pixel exactly once" (emphasis added), you do have a recourse. Namely, NV_texture_barrier. Don't let the "NV" on this extension fool you; it's widely implemented on AMD hardware as well (all HD-series cards). This extension allows you to use a "barrier" function (effectively a function that tells the GPU to clear the framebuffer and texture caches) which, after calling, will allow you to do exactly one pass of read/modify/write in your fragment shader. After that one pass, you need another barrier between that and your second pass.

提交回复
热议问题