mesa: remove outdated version lines in comments
[mesa.git] / src / mesa / main / condrender.c
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
24 */
25
26 /**
27 * \file condrender.c
28 * Conditional rendering functions
29 *
30 * \author Brian Paul
31 */
32
33 #include "glheader.h"
34 #include "condrender.h"
35 #include "enums.h"
36 #include "mtypes.h"
37 #include "queryobj.h"
38
39
40 void GLAPIENTRY
41 _mesa_BeginConditionalRender(GLuint queryId, GLenum mode)
42 {
43 struct gl_query_object *q;
44 GET_CURRENT_CONTEXT(ctx);
45
46 if (!ctx->Extensions.NV_conditional_render || ctx->Query.CondRenderQuery ||
47 queryId == 0) {
48 _mesa_error(ctx, GL_INVALID_OPERATION, "glBeginConditionalRender()");
49 return;
50 }
51
52 ASSERT(ctx->Query.CondRenderMode == GL_NONE);
53
54 switch (mode) {
55 case GL_QUERY_WAIT:
56 case GL_QUERY_NO_WAIT:
57 case GL_QUERY_BY_REGION_WAIT:
58 case GL_QUERY_BY_REGION_NO_WAIT:
59 /* OK */
60 break;
61 default:
62 _mesa_error(ctx, GL_INVALID_ENUM, "glBeginConditionalRender(mode=%s)",
63 _mesa_lookup_enum_by_nr(mode));
64 return;
65 }
66
67 q = _mesa_lookup_query_object(ctx, queryId);
68 if (!q) {
69 _mesa_error(ctx, GL_INVALID_VALUE,
70 "glBeginConditionalRender(bad queryId=%u)", queryId);
71 return;
72 }
73 ASSERT(q->Id == queryId);
74
75 if (q->Target != GL_SAMPLES_PASSED || q->Active) {
76 _mesa_error(ctx, GL_INVALID_OPERATION, "glBeginConditionalRender()");
77 return;
78 }
79
80 ctx->Query.CondRenderQuery = q;
81 ctx->Query.CondRenderMode = mode;
82
83 if (ctx->Driver.BeginConditionalRender)
84 ctx->Driver.BeginConditionalRender(ctx, q, mode);
85 }
86
87
88 void APIENTRY
89 _mesa_EndConditionalRender(void)
90 {
91 GET_CURRENT_CONTEXT(ctx);
92
93 FLUSH_VERTICES(ctx, 0x0);
94
95 if (!ctx->Extensions.NV_conditional_render || !ctx->Query.CondRenderQuery) {
96 _mesa_error(ctx, GL_INVALID_OPERATION, "glEndConditionalRender()");
97 return;
98 }
99
100 if (ctx->Driver.EndConditionalRender)
101 ctx->Driver.EndConditionalRender(ctx, ctx->Query.CondRenderQuery);
102
103 ctx->Query.CondRenderQuery = NULL;
104 ctx->Query.CondRenderMode = GL_NONE;
105 }
106
107
108 /**
109 * This function is called by software rendering commands (all point,
110 * line triangle drawing, glClear, glDrawPixels, glCopyPixels, and
111 * glBitmap, glBlitFramebuffer) to determine if subsequent drawing
112 * commands should be
113 * executed or discarded depending on the current conditional
114 * rendering state. Ideally, this check would be implemented by the
115 * GPU when doing hardware rendering. XXX should this function be
116 * called via a new driver hook?
117 *
118 * \return GL_TRUE if we should render, GL_FALSE if we should discard
119 */
120 GLboolean
121 _mesa_check_conditional_render(struct gl_context *ctx)
122 {
123 struct gl_query_object *q = ctx->Query.CondRenderQuery;
124
125 if (!q) {
126 /* no query in progress - draw normally */
127 return GL_TRUE;
128 }
129
130 switch (ctx->Query.CondRenderMode) {
131 case GL_QUERY_BY_REGION_WAIT:
132 /* fall-through */
133 case GL_QUERY_WAIT:
134 if (!q->Ready) {
135 ctx->Driver.WaitQuery(ctx, q);
136 }
137 return q->Result > 0;
138 case GL_QUERY_BY_REGION_NO_WAIT:
139 /* fall-through */
140 case GL_QUERY_NO_WAIT:
141 if (!q->Ready)
142 ctx->Driver.CheckQuery(ctx, q);
143 return q->Ready ? (q->Result > 0) : GL_TRUE;
144 default:
145 _mesa_problem(ctx, "Bad cond render mode %s in "
146 " _mesa_check_conditional_render()",
147 _mesa_lookup_enum_by_nr(ctx->Query.CondRenderMode));
148 return GL_TRUE;
149 }
150 }