Parsing a array of stucts that contains arrays

I've been trying to get this GLSL shader parsing to work for arrays with no luck. My goal would be to parse out all the possible uniform names from this, they'd look something like this...
"bars[0].shoes[0].something[0]"
"bars[0].shoes[0].something[1]"
"bars[0].shoes[0].something[2]"
"bars[0].shoes[0].something[3]"
I've been trying to get a recursive function to work here like I did for parsing the structs into a map to help with sorting types and members out but this is a bigger problem for me then expected.

1
2
3
4
5
6
7
8
9
10
11
struct Foo
{
    float something[10];
};

struct Bar
{
    Foo shoes[20]
};

uniform Bar bars[5]
Last edited on
I did figure out a solution to this though it's not really inline with the question.

OpenGL has a couple functions to help with this problem glGetProgramiv with GL_ACTIVE_UNIFORMS gets the number of uniforms in a linked shader program, then I just call glGetActiveUniform for each uniform and store it however I need. This seems to work fine but it also may not support an array of arrays of arrays, I honestly can't say that would be to useful in a shader anyway.
1
2
3
4
5
6
7
8
9
10
11
12
GLint count, size;
GLenum type;
GLsizei length;
GLchar name[256];
glGetProgramiv(m_program, GL_ACTIVE_UNIFORMS, &count);

for (int i = 0; i < count; i++)
{
	glGetActiveUniform(m_program, i, sizeof(name), &length, &size, &type, name);
	GLSLUniform uniform = { type, glGetUniformLocation(m_program, name) };
	m_uniformLocations.insert({ std::string(name), uniform });
}
Last edited on
Topic archived. No new replies allowed.