Difference between revisions of "Query Object"
(Link to reference.)
|Line 26:||Line 26:|
=== Query retrieval ===
=== Query retrieval ===
The purpose of query objects is to represent ''asynchronous'' queries of values. Thus, even after a query's scope has ended, the queried value may not be available.
The purpose of query objects is to represent ''asynchronous'' queries of values. Thus, even after a query's scope has ended, the queried value may not be available
=== Query precision ===
=== Query precision ===
Revision as of 10:49, 18 August 2012
|Core in version||1.5|
Query Objects are OpenGL Objects that are used for asynchronous queries of certain kinds of information.
Many kinds of query operations require a scope. The scope of the query is bound by a pair of begin/end functions, such that the query returns some information about the execution of all commands within that scope.
Like textures, query objects have different types, represented by the target parameter taken by many query object functions. Query objects represent a single integer value which can be queried. The different types determine what the value being queried means and where it comes from:
- GL_SAMPLES_PASSED: The number of samples that pass the depth test for all rendering commands within the scope of the query.
- GL_ANY_SAMPLES_PASSED: GL_FALSE if none of the scoped rendering commands generate samples that pass the depth test; otherwise, the value is GL_TRUE. This requires OpenGL 3.3 or ARB_occlusion_query2.
- GL_ANY_SAMPLES_PASSED_CONSERVATIVE: As GL_ANY_SAMPLES_PASSED, except that the implementation may use a less accurate algorithm, which may be faster, but at the cost of more more false positives. This requires OpenGL 4.3 or ARB_ES3_compatibility.
- GL_PRIMITIVES_GENERATED: Records the number of primitives sent to a Geometry Shader output stream (or by stream 0 if no GS is active) by scoped rendering commands. This requires OpenGL 3.0; multiple streams requires 4.0 or ARB_transform_feedback3.
- GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN: Records the number of primitives written by a Geometry Shader stream to a Transform Feedback object (or by stream 0 if no GS is active) by scoped rendering commands. This requires OpenGL 3.0; multiple streams requires 4.0 or ARB_transform_feedback3.
- GL_TIME_ELAPSED: Records the time that it takes for the GPU to execute all of the scoped commands. The timer starts when all commands before the scope have completed, and the timer ends when the last scoped command has completed.
- GL_TIMESTAMP: Records the current time of the GPU.
The purpose of query objects is to represent asynchronous queries of values. Thus, even after a query's scope has ended, the queried value may not be available.
To detect whether they queried value is available, use this function:
glGetQueryObject[ui64v](GLuint id, GLenum pname, GLint * params);
Where id is the query object and pname is GL_QUERY_RESULT_AVAILABLE. This will return GL_FALSE if the query has not completed, and GL_TRUE otherwise.
To get the actual value, the same function is used with GL_QUERY_RESULT. If the value is too large for the bitdepth of the function (ie: an integer requires 48-bits to store, but the user uses the 32-bit version of the function), then the value returned will be the value that is closest to the actual value of the query.
All query objects represent a single integer value. However, each type of query object has a different precision for this value. While you can query the integer value at 32 and 64-bit precision, the OpenGL implementation only provides so much precision for these values.
The precision for a query can be acquired by calling glGetQuery with GL_QUERY_COUNTER_BITS as the second parameter. OpenGL defines the minimum precision for each query type as follows:
|Query type||Minimum precision|
* In OpenGL 3.3, the minimum precision required is a function of the maximum viewport width and height. Specifically, the precision is required to be at least enough to hold a counter that is twice the maximum width and height, thus supporting 2x multisampling at the largest buffer size.
Note that implementations are allowed to return 0 for any of these values. This means that the query type contains no actual information, and the implementation does not really support it..
Calling glGetInteger64v with GL_TIMESTAMP will return the GPU timestamp when all previously given commands have issued, but not necessarily completed. As such, when coupled with an asynchronous timestamp timer query, one can determine the latency between when commands are issued and when they complete.
- Core API Ref Queries and Timers: Reference documentation for all query object API functions.
|This article is a stub. You can help the OpenGL Wiki by expanding it.|