From b9b98603e04c5d426fc61ae15532ba3c52785679 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Fri, 12 May 2017 20:06:29 -0400 Subject: add comments --- main.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'main.c') diff --git a/main.c b/main.c index 6f620b5..2573d4c 100644 --- a/main.c +++ b/main.c @@ -260,11 +260,14 @@ update_particles( ) { if (USE_COMPUTE_SHADER) { UNUSED(ssbo); + glUseProgram(compute_prog); glDispatchCompute(NUM_PARTICLES / WORKGROUP_SIZE, 1, 1); glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT); } else { UNUSED(compute_prog); + + // bind shader storage buffer glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo); // map buffer @@ -275,8 +278,10 @@ update_particles( GL_MAP_READ_BIT | GL_MAP_WRITE_BIT ); + // update particle positions #pragma omp parallel for for (int i = 0; i < NUM_PARTICLES; i++) { + // update x coordinate data[4 * i + 0] += 0.016 * data[4 * (NUM_PARTICLES + i) + 0]; if (data[4 * i + 0] < -1.1) { data[4 * i + 0] += 2.2; @@ -284,6 +289,7 @@ update_particles( data[4 * i + 0] -= 2.2; } + // update y coordinate data[4 * i + 1] += 0.016 * data[4 * (NUM_PARTICLES + i) + 1]; if (data[4 * i + 1] < -1.1) { data[4 * i + 1] += 2.2; @@ -292,6 +298,7 @@ update_particles( } } + // unmap and unbind data buffer glUnmapBuffer(GL_SHADER_STORAGE_BUFFER); glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); } -- cgit v1.2.3