Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL - sampler array limit?

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.

like image 427
Silverlan Avatar asked Feb 03 '14 10:02

Silverlan


People also ask

What is an OpenGL sampler?

A sampler is a set of GLSL variable types. Variables of one of the sampler types must be uniforms or as function parameters. Each sampler in a program represents a single texture of a particular texture type. The type of the sampler corresponds to the type of the texture that can be used by that sampler.

What is gl_FragCoord?

Available only in the fragment language, gl_FragCoord is an input variable that contains the window relative coordinate (x, y, z, 1/w) values for the fragment. If multi-sampling, this value can be for any location within the pixel, or one of the fragment samples.

What is an array texture?

An Array Texture is a Texture where each mipmap level contains an array of images of the same size. Array textures may have Mipmaps, but each mipmap in the texture has the same number of levels. The domain of the images in the array depend on the array texture's specific type.

What is texture sampler?

Texture sampling is the process of reading textures through the GPU. Graphics Hardware embeds a set of texture units that are able to read texture pixels directly or sample these textures using different algorithms.


1 Answers

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.

like image 151
Dan Avatar answered Sep 19 '22 23:09

Dan