As someone who is trying to dive into WebGL for parallelizing simulations, or Machine Learning, or typical IIR filters I've come to realize that for everything that I want to do requires the GPU to update itself and send "gossip" signals to the screen.

Sending data to the screen is fairly straight forward, however having the GPU write to itself in order to step into the next time step for a simulation and then send that information to the screen is something I have no clue about doing. I don't know what it's called or if it's even possible.

I hate asking a "is it possible to do X?" question, but sadly this is one of those because my knowledge regarding WebGL is so bad, and studying WebGL for a few months just to realize that it's not possible is not time I can afford right now. I have no one else to ask.

However, to give this question some more meat to the bones I'll say that I assume that it is possible and it is just a matter of setting up two buffers and linking them together in some special way.

Here's the actual question: I'm familiar with the fact that you set up pipelines in WebGL, does WebGL support pipelines to itself that never goes to the screen so it can modify its internal buffers?


What you are talking about is transform feedback. With transform feedback you can capture primitives (vertices, triangles, lines) in a buffer such they can be used in subsequent draw calls. You don't have to grab the data from the GPU to the CPU and back again as you can directly use the GPU buffer you have just rendered to.

I'm not exactly sure what your use-case exactly is, but you mention simulation and timesteps. Imagine a particle system where each particle has a position and a velocity at each time step of the simulation. We have two buffers A and B. A will be rendered from on even numbered frames and will be written to on odd-numbered frames and B that we write to on even numbered frames and render from on odd-numbered frames. We also have a simple vertex shader that updates the positions of vertices using the aforementioned position and velocity attributes.

Then using some initial position and velocity for each particle we can start rendering from buffer A into buffer B. After having finished this process all particles will have an update position and we can render from buffer B into buffer A.

With this you also have the option to not render to the at all screen by using the GL_RASTERIZER_DISCARD functionality.

Take a look at the examples listed on this page under 'Transform Feedback'. Or at this example.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.