6
votes

I have two sampler arrays in my fragment shader:

uniform sampler2D shadowMaps[12];
uniform samplerCubeShadow shadowMapsCube[12];

This works fine on my pc with opengl 4.2, however on my laptop (opengl 3.1) I'm getting the error 'array size too big'.

If I set it to 8, it works fine. Arrays of other types can be far larger however, and I can add more sampler arrays with a max size of 8 without a problem. So, how is this limit determined?

After lowering the array size to 8 the compilation works, but the linking fails silently (The log is empty and glGetError() returns 0).

If I declare each sampler individually (uniform sampler2D shadowMap1;uniform sampler2D shadowMap2; etc.), neither of these errors occur.

1
How are you then accessing to those samplers? Bare in mind that depending on your OpenGL version, accessing to samplers array using loops is not permited. See: stackoverflow.com/a/12031821/988027Dan
I was in fact using a loop to access them. Hm... the article mentioned array textures, but there doesn't seem to be a texture array type for samplerCubeShadow. Does that mean I'll have to declare them individually and access them inside the loop through if-conditions, or is there another way?Silverlan
You probably want to have a look at this: opengl.org/wiki/GLSL_Sampler#Non-uniform_flow_controlDan
It means you have to use an integral constant expression for the index. No matter what else you do, it's what ends up being in the index that matters for pre-4.0. Running a loop is fine, as long as you're not using the loop counter as index.Damon
Thanks, I've worked around the problem now. It's still failing to link if I have more than a total of 16 samplers in my shader (Again, only on my laptop with opengl 3.1). Is there a way to retrieve the max amount of samplers you can have?Silverlan

1 Answers

8
votes

You have to take two things into account.

First, bear in mind that depending on your OpenGL version, accessing to samplers array using variables inside loops is not permited. See: https://stackoverflow.com/a/12031821/988027

Secondly, quoting from the OpenGL wiki page, there are a maximum amount of texture units you can use at the same time:

OpenGL contexts have a maximum number of texture image units, queriable from the constant GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS​.

Probably, this answer will help you. Particularly, have a look at the shader resource limitations.