+ if (id == 0) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glQueryCounter(id==0)");
+ return;
+ }
+
+ q = _mesa_lookup_query_object(ctx, id);
+ if (!q) {
+ /* XXX the Core profile should throw INVALID_OPERATION here */
+
+ /* create new object */
+ q = ctx->Driver.NewQueryObject(ctx, id);
+ if (!q) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glQueryCounter");
+ return;
+ }
+ _mesa_HashInsert(ctx->Query.QueryObjects, id, q);
+ }
+ else {
+ if (q->Target && q->Target != GL_TIMESTAMP) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glQueryCounter(id has an invalid target)");
+ return;
+ }
+ }
+
+ if (q->Active) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glQueryCounter(id is active)");
+ return;
+ }
+
+ /* This possibly changes the target of a buffer allocated by
+ * CreateQueries. Issue 39) in the ARB_direct_state_access extension states
+ * the following:
+ *
+ * "CreateQueries adds a <target>, so strictly speaking the <target>
+ * command isn't needed for BeginQuery/EndQuery, but in the end, this also
+ * isn't a selector, so we decided not to change it."
+ *
+ * Updating the target of the query object should be acceptable, so let's
+ * do that.
+ */
+
+ q->Target = target;
+ q->Result = 0;
+ q->Ready = GL_FALSE;
+ q->EverBound = GL_TRUE;
+
+ if (ctx->Driver.QueryCounter) {
+ ctx->Driver.QueryCounter(ctx, q);
+ } else {
+ /* QueryCounter is implemented using EndQuery without BeginQuery
+ * in drivers. This is actually Direct3D and Gallium convention.
+ */
+ ctx->Driver.EndQuery(ctx, q);
+ }
+}
+
+
+void GLAPIENTRY
+_mesa_GetQueryIndexediv(GLenum target, GLuint index, GLenum pname,
+ GLint *params)
+{
+ struct gl_query_object *q = NULL, **bindpt = NULL;
+ GET_CURRENT_CONTEXT(ctx);
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "glGetQueryIndexediv(%s, %u, %s)\n",
+ _mesa_lookup_enum_by_nr(target),
+ index,
+ _mesa_lookup_enum_by_nr(pname));
+
+ if (!query_error_check_index(ctx, target, index))
+ return;
+
+ if (target == GL_TIMESTAMP) {
+ if (!ctx->Extensions.ARB_timer_query) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetQueryARB(target)");
+ return;
+ }
+ }
+ else {
+ bindpt = get_query_binding_point(ctx, target, index);
+ if (!bindpt) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetQuery{Indexed}iv(target)");
+ return;
+ }
+
+ q = *bindpt;
+ }