diff options
-rw-r--r-- | main.c | 33 |
1 files changed, 15 insertions, 18 deletions
@@ -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" |