PDA

View Full Version : Linking errors with geometry- / tesselation-shader



art-ganseforth
01-16-2017, 01:55 AM
Hi there!

i need help with geometry- / tesselation-shader. I have an application where i already use vertex- and fragment-shader, which works fine. No i'm trying to implement geometry- and tesselation-shaders for a while without success. Even the simpelest example-code will result in (glsl-)linking errors. This one for example:

Vertex shader:

void main() { gl_Position = ftransform(); }Geometry shader:

layout(points) in;
layout(line_strip, max_vertices = 2) out;

void main() {
gl_Position = gl_in[0].gl_Position + vec4(-0.1, 0.0, 0.0, 0.0);
EmitVertex();

gl_Position = gl_in[0].gl_Position + vec4(0.1, 0.0, 0.0, 0.0);
EmitVertex();

EndPrimitive();
}
Fragment shader:

out vec4 outColor;

void main() { outColor = vec4(1.0, 0.0, 0.0, 1.0); }
Systeminfo:
System: Windows 10 on thinkpad X230
Renderer: Intel(R) HD Graphics 4000
GL-Version: 4.0.0 - Build 10.18.10.4358
SL-Version: 4.00 - Build 10.18.10.4358


Since i don't know if the problem is the shader- or the c-code, here is the C++ code (note: the program can be edited while running. As long there are errors, the previous program stays active):


// create new shader while current are still working
vShNewHandle = glCreateShader (GL_VERTEX_SHADER);
tcShNewHandle = glCreateShader (GL_TESS_CONTROL_SHADER);
teShNewHandle = glCreateShader (GL_TESS_EVALUATION_SHADER);
gShNewHandle = glCreateShader (GL_GEOMETRY_SHADER);
fShNewHandle = glCreateShader (GL_FRAGMENT_SHADER);
prgNewHandle = glCreateProgram ();

// regular expression for testing if shader-code contains a main-function (if not, the specific shader is not compiled and linked)
regEx hasCode ("[\\n\\r][\\t ]*void\\s*main\\s*\\(");
if (hasCode.errmsg()) exit(0);

// compile vertex-shader & attach it to new program
success = GL_FALSE; errHandle = vShNewHandle;
glShaderSource (vShNewHandle, 1, &vs, NULL); glCompileShader (vShNewHandle);
glGetShaderiv (vShNewHandle, GL_COMPILE_STATUS, &success); if (success != GL_TRUE) goto ex;
glAttachShader (prgNewHandle, vShNewHandle);

// if exist compile tesselation-shader & attach them to new program
if (hasCode.Matches(shdShader->tcShSrc) && hasCode.Matches(shdShader->teShSrc)) {
success = GL_FALSE; errHandle = tcShNewHandle;
glShaderSource (tcShNewHandle, 1, &tcs, NULL); glCompileShader (tcShNewHandle);
glGetShaderiv (tcShNewHandle, GL_COMPILE_STATUS, &success); if (success != GL_TRUE) goto ex;
glAttachShader (prgNewHandle, tcShNewHandle);

success = GL_FALSE; errHandle = teShNewHandle;
glShaderSource (teShNewHandle, 1, &tes, NULL); glCompileShader (teShNewHandle);
glGetShaderiv (teShNewHandle, GL_COMPILE_STATUS, &success); if (success != GL_TRUE) goto ex;
glAttachShader (prgNewHandle, teShNewHandle);
}

// if exist compile geometry-shader & attach them to new program
if (hasCode.Matches(shdShader->gShSrc)) {
success = GL_FALSE; errHandle = gShNewHandle;
glShaderSource (gShNewHandle, 1, &gs, NULL); glCompileShader (gShNewHandle);
glGetShaderiv (gShNewHandle, GL_COMPILE_STATUS, &success); if (success != GL_TRUE) goto ex;
glAttachShader (prgNewHandle, gShNewHandle);
}

// compile fragment-shader & attach it to new program
success = GL_FALSE; errHandle = fShNewHandle;
glShaderSource (fShNewHandle, 1, &fs, NULL); glCompileShader (fShNewHandle);
glGetShaderiv (fShNewHandle, GL_COMPILE_STATUS, &success); if (success != GL_TRUE) goto ex;
glAttachShader (prgNewHandle, fShNewHandle);

