Graphics Reference
In-Depth Information
Figure 12.3.
The four new geometric primitives with their adjacent points: lines with adja-
cency (top left), line strip with adjacency (top right), triangles with adjacency (botom left),
and triangle strip with adjacency (botom right).
line strips, triangles, and triangle strips. In all these cases, the vertices are listed
in the order given, and are interpreted as described above. Notice that for the
line primitives, the first and last vertices are the adjacent primitives, while for
the triangle primitives, the vertices begin with one in the actual primitives and
the adjacent vertices are interleaved with the vertices in the primitive.
There is also a new GLSL built-in variable for geometry shaders. The
variable
int gl_PrimitiveIDIn
holds the number of primitives processed since the last time
glBegin( )
was
called. Its value is zero for the first primitive after the
glBegin( )
function,
and calling a vertex array function counts as an implied
glBegin( )
. Geometry
shaders can set the value of
gl_PrimitiveID
to send a primitive number to the
fragment shader.
Layouts for Input and Output Variables
A geometry shader must be told something about its input and output vari-
ables. As you can see in Figure 12.1, a geometry shader is always preceded by a
primitive assembly step, which groups multiple vertices into a single topologi-
cal primitive before handing them to the geometry shader. Thus, on the input
side, geometry shaders need to know what that topology is. This is done with
a GLSL
layout
statement, which goes at the top of the code:
layout(
topology
) in;