user1822451
user1822451

Reputation: 111

gl_PrimitiveID equivalent in vertex shader

is there any way I can query which primitive the current vertex belong inside a vertex shader? I'm using a TBO to output some data that I need to access inside a vertex shader, I can access this data inside the fragment shader using gl_PrimitiveID and it works fine but I can't find a way to do the same inside a vertex shader, gl_VertexID/3 won't work for me because I'm using glDrawElements.

thank you!

luiz

Upvotes: 1

Views: 983

Answers (1)

Andon M. Coleman
Andon M. Coleman

Reputation: 43319

This is impossible if you understand how vertex shader invocations work.

While it is true that the vertex shader has to be evaluated for every vertex in a primitive, the transformed clip-space value will be stored in a post-transform cache. As a result, a vertex shared by 10 different triangles may only be computed once (subsequent primitives that use said vertex will hit the post-T&L cache first). There is no clear relationship between the primitive that caused the vertex to be computed and the vertex shader invocation.

The Geometry Shader stage, on the other hand, has gl_PrimitiveIDIn, which may help you - it is not clear what you are trying to accomplish.

Upvotes: 3

Related Questions