greggman / twgl.js

A Tiny WebGL helper Library
http://twgljs.org
MIT License
2.61k stars 258 forks source link

Trouble Instantiating vec3 Arrays #185

Closed jhancock532 closed 2 years ago

jhancock532 commented 2 years ago

The code vec3[] v = vec3[] (vec3(0., 0., 0.), vec3(0., 0., 0.)); gives me the following error:

^^^ ERROR: 0:12: '=' : cannot convert from 'const array[2] of 3-component vector of float' to 'mediump 3-component vector of float'

Here's the error in a CodePen demo

While on ShaderToy, similar array definitions work fine. https://www.shadertoy.com/view/XssyR4

I've missed something with setting compiling parameters most likely. Implicitly sized array are supported in GLSL ES 3.00 and above only, when I checked the TWGL webgl 2 examples I found #version 300 es being included at the top of fragment shader files, but adding this to my example unfortunately didn't help.

zorro-fr24 commented 2 years ago

You are definitely mixing webgl1 ( GLSL ES 1.00 ) and webgl2 syntax ( GLSL ES 3.00 ) there

I recommend looking here to see how to convert your project.

Hint: include the es version as you mentioned ( make sure there is NO space before the declaration ). Use getContext('webgl2') and use in and out instead of attribute and gl_FragColor respectively ( as detailed in the link above )

jhancock532 commented 2 years ago

Thank you! That helps a lot :)