Context
I'm trying to draw Bezier curves in a canvas. I achieved to draw quadratic and cubic curves from within the shader, but I did have a uniform variable for each and every control point so far.
So, I click on my canvas, add points and when I have enough (respectively 3 and 4), I draw my curve.
Now I'm trying to generalize Bezier curves. Though I achieved to accomplish this on the JavaScript side, I feel like it would be better to do this from the shader side, as the speed of the rendering would be greatly increased.
So, I would like to draw my curve as soon as I have at least two points. But I could keep adding points and draw my curve using every point, in order as control points.
Explanation
So I know it's not possible to set a dynamic array in GLSL, but is it possibliy to dynamically declare a GLSL array based on a JS variable ?
If my question is unclear (I know I have troubles formulating things right straight away), let me explain with an example.
uniform vec2 uMyPoints[<length>];
So this is what I would like to achieve, but of course, the array size must be a constant, according to glsl specifications.
However, from my point of view, I feel like I should be able to set up length from a JS variable. My intuition is that the array size in GLSL would be constant for the duration of the execution of the different shaders during the render, but could change from one rendering to another.
Question
So my question to you is : Based on these, do you know any good way or tricks to be able set a constant in GLSL from a javascript variable ?
If it appears to be possible, this would help me greatly. Thanks for your consideration.
As a matter of comparison : How could we set "numLights" in this example from JS ?
Answer
String substitution suits my needs nicely. Though it's a bit tricky, it will do just fine. Further research led me to know that implicit array size is available Open GL ES version 3, which should be used by future versions of WebGL, but not right now.
In the other hand, the second suggestion does not suits my needs as I precisely wanted to avoid having N points in the shader, as that quantity of points may change.
Thanks for the answer ;)