Texture memory and OpenGL Updatable array in texture memory, accesible as VBO

Good day.

I am trying to implement simple cloth simulation:
I have 2 arrays of particles (2D arrays of float4 - position and one other float for special identification). I want to bind texture to one of them and read from it (I want to read one particle position multiple times). I will write new (changed) position to the second array. Now I want to attach the second array as a VBO and use it for rendering (Opengl). Then bind the same texture to second array and write to first.
This should help me to avoid copying from GPU to CPU and back.

My biggest problem is how to create array (? cudaArray or 2D array or vertex buffer object ?) and how to copy data from CPU to GPU for initialization.
I know how to create vbo, allocate memory (glBufferData), register buffer, map resource and get pointer. But how can I bind texture to this? I only know, how to bind texture to array with pitch (cudaBindTexture2D) or to cudaArray (cudaBindTextureToArray)…
I could also create cudaArray and bind texture to it, but then I don’t know how to connect it with VBO :(

I tried to understand Fluids (OpenGL Version) from nVidia cuda SDK, but it’s complicated for me :(

Can someone help me, please?
Thanks for any advise.

//EDIT: What I have understood from that SDK example (fluids): I should have one array, which will cooperate with VBO and than copy device to device from that array to cudaArray for texture binding… Am I right? If so, can I avoid that copying somehow?


you can attach a texture to the VBO in the same way you attach to an ordinary array of data. The only trick is that you need to register the VBO and map the array onto an array pointer.

look at the programming manual (openGL interoperability, texture memory) to see how it is done, it is very straightfoward you should not have mayor


make sure you use the new maping and register instructions introduced in cuda 3.0 and foward.

Thanks a lot.
I have already solved it. I’m using cuda resources - i found it in Cuda by example book. I’m copying data, but it’s working :)