summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2017-05-12 20:06:29 -0400
committerPaul Duncan <pabs@pablotron.org>2017-05-12 20:06:29 -0400
commitb9b98603e04c5d426fc61ae15532ba3c52785679 (patch)
tree039f1e5a6553473cd9066a4dbb4021458c6b4081
parent64391761785447e91154e13894bef402e2b052f7 (diff)
downloadcompute-test-b9b98603e04c5d426fc61ae15532ba3c52785679.tar.bz2
compute-test-b9b98603e04c5d426fc61ae15532ba3c52785679.zip
add comments
-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);
}