OpenGl read and write to the same texture(OpenGL 读写相同的纹理)
问题描述
我有一个 RGBA16F 纹理,上面有深度、normal.x、normal.y.我想读取 r、g、b 并写入纹理上的 a.我会准确地击中每个像素一次.
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 be a performance problem if I read and write to the same texture in this case?
推荐答案
不会有性能问题.会有一个功能问题.就像那样,它不起作用.
There won't be a performance problem. There will be a functionality problem. As in, it won't work.
您无法从您通过 FBO 写入的图像中读取并期望获得合理的结果.这会产生未定义的行为.
You cannot read from an image that you are writing to via FBO and expect to get reasonable results. That's yields undefined behavior.
如果您使用 shader_image_load_store 进行读/写,您可能可以逃脱.但即便如此,它也是一个读/修改/写操作;你必须写回你读到的 alpha.
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.
话虽如此,如果您确定每个像素恰好命中一次"(强调),那么您确实有追索权.即,NV_texture_barrier.不要让这个扩展上的NV"欺骗你;它也广泛应用于 AMD 硬件(所有 HD 系列卡).这个扩展允许你使用一个屏障"函数(实际上是一个告诉 GPU 清除帧缓冲区和纹理缓存的函数),在调用后,它将允许你完全 one 读取/在片段着色器中修改/写入.在第一次通过之后,您需要在第二次通过之间建立另一个障碍.
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.
这篇关于OpenGL 读写相同的纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:OpenGL 读写相同的纹理


基础教程推荐
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01