2

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.

Andon M. Coleman
  • 42,359
  • 2
  • 81
  • 106
viktorzeid
  • 1,521
  • 1
  • 22
  • 35

1 Answers1

2

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.

Community
  • 1
  • 1
Bartek Banachewicz
  • 38,596
  • 7
  • 91
  • 135
  • 1
    It is my understanding that (cannot test this right now) the patch primitive ID will be incremented after every n-many vertices are processed, where n is the number of vertices the user defines a patch as having. So if you draw 64 vertices and you define your patch primitive to have 32, then half of the patch vertices would belong to `gl_PrimitiveID` 0 and the other half to `gl_PrimitiveID` 1. You should not need anything fancier than that to increase the primitive ID using a regular draw call. – Andon M. Coleman Jun 13 '14 at 11:32
  • @AndonM.Coleman uh.. I feel embarrased, but yes, I think that you're right! Brain freeze or whatever. – Bartek Banachewicz Jun 13 '14 at 11:38