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 ("[\
\\r][\ ]*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