summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2017-05-12 20:40:14 -0400
committerPaul Duncan <pabs@pablotron.org>2017-05-12 20:40:14 -0400
commite38bc0f6944effb2f17b5fa46b22182033f25eb1 (patch)
tree81966cb38287d4b08963d59708b7daaddcccd8d2
parentb9b98603e04c5d426fc61ae15532ba3c52785679 (diff)
downloadcompute-test-e38bc0f6944effb2f17b5fa46b22182033f25eb1.tar.bz2
compute-test-e38bc0f6944effb2f17b5fa46b22182033f25eb1.zip
add PARTICLE_BUFFER_DECLARATION
-rw-r--r--main.c33
1 files changed, 15 insertions, 18 deletions
diff --git a/main.c b/main.c
index 2573d4c..ddccce8 100644
--- a/main.c
+++ b/main.c
@@ -45,6 +45,7 @@ typedef struct {
fullscreen;
} context_t;
+// triangle vertices
static const float
verts[] = {
-1, 1, 0,
@@ -52,35 +53,34 @@ verts[] = {
0.0, -1, 0,
};
+// shared particle shader storage buffer definition
+#define PARTICLE_BUFFER_DECLARATION \
+ "layout (std430, binding = 1) buffer particles {\n" \
+ " mediump vec4 positions[" S(NUM_PARTICLES) "];\n" \
+ " mediump vec4 velocities[" S(NUM_PARTICLES) "];\n" \
+ " mediump vec4 colors[" S(NUM_PARTICLES) "];\n" \
+ "};\n"
+
+// compute shader
static const char
cs_src[] =
"#version 320 es\n"
"\n"
"layout(local_size_x = " S(WORKGROUP_SIZE) ") in;\n"
"\n"
- "layout (std430, binding = 1) buffer particles {\n"
- " mediump vec4 positions[" S(NUM_PARTICLES) "];\n"
- " mediump vec4 velocities[" S(NUM_PARTICLES) "];\n"
- " mediump vec4 colors[" S(NUM_PARTICLES) "];\n"
- "};\n"
+ PARTICLE_BUFFER_DECLARATION
"\n"
- // "// layout (location = 0) in mediump float delta;\n"
- // "\n"
"void main() {\n"
- // " return;\n"
" mediump uint i = gl_GlobalInvocationID.x;\n"
" positions[i].xy += 0.016 * velocities[i].xy;\n"
"}\n";
+// vertex shader
static const char
vs_src[] =
"#version 320 es\n"
"\n"
- "layout (std430, binding = 1) buffer particles {\n"
- " mediump vec4 positions[" S(NUM_PARTICLES) "];\n"
- " mediump vec4 velocities[" S(NUM_PARTICLES) "];\n"
- " mediump vec4 colors[" S(NUM_PARTICLES) "];\n"
- "};\n"
+ PARTICLE_BUFFER_DECLARATION
"\n"
"layout (location = 0) in mediump vec3 pos;\n"
"out mediump flat int instance_id;\n"
@@ -90,15 +90,12 @@ vs_src[] =
" instance_id = gl_InstanceID;\n"
"}\n";
+// fragment shader
static const char
fs_src[] =
"#version 320 es\n"
"\n"
- "layout (std430, binding = 1) buffer particles {\n"
- " mediump vec4 positions[" S(NUM_PARTICLES) "];\n"
- " mediump vec4 velocities[" S(NUM_PARTICLES) "];\n"
- " mediump vec4 colors[" S(NUM_PARTICLES) "];\n"
- "};\n"
+ PARTICLE_BUFFER_DECLARATION
"\n"
"in mediump flat int instance_id;\n"
"out mediump vec4 color;\n"