diff --git a/builtin-programs/gpu/page-shader.folk b/builtin-programs/gpu/page-shader.folk new file mode 100644 index 00000000..8e4ee260 --- /dev/null +++ b/builtin-programs/gpu/page-shader.folk @@ -0,0 +1,35 @@ +set cc [C] +$cc include +$cc include +$cc proc sha1 {char* d} Jim_Obj* { + unsigned char md[20]; + SHA1((unsigned char *)d, strlen(d), md); + return Jim_NewStringObj(interp, (char *)md, 20); +} +$cc endcflags -lssl -lcrypto +set sha1Lib [$cc compile] + + +When /someone/ wishes /p/ draws shader /shaderCode/ { + binary scan [$sha1Lib sha1 $shaderCode] H* sha1 + + Wish the GPU compiles pipeline $sha1 [list \ + {vec2 viewport mat3 surfaceToClip} { + vec2 vertices[6] = vec2[6]( + vec2(0.0, 0.0), vec2(1.0, 0.0), vec2(1.0, 1.0), + vec2(0.0, 0.0), vec2(1.0, 1.0), vec2(0.0, 1.0) + ); + vec3 v = surfaceToClip * vec3(vertices[gl_VertexIndex], 1.0); + return vec4(v.xy/v.z, 0.0, 1.0); + } $shaderCode] + + When the GPU compiles pipeline $sha1 to /anything/ & \ + $p has canvas /id/ with /...wiOptions/ & \ + $p has canvas projection /surfaceToClip/ { + puts "the GPU compiled the pipeline" + set wiResolution [list [dict get $wiOptions width] [dict get $wiOptions height]] + + Wish the GPU draws pipeline $sha1 onto canvas $id \ + with arguments [list $wiResolution $surfaceToClip ] + } +}