A large array (length > 8000) is required in my glsl shader. A simple array of uniform was too large for it as it would raise a compile error. Finally I found sampler1d might be a good solution.
The problem is, I don’t know how to pass a sampler1d object to shader program. I have tried Texture object but it tells me they are not matched.
Texture is the way to go, I’m using the following code to send an array of 4 floats as to my shader :
texture = Texture()
texture.setup_buffer_texture(len(data), Texture.T_float, Texture.F_rgba32, GeomEnums.UH_static)
flattened_data = list(chain.from_iterable(data))
raw_data = array("f", flattened_data)
texture.set_ram_image(raw_data.tobytes())
If you need to only send one float, you can switch to F_r32 and skip the array flattening
However it’s preferable to use samplerBuffer
in your GLSL code :
uniform samplerBuffer data_buffer;
...
vec4 data = texelFetch(data_buffer, index);
Thank you for helping!