mesa: better debug messages in _mesa_test_texobj_completeness()
[mesa.git] / src / mesa / main / queryobj.c
index 0e59ba615a783bd597f1ffe49d78efa616d5b9c4..f0a9a7922b224068a54ab3344b2e69cffe528222 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.5.1
+ * Version:  7.1
  *
- * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
 
 #include "glheader.h"
 #include "context.h"
+#include "enums.h"
 #include "hash.h"
 #include "imports.h"
 #include "queryobj.h"
+#include "mfeatures.h"
 #include "mtypes.h"
+#include "main/dispatch.h"
+
+
+#if FEATURE_queryobj
 
 
 /**
@@ -38,8 +44,8 @@
  * \param id - the new object's ID
  * \return pointer to new query_object object or NULL if out of memory.
  */
-struct gl_query_object *
-_mesa_new_query_object(GLcontext *ctx, GLuint id)
+static struct gl_query_object *
+_mesa_new_query_object(struct gl_context *ctx, GLuint id)
 {
    struct gl_query_object *q = MALLOC_STRUCT(gl_query_object);
    (void) ctx;
@@ -54,33 +60,129 @@ _mesa_new_query_object(GLcontext *ctx, GLuint id)
 
 
 /**
- * Delete an occlusion query object.
+ * Begin a query.  Software driver fallback.
+ * Called via ctx->Driver.BeginQuery().
+ */
+static void
+_mesa_begin_query(struct gl_context *ctx, struct gl_query_object *q)
+{
+   /* no-op */
+}
+
+
+/**
+ * End a query.  Software driver fallback.
+ * Called via ctx->Driver.EndQuery().
+ */
+static void
+_mesa_end_query(struct gl_context *ctx, struct gl_query_object *q)
+{
+   q->Ready = GL_TRUE;
+}
+
+
+/**
+ * Wait for query to complete.  Software driver fallback.
+ * Called via ctx->Driver.WaitQuery().
+ */
+static void
+_mesa_wait_query(struct gl_context *ctx, struct gl_query_object *q)
+{
+   /* For software drivers, _mesa_end_query() should have completed the query.
+    * For real hardware, implement a proper WaitQuery() driver function,
+    * which may require issuing a flush.
+    */
+   assert(q->Ready);
+}
+
+
+/**
+ * Check if a query results are ready.  Software driver fallback.
+ * Called via ctx->Driver.CheckQuery().
+ */
+static void
+_mesa_check_query(struct gl_context *ctx, struct gl_query_object *q)
+{
+   /* No-op for sw rendering.
+    * HW drivers may need to flush at this time.
+    */
+}
+
+
+/**
+ * Delete a query object.  Called via ctx->Driver.DeleteQuery().
  * Not removed from hash table here.
- * XXX maybe add Delete() method to gl_query_object class and call that instead
  */
 static void
-delete_query_object(struct gl_query_object *q)
+_mesa_delete_query(struct gl_context *ctx, struct gl_query_object *q)
 {
-   FREE(q);
+   free(q);
 }
 
 
-static struct gl_query_object *
-lookup_query_object(GLcontext *ctx, GLuint id)
+void
+_mesa_init_query_object_functions(struct dd_function_table *driver)
 {
-   return (struct gl_query_object *)
-      _mesa_HashLookup(ctx->Query.QueryObjects, id);
+   driver->NewQueryObject = _mesa_new_query_object;
+   driver->DeleteQuery = _mesa_delete_query;
+   driver->BeginQuery = _mesa_begin_query;
+   driver->EndQuery = _mesa_end_query;
+   driver->WaitQuery = _mesa_wait_query;
+   driver->CheckQuery = _mesa_check_query;
 }
 
 
+/**
+ * Return pointer to the query object binding point for the given target.
+ * \return NULL if invalid target, else the address of binding point
+ */
+static struct gl_query_object **
+get_query_binding_point(struct gl_context *ctx, GLenum target)
+{
+   switch (target) {
+   case GL_SAMPLES_PASSED_ARB:
+      if (ctx->Extensions.ARB_occlusion_query)
+         return &ctx->Query.CurrentOcclusionObject;
+      else
+         return NULL;
+   case GL_ANY_SAMPLES_PASSED:
+      if (ctx->Extensions.ARB_occlusion_query2)
+         return &ctx->Query.CurrentOcclusionObject;
+      else
+         return NULL;
+   case GL_TIME_ELAPSED_EXT:
+      if (ctx->Extensions.EXT_timer_query)
+         return &ctx->Query.CurrentTimerObject;
+      else
+         return NULL;
+#if FEATURE_EXT_transform_feedback
+   case GL_PRIMITIVES_GENERATED:
+      if (ctx->Extensions.EXT_transform_feedback)
+         return &ctx->Query.PrimitivesGenerated;
+      else
+         return NULL;
+   case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
+      if (ctx->Extensions.EXT_transform_feedback)
+         return &ctx->Query.PrimitivesWritten;
+      else
+         return NULL;
+#endif
+   default:
+      return NULL;
+   }
+}
+
 
-void GLAPIENTRY
+static void GLAPIENTRY
 _mesa_GenQueriesARB(GLsizei n, GLuint *ids)
 {
    GLuint first;
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
+   if (MESA_VERBOSE & VERBOSE_API)
+      _mesa_debug(ctx, "glGenQueries(%d)\n", n);
+
    if (n < 0) {
       _mesa_error(ctx, GL_INVALID_VALUE, "glGenQueriesARB(n < 0)");
       return;
@@ -110,12 +212,16 @@ _mesa_GenQueriesARB(GLsizei n, GLuint *ids)
 }
 
 
-void GLAPIENTRY
+static void GLAPIENTRY
 _mesa_DeleteQueriesARB(GLsizei n, const GLuint *ids)
 {
    GLint i;
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
+   FLUSH_VERTICES(ctx, 0);
+
+   if (MESA_VERBOSE & VERBOSE_API)
+      _mesa_debug(ctx, "glDeleeteQueries(%d)\n", n);
 
    if (n < 0) {
       _mesa_error(ctx, GL_INVALID_VALUE, "glDeleteQueriesARB(n < 0)");
@@ -131,65 +237,50 @@ _mesa_DeleteQueriesARB(GLsizei n, const GLuint *ids)
 
    for (i = 0; i < n; i++) {
       if (ids[i] > 0) {
-         struct gl_query_object *q = lookup_query_object(ctx, ids[i]);
+         struct gl_query_object *q = _mesa_lookup_query_object(ctx, ids[i]);
          if (q) {
             ASSERT(!q->Active); /* should be caught earlier */
             _mesa_HashRemove(ctx->Query.QueryObjects, ids[i]);
-            delete_query_object(q);
+            ctx->Driver.DeleteQuery(ctx, q);
          }
       }
    }
 }
 
 
-GLboolean GLAPIENTRY
+static GLboolean GLAPIENTRY
 _mesa_IsQueryARB(GLuint id)
 {
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
 
-   if (id && lookup_query_object(ctx, id))
+   if (MESA_VERBOSE & VERBOSE_API)
+      _mesa_debug(ctx, "glIsQuery(%u)\n", id);
+
+   if (id && _mesa_lookup_query_object(ctx, id))
       return GL_TRUE;
    else
       return GL_FALSE;
 }
 
 
-void GLAPIENTRY
+static void GLAPIENTRY
 _mesa_BeginQueryARB(GLenum target, GLuint id)
 {
-   struct gl_query_object *q;
+   struct gl_query_object *q, **bindpt;
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
+   if (MESA_VERBOSE & VERBOSE_API)
+      _mesa_debug(ctx, "glBeginQuery(%s, %u)\n",
+                  _mesa_lookup_enum_by_nr(target), id);
+
    FLUSH_VERTICES(ctx, _NEW_DEPTH);
 
-   switch (target) {
-      case GL_SAMPLES_PASSED_ARB:
-         if (!ctx->Extensions.ARB_occlusion_query) {
-            _mesa_error(ctx, GL_INVALID_ENUM, "glBeginQueryARB(target)");
-            return;
-         }
-         if (ctx->Query.CurrentOcclusionObject) {
-            _mesa_error(ctx, GL_INVALID_OPERATION, "glBeginQueryARB");
-            return;
-         }
-         break;
-#if FEATURE_EXT_timer_query
-      case GL_TIME_ELAPSED_EXT:
-         if (!ctx->Extensions.EXT_timer_query) {
-            _mesa_error(ctx, GL_INVALID_ENUM, "glBeginQueryARB(target)");
-            return;
-         }
-         if (ctx->Query.CurrentTimerObject) {
-            _mesa_error(ctx, GL_INVALID_OPERATION, "glBeginQueryARB");
-            return;
-         }
-         break;
-#endif
-      default:
-         _mesa_error(ctx, GL_INVALID_ENUM, "glBeginQueryARB(target)");
-         return;
+   bindpt = get_query_binding_point(ctx, target);
+   if (!bindpt) {
+      _mesa_error(ctx, GL_INVALID_ENUM, "glBeginQueryARB(target)");
+      return;
    }
 
    if (id == 0) {
@@ -197,7 +288,7 @@ _mesa_BeginQueryARB(GLenum target, GLuint id)
       return;
    }
 
-   q = lookup_query_object(ctx, id);
+   q = _mesa_lookup_query_object(ctx, id);
    if (!q) {
       /* create new object */
       q = ctx->Driver.NewQueryObject(ctx, id);
@@ -216,58 +307,40 @@ _mesa_BeginQueryARB(GLenum target, GLuint id)
       }
    }
 
+   q->Target = target;
    q->Active = GL_TRUE;
    q->Result = 0;
    q->Ready = GL_FALSE;
 
-   if (target == GL_SAMPLES_PASSED_ARB) {
-      ctx->Query.CurrentOcclusionObject = q;
-   }
-#if FEATURE_EXT_timer_query
-   else if (target == GL_TIME_ELAPSED_EXT) {
-      ctx->Query.CurrentTimerObject = q;
-   }
-#endif
+   /* XXX should probably refcount query objects */
+   *bindpt = q;
 
-   if (ctx->Driver.BeginQuery) {
-      ctx->Driver.BeginQuery(ctx, target, q);
-   }
+   ctx->Driver.BeginQuery(ctx, q);
 }
 
 
-void GLAPIENTRY
+static void GLAPIENTRY
 _mesa_EndQueryARB(GLenum target)
 {
-   struct gl_query_object *q;
+   struct gl_query_object *q, **bindpt;
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
+   if (MESA_VERBOSE & VERBOSE_API)
+      _mesa_debug(ctx, "glEndQuery(%s)\n", _mesa_lookup_enum_by_nr(target));
+
    FLUSH_VERTICES(ctx, _NEW_DEPTH);
 
-   switch (target) {
-      case GL_SAMPLES_PASSED_ARB:
-         if (!ctx->Extensions.ARB_occlusion_query) {
-            _mesa_error(ctx, GL_INVALID_ENUM, "glEndQueryARB(target)");
-            return;
-         }
-         q = ctx->Query.CurrentOcclusionObject;
-         ctx->Query.CurrentOcclusionObject = NULL;
-         break;
-#if FEATURE_EXT_timer_query
-      case GL_TIME_ELAPSED_EXT:
-         if (!ctx->Extensions.EXT_timer_query) {
-            _mesa_error(ctx, GL_INVALID_ENUM, "glEndQueryARB(target)");
-            return;
-         }
-         q = ctx->Query.CurrentTimerObject;
-         ctx->Query.CurrentTimerObject = NULL;
-         break;
-#endif
-      default:
-         _mesa_error(ctx, GL_INVALID_ENUM, "glEndQueryARB(target)");
-         return;
+   bindpt = get_query_binding_point(ctx, target);
+   if (!bindpt) {
+      _mesa_error(ctx, GL_INVALID_ENUM, "glEndQueryARB(target)");
+      return;
    }
 
+   /* XXX should probably refcount query objects */
+   q = *bindpt;
+   *bindpt = NULL;
+
    if (!q || !q->Active) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
                   "glEndQueryARB(no matching glBeginQueryARB)");
@@ -275,45 +348,30 @@ _mesa_EndQueryARB(GLenum target)
    }
 
    q->Active = GL_FALSE;
-   if (ctx->Driver.EndQuery) {
-      ctx->Driver.EndQuery(ctx, target, q);
-   }
-   else {
-      /* if we're using software rendering/querying */
-      q->Ready = GL_TRUE;
-   }
+   ctx->Driver.EndQuery(ctx, q);
 }
 
 
-void GLAPIENTRY
+static void GLAPIENTRY
 _mesa_GetQueryivARB(GLenum target, GLenum pname, GLint *params)
 {
-   struct gl_query_object *q;
+   struct gl_query_object *q, **bindpt;
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-   switch (target) {
-      case GL_SAMPLES_PASSED_ARB:
-         if (!ctx->Extensions.ARB_occlusion_query) {
-            _mesa_error(ctx, GL_INVALID_ENUM, "glEndQueryARB(target)");
-            return;
-         }
-         q = ctx->Query.CurrentOcclusionObject;
-         break;
-#if FEATURE_EXT_timer_query
-      case GL_TIME_ELAPSED_EXT:
-         if (!ctx->Extensions.EXT_timer_query) {
-            _mesa_error(ctx, GL_INVALID_ENUM, "glEndQueryARB(target)");
-            return;
-         }
-         q = ctx->Query.CurrentTimerObject;
-         break;
-#endif
-      default:
-         _mesa_error(ctx, GL_INVALID_ENUM, "glGetQueryivARB(target)");
-         return;
+   if (MESA_VERBOSE & VERBOSE_API)
+      _mesa_debug(ctx, "glGetQueryiv(%s, %s)\n",
+                  _mesa_lookup_enum_by_nr(target),
+                  _mesa_lookup_enum_by_nr(pname));
+
+   bindpt = get_query_binding_point(ctx, target);
+   if (!bindpt) {
+      _mesa_error(ctx, GL_INVALID_ENUM, "glGetQueryARB(target)");
+      return;
    }
 
+   q = *bindpt;
+
    switch (pname) {
       case GL_QUERY_COUNTER_BITS_ARB:
          *params = 8 * sizeof(q->Result);
@@ -328,15 +386,19 @@ _mesa_GetQueryivARB(GLenum target, GLenum pname, GLint *params)
 }
 
 
-void GLAPIENTRY
+static void GLAPIENTRY
 _mesa_GetQueryObjectivARB(GLuint id, GLenum pname, GLint *params)
 {
    struct gl_query_object *q = NULL;
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
+   if (MESA_VERBOSE & VERBOSE_API)
+      _mesa_debug(ctx, "glGetQueryObjectiv(%u, %s)\n", id,
+                  _mesa_lookup_enum_by_nr(pname));
+
    if (id)
-      q = lookup_query_object(ctx, id);
+      q = _mesa_lookup_query_object(ctx, id);
 
    if (!q || q->Active) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
@@ -346,23 +408,26 @@ _mesa_GetQueryObjectivARB(GLuint id, GLenum pname, GLint *params)
 
    switch (pname) {
       case GL_QUERY_RESULT_ARB:
-         while (!q->Ready) {
-            /* Wait for the query to finish! */
-            /* If using software rendering, the result will always be ready
-             * by time we get here.  Otherwise, we must be using hardware!
-             */
-            ASSERT(ctx->Driver.EndQuery);
-         }
+         if (!q->Ready)
+            ctx->Driver.WaitQuery(ctx, q);
          /* if result is too large for returned type, clamp to max value */
-         if (q->Result > 0x7fffffff) {
-            *params = 0x7fffffff;
-         }
-         else {
-            *params = q->Result;
+         if (q->Target == GL_ANY_SAMPLES_PASSED) {
+            if (q->Result)
+               *params = GL_TRUE;
+            else
+               *params = GL_FALSE;
+         } else {
+            if (q->Result > 0x7fffffff) {
+               *params = 0x7fffffff;
+            }
+            else {
+               *params = (GLint)q->Result;
+            }
          }
          break;
       case GL_QUERY_RESULT_AVAILABLE_ARB:
-         /* XXX revisit when we have a hardware implementation! */
+        if (!q->Ready)
+           ctx->Driver.CheckQuery( ctx, q );
          *params = q->Ready;
          break;
       default:
@@ -372,15 +437,19 @@ _mesa_GetQueryObjectivARB(GLuint id, GLenum pname, GLint *params)
 }
 
 
-void GLAPIENTRY
+static void GLAPIENTRY
 _mesa_GetQueryObjectuivARB(GLuint id, GLenum pname, GLuint *params)
 {
    struct gl_query_object *q = NULL;
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
+   if (MESA_VERBOSE & VERBOSE_API)
+      _mesa_debug(ctx, "glGetQueryObjectuiv(%u, %s)\n", id,
+                  _mesa_lookup_enum_by_nr(pname));
+
    if (id)
-      q = lookup_query_object(ctx, id);
+      q = _mesa_lookup_query_object(ctx, id);
 
    if (!q || q->Active) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
@@ -390,23 +459,26 @@ _mesa_GetQueryObjectuivARB(GLuint id, GLenum pname, GLuint *params)
 
    switch (pname) {
       case GL_QUERY_RESULT_ARB:
-         while (!q->Ready) {
-            /* Wait for the query to finish! */
-            /* If using software rendering, the result will always be ready
-             * by time we get here.  Otherwise, we must be using hardware!
-             */
-            ASSERT(ctx->Driver.EndQuery);
-         }
+         if (!q->Ready)
+            ctx->Driver.WaitQuery(ctx, q);
          /* if result is too large for returned type, clamp to max value */
-         if (q->Result > 0xffffffff) {
-            *params = 0xffffffff;
-         }
-         else {
-            *params = q->Result;
+         if (q->Target == GL_ANY_SAMPLES_PASSED) {
+            if (q->Result)
+               *params = GL_TRUE;
+            else
+               *params = GL_FALSE;
+         } else {
+            if (q->Result > 0xffffffff) {
+               *params = 0xffffffff;
+            }
+            else {
+               *params = (GLuint)q->Result;
+            }
          }
          break;
       case GL_QUERY_RESULT_AVAILABLE_ARB:
-         /* XXX revisit when we have a hardware implementation! */
+        if (!q->Ready)
+           ctx->Driver.CheckQuery( ctx, q );
          *params = q->Ready;
          break;
       default:
@@ -416,20 +488,22 @@ _mesa_GetQueryObjectuivARB(GLuint id, GLenum pname, GLuint *params)
 }
 
 
-#if FEATURE_EXT_timer_query
-
 /**
  * New with GL_EXT_timer_query
  */
-void GLAPIENTRY
+static void GLAPIENTRY
 _mesa_GetQueryObjecti64vEXT(GLuint id, GLenum pname, GLint64EXT *params)
 {
    struct gl_query_object *q = NULL;
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
+   if (MESA_VERBOSE & VERBOSE_API)
+      _mesa_debug(ctx, "glGetQueryObjecti64v(%u, %s)\n", id,
+                  _mesa_lookup_enum_by_nr(pname));
+
    if (id)
-      q = lookup_query_object(ctx, id);
+      q = _mesa_lookup_query_object(ctx, id);
 
    if (!q || q->Active) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
@@ -439,17 +513,13 @@ _mesa_GetQueryObjecti64vEXT(GLuint id, GLenum pname, GLint64EXT *params)
 
    switch (pname) {
       case GL_QUERY_RESULT_ARB:
-         while (!q->Ready) {
-            /* Wait for the query to finish! */
-            /* If using software rendering, the result will always be ready
-             * by time we get here.  Otherwise, we must be using hardware!
-             */
-            ASSERT(ctx->Driver.EndQuery);
-         }
+         if (!q->Ready)
+            ctx->Driver.WaitQuery(ctx, q);
          *params = q->Result;
          break;
       case GL_QUERY_RESULT_AVAILABLE_ARB:
-         /* XXX revisit when we have a hardware implementation! */
+        if (!q->Ready)
+           ctx->Driver.CheckQuery( ctx, q );
          *params = q->Ready;
          break;
       default:
@@ -462,15 +532,19 @@ _mesa_GetQueryObjecti64vEXT(GLuint id, GLenum pname, GLint64EXT *params)
 /**
  * New with GL_EXT_timer_query
  */
-void GLAPIENTRY
+static void GLAPIENTRY
 _mesa_GetQueryObjectui64vEXT(GLuint id, GLenum pname, GLuint64EXT *params)
 {
    struct gl_query_object *q = NULL;
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
+   if (MESA_VERBOSE & VERBOSE_API)
+      _mesa_debug(ctx, "glGetQueryObjectui64v(%u, %s)\n", id,
+                  _mesa_lookup_enum_by_nr(pname));
+
    if (id)
-      q = lookup_query_object(ctx, id);
+      q = _mesa_lookup_query_object(ctx, id);
 
    if (!q || q->Active) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
@@ -480,17 +554,13 @@ _mesa_GetQueryObjectui64vEXT(GLuint id, GLenum pname, GLuint64EXT *params)
 
    switch (pname) {
       case GL_QUERY_RESULT_ARB:
-         while (!q->Ready) {
-            /* Wait for the query to finish! */
-            /* If using software rendering, the result will always be ready
-             * by time we get here.  Otherwise, we must be using hardware!
-             */
-            ASSERT(ctx->Driver.EndQuery);
-         }
+         if (!q->Ready)
+            ctx->Driver.WaitQuery(ctx, q);
          *params = q->Result;
          break;
       case GL_QUERY_RESULT_AVAILABLE_ARB:
-         /* XXX revisit when we have a hardware implementation! */
+        if (!q->Ready)
+           ctx->Driver.CheckQuery( ctx, q );
          *params = q->Ready;
          break;
       default:
@@ -499,19 +569,35 @@ _mesa_GetQueryObjectui64vEXT(GLuint id, GLenum pname, GLuint64EXT *params)
    }
 }
 
-#endif /* FEATURE_EXT_timer_query */
+
+void
+_mesa_init_queryobj_dispatch(struct _glapi_table *disp)
+{
+   SET_GenQueriesARB(disp, _mesa_GenQueriesARB);
+   SET_DeleteQueriesARB(disp, _mesa_DeleteQueriesARB);
+   SET_IsQueryARB(disp, _mesa_IsQueryARB);
+   SET_BeginQueryARB(disp, _mesa_BeginQueryARB);
+   SET_EndQueryARB(disp, _mesa_EndQueryARB);
+   SET_GetQueryivARB(disp, _mesa_GetQueryivARB);
+   SET_GetQueryObjectivARB(disp, _mesa_GetQueryObjectivARB);
+   SET_GetQueryObjectuivARB(disp, _mesa_GetQueryObjectuivARB);
+
+   SET_GetQueryObjecti64vEXT(disp, _mesa_GetQueryObjecti64vEXT);
+   SET_GetQueryObjectui64vEXT(disp, _mesa_GetQueryObjectui64vEXT);
+}
+
+
+#endif /* FEATURE_queryobj */
 
 
 /**
  * Allocate/init the context state related to query objects.
  */
 void
-_mesa_init_query(GLcontext *ctx)
+_mesa_init_queryobj(struct gl_context *ctx)
 {
-#if FEATURE_ARB_occlusion_query
    ctx->Query.QueryObjects = _mesa_NewHashTable();
    ctx->Query.CurrentOcclusionObject = NULL;
-#endif
 }
 
 
@@ -522,8 +608,8 @@ static void
 delete_queryobj_cb(GLuint id, void *data, void *userData)
 {
    struct gl_query_object *q= (struct gl_query_object *) data;
-   (void) userData;
-   delete_query_object(q);
+   struct gl_context *ctx = (struct gl_context *)userData;
+   ctx->Driver.DeleteQuery(ctx, q);
 }
 
 
@@ -531,8 +617,8 @@ delete_queryobj_cb(GLuint id, void *data, void *userData)
  * Free the context state related to query objects.
  */
 void
-_mesa_free_query_data(GLcontext *ctx)
+_mesa_free_queryobj_data(struct gl_context *ctx)
 {
-   _mesa_HashDeleteAll(ctx->Query.QueryObjects, delete_queryobj_cb, NULL);
+   _mesa_HashDeleteAll(ctx->Query.QueryObjects, delete_queryobj_cb, ctx);
    _mesa_DeleteHashTable(ctx->Query.QueryObjects);
 }