Strange behaviour of uniform struct

  Kiến thức lập trình

I was working on my OpenGL code, and noticed a weird behavior when getting uniform location from a uniform which has a type of anonymous struct. Wiki says anonymous structs are prohibited, but I was actually able to create them in vertex shader as a uniform type no problem:

uniform struct // no name here! compiled fine!
    mat4 device;
    mat4 position;
    mat3 normal;
} uni_transforms;

I also tried putting all my sampler2D into one uniform struct and ran into a problem: I cannot do anonymous structures where sampler2D are present: the shaders compiled just fine, but I was not able to get sampler2D‘s uniform location (and no, the uniform is used in the shader code so it’s not discarded as unused):

uniform struct
    sampler2D diffuse;
    sampler2D specular;
    sampler2D normal;
} uni_textures;

I tried adding a type name to the declaration after struct, and now (apparently) the uniform was there, the location was found.

Why am I able to create anonymous structs when standard says I can’t? Why am I not able to create them with sampler2D?

In case implementation matters, I ran this code on Intel UHD Graphics 620 on i5-8265U, Windows 10.