1
votes

i have a problem with my GLSL shader. When i want to compile the fragment shader part, i get the following error:

0:24: error(#181) Cannot be used with a structure: out
error(#273) 1 compilation errors. No code generated

So the problem lies around my out variable, i assume. Here is my fragment shader:

#version 410

uniform mat4 gWVP;
uniform mat4 gWorld;

uniform sampler2D gColorMap;                

in VSOutput
{
    vec3 WorldSpacePos;
    vec2 TexCoord;
    vec3 Normal;  
} FSin;


struct FSOutput
{                   
    vec3 WorldSpacePos;    
    vec3 Diffuse;     
    vec3 Normal;      
    vec3 TexCoord;
};

out FSOutput FSOut;

void main()
{                                           
    FSOut.WorldSpacePos = FSin.WorldSpacePos;                   
    FSOut.Diffuse      = texture(gColorMap, FSin.TexCoord).xyz; 
    FSOut.Normal       = normalize(FSin.Normal);                    
    FSOut.TexCoord     = vec3(FSin.TexCoord, 0.0);              
}

As i know it should be possible to output structs in OpenGL 4.0+, shouldn't it? So I dont get the error, is it a driver problem or something like that? I'm running on a Radeon HD 6950 with 13.4 drivers.

1
Some stages allow you to output structures, fragment shaders are not one of those stages. The outputs from a fragment shader are pretty strict - the closest you could get to what you want is to use an array of vec3; this is similar to the way the old gl_FragData [n] construct worked.Andon M. Coleman

1 Answers

6
votes

As i know it should be possible to output structs in OpenGL 4.0+, shouldn't it?

No, it shouldn't.

The GLSL specification is quite clear on this: vertex shader inputs and fragment shader outputs cannot be structs. From the GLSL 4.4 specification, section 4.3.6:

Fragment outputs can only be float, single-precision floating-point vectors, signed or unsigned integers or integer vectors, or arrays of any these. It is a compile-time error to declare any double-precision type, matrix, or structure as an output.

They also can't be aggregated into interface blocks, in case you're wondering. They must be loose variables.