Reputation: 52957
I'm trying to load a big array of floats on the GPU. That array will be used by the fragment shader in order to perform its computations. Weirdly, adding the following line to the fragment shader:
uniform vec3 xyz[512*512];
Is enough to trigger the following error when compiling it:
Uncaught OpenGL error: ERROR: 0:4: '' : array size too large
ERROR: 0:6: 'x' : field selection requires structure, vector, or matrix on left hand side
Why does this happen? A 512*512 array doesn't seem unreasonable since that is merely around 3mb, much less than the amount of memory on my GPU.
Upvotes: 1
Views: 1737
Reputation: 2188
Every index in an array counts towards the limit of maximum uniform vectors, which highly depends on the implementation. There are separate limits for uniforms used in vertex and fragment shaders (uniforms used in both count towards both). To query those limits use
gl.getParameter( gl.MAX_VERTEX_UNIFORM_VECTORS );
gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS );
Usually they are around ~200, but the best thing is to look up on webglstats.
If you want to send that much data as a uniform you'd usually send it as a (float) texture.
Upvotes: 4