I'm studying the graphics pipeline and I have some questions about the tessellation phase. My basic reading material is "OpenGL SuperBible Sixth Edition: Comprehensive Tutorial and Reference".
Question #1: In the SuperBible I read that the vertex shader runs once per patch vertex (or control point in a tessellation context) "feeding" the Tessellation Control Shader one vertex at a time. The TCS, in turn, runs on groups of vertices. In this link though
http://web.engr.oregonstate.edu/~mjb/cs519/Handouts/tessellation.1pp.pdf
it says that the TCS runs once per "output vertex" (which I assume are the vertices being output by the VS). Which of the two is true? Did I get the whole thing wrong or is one of them wrong?
Question #2: This one is about the GLSL. The following shaders are from a SuperBible example.
Vertex Shader
#version 410 core
void main(void)
{
const vec4 vertices[] = vec4[](vec4( 0.25, -0.25, 0.5, 1.0),
vec4(-0.25, -0.25, 0.5, 1.0),
vec4( 0.25, 0.25, 0.5, 1.0));
gl_Position = vertices[gl_VertexID];
}
Tessellation Contron Shader
#version 410 core
layout (vertices = 3) out;
void main(void)
{
if (gl_InvocationID == 0)
{
gl_TessLevelInner[0] = 5.0;
gl_TessLevelOuter[0] = 5.0;
gl_TessLevelOuter[1] = 5.0;
gl_TessLevelOuter[2] = 5.0;
}
gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;
}
a) What do the tokens gl_VertexID (on the vertex shader) and gl_InvocationID (on the TCS) mean? They confuse me because they are not explicitly declared anywhere in the programs.
b) I understand that in the TCS the gl_Position variable takes its data from the vertex shader but nowhere in the vertex shader is it explicitly declared that gl_Position should be the output (e.g. with the out keyword before the main program). I thought that to pass data through the various shaders and pipeline phases, one must explicitly declare inputs and outputs with the same name, so what's happening in this case?