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
Well, it's obvious what you're doing, both reading from and writing to the same texture. Just create two textures, one that will be set as rendertarget, and the second to read from. So you read tex1, write to tex2, then in the next frame swap their usage, so you write to tex1 and read from tex2. Just alternate their usage over the frames.
Simultaneous read/write is not supported in webGL. Only very recent version of OpenGL have Image objects that can be used in such ways, but webGL doesn't support them yet, that's why you have to use two textures and ping-pong them back and forth, alternating how they're used.