| 147 | } |
| 148 | |
| 149 | void ParticleSystem::_initialize(int numParticles) |
| 150 | { |
| 151 | assert(!m_bInitialized); |
| 152 | |
| 153 | m_numParticles = numParticles; |
| 154 | |
| 155 | // allocate host storage |
| 156 | m_hPos = new float[m_numParticles * 4]; |
| 157 | m_hVel = new float[m_numParticles * 4]; |
| 158 | memset(m_hPos, 0, m_numParticles * 4 * sizeof(float)); |
| 159 | memset(m_hVel, 0, m_numParticles * 4 * sizeof(float)); |
| 160 | |
| 161 | m_hCellStart = new uint[m_numGridCells]; |
| 162 | memset(m_hCellStart, 0, m_numGridCells * sizeof(uint)); |
| 163 | |
| 164 | m_hCellEnd = new uint[m_numGridCells]; |
| 165 | memset(m_hCellEnd, 0, m_numGridCells * sizeof(uint)); |
| 166 | |
| 167 | // allocate GPU data |
| 168 | unsigned int memSize = sizeof(float) * 4 * m_numParticles; |
| 169 | |
| 170 | if (m_bUseOpenGL) { |
| 171 | m_posVbo = createVBO(memSize); |
| 172 | registerGLBufferObject(m_posVbo, &m_cuda_posvbo_resource); |
| 173 | } |
| 174 | else { |
| 175 | checkCudaErrors(cudaMalloc((void **)&m_cudaPosVBO, memSize)); |
| 176 | } |
| 177 | |
| 178 | allocateArray((void **)&m_dVel, memSize); |
| 179 | |
| 180 | allocateArray((void **)&m_dSortedPos, memSize); |
| 181 | allocateArray((void **)&m_dSortedVel, memSize); |
| 182 | |
| 183 | allocateArray((void **)&m_dGridParticleHash, m_numParticles * sizeof(uint)); |
| 184 | allocateArray((void **)&m_dGridParticleIndex, m_numParticles * sizeof(uint)); |
| 185 | |
| 186 | allocateArray((void **)&m_dCellStart, m_numGridCells * sizeof(uint)); |
| 187 | allocateArray((void **)&m_dCellEnd, m_numGridCells * sizeof(uint)); |
| 188 | |
| 189 | if (m_bUseOpenGL) { |
| 190 | m_colorVBO = createVBO(m_numParticles * 4 * sizeof(float)); |
| 191 | registerGLBufferObject(m_colorVBO, &m_cuda_colorvbo_resource); |
| 192 | |
| 193 | // fill color buffer |
| 194 | glBindBuffer(GL_ARRAY_BUFFER, m_colorVBO); |
| 195 | float *data = (float *)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); |
| 196 | float *ptr = data; |
| 197 | |
| 198 | for (uint i = 0; i < m_numParticles; i++) { |
| 199 | float t = i / (float)m_numParticles; |
| 200 | #if 0 |
| 201 | *ptr++ = rand() / (float) RAND_MAX; |
| 202 | *ptr++ = rand() / (float) RAND_MAX; |
| 203 | *ptr++ = rand() / (float) RAND_MAX; |
| 204 | #else |
| 205 | colorRamp(t, ptr); |
| 206 | ptr += 3; |
nothing calls this directly
no test coverage detected