Multiple functions in shader program

Hi all,

Is there any limit to the number of functions you can specify within one shader program?

I have written a geometry shader which has numerous functions specified before the main(). For some reason only the first of these functions will work no matter what order I specify them in.

I’ve written psuedo code below for a n outline of my geometry shader. Hopefully someone can identify what silly thing I’m doing wrong?

#version 330
#extension GL_EXT_geometry_shader4 : enable
precision highp float;

void func1()
{

}

void func2
{

}

void func3
{

}

main()
{
func1();
func2();
func3();
}

As I said, no matter what order the functions are called or which order they are declared, only the first one declared will work.

Also, I have no compilation errors.

Thanks,

Jonathan

It should work just fine. Can you provide a full source code? Including the function bodies? Maybe the problem is there.

Btw, what GPU and driver version you use?

In the code below only CreateCircle will work. I’m using the geometry shader to create a primitive at points so the functions only emit vertices, nothing extreme. Also, I know each of the functions does as expected as I can run each of them individually by declaring them as first function. My only guess might be that Im not ‘closing’ the function correctly?

Im running an AMD FirePro V7900 with driver version 8.911.3.1000 dated 16/01/2012

#version 330
#extension GL_EXT_geometry_shader4 : enable
precision highp float;

void createCircleGeometry(in vec4 v, in float f_size, in mat4 orientation)
{
int NVC = 9;
float fNVC = 9.;
float a = 0.;
float s = 3.1415 * 2. / fNVC;

for(int i=0; i<NVC; i++, a+=s)
{
    //gl_Position = v + (gl_ModelViewProjectionMatrix * (orientation*vec4(cos(a)*f_size, sin(a)*f_size, 0., 0.)));

gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(cos(a)*f_size, sin(a)*f_size, 0., 0.));
EmitVertex();
gl_Position = v;
EmitVertex();
}
gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(cos(0)*f_size, sin(0)*f_size, 0., 0.));
EmitVertex();
EndPrimitive();
}

void createTriangleGeometry(in vec4 v, in float f_size, in mat4 orientation)
{
gl_Position = v; EmitVertex(); //n1
gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(0., f_size, 0., 0.)); EmitVertex(); //n2
gl_Position = v; EmitVertex(); //n3
gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(f_size/4, f_size/2, 0., 0.)); EmitVertex(); //n4
gl_Position = v; EmitVertex(); //n5
gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(f_size/2, 0., 0., 0.)); EmitVertex(); //n6
gl_Position = v; EmitVertex(); //n7
gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(f_size, -f_size, 0., 0.)); EmitVertex(); //n8
gl_Position = v; EmitVertex(); //n9
gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(0., -f_size, 0., 0.)); EmitVertex(); //n10
gl_Position = v; EmitVertex(); //n11
gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(-f_size, -f_size, 0., 0.)); EmitVertex(); //n12
gl_Position = v; EmitVertex(); //n13
gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(-f_size/2, 0., 0., 0.)); EmitVertex(); //n14
gl_Position = v; EmitVertex(); //n15
gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(-f_size/4, f_size/2, 0., 0.)); EmitVertex(); //n16
gl_Position = v; EmitVertex(); //n17
gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(0., f_size, 0., 0.)); EmitVertex(); //n18
gl_Position = v; EmitVertex(); //n19
EndPrimitive();
}

void createRectangleGeometry(in vec4 v, in float f_size, in mat4 orientation)
{
gl_Position = v; EmitVertex(); //n1
gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(0., f_size, 0., 0.)); EmitVertex(); //n2
gl_Position = v; EmitVertex(); //n3
gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(f_size, f_size, 0., 0.)); EmitVertex(); //n4
gl_Position = v; EmitVertex(); //n5
gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(f_size, 0., 0., 0.)); EmitVertex(); //n6
gl_Position = v; EmitVertex(); //n7
gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(f_size, -f_size, 0., 0.)); EmitVertex(); //n8
gl_Position = v; EmitVertex(); //n9
gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(0., -f_size, 0., 0.)); EmitVertex(); //n10
gl_Position = v; EmitVertex(); //n11
gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(-f_size, -f_size, 0., 0.)); EmitVertex(); //n12
gl_Position = v; EmitVertex(); //n13
gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(-f_size, 0., 0., 0.)); EmitVertex(); //n14
gl_Position = v; EmitVertex(); //n15
gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(-f_size, f_size, 0., 0.)); EmitVertex(); //n16
gl_Position = v; EmitVertex(); //n17
gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(0., f_size, 0., 0.)); EmitVertex(); //n18
gl_Position = v; EmitVertex(); //n19
EndPrimitive();
}

in vec4 v_colorVS;
in float f_size;
in float f_style;
in float f_dip;
in float f_azimuth;

out vec4 v_color_out;

void main(void)
{
v_color_out = v_colorVS[0];
vec4 v = gl_PositionIn[0];

// Create the orientation matrix
mat4 dip_rot = mat4( 1.,            0.,             0., 0.,
                     0., cos(f_dip[0]), -sin(f_dip[0]), 0.,
                     0., sin(f_dip[0]),  cos(f_dip[0]), 0.,
  				 0.,            0.,             0., 1.);
mat4 azimuth_rot = mat4( cos(f_azimuth[0]), -sin(f_azimuth[0]), 0., 0.,
                         sin(f_azimuth[0]),  cos(f_azimuth[0]), 0., 0.,
                                        0., 				0., 1., 0.,
  									0.,         	    0., 0., 1.);
mat4 orientation = matrixCompMult(dip_rot,azimuth_rot);
// Create the marker geometry
createCircleGeometry(v,f_size[0],orientation);
//createRectangleGeometry(v,f_size[0],orientation);
//createTriangleGeometry(v,f_size[0],orientation);

}

Did you set GL_GEOMETRY_VERTICES_OUT_EXT properly on the application side? Maybe your functions do get called just the geometry shader is not allowed to emit any more vertices.

Btw, why do you still use EXT_geometry_shader4? Everybody should use ARB_geometry_shader4 instead as that’s what is included in core OpenGL.

Btw, why do you still use EXT_geometry_shader4? Everybody should use ARB_geometry_shader4 instead as that’s what is included in core OpenGL.

It most certainly is not. Core geometry shader functionality has little to do with ARB_geometry_shader4. The ARB version is basically the EXT version with “ARB” suffixes. The primitive types are specified in OpenGL at link time, rather than in the shader itself as in the core version. The ARB one uses the tortured “varying in/varying out” syntax of the EXT version, instead of the simple “in/out” of the core. And it doesn’t allow for interface blocks, just like the EXT version.

It is in every way the ARB version of the EXT extension, not core geometry shaders.

Wow, that’s true. Shame on me…
To be honest, I’ve never ever checked ARB_geometry_shader4, I thought it uses the same shader specified parameters as the core version.

Then I rephrase: you should use core OpenGL geometry shaders :slight_smile:

Managed to solve this this morning guys. I think it was related to outputting too many vertices but I’m not exactly sure where my error was - not in the shader programs anyway. I restructured my code slightly and ‘hey presto’ - results!!

I was using EXT_geometry_shader4 as it was what was defined in the examples I’d been looking at. I’ve switched to ARB_geometry_shader4 without any noticable difference and I’ll do a bit of reading into the benefits. Thanks for the input :slight_smile:

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