PDA

View Full Version : Error with Geometry shaders



debonair
02-05-2013, 02:55 AM
Here are my shaders:


Vertex Shader:

in vec4 v_color;
flat out vec4 out_color;
in vec2 Position;

void main()
{
gl_Position = vec4(Position,0.0,1.0);
out_color = v_color;
}

Geom shader:

#version 150
#extension GL_EXT_geometry_shader4 : enable
layout (triangles)in;
layout (triangle_strip, max_vertices=4)out;
flat in vec4 out_color[];

flat out vec4 col;

void main()
{
int i;
vec4 vertex;

for(i=0;i<gl_in.length();i++)
{
gl_Position = gl_in[i].gl_Position;
col=out_color[i];
EmitVertex();
}


gl_Position = gl_in[1].gl_Position + vec4(0.5,0.5,0.0,0.0);
col=out_color[1];
EmitVertex();


EndPrimitive();
}

Frag shader:

out vec4 Color;
flat in vec4 col;

void main()
{
Color = vec4(col);
}



Now, when i execute this on AMD supporting opengl 4.3 it works fine.
But with nvidia supporting 3.2 it gives errors:
"
Compile failed.
ERROR: 0:5: 'flat' : non varyings cannot have varying modifier qualifiers
ERROR: 0:7: 'flat' : non varyings cannot have varying modifier qualifiers
ERROR: 2 compilation errors. No code generated.
"
it gives error though they are of varying types. Please let me know what changes can be done so that it will work with nvidia too.

randall
02-05-2013, 10:53 AM
This is not needed:

#extension GL_EXT_geometry_shader4 : enable

You are using 'core' Geometry Shader version not EXT.

debonair
02-05-2013, 10:50 PM
This is not needed:

#extension GL_EXT_geometry_shader4 : enable

You are using 'core' Geometry Shader version not EXT.

I removed that line and kept only
#version 150
But still, same error.

tonyo_au
02-06-2013, 05:12 PM
I thought the qualifiers "in" and "out" are from version 3.00 and forward but you have told the compiler you are version 1.5 - this may be confusing it.

Alfonse Reinheart
02-06-2013, 05:51 PM
GLSL version 1.50 is from OpenGL version 3.2. (http://www.opengl.org/wiki/GLSL_Core_Language#OpenGL_and_GLSL_versions). They switched to sane numbering for GL 3.3/GLSL 3.30.

tonyo_au
02-06-2013, 06:37 PM
Thanks Alfonse

debonair
02-07-2013, 01:49 AM
Can anyone shed some light on this issue?
BTW, qualifiers in and out is not an issue as it works without geometry shaders.

Dark Photon
02-07-2013, 05:33 AM
Can anyone shed some light on this issue?

What you're doing in the vertex and fragment shaders is not valid GLSL 1.10 (the default). Slap a #version 330 at the top of each and they'll compile.

debonair
02-07-2013, 06:33 AM
What you're doing in the vertex and fragment shaders is not valid GLSL 1.10 (the default). Slap a #version 330 at the top of each and they'll compile.

Unfortunately i have to make it work with driver supporting glsl150. Can you please tell me how can i achieve same effect using glsl150 ?

arekkusu
02-07-2013, 10:25 AM
Slap a #version 150 at the top of the vertex and fragment shader. "flat in" was not legal syntax in #version 110 ten years ago, so it fails to parse.

Also, at least in Apple's Core Profile, you would not be able to link a 110 and 150 shader together anyway; all of your shader versions need to be 140 or higher (#version is mandatory.)

Just to be clear, if you don't specify #version, the driver has to assume the worst (most backwards-compatible) case and you get the oldest version.

debonair
02-08-2013, 05:33 AM
Slap a #version 150 at the top of the vertex and fragment shader. "flat in" was not legal syntax in #version 110 ten years ago, so it fails to parse.


I added version 150 in each of the shader still the error persists..

arekkusu
02-08-2013, 12:37 PM
Time to report a bug to Nvidia, then.