2 * Mesa 3-D graphics library
4 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
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:
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
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.
28 * Conditional rendering functions
34 #include "condrender.h"
40 static ALWAYS_INLINE
void
41 begin_conditional_render(struct gl_context
*ctx
, GLuint queryId
, GLenum mode
,
44 struct gl_query_object
*q
= NULL
;
46 assert(ctx
->Query
.CondRenderMode
== GL_NONE
);
49 q
= _mesa_lookup_query_object(ctx
, queryId
);
52 /* Section 2.14 (Conditional Rendering) of the OpenGL 3.0 spec says:
54 * "The error INVALID_VALUE is generated if <id> is not the name of an
55 * existing query object query."
58 _mesa_error(ctx
, GL_INVALID_VALUE
,
59 "glBeginConditionalRender(bad queryId=%u)", queryId
);
62 assert(q
->Id
== queryId
);
66 case GL_QUERY_NO_WAIT
:
67 case GL_QUERY_BY_REGION_WAIT
:
68 case GL_QUERY_BY_REGION_NO_WAIT
:
70 case GL_QUERY_WAIT_INVERTED
:
71 case GL_QUERY_NO_WAIT_INVERTED
:
72 case GL_QUERY_BY_REGION_WAIT_INVERTED
:
73 case GL_QUERY_BY_REGION_NO_WAIT_INVERTED
:
74 if (ctx
->Extensions
.ARB_conditional_render_inverted
)
76 /* fallthrough - invalid */
78 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBeginConditionalRender(mode=%s)",
79 _mesa_enum_to_string(mode
));
83 /* Section 2.14 (Conditional Rendering) of the OpenGL 3.0 spec says:
85 * "The error INVALID_OPERATION is generated if <id> is the name of a
86 * query object with a target other than SAMPLES_PASSED, or <id> is
87 * the name of a query currently in progress."
89 if ((q
->Target
!= GL_SAMPLES_PASSED
&&
90 q
->Target
!= GL_ANY_SAMPLES_PASSED
&&
91 q
->Target
!= GL_ANY_SAMPLES_PASSED_CONSERVATIVE
&&
92 q
->Target
!= GL_TRANSFORM_FEEDBACK_STREAM_OVERFLOW_ARB
&&
93 q
->Target
!= GL_TRANSFORM_FEEDBACK_OVERFLOW_ARB
) || q
->Active
) {
94 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBeginConditionalRender()");
99 ctx
->Query
.CondRenderQuery
= q
;
100 ctx
->Query
.CondRenderMode
= mode
;
102 if (ctx
->Driver
.BeginConditionalRender
)
103 ctx
->Driver
.BeginConditionalRender(ctx
, q
, mode
);
108 _mesa_BeginConditionalRender_no_error(GLuint queryId
, GLenum mode
)
110 GET_CURRENT_CONTEXT(ctx
);
111 begin_conditional_render(ctx
, queryId
, mode
, true);
116 _mesa_BeginConditionalRender(GLuint queryId
, GLenum mode
)
118 GET_CURRENT_CONTEXT(ctx
);
120 /* Section 2.14 (Conditional Rendering) of the OpenGL 3.0 spec says:
122 * "If BeginConditionalRender is called while conditional rendering is
123 * in progress, or if EndConditionalRender is called while conditional
124 * rendering is not in progress, the error INVALID_OPERATION is
127 if (!ctx
->Extensions
.NV_conditional_render
|| ctx
->Query
.CondRenderQuery
) {
128 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBeginConditionalRender()");
132 begin_conditional_render(ctx
, queryId
, mode
, false);
137 end_conditional_render(struct gl_context
*ctx
)
139 FLUSH_VERTICES(ctx
, 0x0);
141 if (ctx
->Driver
.EndConditionalRender
)
142 ctx
->Driver
.EndConditionalRender(ctx
, ctx
->Query
.CondRenderQuery
);
144 ctx
->Query
.CondRenderQuery
= NULL
;
145 ctx
->Query
.CondRenderMode
= GL_NONE
;
150 _mesa_EndConditionalRender_no_error(void)
152 GET_CURRENT_CONTEXT(ctx
);
153 end_conditional_render(ctx
);
158 _mesa_EndConditionalRender(void)
160 GET_CURRENT_CONTEXT(ctx
);
162 if (!ctx
->Extensions
.NV_conditional_render
|| !ctx
->Query
.CondRenderQuery
) {
163 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glEndConditionalRender()");
167 end_conditional_render(ctx
);
172 * This function is called by software rendering commands (all point,
173 * line triangle drawing, glClear, glDrawPixels, glCopyPixels, and
174 * glBitmap, glBlitFramebuffer) to determine if subsequent drawing
176 * executed or discarded depending on the current conditional
177 * rendering state. Ideally, this check would be implemented by the
178 * GPU when doing hardware rendering. XXX should this function be
179 * called via a new driver hook?
181 * \return GL_TRUE if we should render, GL_FALSE if we should discard
184 _mesa_check_conditional_render(struct gl_context
*ctx
)
186 struct gl_query_object
*q
= ctx
->Query
.CondRenderQuery
;
189 /* no query in progress - draw normally */
193 switch (ctx
->Query
.CondRenderMode
) {
194 case GL_QUERY_BY_REGION_WAIT
:
198 ctx
->Driver
.WaitQuery(ctx
, q
);
200 return q
->Result
> 0;
201 case GL_QUERY_BY_REGION_WAIT_INVERTED
:
203 case GL_QUERY_WAIT_INVERTED
:
205 ctx
->Driver
.WaitQuery(ctx
, q
);
207 return q
->Result
== 0;
208 case GL_QUERY_BY_REGION_NO_WAIT
:
210 case GL_QUERY_NO_WAIT
:
212 ctx
->Driver
.CheckQuery(ctx
, q
);
213 return q
->Ready
? (q
->Result
> 0) : GL_TRUE
;
214 case GL_QUERY_BY_REGION_NO_WAIT_INVERTED
:
216 case GL_QUERY_NO_WAIT_INVERTED
:
218 ctx
->Driver
.CheckQuery(ctx
, q
);
219 return q
->Ready
? (q
->Result
== 0) : GL_TRUE
;
221 _mesa_problem(ctx
, "Bad cond render mode %s in "
222 " _mesa_check_conditional_render()",
223 _mesa_enum_to_string(ctx
->Query
.CondRenderMode
));