Note that there are some explanatory texts on larger screens.

plurals
  1. POLinking error at tessellation shaders in GLSL
    text
    copied!<p>I'm testing the triangle tessellation from the link <a href="http://prideout.net/blog/?p=48#shaders" rel="nofollow">http://prideout.net/blog/?p=48#shaders</a>. All the shader are compiled correctly, but when I try to link the program using the command: </p> <pre><code>glLinkProgram(programID); </code></pre> <p>I got the following error:</p> <pre><code>Tessellation control info (0): error C6029: No input primitive type ---------------------------------------- Tessellation evaluation info (0): error c7005: No tessellation primitive mode specified ----------------------------------------------------------- Geometry info (0): error C6022: No input primitive type (0): error C6029: No ouput primitive type ---------------------------------------- Not valid </code></pre> <p>It's so strange I declare output for TC Shader using command:</p> <pre><code>layout(vertices = 3) out; </code></pre> <p>And input layout for TE shader using command:</p> <pre><code>layout(triangles, equal_spacing, cw) in; </code></pre> <p>Why I still got this error? I hope to see you answer about it.</p> <p>I put my shaders in below:</p> <p>Vertex shader:</p> <pre><code>#version 410 core in vec4 Position; out vec3 vPosition; void main() { vPosition = Position.xyz; } </code></pre> <p>TC shader:</p> <pre><code>#version 410 core layout(vertices = 3) out; in vec3 vPosition[]; out vec3 tcPosition[]; #define ID gl_InvocationID void main() { float TessLevelInner = 3; float TessLevelOuter = 2; tcPosition[ID] = vPosition[ID]; if (ID == 0) { gl_TessLevelInner[0] = TessLevelInner; gl_TessLevelOuter[0] = TessLevelOuter; gl_TessLevelOuter[1] = TessLevelOuter; gl_TessLevelOuter[2] = TessLevelOuter; } } </code></pre> <p>TE Shader:</p> <pre><code>#version 410 core //TessEval layout(triangles, equal_spacing, cw) in; in vec3 tcPosition[]; out vec3 tePosition; out vec3 tePatchDistance; uniform mat4 Projection; uniform mat4 Modelview; void main() { vec3 p0 = gl_TessCoord.x * tcPosition[0]; vec3 p1 = gl_TessCoord.y * tcPosition[1]; vec3 p2 = gl_TessCoord.z * tcPosition[2]; tePatchDistance = gl_TessCoord; tePosition = normalize(p0 + p1 + p2); gl_Position = Projection * Modelview * vec4(tePosition, 1); } </code></pre> <p>Geometry shader:</p> <pre><code>#version 410 core //geometry shader layout(triangles) in; layout(triangle_strip, max_vertices = 3) out; in vec3 tePosition[3]; in vec3 tePatchDistance[3]; out vec3 gFacetNormal; out vec3 gPatchDistance; out vec3 gTriDistance; uniform mat4 Modelview; uniform mat3 NormalMatrix; void main() { vec3 A = tePosition[2] - tePosition[0]; vec3 B = tePosition[1] - tePosition[0]; gFacetNormal = NormalMatrix * normalize(cross(A, B)); gPatchDistance = tePatchDistance[0]; gTriDistance = vec3(1, 0, 0); gl_Position = gl_in[0].gl_Position; EmitVertex(); gPatchDistance = tePatchDistance[1]; gTriDistance = vec3(0, 1, 0); gl_Position = gl_in[1].gl_Position; EmitVertex(); gPatchDistance = tePatchDistance[2]; gTriDistance = vec3(0, 0, 1); gl_Position = gl_in[2].gl_Position; EmitVertex(); EndPrimitive(); } </code></pre> <p>Fragment Shader:</p> <pre><code>#version 410 core //fragment shader out vec4 FragColor; in vec3 gFacetNormal; in vec3 gTriDistance; in vec3 gPatchDistance; in float gPrimitive; uniform vec3 LightPosition; float amplify(float d, float scale, float offset) { d = scale * d + offset; d = clamp(d, 0, 1); d = 1 - exp2(-2*d*d); return d; } void main() { vec3 AmbientMaterial = vec3(0.04f, 0.04f, 0.04f); vec3 DiffuseMaterial = vec3(0, 0.75, 0.75); vec3 LightPosition = vec3(0.25, 0.25, 1); vec3 N = normalize(gFacetNormal); vec3 L = LightPosition; float df = abs(dot(N, L)); vec3 color = AmbientMaterial + df * DiffuseMaterial; float d1 = min(min(gTriDistance.x, gTriDistance.y), gTriDistance.z); float d2 = min(min(gPatchDistance.x, gPatchDistance.y), gPatchDistance.z); color = amplify(d1, 40, -0.5) * amplify(d2, 60, -0.5) * color; FragColor = vec4(color, 1.0); } </code></pre> <p>FINALLY, this is the code I set up shader sources:</p> <pre><code> std::string filename = "shaders//terrain//terrain_TCShader.glsl" FILE* fp = fopen(fileName.c_str(), "rt"); if (!fp) return; // Get all lines from a file vector&lt;string&gt; sLines; char sLine[255]; while (fgets(sLine, 255, fp)) sLines.push_back(sLine); fclose(fp); const char** sProgram = new const char*[sLines.size()]; for (int i = 0; i &lt; sLines.size(); i++){ sProgram[i] = sLines[i].c_str(); } //Also for GL_TESS_EVALUATION_SHADER, ..VERTEX, ...FRAGMENT pShader[st] = glCreateShader(GL_TESS_CONTROL_SHADER); glShaderSource(pShader[st], 1, (const GLchar**)sProgram, NULL); glAttachShader(pProgram, pShader[st]); glCompileShader(pShader[st]); //==&gt; I tried to check error here but it's ok, the compiler do not notify anything </code></pre> <p>After compile all the shader, I link the program</p> <pre><code>glLinkProgram(pProgram); </code></pre> <p>//And check error again:</p> <pre><code>glGetProgramiv(pProgram, GL_INFO_LOG_LENGTH,&amp;infologLength); if (infologLength &gt; 0) { infoLog = (char *)malloc(infologLength); glGetProgramInfoLog(pProgram, infologLength, &amp;charsWritten, infoLog); } </code></pre> <p>//I got the error here, as I described above.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload