mesa: new _mesa_valid_to_render() function
[mesa.git] / src / mesa / main / queryobj.c
index 688d0fc7bcd25b79e3da0d9db10928f1b6cfb65e..a73c6e05081bb98d86eea68c5a3c24dd63fe5f9b 100644 (file)
@@ -38,7 +38,7 @@
  * \param id - the new object's ID
  * \return pointer to new query_object object or NULL if out of memory.
  */
-struct gl_query_object *
+static struct gl_query_object *
 _mesa_new_query_object(GLcontext *ctx, GLuint id)
 {
    struct gl_query_object *q = MALLOC_STRUCT(gl_query_object);
@@ -57,7 +57,7 @@ _mesa_new_query_object(GLcontext *ctx, GLuint id)
  * Begin a query.  Software driver fallback.
  * Called via ctx->Driver.BeginQuery().
  */
-void
+static void
 _mesa_begin_query(GLcontext *ctx, struct gl_query_object *q)
 {
    /* no-op */
@@ -68,7 +68,7 @@ _mesa_begin_query(GLcontext *ctx, struct gl_query_object *q)
  * End a query.  Software driver fallback.
  * Called via ctx->Driver.EndQuery().
  */
-void
+static void
 _mesa_end_query(GLcontext *ctx, struct gl_query_object *q)
 {
    q->Ready = GL_TRUE;
@@ -79,23 +79,36 @@ _mesa_end_query(GLcontext *ctx, struct gl_query_object *q)
  * Wait for query to complete.  Software driver fallback.
  * Called via ctx->Driver.WaitQuery().
  */
-void
+static void
 _mesa_wait_query(GLcontext *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.
+    * For real hardware, implement a proper WaitQuery() driver function,
+    * which may require issuing a flush.
     */
    assert(q->Ready);
 }
 
 
 /**
- * Delete an occlusion query object.
+ * Check if a query results are ready.  Software driver fallback.
+ * Called via ctx->Driver.CheckQuery().
+ */
+static void
+_mesa_check_query(GLcontext *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(GLcontext *ctx, struct gl_query_object *q)
 {
    _mesa_free(q);
 }
@@ -110,6 +123,18 @@ lookup_query_object(GLcontext *ctx, GLuint id)
 
 
 
+void
+_mesa_init_query_object_functions(struct dd_function_table *driver)
+{
+   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;
+}
+
+
 void GLAPIENTRY
 _mesa_GenQueriesARB(GLsizei n, GLuint *ids)
 {
@@ -171,7 +196,7 @@ _mesa_DeleteQueriesARB(GLsizei n, const GLuint *ids)
          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);
          }
       }
    }
@@ -382,10 +407,12 @@ _mesa_GetQueryObjectivARB(GLuint id, GLenum pname, GLint *params)
             *params = 0x7fffffff;
          }
          else {
-            *params = q->Result;
+            *params = (GLint)q->Result;
          }
          break;
       case GL_QUERY_RESULT_AVAILABLE_ARB:
+        if (!q->Ready)
+           ctx->Driver.CheckQuery( ctx, q );
          *params = q->Ready;
          break;
       default:
@@ -420,10 +447,12 @@ _mesa_GetQueryObjectuivARB(GLuint id, GLenum pname, GLuint *params)
             *params = 0xffffffff;
          }
          else {
-            *params = q->Result;
+            *params = (GLuint)q->Result;
          }
          break;
       case GL_QUERY_RESULT_AVAILABLE_ARB:
+        if (!q->Ready)
+           ctx->Driver.CheckQuery( ctx, q );
          *params = q->Ready;
          break;
       default:
@@ -461,6 +490,8 @@ _mesa_GetQueryObjecti64vEXT(GLuint id, GLenum pname, GLint64EXT *params)
          *params = q->Result;
          break;
       case GL_QUERY_RESULT_AVAILABLE_ARB:
+        if (!q->Ready)
+           ctx->Driver.CheckQuery( ctx, q );
          *params = q->Ready;
          break;
       default:
@@ -496,6 +527,8 @@ _mesa_GetQueryObjectui64vEXT(GLuint id, GLenum pname, GLuint64EXT *params)
          *params = q->Result;
          break;
       case GL_QUERY_RESULT_AVAILABLE_ARB:
+        if (!q->Ready)
+           ctx->Driver.CheckQuery( ctx, q );
          *params = q->Ready;
          break;
       default:
@@ -527,8 +560,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);
+   GLcontext *ctx = (GLcontext *)userData;
+   ctx->Driver.DeleteQuery(ctx, q);
 }
 
 
@@ -538,6 +571,6 @@ delete_queryobj_cb(GLuint id, void *data, void *userData)
 void
 _mesa_free_query_data(GLcontext *ctx)
 {
-   _mesa_HashDeleteAll(ctx->Query.QueryObjects, delete_queryobj_cb, NULL);
+   _mesa_HashDeleteAll(ctx->Query.QueryObjects, delete_queryobj_cb, ctx);
    _mesa_DeleteHashTable(ctx->Query.QueryObjects);
 }