Hi,
I am trying to do Physics (time integration and collision detection) on CUDA. Since I have based my program on SimpleGL example from the SDK I use VBOs.
After running my physics kernel I draw from the desired VBO and the results are fine but I want to map this buffer into client memory to use as a normal vertex array so I use glMapBuffer. But this is giving me errors at run time.
Specifically I do the following in the display loop:
// run CUDA kernels to generate vertex positions
runCuda(vboFloor); // generate vertex positions for floor(kernel from the simpleGL example)
cudaIntegrator(vboNewPosA,dt);//My physics Kernel
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// set view matrix
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, translate_z);
glRotatef(rotate_x, 1.0, 0.0, 0.0);
glRotatef(rotate_y, 0.0, 1.0, 0.0);
// render from the floor vbo
glBindBuffer(GL_ARRAY_BUFFER, vboFloor);
glVertexPointer(4, GL_FLOAT, 0, 0);
glEnableClientState(GL_VERTEX_ARRAY);
glColor3f(0.0, 0.0, 0.0);
glPointSize(1.0f);
glDrawArrays(GL_POINTS, 0, mesh_width * mesh_height);
glDisableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, 0);
// this snippet works
#if 0
// render new positions
glBindBuffer(GL_ARRAY_BUFFER, vboNewPosA);
glVertexPointer(4, GL_FLOAT, 0, 0);
glEnableClientState(GL_VERTEX_ARRAY);
glColor3f(1.0, 0.0, 0.0);
glPointSize(5.0f);
glDrawArrays(GL_POINTS, 0, GRIDX * GRIDY);
glDisableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, 0);
#endif
glBindBuffer(GL_ARRAY_BUFFER, vboNewPosA);
float *data = (float *) glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
if(data != NULL)
{
glUnmapBuffer(GL_ARRAY_BUFFER);
}
I create the VBOs in the same manner they are done in SimpleGL example.
I do cudaGlMapBuffer and cudaGLUnmapBuffer in the kernels and want to use them as pure and simple GL vertex arrays.
Any pointers ?
Thanks