viktorzeid
viktorzeid

Reputation: 1561

How is gl_PrimitiveID interpreted in Tessellation Control and Evaluation shaders?

The OpenGL spec. says:

The variable gl_PrimitiveID is filled with the number of primitives processed by the drawing command which generated the input vertices. The first primitive generated by a drawing command is numbered zero, and the primitive ID counter is incremented after every individual point, line, or triangle primitive is processed. Restarting a primitive topology using the primitive restart index has no effect on the primitive ID counter.

Unfortunately, I do not quite understand that.

If I make a draw call with GL_PATCHES with number of vertices = 32, do all 32 vertices have gl_PrimitiveID = 0 in the Tesselation Control shader?

   Tessellation Control shaders still output a Patch, and a Patch is a single primitive.

Is it correct to assume that when this patch is tessellated as triangles in the Tessellation Evaluation shader, every nth vertex will have its gl_PrimitiveID = n/3?

If not, please explain what their values will be.

Upvotes: 2

Views: 992

Answers (1)

Bartek Banachewicz
Bartek Banachewicz

Reputation: 39400

OpenGL wiki seems to agree:

gl_PrimitiveID​

the index of the current patch within this rendering command.

Looking this up in spec shouldn't be hard, if you need confirmation.

I guess the number of patch within the rendering command would change simply when you process enough vertices and start a new patch.

Upvotes: 2

Related Questions