Uniform struct array

Hi, all.

I try to write a structure and declare an array as follow :


struct ShadowMapping
{
	mat4            light_coordinate_system;
	sampler2DShadow shadow_map;
	int             shadow_map_width;
	int             shadow_map_height;
};

...

//shadow mapping info
uniform ShadowMapping shadow_mapping_list[8]; //declaration
uniform int           shadow_mapping_number;

Then I use the array in my shading program(fragment shader).

If the condition in for loop is large than 1, I won’t get all location of variables in my shader.

So how can I use the uniform struct array in my shader?

P.S. I post my code occurring the problem.



        int i;
        for( i = 0 ; i < shadow_mapping_number ; i++)//if I modify the shadow_mapping_number to a constant 1, it's working. Otherwise, it's failure.
	{
		//use the uniform struct array by the form : shadow_mapping_list[i].light_coordinate_system, and etc... .
	}

And my version of glsl is #version 120
Graphics card is Nvidia GTX 460

By the way, the complied result is on error occurred in any shader.

Thanks.

Of course it’s an error. Samplers are opaque types. And you can’t put opaque types in structs. Nor can they be aggregated into interface blocks.

I’m pretty sure that if you printed out that error, it would tell you exactly what was wrong.

[QUOTE=Alfonse Reinheart;1250289]Of course it’s an error. Samplers are opaque types. And you can’t put opaque types in structs. Nor can they be aggregated into interface blocks.

I’m pretty sure that if you printed out that error, it would tell you exactly what was wrong.[/QUOTE]

Thank you very much.

I check my compiler error after reading your answer.

But I didn’t see any error in vertex shader log, fragment shader log, and linking log.

Maybe it’s related with compiler.

And I have another question.

If I want to use an array with sampler, what type I should declare ? Is sampler2DArray or else?

And how I bind the textures from c++ program to shading program ??

Use texture arrays

Thank you. I will try it.:slight_smile:

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.