From e38bc0f6944effb2f17b5fa46b22182033f25eb1 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Fri, 12 May 2017 20:40:14 -0400 Subject: add PARTICLE_BUFFER_DECLARATION --- main.c | 33 +++++++++++++++------------------ 1 file 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" -- cgit v1.2.3