Reputation: 5237
I have N texture units that need to be accessed simultaneously from the fragment shader. N varies with the data being loaded. So, in the shader, I need something like:
// illegal syntax?
uniform sampler2D tex[N];
Also, sampler2DArray does not seem supported in OpenGL ES 2.0.
Just wondering if there are any other tricks or GLSL preprocessor constructs I can use to achieve the above.
Or, is the better option to generate the shader code dynamically? I could generate something like the code below, and load the shader:
uniform sampler2D tex1;
...
uniform sampler2D texN;
Upvotes: 1
Views: 2003
Reputation: 690
Do you need to explicitly set the array's size? To my understanding, you can specify a uniform array of sampler2D's of an arbitrary size using:
uniform sampler2D tex[];
which I think will generally work the way you intend, but without explicitly setting the size. I'm using this method but am currently supplying only one texture to the array, and referencing it later in the code with its array index tex[0]. Haven't built everything up to the point where I'm ready to put more than 1 texture in there yet, so I'm not 100% on this.
I'm very new to OpenGL so there may be some benefit to defining the array's size that I'm unaware of.
Upvotes: 0
Reputation: 722
you can try defining a constant maximum number of samplers, and receive the actual size at runtime.
uniform sampler2D tex[MAX_VALUE];
uniform int size;
int main(){
....
}
Upvotes: 1