Reputation: 867
If I have a fragment-shader that looks like this:
#version 450
#define MAX_NUM_LIGHTS 10
#define NUM_CASCADES 6
uniform sampler2D depthMap[NUM_CASCADES][MAX_NUM_LIGHTS];
...
How do I send a value from my c++ program via glUniform...
to the shader?
If i had just:
#define MAX_NUM_LIGHTS 10
uniform sampler2D depthMap[MAX_NUM_LIGHTS];
...
I would do this like so:
...
GLint tmp[MAX_NUM_LIGHTS];
for(GLint i = 0; i<MAX_NUM_LIGHTS; i++)
{
tmp[i] = 2+i; // all textures up to GL_TEXTURE1 are already bound.
glActiveTexture(GL_TEXTURE2+i);
glBindTexture(GL_TEXTURE_2D, depthMapID[i]);
}
glUniform1iv(model.depthMap_UniformLocation, MAX_NUM_LIGHTS, tmp);
glUniform1iv
does not work for multidimensional arrays and I couldn't find a function that fits here: https://www.khronos.org/registry/OpenGL-Refpages/es2.0/xhtml/glUniform.xml or: https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_arrays_of_arrays.txt
Upvotes: 1
Views: 656
Reputation: 474436
Arrays of arrays in OpenGL work like arrays of structs. This means that each array of array has an individual uniform location, and therefore an individual name. However, once you get down to an array of basic types, it acts like a regular array of basic types: you can pour lots of values into the first location of that array.
In your case, you have 6 uniforms, named "depthMap[0]" through "depthMap[5]". Each of these is a 10-element array.
Upvotes: 3