2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
33 #include "main/dispatch.h"
37 * Allocate a new query object. This is a fallback routine called via
38 * ctx->Driver.NewQueryObject().
39 * \param ctx - rendering context
40 * \param id - the new object's ID
41 * \return pointer to new query_object object or NULL if out of memory.
43 static struct gl_query_object
*
44 _mesa_new_query_object(struct gl_context
*ctx
, GLuint id
)
46 struct gl_query_object
*q
= CALLOC_STRUCT(gl_query_object
);
53 /* This is to satisfy the language of the specification: "In the initial
54 * state of a query object, the result is available" (OpenGL 3.1 §
59 /* OpenGL 3.1 § 2.13 says about GenQueries, "These names are marked as
60 * used, but no object is associated with them until the first time they
61 * are used by BeginQuery." Since our implementation actually does
62 * allocate an object at this point, use a flag to indicate that this
63 * object has not yet been bound so should not be considered a query.
65 q
->EverBound
= GL_FALSE
;
72 * Begin a query. Software driver fallback.
73 * Called via ctx->Driver.BeginQuery().
76 _mesa_begin_query(struct gl_context
*ctx
, struct gl_query_object
*q
)
78 ctx
->NewState
|= _NEW_DEPTH
; /* for swrast */
83 * End a query. Software driver fallback.
84 * Called via ctx->Driver.EndQuery().
87 _mesa_end_query(struct gl_context
*ctx
, struct gl_query_object
*q
)
89 ctx
->NewState
|= _NEW_DEPTH
; /* for swrast */
95 * Wait for query to complete. Software driver fallback.
96 * Called via ctx->Driver.WaitQuery().
99 _mesa_wait_query(struct gl_context
*ctx
, struct gl_query_object
*q
)
101 /* For software drivers, _mesa_end_query() should have completed the query.
102 * For real hardware, implement a proper WaitQuery() driver function,
103 * which may require issuing a flush.
110 * Check if a query results are ready. Software driver fallback.
111 * Called via ctx->Driver.CheckQuery().
114 _mesa_check_query(struct gl_context
*ctx
, struct gl_query_object
*q
)
116 /* No-op for sw rendering.
117 * HW drivers may need to flush at this time.
123 * Delete a query object. Called via ctx->Driver.DeleteQuery().
124 * Not removed from hash table here.
127 _mesa_delete_query(struct gl_context
*ctx
, struct gl_query_object
*q
)
135 _mesa_init_query_object_functions(struct dd_function_table
*driver
)
137 driver
->NewQueryObject
= _mesa_new_query_object
;
138 driver
->DeleteQuery
= _mesa_delete_query
;
139 driver
->BeginQuery
= _mesa_begin_query
;
140 driver
->EndQuery
= _mesa_end_query
;
141 driver
->WaitQuery
= _mesa_wait_query
;
142 driver
->CheckQuery
= _mesa_check_query
;
145 static struct gl_query_object
**
146 get_pipe_stats_binding_point(struct gl_context
*ctx
,
149 if (!_mesa_is_desktop_gl(ctx
) ||
150 !ctx
->Extensions
.ARB_pipeline_statistics_query
)
153 const int which
= target
- GL_VERTICES_SUBMITTED_ARB
;
154 assert(which
< MAX_PIPELINE_STATISTICS
);
155 return &ctx
->Query
.pipeline_stats
[which
];
159 * Return pointer to the query object binding point for the given target and
161 * \return NULL if invalid target, else the address of binding point
163 static struct gl_query_object
**
164 get_query_binding_point(struct gl_context
*ctx
, GLenum target
, GLuint index
)
167 case GL_SAMPLES_PASSED_ARB
:
168 if (ctx
->Extensions
.ARB_occlusion_query
)
169 return &ctx
->Query
.CurrentOcclusionObject
;
172 case GL_ANY_SAMPLES_PASSED
:
173 if (ctx
->Extensions
.ARB_occlusion_query2
)
174 return &ctx
->Query
.CurrentOcclusionObject
;
177 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE
:
178 if (ctx
->Extensions
.ARB_ES3_compatibility
179 || (ctx
->API
== API_OPENGLES2
&& ctx
->Version
>= 30))
180 return &ctx
->Query
.CurrentOcclusionObject
;
183 case GL_TIME_ELAPSED_EXT
:
184 if (ctx
->Extensions
.EXT_timer_query
)
185 return &ctx
->Query
.CurrentTimerObject
;
188 case GL_PRIMITIVES_GENERATED
:
189 if (ctx
->Extensions
.EXT_transform_feedback
)
190 return &ctx
->Query
.PrimitivesGenerated
[index
];
193 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
:
194 if (ctx
->Extensions
.EXT_transform_feedback
)
195 return &ctx
->Query
.PrimitivesWritten
[index
];
199 case GL_VERTICES_SUBMITTED_ARB
:
200 case GL_PRIMITIVES_SUBMITTED_ARB
:
201 case GL_VERTEX_SHADER_INVOCATIONS_ARB
:
202 case GL_FRAGMENT_SHADER_INVOCATIONS_ARB
:
203 case GL_CLIPPING_INPUT_PRIMITIVES_ARB
:
204 case GL_CLIPPING_OUTPUT_PRIMITIVES_ARB
:
205 return get_pipe_stats_binding_point(ctx
, target
);
207 case GL_GEOMETRY_SHADER_INVOCATIONS
:
208 /* GL_GEOMETRY_SHADER_INVOCATIONS is defined in a non-sequential order */
209 target
= GL_VERTICES_SUBMITTED_ARB
+ MAX_PIPELINE_STATISTICS
- 1;
211 case GL_GEOMETRY_SHADER_PRIMITIVES_EMITTED_ARB
:
212 if (_mesa_has_geometry_shaders(ctx
))
213 return get_pipe_stats_binding_point(ctx
, target
);
217 case GL_TESS_CONTROL_SHADER_PATCHES_ARB
:
218 case GL_TESS_EVALUATION_SHADER_INVOCATIONS_ARB
:
219 if (ctx
->Extensions
.ARB_tessellation_shader
)
220 return get_pipe_stats_binding_point(ctx
, target
);
224 case GL_COMPUTE_SHADER_INVOCATIONS_ARB
:
225 if (_mesa_has_compute_shaders(ctx
))
226 return get_pipe_stats_binding_point(ctx
, target
);
237 _mesa_GenQueries(GLsizei n
, GLuint
*ids
)
240 GET_CURRENT_CONTEXT(ctx
);
242 if (MESA_VERBOSE
& VERBOSE_API
)
243 _mesa_debug(ctx
, "glGenQueries(%d)\n", n
);
246 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenQueriesARB(n < 0)");
250 first
= _mesa_HashFindFreeKeyBlock(ctx
->Query
.QueryObjects
, n
);
253 for (i
= 0; i
< n
; i
++) {
254 struct gl_query_object
*q
255 = ctx
->Driver
.NewQueryObject(ctx
, first
+ i
);
257 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glGenQueriesARB");
261 _mesa_HashInsert(ctx
->Query
.QueryObjects
, first
+ i
, q
);
268 _mesa_DeleteQueries(GLsizei n
, const GLuint
*ids
)
271 GET_CURRENT_CONTEXT(ctx
);
272 FLUSH_VERTICES(ctx
, 0);
274 if (MESA_VERBOSE
& VERBOSE_API
)
275 _mesa_debug(ctx
, "glDeleteQueries(%d)\n", n
);
278 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteQueriesARB(n < 0)");
282 for (i
= 0; i
< n
; i
++) {
284 struct gl_query_object
*q
= _mesa_lookup_query_object(ctx
, ids
[i
]);
287 struct gl_query_object
**bindpt
;
288 bindpt
= get_query_binding_point(ctx
, q
->Target
, q
->Stream
);
289 assert(bindpt
); /* Should be non-null for active q. */
293 q
->Active
= GL_FALSE
;
294 ctx
->Driver
.EndQuery(ctx
, q
);
296 _mesa_HashRemove(ctx
->Query
.QueryObjects
, ids
[i
]);
297 ctx
->Driver
.DeleteQuery(ctx
, q
);
305 _mesa_IsQuery(GLuint id
)
307 struct gl_query_object
*q
;
309 GET_CURRENT_CONTEXT(ctx
);
310 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
312 if (MESA_VERBOSE
& VERBOSE_API
)
313 _mesa_debug(ctx
, "glIsQuery(%u)\n", id
);
318 q
= _mesa_lookup_query_object(ctx
, id
);
326 query_error_check_index(struct gl_context
*ctx
, GLenum target
, GLuint index
)
329 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
:
330 case GL_PRIMITIVES_GENERATED
:
331 if (index
>= ctx
->Const
.MaxVertexStreams
) {
332 _mesa_error(ctx
, GL_INVALID_VALUE
,
333 "glBeginQueryIndexed(index>=MaxVertexStreams)");
339 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBeginQueryIndexed(index>0)");
347 _mesa_BeginQueryIndexed(GLenum target
, GLuint index
, GLuint id
)
349 struct gl_query_object
*q
, **bindpt
;
350 GET_CURRENT_CONTEXT(ctx
);
352 if (MESA_VERBOSE
& VERBOSE_API
)
353 _mesa_debug(ctx
, "glBeginQueryIndexed(%s, %u, %u)\n",
354 _mesa_lookup_enum_by_nr(target
), index
, id
);
356 if (!query_error_check_index(ctx
, target
, index
))
359 FLUSH_VERTICES(ctx
, 0);
361 bindpt
= get_query_binding_point(ctx
, target
, index
);
363 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBeginQuery{Indexed}(target)");
367 /* From the GL_ARB_occlusion_query spec:
369 * "If BeginQueryARB is called while another query is already in
370 * progress with the same target, an INVALID_OPERATION error is
374 _mesa_error(ctx
, GL_INVALID_OPERATION
,
375 "glBeginQuery{Indexed}(target=%s is active)",
376 _mesa_lookup_enum_by_nr(target
));
381 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBeginQuery{Indexed}(id==0)");
385 q
= _mesa_lookup_query_object(ctx
, id
);
387 if (ctx
->API
!= API_OPENGL_COMPAT
) {
388 _mesa_error(ctx
, GL_INVALID_OPERATION
,
389 "glBeginQuery{Indexed}(non-gen name)");
392 /* create new object */
393 q
= ctx
->Driver
.NewQueryObject(ctx
, id
);
395 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBeginQuery{Indexed}");
398 _mesa_HashInsert(ctx
->Query
.QueryObjects
, id
, q
);
402 /* pre-existing object */
404 _mesa_error(ctx
, GL_INVALID_OPERATION
,
405 "glBeginQuery{Indexed}(query already active)");
414 q
->EverBound
= GL_TRUE
;
417 /* XXX should probably refcount query objects */
420 ctx
->Driver
.BeginQuery(ctx
, q
);
425 _mesa_EndQueryIndexed(GLenum target
, GLuint index
)
427 struct gl_query_object
*q
, **bindpt
;
428 GET_CURRENT_CONTEXT(ctx
);
430 if (MESA_VERBOSE
& VERBOSE_API
)
431 _mesa_debug(ctx
, "glEndQueryIndexed(%s, %u)\n",
432 _mesa_lookup_enum_by_nr(target
), index
);
434 if (!query_error_check_index(ctx
, target
, index
))
437 FLUSH_VERTICES(ctx
, 0);
439 bindpt
= get_query_binding_point(ctx
, target
, index
);
441 _mesa_error(ctx
, GL_INVALID_ENUM
, "glEndQuery{Indexed}(target)");
445 /* XXX should probably refcount query objects */
448 /* Check for GL_ANY_SAMPLES_PASSED vs GL_SAMPLES_PASSED. */
449 if (q
&& q
->Target
!= target
) {
450 _mesa_error(ctx
, GL_INVALID_OPERATION
,
451 "glEndQuery(target=%s with active query of target %s)",
452 _mesa_lookup_enum_by_nr(target
),
453 _mesa_lookup_enum_by_nr(q
->Target
));
459 if (!q
|| !q
->Active
) {
460 _mesa_error(ctx
, GL_INVALID_OPERATION
,
461 "glEndQuery{Indexed}(no matching glBeginQuery{Indexed})");
465 q
->Active
= GL_FALSE
;
466 ctx
->Driver
.EndQuery(ctx
, q
);
470 _mesa_BeginQuery(GLenum target
, GLuint id
)
472 _mesa_BeginQueryIndexed(target
, 0, id
);
476 _mesa_EndQuery(GLenum target
)
478 _mesa_EndQueryIndexed(target
, 0);
482 _mesa_QueryCounter(GLuint id
, GLenum target
)
484 struct gl_query_object
*q
;
485 GET_CURRENT_CONTEXT(ctx
);
487 if (MESA_VERBOSE
& VERBOSE_API
)
488 _mesa_debug(ctx
, "glQueryCounter(%u, %s)\n", id
,
489 _mesa_lookup_enum_by_nr(target
));
492 if (target
!= GL_TIMESTAMP
) {
493 _mesa_error(ctx
, GL_INVALID_ENUM
, "glQueryCounter(target)");
498 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glQueryCounter(id==0)");
502 q
= _mesa_lookup_query_object(ctx
, id
);
504 /* XXX the Core profile should throw INVALID_OPERATION here */
506 /* create new object */
507 q
= ctx
->Driver
.NewQueryObject(ctx
, id
);
509 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glQueryCounter");
512 _mesa_HashInsert(ctx
->Query
.QueryObjects
, id
, q
);
515 if (q
->Target
&& q
->Target
!= GL_TIMESTAMP
) {
516 _mesa_error(ctx
, GL_INVALID_OPERATION
,
517 "glQueryCounter(id has an invalid target)");
523 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glQueryCounter(id is active)");
530 q
->EverBound
= GL_TRUE
;
532 if (ctx
->Driver
.QueryCounter
) {
533 ctx
->Driver
.QueryCounter(ctx
, q
);
535 /* QueryCounter is implemented using EndQuery without BeginQuery
536 * in drivers. This is actually Direct3D and Gallium convention.
538 ctx
->Driver
.EndQuery(ctx
, q
);
544 _mesa_GetQueryIndexediv(GLenum target
, GLuint index
, GLenum pname
,
547 struct gl_query_object
*q
= NULL
, **bindpt
= NULL
;
548 GET_CURRENT_CONTEXT(ctx
);
550 if (MESA_VERBOSE
& VERBOSE_API
)
551 _mesa_debug(ctx
, "glGetQueryIndexediv(%s, %u, %s)\n",
552 _mesa_lookup_enum_by_nr(target
),
554 _mesa_lookup_enum_by_nr(pname
));
556 if (!query_error_check_index(ctx
, target
, index
))
559 if (target
== GL_TIMESTAMP
) {
560 if (!ctx
->Extensions
.ARB_timer_query
) {
561 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetQueryARB(target)");
566 bindpt
= get_query_binding_point(ctx
, target
, index
);
568 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetQuery{Indexed}iv(target)");
576 case GL_QUERY_COUNTER_BITS_ARB
:
578 case GL_SAMPLES_PASSED
:
579 *params
= ctx
->Const
.QueryCounterBits
.SamplesPassed
;
581 case GL_ANY_SAMPLES_PASSED
:
582 /* The minimum value of this is 1 if it's nonzero, and the value
583 * is only ever GL_TRUE or GL_FALSE, so no sense in reporting more
588 case GL_TIME_ELAPSED
:
589 *params
= ctx
->Const
.QueryCounterBits
.TimeElapsed
;
592 *params
= ctx
->Const
.QueryCounterBits
.Timestamp
;
594 case GL_PRIMITIVES_GENERATED
:
595 *params
= ctx
->Const
.QueryCounterBits
.PrimitivesGenerated
;
597 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
:
598 *params
= ctx
->Const
.QueryCounterBits
.PrimitivesWritten
;
600 case GL_VERTICES_SUBMITTED_ARB
:
601 *params
= ctx
->Const
.QueryCounterBits
.VerticesSubmitted
;
603 case GL_PRIMITIVES_SUBMITTED_ARB
:
604 *params
= ctx
->Const
.QueryCounterBits
.PrimitivesSubmitted
;
606 case GL_VERTEX_SHADER_INVOCATIONS_ARB
:
607 *params
= ctx
->Const
.QueryCounterBits
.VsInvocations
;
609 case GL_TESS_CONTROL_SHADER_PATCHES_ARB
:
610 *params
= ctx
->Const
.QueryCounterBits
.TessPatches
;
612 case GL_TESS_EVALUATION_SHADER_INVOCATIONS_ARB
:
613 *params
= ctx
->Const
.QueryCounterBits
.TessInvocations
;
615 case GL_GEOMETRY_SHADER_INVOCATIONS
:
616 *params
= ctx
->Const
.QueryCounterBits
.GsInvocations
;
618 case GL_GEOMETRY_SHADER_PRIMITIVES_EMITTED_ARB
:
619 *params
= ctx
->Const
.QueryCounterBits
.GsPrimitives
;
621 case GL_FRAGMENT_SHADER_INVOCATIONS_ARB
:
622 *params
= ctx
->Const
.QueryCounterBits
.FsInvocations
;
624 case GL_COMPUTE_SHADER_INVOCATIONS_ARB
:
625 *params
= ctx
->Const
.QueryCounterBits
.ComputeInvocations
;
627 case GL_CLIPPING_INPUT_PRIMITIVES_ARB
:
628 *params
= ctx
->Const
.QueryCounterBits
.ClInPrimitives
;
630 case GL_CLIPPING_OUTPUT_PRIMITIVES_ARB
:
631 *params
= ctx
->Const
.QueryCounterBits
.ClOutPrimitives
;
635 "Unknown target in glGetQueryIndexediv(target = %s)",
636 _mesa_lookup_enum_by_nr(target
));
641 case GL_CURRENT_QUERY_ARB
:
642 *params
= (q
&& q
->Target
== target
) ? q
->Id
: 0;
645 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetQuery{Indexed}iv(pname)");
651 _mesa_GetQueryiv(GLenum target
, GLenum pname
, GLint
*params
)
653 _mesa_GetQueryIndexediv(target
, 0, pname
, params
);
657 _mesa_GetQueryObjectiv(GLuint id
, GLenum pname
, GLint
*params
)
659 struct gl_query_object
*q
= NULL
;
660 GET_CURRENT_CONTEXT(ctx
);
662 if (MESA_VERBOSE
& VERBOSE_API
)
663 _mesa_debug(ctx
, "glGetQueryObjectiv(%u, %s)\n", id
,
664 _mesa_lookup_enum_by_nr(pname
));
667 q
= _mesa_lookup_query_object(ctx
, id
);
669 if (!q
|| q
->Active
) {
670 _mesa_error(ctx
, GL_INVALID_OPERATION
,
671 "glGetQueryObjectivARB(id=%d is invalid or active)", id
);
676 case GL_QUERY_RESULT_ARB
:
678 ctx
->Driver
.WaitQuery(ctx
, q
);
679 /* if result is too large for returned type, clamp to max value */
680 if (q
->Target
== GL_ANY_SAMPLES_PASSED
681 || q
->Target
== GL_ANY_SAMPLES_PASSED_CONSERVATIVE
) {
687 if (q
->Result
> 0x7fffffff) {
688 *params
= 0x7fffffff;
691 *params
= (GLint
)q
->Result
;
695 case GL_QUERY_RESULT_AVAILABLE_ARB
:
697 ctx
->Driver
.CheckQuery( ctx
, q
);
701 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetQueryObjectivARB(pname)");
708 _mesa_GetQueryObjectuiv(GLuint id
, GLenum pname
, GLuint
*params
)
710 struct gl_query_object
*q
= NULL
;
711 GET_CURRENT_CONTEXT(ctx
);
713 if (MESA_VERBOSE
& VERBOSE_API
)
714 _mesa_debug(ctx
, "glGetQueryObjectuiv(%u, %s)\n", id
,
715 _mesa_lookup_enum_by_nr(pname
));
718 q
= _mesa_lookup_query_object(ctx
, id
);
720 if (!q
|| q
->Active
) {
721 _mesa_error(ctx
, GL_INVALID_OPERATION
,
722 "glGetQueryObjectuivARB(id=%d is invalid or active)", id
);
727 case GL_QUERY_RESULT_ARB
:
729 ctx
->Driver
.WaitQuery(ctx
, q
);
730 /* if result is too large for returned type, clamp to max value */
731 if (q
->Target
== GL_ANY_SAMPLES_PASSED
732 || q
->Target
== GL_ANY_SAMPLES_PASSED_CONSERVATIVE
) {
738 if (q
->Result
> 0xffffffff) {
739 *params
= 0xffffffff;
742 *params
= (GLuint
)q
->Result
;
746 case GL_QUERY_RESULT_AVAILABLE_ARB
:
748 ctx
->Driver
.CheckQuery( ctx
, q
);
752 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetQueryObjectuivARB(pname)");
759 * New with GL_EXT_timer_query
762 _mesa_GetQueryObjecti64v(GLuint id
, GLenum pname
, GLint64EXT
*params
)
764 struct gl_query_object
*q
= NULL
;
765 GET_CURRENT_CONTEXT(ctx
);
767 if (MESA_VERBOSE
& VERBOSE_API
)
768 _mesa_debug(ctx
, "glGetQueryObjecti64v(%u, %s)\n", id
,
769 _mesa_lookup_enum_by_nr(pname
));
772 q
= _mesa_lookup_query_object(ctx
, id
);
774 if (!q
|| q
->Active
) {
775 _mesa_error(ctx
, GL_INVALID_OPERATION
,
776 "glGetQueryObjectui64vARB(id=%d is invalid or active)", id
);
781 case GL_QUERY_RESULT_ARB
:
783 ctx
->Driver
.WaitQuery(ctx
, q
);
786 case GL_QUERY_RESULT_AVAILABLE_ARB
:
788 ctx
->Driver
.CheckQuery( ctx
, q
);
792 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetQueryObjecti64vARB(pname)");
799 * New with GL_EXT_timer_query
802 _mesa_GetQueryObjectui64v(GLuint id
, GLenum pname
, GLuint64EXT
*params
)
804 struct gl_query_object
*q
= NULL
;
805 GET_CURRENT_CONTEXT(ctx
);
807 if (MESA_VERBOSE
& VERBOSE_API
)
808 _mesa_debug(ctx
, "glGetQueryObjectui64v(%u, %s)\n", id
,
809 _mesa_lookup_enum_by_nr(pname
));
812 q
= _mesa_lookup_query_object(ctx
, id
);
814 if (!q
|| q
->Active
) {
815 _mesa_error(ctx
, GL_INVALID_OPERATION
,
816 "glGetQueryObjectuui64vARB(id=%d is invalid or active)", id
);
821 case GL_QUERY_RESULT_ARB
:
823 ctx
->Driver
.WaitQuery(ctx
, q
);
826 case GL_QUERY_RESULT_AVAILABLE_ARB
:
828 ctx
->Driver
.CheckQuery( ctx
, q
);
832 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetQueryObjectui64vARB(pname)");
838 * Allocate/init the context state related to query objects.
841 _mesa_init_queryobj(struct gl_context
*ctx
)
843 ctx
->Query
.QueryObjects
= _mesa_NewHashTable();
844 ctx
->Query
.CurrentOcclusionObject
= NULL
;
846 ctx
->Const
.QueryCounterBits
.SamplesPassed
= 64;
847 ctx
->Const
.QueryCounterBits
.TimeElapsed
= 64;
848 ctx
->Const
.QueryCounterBits
.Timestamp
= 64;
849 ctx
->Const
.QueryCounterBits
.PrimitivesGenerated
= 64;
850 ctx
->Const
.QueryCounterBits
.PrimitivesWritten
= 64;
852 ctx
->Const
.QueryCounterBits
.VerticesSubmitted
= 64;
853 ctx
->Const
.QueryCounterBits
.PrimitivesSubmitted
= 64;
854 ctx
->Const
.QueryCounterBits
.VsInvocations
= 64;
855 ctx
->Const
.QueryCounterBits
.TessPatches
= 64;
856 ctx
->Const
.QueryCounterBits
.TessInvocations
= 64;
857 ctx
->Const
.QueryCounterBits
.GsInvocations
= 64;
858 ctx
->Const
.QueryCounterBits
.GsPrimitives
= 64;
859 ctx
->Const
.QueryCounterBits
.FsInvocations
= 64;
860 ctx
->Const
.QueryCounterBits
.ComputeInvocations
= 64;
861 ctx
->Const
.QueryCounterBits
.ClInPrimitives
= 64;
862 ctx
->Const
.QueryCounterBits
.ClOutPrimitives
= 64;
867 * Callback for deleting a query object. Called by _mesa_HashDeleteAll().
870 delete_queryobj_cb(GLuint id
, void *data
, void *userData
)
872 struct gl_query_object
*q
= (struct gl_query_object
*) data
;
873 struct gl_context
*ctx
= (struct gl_context
*)userData
;
874 ctx
->Driver
.DeleteQuery(ctx
, q
);
879 * Free the context state related to query objects.
882 _mesa_free_queryobj_data(struct gl_context
*ctx
)
884 _mesa_HashDeleteAll(ctx
->Query
.QueryObjects
, delete_queryobj_cb
, ctx
);
885 _mesa_DeleteHashTable(ctx
->Query
.QueryObjects
);