2005
Sams Publishing
2010-2014
Khronos Group
glBeginQuery
3G

# glBeginQuery

delimit the boundaries of a query object

## C Specification

                    void glBeginQuery
                    GLenum target
                    GLuint id

                    void glEndQuery
                    GLenum target

## Parameters for `glBeginQuery`

`target`

  Specifies the target type of query object established between `glBeginQuery` and the subsequent `glEndQuery`. The symbolic constant must be one of `GL_ANY_SAMPLES_PASSED`, `GL_ANY_SAMPLES_PASSED_CONSERVATIVE`, or `GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN`.

`id`

  Specifies the name of a query object.

## Parameters for `glEndQuery`

`target`

  Specifies the target type of query object to be concluded. The symbolic constant must be one of `GL_ANY_SAMPLES_PASSED`, `GL_ANY_SAMPLES_PASSED_CONSERVATIVE`, or `GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN`.

## Description

`glBeginQuery` and glEndQuery delimit the boundaries of a query object. `query` must be a name previously returned from a call to glGenQueries. If a query object with name `id` does not yet exist it is created with the type determined by `target`. `target` must be one of `GL_ANY_SAMPLES_PASSED`, `GL_ANY_SAMPLES_PASSED_CONSERVATIVE`, or `GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN`. The behavior of the query object depends on its type and is as follows.

If `target` is `GL_ANY_SAMPLES_PASSED`, `id` must be an unused name, or the name of an existing boolean occlusion query object. When `glBeginQuery` is executed, the query object's samples-passed flag is reset to `GL_FALSE`. Subsequent rendering causes the flag to be set to `GL_TRUE` if any sample passes the depth test. When `glEndQuery` is executed, the samples-passed flag is assigned to the query object's result value. This value can be queried by calling glGetQueryObjectuiv with `pname` `GL_QUERY_RESULT`.

If `target` is `GL_ANY_SAMPLES_PASSED_CONSERVATIVE`, `id` must be an unused name, or the name of an existing boolean occlusion query object. When `glBeginQuery` is executed, the query object's samples-passed flag is reset to `GL_FALSE`. Subsequent rendering causes the flag to be set to `GL_TRUE` if any sample passes the depth test. The implementation may choose to use a less precision version of the test, which can additionally set the samples-passed flag to `GL_TRUE` in some other implementation-dependent cases. When `glEndQuery` is executed, the samples-passed flag is assigned to the query object's result value. This value can be queried by calling glGetQueryObjectuiv with `pname` `GL_QUERY_RESULT`.

If `target` is `GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN`, `id` must be an unused name, or the name of an existing primitive query object previously bound to the `GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN` query binding. When `glBeginQuery` is executed, the query object's primitives-written counter is reset to 0. Subsequent rendering will increment the counter once for every vertex that is written into the bound transform feedback buffer(s). If transform feedback mode is not activated between the call to `glBeginQuery` and `glEndQuery`, the counter will not be incremented. When `glEndQuery` is executed, the primitives-written counter is assigned to the query object's result value. This value can be queried by calling glGetQueryObjectuiv with `pname` `GL_QUERY_RESULT`.

## Errors

`GL_INVALID_ENUM` is generated if `target` is not one of the accepted tokens.

`GL_INVALID_OPERATION` is generated if `glBeginQuery` is executed while a query object of the same `target` is already active. Note: `GL_ANY_SAMPLES_PASSED` and `GL_ANY_SAMPLES_PASSED_CONSERVATIVE` alias to the same target for the purposes of this error.

`GL_INVALID_OPERATION` is generated if `glEndQuery` is executed when a query object of the same `target` is not active.

`GL_INVALID_OPERATION` is generated if `id` is 0.

`GL_INVALID_OPERATION` is generated if `id` not a name returned from a previous call to `glGenQueries`, or if such a name has since been deleted with `glDeleteQueries`.

`GL_INVALID_OPERATION` is generated if `id` is the name of an already active query object.

`GL_INVALID_OPERATION` is generated if `id` refers to an existing query object whose type does not does not match `target`.

## API Version Support

`glBeginQuery`
`glEndQuery`

## See Also

glDeleteQueries, glGenQueries, glGetQueryiv, glGetQueryObjectuiv, 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/.