// link new program - THIS IS, WHERE THE ERROR APPEARS
success = GL_FALSE; errHandle = prgNewHandle;
glUseProgram (prgNewHandle); glLinkProgram (prgNewHandle);
glGetProgramiv (prgNewHandle, GL_LINK_STATUS, &success); if (success != GL_TRUE) goto ex;

// if successful so far, swap active handles with used handels
GLuint tmpHandle;
tmpHandle = vShHandle; vShHandle = vShNewHandle; vShNewHandle = tmpHandle;
tmpHandle = tcShHandle; tcShHandle = tcShNewHandle; tcShNewHandle = tmpHandle;
tmpHandle = teShHandle; teShHandle = teShNewHandle; teShNewHandle = tmpHandle;
tmpHandle = gShHandle; gShHandle = gShNewHandle; gShNewHandle = tmpHandle;
tmpHandle = fShHandle; fShHandle = fShNewHandle; fShNewHandle = tmpHandle;
tmpHandle = prgHandle; prgHandle = prgNewHandle; prgNewHandle = tmpHandle;

canLink = true;

ex:
// dispay error-message if there is one
OutStatus ();

// delete handles, which are the new handels if the progam has errors or the old progam if the new program is okay.
glUseProgram (0);
glDeleteProgram (prgNewHandle);
glDeleteShader (vShNewHandle);
glDeleteShader (tcShNewHandle);
glDeleteShader (teShNewHandle);
glDeleteShader (gShNewHandle);
glDeleteShader (fShNewHandle);



As long as there is no geometry- or tesselation-shader is used, everything works fine but if i try to use them the program is not linked anymore.
Is there anyone who has an idea what is wrong??

Thank you for reading...


Kind regards,
Frank

art-ganseforth
01-16-2017, 05:03 AM
Okay, now i have a working geometry-shader, but i don't really know, why it works now. The only point i'm sure is: the problem was not the C-Code.

But still i have Problems with tesselation-shaders. I'll start a new thread with this...


For completeness here is the working geometry-shader:

layout(triangles) in;
layout(line_strip, max_vertices = 3) out;

vec4 normalVec(vec4 p, vec4 vX, vec4 vY) {
vX = vX - p; vY = vY - p;
p.x = (vX.y * vY.z) - (vX.z * vY.y);
p.y = (vX.z * vY.x) - (vX.x * vY.z);
p.z = (vX.x * vY.y) - (vX.y * vY.x);
p.w = (vX.w * vY.w) - (vX.w * vY.w);
return p;
}

void main()
{
vec4 test = normalVec(gl_in[0].gl_Position,gl_in[1].gl_Position,gl_in[2].gl_Position);
gl_Position = gl_in[0].gl_Position;// + gl_in[1].gl_Position;//vec4(-0.1, 0.0, 0.0, 0.0);
EmitVertex();

gl_Position = gl_in[0].gl_Position+test*16 ;//gl_in[1].gl_Position;// * gl_in[0].gl_Position;// vec4(0.1, 0.1, 0.0, 0.0);
EmitVertex();

gl_Position = gl_in[2].gl_Position;// + gl_in[0].gl_Position.x;// vec4(0.1, 0.1, 0.0, 0.0);
EmitVertex();

EndPrimitive();
}

Regards,
Frank

GClements
01-16-2017, 05:07 AM
i need help with geometry- / tesselation-shader. I have an application where i already use vertex- and fragment-shader, which works fine. No i'm trying to implement geometry- and tesselation-shaders for a while without success. Even the simpelest example-code will result in (glsl-)linking errors.

What errors, exactly? Call glGetProgramInfoLog() to obtain any errors or other messages related to linking.

art-ganseforth
01-16-2017, 07:17 AM
I already use glGetShaderInfoLog but unfortunately linking-errors are not specified in the log-text.

But anyway, i'm a little further on in between. I have a working example with geometry-shader. But i'm still missing a working tesselation-shader (see my new post here (https://www.opengl.org/discussion_boards/showthread.php/199212-Newbie-needs-help-with-tesselation?p=1285514#post1285514)).

Thanks anyway for replying...




PS. is there any possibility to mark the thread as "solved"??

john_connor
01-16-2017, 08:29 AM
I already use glGetShaderInfoLog but unfortunately linking-errors are not specified in the log-text.

glGetShaderInfoLog(...) != glGetProgramInfoLog(...)

the latter should give you infos about linking errors

art-ganseforth
01-16-2017, 10:34 AM
UUps...

You're right. Now i get correct linking-error-messages - thanks a lot ;)

Regards,
Frank