0

I'm struggling to understand a concept and I was hoping somebody could set me straight on it.

I'm trying to build GLSL simulations that will retain data across each draw call, but I want it all to be done on the GPU so it's quick and efficient. I understand that you do this by rendering the data you want to a texture and then reading from that texture.

I have a simple demo where I have a rendertarget which I'm drawing a color to and each draw call I want to increase the value of the color by 0.01 by reading in the current color and adding 0.01 to it, however I get the error:

Source and destination textures of the draw are the same.

Which makes me think I've misunderstood this concept entirely because I get the impression you can't pass the current rendertarget in as a texture. Could someone clear this up for me because I feel pretty confused right now

4

1 回答 1

1

嗯,很明显你在做什么,读取和写入相同的纹理。只需创建两个纹理,一个将设置为渲染目标,第二个用于读取。因此,您读取 tex1,写入 tex2,然后在下一帧交换它们的用法,因此您写入 tex1 并从 tex2 读取。只需在框架上交替使用它们即可。

webGL 不支持同时读/写。只有最新版本的 OpenGL 具有可以以这种方式使用的 Image 对象,但 webGL 尚不支持它们,这就是为什么您必须使用两个纹理并来回乒乓球,交替使用它们的原因。

于 2016-05-07T16:00:15.383 回答