Reputation: 3931
I was trying to think why would OpenGL need to know the primitive type when calling glBeginTransformFeedback. In essence, it's just data that is stored into a buffer.
My guess would be that OpenGL somehow needs it in order to compute how much space is needed so draw commands can be run in parallel without stomping on each others data. But when you submit a draw command, OpenGL should be able to infer the required space from the primitive type specified in the draw.
In the case of using a geometry shader I think the amount of space required can't be known a priory because each individual execution could output a different number of primitives (I imagine that should be quite challenging to implement in the hardware!). But in that case, I don't think specifying the primitive type in glBeginTransformFeedback
would help anyways. The output primitive type can be infered as well from the bound program.
So as I see it, specifiying the primitive type in glBeginTransformFeedback
just puts a limitiation in the type of primitives you can render. Why is this limitiation?
Upvotes: 0
Views: 190
Reputation: 45322
The ultimate answer to your question is "because the spec says so". The reasoning behind that isn't explained in the spec. But in the extensions where transform feedback was initially introduced, NV_transform_feedback
and EXT_transform_feedback
, you'll find the following in the issues sections:
Why only one feedback primitive mode per feedback invocation?
RESOLVED: Having primitive tokens breaks up the stream and makes it less amenable to being read back in as a vertex buffer. Also, mixing multiple primitive types makes the counting of primitives less clear for the application.
There is really no hard technical reason given, it is just a design choice they made at some point.
Upvotes: 1
Reputation: 2516
I think it is to avoid querying the output type from the bound program. The primitive type given to the draw command is not always the same as the primitive type that is stored into the transform feedback buffer: both geometry and tessellation shaders can turn triangles / patches into points.
If the draw command specifies triangles but the program emits points, which is the programmer expecting to be stored? Specifying the primitive type with glBeginTransformFeedback makes it possible to check before drawing anything.
Transform feedback could work by storing whatever the program emits as you suggest, and that might even be preferable in some cases, but then there would have to some query mechanism "what type of geometry is in the feedback buffer?" afterwards.
Upvotes: 0