问题描述
我有一个带有 2 个纹理的帧缓冲区,是否可以在同一个片段着色器函数中从纹理 A 读取并写入纹理 B?
I have a Framebuffer with 2 textures attached is it possible to read from texture A and write to texture B, in the same fragment shader function ?
谢谢.
推荐答案
扩展 Reto 的答案.
Extending Reto's answer.
您可以从纹理 A 读取并写入纹理 B,但您不能这样做:
You can read from texture A and write to texture B, BUT you cannot do this:
uniform sampler2D B; // Sampler for texture B.
layout (location = 0) out vec3 A; // Write to texture
A = texture(B,Texcoord);
这是无效的,您必须使用三级变量.
This is invalid, and you must use a tertiary variable.
您不能在同一个绘制调用中读取和写入纹理,但您可以在同一个绘制调用中读取一个纹理并写入另一个位于同一帧缓冲区中的纹理.您必须确保在绑定帧缓冲区时像这样绑定它.
You cannot read and write to the texture on the same draw call, but you can read from one texture and write to another texture that both reside on the same framebuffer in the same draw call. You have to make sure when you bind the frame buffer you bind it like this.
glbindframebuffer(GL_FRAMEBUFFER, fboHandle)
这是因为帧缓冲区将被写入和读取,并且`GL_FRAMEBUFFER 将允许您执行此操作.
This is because the framebuffer will be written to and read from and the `GL_FRAMEBUFFER, will allow you to do this.
这篇关于从一个纹理读取并在同一帧缓冲区中写入一个单独的纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!