OpenGL 读写相同的纹理

OpenGl read and write to the same texture(OpenGL 读写相同的纹理)
本文介绍了OpenGL 读写相同的纹理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有一个 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 transforming objects with multiple rotations of Different axis(OpenGL 变换不同轴多次旋转的对象)
GLFW first responder error(GLFW 第一响应者错误)
SOIL not linking correctly(SOIL 连接不正确)
Core profile vs version string? Only getting GLSL 1.3/OGL 3.0 in mesa 10.0.1(核心配置文件与版本字符串?在 mesa 10.0.1 中只获得 GLSL 1.3/OGL 3.0)
What is the range of OpenGL texture ID?(OpenGL 纹理 ID 的范围是多少?)
How taxing are OpenGL glDrawElements() calls compared to basic logic code?(与基本逻辑代码相比,OpenGL glDrawElements() 调用的繁重程度如何?)