Create a GL query object.
target (Glenum or int) – Target for the query.
Query object.
Examples
Get GPU time elapsed executing rendering/GL calls associated with some stimuli (this is not the difference in absolute time between consecutive beginQuery and endQuery calls!):
# create a new query object
qGPU = createQueryObject(GL_TIME_ELAPSED)
beginQuery(query)
myStim.draw() # OpenGL calls here
endQuery(query)
# get time elapsed in seconds spent on the GPU
timeRendering = getQueryValue(qGPU) * 1e-9
You can also use queries to test if vertices are occluded, as their samples would be rejected during depth testing:
drawVAO(shape0, GL_TRIANGLES) # draw the first object
# check if the object was completely occluded
qOcclusion = createQueryObject(GL_ANY_SAMPLES_PASSED)
# draw the next shape within query context
beginQuery(qOcclusion)
drawVAO(shape1, GL_TRIANGLES) # draw the second object
endQuery(qOcclusion)
isOccluded = getQueryValue(qOcclusion) == 1
This can be leveraged to perform occlusion testing/culling, where you can render a cheap version of your mesh/shape, then the more expensive version if samples were passed.