title: WebGL - Variables array sizes over vertex shader calls
body: <p><strong>Context</strong></p>
  
  <p>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.</p>
  
  <p>So, I click on my canvas, add points and when I have enough (respectively 3 and 4), I draw my curve.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p><strong>Explanation</strong></p>
  
  <p>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 ?</p>
  
  <p>If my question is unclear (I know I have troubles formulating things right straight away), let me explain with an example.</p>
  
  <pre><code>uniform vec2 uMyPoints[&lt;length&gt;];
  </code></pre>
  
  <p>So this is what I would like to achieve, but of course, the array size must be a constant, according to glsl specifications.</p>
  
  <p>However, from my point of view, I feel like I should be able to set up <code>length</code> 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.</p>
  
  <p><strong>Question</strong></p>
  
  <p>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 ?</p>
  
  <p>If it appears to be possible, this would help me greatly. Thanks for your consideration.</p>
  
  <p>As a matter of comparison : How could we set "<a href="https://stackoverflow.com/questions/8202173/setting-the-values-of-a-struct-array-from-js-to-glsl">numLights" in this example</a> from JS ?</p>
  
  <p><strong>Answer</strong></p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>Thanks for the answer ;)</p>