Closed coderobe closed 5 years ago
I was planning to expand on this feature by allowing multiple named bindings, ie. glava -i primary:vec4 -i secondary:vec4
(the :type
syntax could be omitted to default to vec4), and then specify them via stdin as binding=value
. I would support the legacy behavior by interpreting no argument as STDIN:vec4
and [type]
as STDIN:[type]
.
Admittedly that would make implementing this not possible if users are able to specify the names of the bindings. I could workaround that by assigning each binding an alias using an index (ie. primary=BIND0
, secondary=BIND1
, etc..) which would allow the following setup for graph.glsl
:
#if USE_BIND0 == 1 && USE_BIND1 == 1
#define COLOR mix(BIND0, BIND1, clamp(pos / GRADIENT_SCALE, 0, 1))
#else
#define COLOR mix(#802A2A, #4F4F92, clamp(pos / GRADIENT_SCALE, 0, 1))
#endif
But this would confuse people since the default behavior would ignore the names of the bindings, and rely on the order in which they were specified on the command line. I could strictly require index bindings (ie. -i 0:vec4
), but that's not exactly user-friendly either. And these solutions muck up user config files, and I don't want that.
The best solution I can come up with would be to allow --stdin
arguments to override existing macro definitions to a dynamic value, ie: -i COLOR:vec4
would simply override any COLOR
definition in all shaders at compile time and have it bound to a uniform that could be set via COLOR=value
in stdin. In order to get this to work, I would have to yet again modify how glsl_ext.c
handles defines.
Discussed this with @coderobe on IRC and came up with an infinitely better solution that doesn't break namespace and is much cleaner:
--pipe
flag that handles named bindings in the aforementioned format.@variable:default
. The @
prefix would separate the namespace (similar to using a prefix, except in this case glsl_ext.c
will handle the expansion), and default
would be emitted if variable
was not set via --pipe
.@
or @:default
.--stdin
flag would continue to function separately, will be deprecated (with a warning) in favor of the new flag and removed in a later release.There was another tempting solution, but I ultimately decided against it:
<coderobe> embed V8 and run javascript on the cpu for the algorithms, then stream the return value to glava
I'm not sure what to do for https://github.com/wacossusca34/glava/blob/7ff896d6d834e8c80392ca535c5528661f0c9c68/shaders/graph.glsl#L11 as that would require more advanced input support to control all colors - do we want to leave this PR waiting until we can support this in the graph mod as well, or do you have another idea?