从一个纹理读取并在同一帧缓冲区中写入一个单独的纹理 [英] Read from one texture and write to a separate texture with in the same frame buffer

查看:36
本文介绍了从一个纹理读取并在同一帧缓冲区中写入一个单独的纹理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 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.

这篇关于从一个纹理读取并在同一帧缓冲区中写入一个单独的纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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