It is often useful to determine how many primitives were written during transform feedback pass. For example, if a geometry shader was active, the number of primitives written could be different than the number of primitives that were sent down the pipeline.
OpenGL provides a way to query for this information using query objects. To do so, start by creating a query object:
GLuint query; glGenQueries(1, &query);
Then, prior to starting the transform feedback pass, start the counting process using the following command:
glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, query);
After the end of the transform feedback pass, call glEndQuery to stop counting:
glEndQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);
Then, we can get the number of primitives by using the following code:
GLuintprimWritten; glGetQueryObjectuiv(query, GL_QUERY_RESULT, &primWritten); printf("Primitives written: %dn", primWritten);