GLBEGINQUERY(3G)
π glBeginQuery(3G) β the query-boundaries glow-up
ok so this is the 3G manual page for glBeginQuery / glEndQuery, and bestie, it's literally the "start the stopwatch / stop the stopwatch" of OpenGL queries. Stay with me, it's gonna slay. π
β¨ NAME β¨
glBeginQuery β delimit the boundaries of a query object π«Ά
β¨ C SPECIFICATION β¨
void glBeginQuery(GLenum target, GLuint id);
void glEndQuery(GLenum target);
β¨ PARAMETERS FOR GLBEGINQUERY β¨
targetβ tells everyone what kind of query object we're setting up betweenglBeginQueryand theglEndQuerythat comes right after it. This symbolic constant has to be one ofGL_SAMPLES_PASSED,GL_ANY_SAMPLES_PASSED,GL_ANY_SAMPLES_PASSED_CONSERVATIVE,GL_PRIMITIVES_GENERATED,GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, orGL_TIME_ELAPSED.idβ the name of a query object. like, its whole identity π
β¨ PARAMETERS FOR GLENDQUERY β¨
targetβ tells everyone what kind of query object we're wrapping up now. This symbolic constant has to be one ofGL_SAMPLES_PASSED,GL_ANY_SAMPLES_PASSED,GL_ANY_SAMPLES_PASSED_CONSERVATIVE,GL_PRIMITIVES_GENERATED,GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, orGL_TIME_ELAPSED.
πΈ DESCRIPTION πΈ
glBeginQuery and glEndQuery delimit the boundaries of a query object. the query has to be a name that came back from an earlier call to glGenQueries(), no cap. and if a query object with name id doesn't exist yet? it literally gets created on the spot with the type that target decides. π
target must be one of GL_SAMPLES_PASSED, GL_ANY_SAMPLES_PASSED, GL_PRIMITIVES_GENERATED, GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, or GL_TIME_ELAPSED. the behavior of the query object depends on its type, and it goes a little something like this:
π¦ when target is GL_SAMPLES_PASSED
id must be an unused name, or the name of an existing occlusion query object. when glBeginQuery runs, the query object's samples-passed counter gets reset to 0. after that, rendering bumps the counter for every sample that passes the depth test. here's the vibe check:
- if
GL_SAMPLE_BUFFERSis0, then the samples-passed count goes up by1for each fragment. - if
GL_SAMPLE_BUFFERSis1, then the samples-passed count goes up by the number of samples whose coverage bit is set. but β and this is the messy part β implementations, at their discression, may instead increase the samples-passed count by the value ofGL_SAMPLESif any sample in the fragment is covered. π
when glEndQuery runs, the samples-passed counter gets assigned to the query object's result value. you can query that value by calling glGetQueryObject() with pname GL_QUERY_RESULT.
π¦ when target is GL_ANY_SAMPLES_PASSED or GL_ANY_SAMPLES_PASSED_CONSERVATIVE
id must be an unused name, or the name of an existing boolean occlusion query object. when glBeginQuery runs, the query object's samples-passed flag gets reset to GL_FALSE. then rendering causes the flag to be set to GL_TRUE:
- if any sample passes the depth test β that's the
GL_ANY_SAMPLES_PASSEDcase. - if the implementation determines that any sample might pass the depth test β that's the
GL_ANY_SAMPLES_PASSED_CONSERVATIVEcase.
the implementation may be able to provide a more efficient test in the GL_ANY_SAMPLES_PASSED_CONSERVATIVE case if some false positives are acceptable to the application. trade-offs, we love them. β¨
when glEndQuery runs, the samples-passed flag gets assigned to the query object's result value, and you can query that value with glGetQueryObject() and pname GL_QUERY_RESULT.
π¦ when target is GL_PRIMITIVES_GENERATED
id must be an unused name, or the name of an existing primitive query object that was previously bound to the GL_PRIMITIVES_GENERATED query binding. when glBeginQuery runs, the query object's primitives-generated counter gets reset to 0. after that, rendering increments the counter once for every vertex that's emitted from the geometry shader β or from the vertex shader if there's no geometry shader in the picture. when glEndQuery runs, the primitives-generated counter gets assigned to the query object's result value, and yeah, glGetQueryObject() with pname GL_QUERY_RESULT is how you grab it. π
π¦ when target is GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
id must be an unused name, or the name of an existing primitive query object that was previously bound to the GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN query binding. when glBeginQuery runs, the query object's primitives-written counter gets reset to 0. after that, rendering increments the counter once for every vertex that's written into the bound transform feedback buffer(s). π«§ important: if transform feedback mode is not activated between the call to glBeginQuery and glEndQuery, the counter will not be incremented. like, at all. when glEndQuery runs, the primitives-written counter gets assigned to the query object's result value, queryable via glGetQueryObject() with pname GL_QUERY_RESULT.
π¦ when target is GL_TIME_ELAPSED
id must be an unused name, or the name of an existing timer query object that was previously bound to the GL_TIME_ELAPSED query binding. when glBeginQuery runs, the query object's time counter gets reset to 0. when glEndQuery runs, the elapsed server time that has passed since the call to glBeginQuery gets written into the query object's time counter. that value can be queried by calling glGetQueryObject() with pname GL_QUERY_RESULT. β±οΈ
π§ the flush tea
querying GL_QUERY_RESULT implicitly flushes the GL pipeline until the rendering delimited by the query object has completed and the result is available. GL_QUERY_RESULT_AVAILABLE can be queried to determine if the result is immediately available or if the rendering is not yet complete. iykyk. π
π NOTES π
- if the query target's count exceeds the maximum value representable in the number of available bits, as reported by
glGetQueryiv()withtargetset to the appropriate query target and pnameGL_QUERY_COUNTER_BITS, the count becomes undefined. π - an implementation may support
0bits in its counter, in which case query results are always undefined and essentially useless. literally giving nothing. π« - when
GL_SAMPLE_BUFFERSis0, the samples-passed counter of an occlusion query increments once for each fragment that passes the depth test. whenGL_SAMPLE_BUFFERSis1, an implementation may either increment the samples-passed counter individually for each sample of a fragment that passes the depth test, or it may choose to increment the counter for all samples of a fragment if any one of them passes the depth test. - the query targets
GL_ANY_SAMPLES_PASSEDandGL_TIME_ELAPSEDare availale only if the GL version is3.3or higher. - the query target
GL_ANY_SAMPLES_PASSED_CONSERVATIVEis available only of the GL version is4.3or higher.
π₯ ERRORS π₯
GL_INVALID_ENUMis generated iftargetis not one of the accepted tokens. π«GL_INVALID_OPERATIONis generated ifglBeginQueryis executed while a query object of the same target is already active. (one at a time, bestie!!)GL_INVALID_OPERATIONis generated ifglEndQueryis executed when a query object of the same target is not active.GL_INVALID_OPERATIONis generated ifidis0.GL_INVALID_OPERATIONis generated ifidis the name of an already active query object.GL_INVALID_OPERATIONis generated ifidrefers to an existing query object whose type does not does not matchtarget. π
π VERSION SUPPORT π
(the original is a whole table, so here it is laid out as the vibe-check list it truly is β¨ β the columns were the OpenGL versions and every single cell is a checkmark, okay?)
glBeginQuery is supported in: 2.0 β, 2.1 β, 3.0 β, 3.1 β, 3.2 β, 3.3 β, 4.0 β, 4.1 β, 4.2 β, 4.3 β, 4.4 β, 4.5 β
glEndQuery is supported in: 2.0 β, 2.1 β, 3.0 β, 3.1 β, 3.2 β, 3.3 β, 4.0 β, 4.1 β, 4.2 β, 4.3 β, 4.4 β, 4.5 β
like... every OpenGL version in the Function / Feature Name vs OpenGL Version grid said yes. periodt. π
π
π SEE ALSO π
glBeginQueryIndexed(), glDeleteQueries(), glEndQuery, glGenQueries(), glGetQueryObject(), glGetQueryiv(), glIsQuery()
π COPYRIGHT π
Copyright Β© 2005 Addison-Wesley. Copyright Β© 2010-2014 Khronos Group. This material may be distributed subject to the terms and conditions set forth in the Open Publication License, v 1.0, 8 June 1999. http://opencontent.org/openpub/.
Copyright Β© 2005 Sams Publishing Copyright Β© 2010-2014 Khronos Group
ok that's the whole page, you ate that π«Ά source slot was stuck at [FIXME: source] and the date said 08/09/2021 β iconic of the docs team honestly, go off besties πβ¨π
π¦ where this page comes from
- centos-stream 9: gl-manpages 1.1-24.20190306.el9 Β· MIT and Open Publication
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms