mesa: Change "BRIAN PAUL" to "THE AUTHORS" in license text.
[mesa.git] / src / mesa / main / queryobj.c
index aa7c800d45b3c5027569240870c98f692515763e..1a0dda49dba7c93405cf6a4958d431fb4eb894ea 100644 (file)
@@ -17,7 +17,7 @@
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
@@ -29,7 +29,6 @@
 #include "hash.h"
 #include "imports.h"
 #include "queryobj.h"
-#include "mfeatures.h"
 #include "mtypes.h"
 #include "main/dispatch.h"
 
@@ -50,7 +49,20 @@ _mesa_new_query_object(struct gl_context *ctx, GLuint id)
       q->Id = id;
       q->Result = 0;
       q->Active = GL_FALSE;
-      q->Ready = GL_TRUE;   /* correct, see spec */
+
+      /* This is to satisfy the language of the specification: "In the initial
+       * state of a query object, the result is available" (OpenGL 3.1 §
+       * 2.13).
+       */
+      q->Ready = GL_TRUE;
+
+      /* OpenGL 3.1 § 2.13 says about GenQueries, "These names are marked as
+       * used, but no object is associated with them until the first time they
+       * are used by BeginQuery." Since our implementation actually does
+       * allocate an object at this point, use a flag to indicate that this
+       * object has not yet been bound so should not be considered a query.
+       */
+      q->EverBound = GL_FALSE;
    }
    return q;
 }
@@ -63,7 +75,7 @@ _mesa_new_query_object(struct gl_context *ctx, GLuint id)
 static void
 _mesa_begin_query(struct gl_context *ctx, struct gl_query_object *q)
 {
-   /* no-op */
+   ctx->NewState |= _NEW_DEPTH; /* for swrast */
 }
 
 
@@ -74,6 +86,7 @@ _mesa_begin_query(struct gl_context *ctx, struct gl_query_object *q)
 static void
 _mesa_end_query(struct gl_context *ctx, struct gl_query_object *q)
 {
+   ctx->NewState |= _NEW_DEPTH; /* for swrast */
    q->Ready = GL_TRUE;
 }
 
@@ -179,7 +192,6 @@ _mesa_GenQueries(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);
@@ -218,7 +230,6 @@ _mesa_DeleteQueries(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)
@@ -252,16 +263,22 @@ _mesa_DeleteQueries(GLsizei n, const GLuint *ids)
 GLboolean GLAPIENTRY
 _mesa_IsQuery(GLuint id)
 {
+   struct gl_query_object *q;
+
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
 
    if (MESA_VERBOSE & VERBOSE_API)
       _mesa_debug(ctx, "glIsQuery(%u)\n", id);
 
-   if (id && _mesa_lookup_query_object(ctx, id))
-      return GL_TRUE;
-   else
+   if (id == 0)
       return GL_FALSE;
+
+   q = _mesa_lookup_query_object(ctx, id);
+   if (q == NULL)
+      return GL_FALSE;
+
+   return q->EverBound;
 }
 
 static GLboolean
