Reputation: 649
The Khronos wiki for the Tessellation Control Shader states that
The output patch size does not have to match the input patch size.
Why is that? And why do we have to specify the input patch size at all when the control shader is able to change that before the primitive generation gets the patch?
Is the following explanation correct?
The input patch (to the TCS) size is set by glPatchParameter(GL_PATCH_VERTICES, X)
. This has the consequence that the length of the in
attribute arrays is X.
TCS:
in vec4 vs_tc_position[]; // This has a length of X
The output patch size is defined by the TCSs layout (vertices = Y) out;
. This means the length of the out attribute arrays is Y.
TCS:
out vec4 tc_te_position[]; // This has a length of Y
The TCS is called Y times and passes the output directly to the TES. So, the in
attribute arrays of the TES have a length of Y.
TES:
in vec4 tc_te_position[]; // This has a length of Y
The number of output patch vertices is irrelevant to the Tessellation Primitive Generation (TPG) because it only sees an abstract patch. The number of vertices of the abstract patch is defined by the TESs layout (TYPE) in;
.
The TES is called for every new vertex that results from the abstract patch due to the tessellation levels defined by the TCS (when it exists) or by glPatchParameter(GL_PATCH_DEFAULT_{OUTER|INNER}_LEVEL)
. The TES can then interpolate the attributes based on the gl_TessCoord
from the abstract patch and all the vertices (which are more like control points) from the TCS.
So, the following situation could be possible.
glPatchParameteri(GL_PATCH_VERTICES, 1);
The TCS gets one vertex per patch.
layout (vertices = 5) out;
The TCS creates 5 vertices for the output patch. Somehow.
layout (quads) in;
The TPG uses a quad as an abstract patch and subdivides. Then the TES is called on every new vertex and interpolates the attribute of the 5 output vertices from the TCS with the gl_TessCoord
from the abstract patch (somehow) to compute the attributes for the new vertices.
Upvotes: 4
Views: 1121
Reputation: 473447
The input patch size has to be specified because you don't have to have a TCS at all.
Also, remember that the input patch size is used to interpret the stream of vertices you render with. Every X vertices is a single patch, so OpenGL needs to know what X to use. Even with a TCS, OpenGL needs to have an input size to know how many vertices to pass to the TCS operation.
As for why the input and output patch sizes can be different, that is there to give freedom to the TCS and the user to do whatever they want. TCS's are able to add, remove, or modify data however they want, including adding or removing entire values.
So a TCS can turn a single input vertex into 4 output vertices; this could be useful for something like quad tessellation.
Upvotes: 3