00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
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
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 }