@@ -290,7 +307,6 @@ _mesa_BeginQueryIndexed(GLenum target, GLuint index, GLuint id)
 {
    struct gl_query_object *q, **bindpt;
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    if (MESA_VERBOSE & VERBOSE_API)
       _mesa_debug(ctx, "glBeginQueryIndexed(%s, %u, %u)\n",
@@ -299,7 +315,7 @@ _mesa_BeginQueryIndexed(GLenum target, GLuint index, GLuint id)
    if (!query_error_check_index(ctx, target, index))
       return;
 
-   FLUSH_VERTICES(ctx, _NEW_DEPTH);
+   FLUSH_VERTICES(ctx, 0);
 
    bindpt = get_query_binding_point(ctx, target);
    if (!bindpt) {
@@ -354,6 +370,7 @@ _mesa_BeginQueryIndexed(GLenum target, GLuint index, GLuint id)
    q->Active = GL_TRUE;
    q->Result = 0;
    q->Ready = GL_FALSE;
+   q->EverBound = GL_TRUE;
 
    /* XXX should probably refcount query objects */
    *bindpt = q;
@@ -367,7 +384,6 @@ _mesa_EndQueryIndexed(GLenum target, GLuint index)
 {
    struct gl_query_object *q, **bindpt;
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    if (MESA_VERBOSE & VERBOSE_API)
       _mesa_debug(ctx, "glEndQueryIndexed(%s, %u)\n",
@@ -376,7 +392,7 @@ _mesa_EndQueryIndexed(GLenum target, GLuint index)
    if (!query_error_check_index(ctx, target, index))
       return;
 
-   FLUSH_VERTICES(ctx, _NEW_DEPTH);
+   FLUSH_VERTICES(ctx, 0);
 
    bindpt = get_query_binding_point(ctx, target);
    if (!bindpt) {
@@ -425,7 +441,6 @@ _mesa_QueryCounter(GLuint id, GLenum target)
 {
    struct gl_query_object *q;
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    if (MESA_VERBOSE & VERBOSE_API)
       _mesa_debug(ctx, "glQueryCounter(%u, %s)\n", id,
@@ -471,9 +486,14 @@ _mesa_QueryCounter(GLuint id, GLenum target)
    q->Result = 0;
    q->Ready = GL_FALSE;
 
-   /* QueryCounter is implemented using EndQuery without BeginQuery
-    * in drivers. This is actually Direct3D and Gallium convention. */
-   ctx->Driver.EndQuery(ctx, q);
+   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);
+   }
 }
 
 
@@ -483,7 +503,6 @@ _mesa_GetQueryIndexediv(GLenum target, GLuint index, GLenum pname,
 {
    struct gl_query_object *q = NULL, **bindpt = NULL;
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    if (MESA_VERBOSE & VERBOSE_API)
       _mesa_debug(ctx, "glGetQueryIndexediv(%s, %u, %s)\n",
@@ -563,7 +582,6 @@ _mesa_GetQueryObjectiv(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,
@@ -615,7 +633,6 @@ _mesa_GetQueryObjectuiv(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,
@@ -670,7 +687,6 @@ _mesa_GetQueryObjecti64v(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,
@@ -711,7 +727,6 @@ _mesa_GetQueryObjectui64v(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,
@@ -743,33 +758,6 @@ _mesa_GetQueryObjectui64v(GLuint id, GLenum pname, GLuint64EXT *params)
    }
 }
 
-
-void
-_mesa_init_queryobj_dispatch(const struct gl_context *ctx,
-                             struct _glapi_table *disp)
-{
-   SET_GenQueries(disp, _mesa_GenQueries);
-   SET_DeleteQueries(disp, _mesa_DeleteQueries);
-   SET_IsQuery(disp, _mesa_IsQuery);
-   SET_BeginQuery(disp, _mesa_BeginQuery);
-   SET_EndQuery(disp, _mesa_EndQuery);
-   SET_GetQueryiv(disp, _mesa_GetQueryiv);
-   SET_GetQueryObjectuiv(disp, _mesa_GetQueryObjectuiv);
-
-   if (_mesa_is_desktop_gl(ctx)) {
-      SET_GetQueryObjectiv(disp, _mesa_GetQueryObjectiv);
-      SET_QueryCounter(disp, _mesa_QueryCounter);
-
-      SET_GetQueryObjecti64v(disp, _mesa_GetQueryObjecti64v);
-      SET_GetQueryObjectui64v(disp, _mesa_GetQueryObjectui64v);
-
-      SET_BeginQueryIndexed(disp, _mesa_BeginQueryIndexed);
-      SET_EndQueryIndexed(disp, _mesa_EndQueryIndexed);
-      SET_GetQueryIndexediv(disp, _mesa_GetQueryIndexediv);
-   }
-}
-
-
 /**
  * Allocate/init the context state related to query objects.
  */