/*
* Mesa 3-D graphics library
- * Version: 6.3
+ * Version: 6.5
*
- * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2005 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"),
}
+#if ENABLE_EXT_timer_query
+
+/*
+ * The GL_EXT_timer_query extension is not enabled for the XServer
+ * indirect renderer. Not sure about how/if wrapping of gettimeofday()
+ * is done, etc.
+ */
+
+struct xmesa_query_object
+{
+ struct gl_query_object Base;
+ struct timeval StartTime;
+};
+
+
+static struct gl_query_object *
+xmesa_new_query_object(GLcontext *ctx, GLuint id)
+{
+ struct xmesa_query_object *q = CALLOC_STRUCT(xmesa_query_object);
+ if (q) {
+ q->Base.Id = id;
+ q->Base.Ready = GL_TRUE;
+ }
+ return &q->Base;
+}
+
+
+static void
+xmesa_begin_query(GLcontext *ctx, GLenum target, struct gl_query_object *q)
+{
+ if (target == GL_TIME_ELAPSED_EXT) {
+ struct xmesa_query_object *xq = (struct xmesa_query_object *) q;
+ (void) gettimeofday(&xq->StartTime, NULL);
+ }
+}
+
+
+/**
+ * Return the difference between the two given times in microseconds.
+ */
+static unsigned int
+time_diff(const struct timeval *t0, const struct timeval *t1)
+{
+ time_t seconds0 = t0->tv_sec & 0xff; /* 0 .. 255 seconds */
+ time_t seconds1 = t1->tv_sec & 0xff; /* 0 .. 255 seconds */
+ suseconds_t useconds0 = seconds0 * 1000000 + t0->tv_usec;
+ suseconds_t useconds1 = seconds1 * 1000000 + t1->tv_usec;
+ return useconds1 - useconds0;
+}
+
+
+static void
+xmesa_end_query(GLcontext *ctx, GLenum target, struct gl_query_object *q)
+{
+ if (target == GL_TIME_ELAPSED_EXT) {
+ struct xmesa_query_object *xq = (struct xmesa_query_object *) q;
+ struct timeval endTime;
+ unsigned int dt;
+ (void) gettimeofday(&endTime, NULL);
+ dt = time_diff(&xq->StartTime, &endTime);
+ /* clamp if we'd overflow a 32-bit unsigned int */
+ if (dt >= 0xffffffffU / 1000U)
+ q->Result = 0xffffffffU;
+ else
+ q->Result = dt * 1000; /* result is in nanoseconds! */
+ }
+ q->Ready = GL_TRUE;
+}
+
+#endif /* ENABLE_timer_query */
+
+
/**
* Initialize the device driver function table with the functions
* we implement in this driver.
}
#endif
driver->TestProxyTexImage = test_proxy_teximage;
-#if SWTC
+#if ENABLE_EXT_texure_compression_s3tc
driver->ChooseTextureFormat = choose_tex_format;
#else
(void) choose_tex_format;
#endif
+
+#if ENABLE_EXT_timer_query
+ driver->NewQueryObject = xmesa_new_query_object;
+ driver->BeginQuery = xmesa_begin_query;
+ driver->EndQuery = xmesa_end_query;
+#endif
}
*/
-/*
- * Functions to implement the GL_ARB_occlusion_query extension.
- */
-
-
#include "glheader.h"
#include "context.h"
#include "hash.h"
/**
- * Allocate a new occlusion query object.
- * \param target - must be GL_SAMPLES_PASSED_ARB at this time
+ * Allocate a new query object. This is a fallback routine called via
+ * ctx->Driver.NewQueryObject().
+ * \param target - GL_SAMPLES_PASSED_ARB or GL_TIME_ELAPSED_EXT or 0.
+ * \param ctx - rendering context
* \param id - the object's ID
* \return pointer to new query_object object or NULL if out of memory.
*/
-static struct gl_query_object *
-new_query_object(GLenum target, GLuint id)
+struct gl_query_object *
+_mesa_new_query_object(GLcontext *ctx, GLuint id)
{
struct gl_query_object *q = MALLOC_STRUCT(gl_query_object);
if (q) {
- q->Target = target;
q->Id = id;
q->Result = 0;
q->Active = GL_FALSE;
void GLAPIENTRY
_mesa_GenQueriesARB(GLsizei n, GLuint *ids)
{
- GET_CURRENT_CONTEXT(ctx);
GLuint first;
+ GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END(ctx);
if (n < 0) {
}
/* No query objects can be active at this time! */
- if (ctx->Query.CurrentOcclusionObject) {
+ if (ctx->Query.CurrentOcclusionObject ||
+ ctx->Query.CurrentTimerObject) {
_mesa_error(ctx, GL_INVALID_OPERATION, "glGenQueriesARB");
return;
}
if (first) {
GLsizei i;
for (i = 0; i < n; i++) {
- struct gl_query_object *q = new_query_object(GL_SAMPLES_PASSED_ARB,
- first + i);
+ struct gl_query_object *q
+ = ctx->Driver.NewQueryObject(ctx, first + i);
if (!q) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glGenQueriesARB");
return;
void GLAPIENTRY
_mesa_DeleteQueriesARB(GLsizei n, const GLuint *ids)
{
- GET_CURRENT_CONTEXT(ctx);
GLint i;
+ GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END(ctx);
if (n < 0) {
}
/* No query objects can be active at this time! */
- if (ctx->Query.CurrentOcclusionObject) {
+ if (ctx->Query.CurrentOcclusionObject ||
+ ctx->Query.CurrentTimerObject) {
_mesa_error(ctx, GL_INVALID_OPERATION, "glDeleteQueriesARB");
return;
}
void GLAPIENTRY
_mesa_BeginQueryARB(GLenum target, GLuint id)
{
- GET_CURRENT_CONTEXT(ctx);
struct gl_query_object *q;
+ GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END(ctx);
FLUSH_VERTICES(ctx, _NEW_DEPTH);
- if (target != GL_SAMPLES_PASSED_ARB) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glBeginQueryARB(target)");
- return;
+ 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;
+ 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;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glBeginQueryARB(target)");
+ return;
}
if (id == 0) {
return;
}
- if (ctx->Query.CurrentOcclusionObject) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glBeginQueryARB(target)");
- return;
- }
-
q = lookup_query_object(ctx, id);
if (!q) {
/* create new object */
- q = new_query_object(target, id);
+ q = ctx->Driver.NewQueryObject(ctx, id);
if (!q) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glBeginQueryARB");
return;
}
else {
/* pre-existing object */
- if (q->Target != target) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glBeginQueryARB(target mismatch)");
- return;
- }
if (q->Active) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"glBeginQueryARB(query already active)");
q->Active = GL_TRUE;
q->Result = 0;
q->Ready = GL_FALSE;
- ctx->Query.CurrentOcclusionObject = q;
+
+ if (target == GL_SAMPLES_PASSED_ARB) {
+ ctx->Query.CurrentOcclusionObject = q;
+ }
+ else if (target == GL_TIME_ELAPSED_EXT) {
+ ctx->Query.CurrentTimerObject = q;
+ }
if (ctx->Driver.BeginQuery) {
- ctx->Driver.BeginQuery(ctx, q);
+ ctx->Driver.BeginQuery(ctx, target, q);
}
}
void GLAPIENTRY
_mesa_EndQueryARB(GLenum target)
{
- GET_CURRENT_CONTEXT(ctx);
struct gl_query_object *q;
+ GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END(ctx);
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;
+ 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;
default:
_mesa_error(ctx, GL_INVALID_ENUM, "glEndQueryARB(target)");
return;
q->Active = GL_FALSE;
if (ctx->Driver.EndQuery) {
- ctx->Driver.EndQuery(ctx, q);
+ ctx->Driver.EndQuery(ctx, target, q);
}
else {
+ /* if we're using software rendering/querying */
q->Ready = GL_TRUE;
}
}
void GLAPIENTRY
_mesa_GetQueryivARB(GLenum target, GLenum pname, GLint *params)
{
- GET_CURRENT_CONTEXT(ctx);
struct gl_query_object *q;
+ 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;
+ 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;
default:
_mesa_error(ctx, GL_INVALID_ENUM, "glGetQueryivARB(target)");
return;
void GLAPIENTRY
_mesa_GetQueryObjectivARB(GLuint id, GLenum pname, GLint *params)
{
- GET_CURRENT_CONTEXT(ctx);
struct gl_query_object *q = NULL;
+ GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END(ctx);
if (id)
void GLAPIENTRY
_mesa_GetQueryObjectuivARB(GLuint id, GLenum pname, GLuint *params)
{
- GET_CURRENT_CONTEXT(ctx);
struct gl_query_object *q = NULL;
+ GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END(ctx);
if (id)
/**
- * Allocate/init the context state related to occlusion query objects.
+ * Allocate/init the context state related to query objects.
*/
void
-_mesa_init_occlude(GLcontext *ctx)
+_mesa_init_query(GLcontext *ctx)
{
#if FEATURE_ARB_occlusion_query
ctx->Query.QueryObjects = _mesa_NewHashTable();
/**
- * Free the context state related to occlusion query objects.
+ * Free the context state related to query objects.
*/
void
-_mesa_free_occlude_data(GLcontext *ctx)
+_mesa_free_query_data(GLcontext *ctx)
{
while (1) {
GLuint id = _mesa_HashFirstEntry(ctx->Query.QueryObjects);