# problem in FluidsGL sample Why two buffer data are used?

**URL:** <https://forums.developer.nvidia.com/t/problem-in-fluidsgl-sample-why-two-buffer-data-are-used/2330>\
**Category:** CUDA Programming and Performance\
**Created:** [January 15, 2008, 4:01am UTC](https://forums.developer.nvidia.com/t/problem-in-fluidsgl-sample-why-two-buffer-data-are-used/2330 "2008-01-15T04:01:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![demaxism](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@demaxism](https://forums.developer.nvidia.com/u/demaxism)\
**Post date:** [January 15, 2008, 4:01am UTC](https://forums.developer.nvidia.com/t/problem-in-fluidsgl-sample-why-two-buffer-data-are-used/2330/1 "2008-01-15T04:01:44Z")

</div>

hi, I read the code of FluidsGL in CUDAsdk, in fluidsGL.cu

//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（ｃＤａｔａ） * 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?

---

<div class="post-metadata">

**Author:** ![Simon\_Green](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Simon\_Green](https://forums.developer.nvidia.com/u/Simon_Green)\
**Post date:** [January 15, 2008, 6:18pm UTC](https://forums.developer.nvidia.com/t/problem-in-fluidsgl-sample-why-two-buffer-data-are-used/2330/2 "2008-01-15T18:18:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![demaxism](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@demaxism](https://forums.developer.nvidia.com/u/demaxism)\
**Post date:** [January 16, 2008, 11:43am UTC](https://forums.developer.nvidia.com/t/problem-in-fluidsgl-sample-why-two-buffer-data-are-used/2330/3 "2008-01-16T11:43:57Z")

</div>

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
