problem in FluidsGL sample Why two buffer data are used?

hi, I read the code of FluidsGL in CUDAsdk, in

//two particle data are prepared:

static cData *mparticles = NULL;

static cData *particles = NULL;

//particles is used for generate buffer in main

int main ( int argc, char** argv ) {


glGenBuffersARB( 1, &pbuffer );

glBindBufferARB( GL_ARRAY_BUFFER_ARB, pbuffer );

glBufferDataARB( GL_ARRAY_BUFFER_ARB, sizeof(cData) * DS, particles, GL_DYNAMIC_DRAW_ARB);



//but in the display func, the mparticles is used for mapping buffer

advertParticles( mparticles, dvfield, DIM, DIM, DT );

void advectParticles( cData *p, cData *v, int dx, intdy, float dt ) {


cudaGLMapBufferObject((void*)&p, pbuffer );



Here I change the parameter of advertParticle:

advertParticles( particles, dvfield, DIM, DIM, DT );

then it also works well, I dont know why two particle data are used?

Ah, it looks like the advectParticles() function doesn’t actually use the the p pointer that is passed into it. You can pass zero and it still works.

I guess that at some point in the past this code used an array in global memory to store the particle positions, but then it was changed to use memory from a OpenGL vertex buffer (VBO) so that the particles could be rendered directly.

The “particles” array stores the particle positions in host memory. “pbuffer” is the VBO that stores the particle positions on the GPU.

thanks simon
really !It works using zero.
I think the code uses two particle arrays because one is for current state and another is for written to next state. when we pass zero or mparticle, a new array is generated for the next fluid state, when we pass particle, the function just updata current array itself, both seems work well. hoho i just guess