summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c7
1 files changed, 7 insertions, 0 deletions
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);
}