I have a CUDA kernel called update
which takes two float* as a input and updates the first one. After the update, I need to update the VBO from OpenGL with the new data from the first pointer. Now I've been looking for some cuda-GL interop, but for me, all of this was really hard to understand. I'm looking for a clean and easy way to update a VBO using the data from a device pointer. I imagined something like this:
//initialize VBO
glGenBuffers(1, &vboID);
glBindBuffers(GL_ARRAY_BUFFER, vboID);
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*SIZE, (void*)0, GL_STREAM_DRAW);
cudaMalloc((void**)&positions, sizeof(float)*SIZE);
//per frame code
glBindBuffer(GL_ARRAY_BUFFER, vboID);
update<<<SIZE/TPB, TPB>>>(positions, velocities);
//somehow transfer the data from the positions pointer to the VBO
glBindBuffer(GL_ARRAY_BUFFER, 0);