st_cb_queryobj.c

Go to the documentation of this file.
00001 /**************************************************************************
00002  * 
00003  * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
00004  * All Rights Reserved.
00005  * 
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  * 
00014  * The above copyright notice and this permission notice (including the
00015  * next paragraph) shall be included in all copies or substantial portions
00016  * of the Software.
00017  * 
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
00021  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
00022  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00023  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00024  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025  * 
00026  **************************************************************************/
00027 
00028 
00036 #include "main/imports.h"
00037 #include "main/context.h"
00038 #include "main/image.h"
00039 
00040 #include "pipe/p_context.h"
00041 #include "pipe/p_defines.h"
00042 #include "st_context.h"
00043 #include "st_cb_queryobj.h"
00044 #include "st_public.h"
00045 
00046 
00047 struct st_query_object
00048 {
00049    struct gl_query_object base;
00050    struct pipe_query *pq;
00051 };
00052 
00053 
00057 static struct st_query_object *
00058 st_query_object(struct gl_query_object *q)
00059 {
00060    return (struct st_query_object *) q;
00061 }
00062 
00063 
00064 static struct gl_query_object *
00065 st_NewQueryObject(GLcontext *ctx, GLuint id)
00066 {
00067    struct st_query_object *stq = CALLOC_STRUCT(st_query_object);
00068    if (stq) {
00069       stq->base.Id = id;
00070       stq->base.Ready = GL_TRUE;
00071       stq->pq = NULL;
00072       return &stq->base;
00073    }
00074    return NULL;
00075 }
00076 
00077 
00078 
00079 static void
00080 st_DeleteQuery(GLcontext *ctx, struct gl_query_object *q)
00081 {
00082    struct pipe_context *pipe = ctx->st->pipe;
00083    struct st_query_object *stq = st_query_object(q);
00084 
00085    if (stq->pq) {
00086       pipe->destroy_query(pipe, stq->pq);
00087       stq->pq = NULL;
00088    }
00089 
00090    FREE(stq);
00091 }
00092 
00093 
00094 static void
00095 st_BeginQuery(GLcontext *ctx, struct gl_query_object *q)
00096 {
00097    struct pipe_context *pipe = ctx->st->pipe;
00098    struct st_query_object *stq = st_query_object(q);
00099 
00100    switch (q->Target) {
00101    case GL_SAMPLES_PASSED_ARB:
00102       if (!stq->pq)
00103          stq->pq = pipe->create_query( pipe, PIPE_QUERY_OCCLUSION_COUNTER );
00104       break;
00105    default:
00106       assert(0);
00107       return;
00108    }
00109 
00110    pipe->begin_query(pipe, stq->pq);
00111 }
00112 
00113 
00114 static void
00115 st_EndQuery(GLcontext *ctx, struct gl_query_object *q)
00116 {
00117    struct pipe_context *pipe = ctx->st->pipe;
00118    struct st_query_object *stq = st_query_object(q);
00119 
00120    pipe->end_query(pipe, stq->pq);
00121 }
00122 
00123 
00124 static void
00125 st_WaitQuery(GLcontext *ctx, struct gl_query_object *q)
00126 {
00127    struct pipe_context *pipe = ctx->st->pipe;
00128    struct st_query_object *stq = st_query_object(q);
00129 
00130    /* this function should only be called if we don't have a ready result */
00131    assert(!stq->base.Ready);
00132 
00133    while (!stq->base.Ready &&
00134           !pipe->get_query_result(pipe, 
00135                                   stq->pq,
00136                                   TRUE,
00137                                   &q->Result))
00138    {
00139       /* nothing */
00140    }
00141                             
00142    q->Ready = GL_TRUE;
00143 }
00144 
00145 
00146 static void
00147 st_CheckQuery(GLcontext *ctx, struct gl_query_object *q)
00148 {
00149    struct pipe_context *pipe = ctx->st->pipe;
00150    struct st_query_object *stq = st_query_object(q);
00151 
00152    if (!q->Ready) {
00153       q->Ready = pipe->get_query_result(pipe, 
00154                                         stq->pq,
00155                                         FALSE,
00156                                         &q->Result);
00157    }
00158 }
00159 
00160 
00161 
00162 
00163 void st_init_query_functions(struct dd_function_table *functions)
00164 {
00165    functions->NewQueryObject = st_NewQueryObject;
00166    functions->DeleteQuery = st_DeleteQuery;
00167    functions->BeginQuery = st_BeginQuery;
00168    functions->EndQuery = st_EndQuery;
00169    functions->WaitQuery = st_WaitQuery;
00170    functions->CheckQuery = st_CheckQuery;
00171 }

Generated on Tue Sep 29 06:25:18 2009 for Gallium3D by  doxygen 1.5.4