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"
41 _mesa_BeginConditionalRender(GLuint queryId
, GLenum mode
)
43 struct gl_query_object
*q
= NULL
;
44 GET_CURRENT_CONTEXT(ctx
);
46 /* Section 2.14 (Conditional Rendering) of the OpenGL 3.0 spec says:
48 * "If BeginConditionalRender is called while conditional rendering is
49 * in progress, or if EndConditionalRender is called while conditional
50 * rendering is not in progress, the error INVALID_OPERATION is
53 if (!ctx
->Extensions
.NV_conditional_render
|| ctx
->Query
.CondRenderQuery
) {
54 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBeginConditionalRender()");
58 ASSERT(ctx
->Query
.CondRenderMode
== GL_NONE
);
60 /* Section 2.14 (Conditional Rendering) of the OpenGL 3.0 spec says:
62 * "The error INVALID_VALUE is generated if <id> is not the name of an
63 * existing query object query."
66 q
= _mesa_lookup_query_object(ctx
, queryId
);
69 _mesa_error(ctx
, GL_INVALID_VALUE
,
70 "glBeginConditionalRender(bad queryId=%u)", queryId
);
73 ASSERT(q
->Id
== queryId
);
77 case GL_QUERY_NO_WAIT
:
78 case GL_QUERY_BY_REGION_WAIT
:
79 case GL_QUERY_BY_REGION_NO_WAIT
:
81 case GL_QUERY_WAIT_INVERTED
:
82 case GL_QUERY_NO_WAIT_INVERTED
:
83 case GL_QUERY_BY_REGION_WAIT_INVERTED
:
84 case GL_QUERY_BY_REGION_NO_WAIT_INVERTED
:
85 if (ctx
->Extensions
.ARB_conditional_render_inverted
)
87 /* fallthrough - invalid */
89 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBeginConditionalRender(mode=%s)",
90 _mesa_lookup_enum_by_nr(mode
));
94 /* Section 2.14 (Conditional Rendering) of the OpenGL 3.0 spec says:
96 * "The error INVALID_OPERATION is generated if <id> is the name of a
97 * query object with a target other than SAMPLES_PASSED, or <id> is the
98 * name of a query currently in progress."
100 if ((q
->Target
!= GL_SAMPLES_PASSED
&&
101 q
->Target
!= GL_ANY_SAMPLES_PASSED
&&
102 q
->Target
!= GL_ANY_SAMPLES_PASSED_CONSERVATIVE
) || q
->Active
) {
103 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBeginConditionalRender()");
107 ctx
->Query
.CondRenderQuery
= q
;
108 ctx
->Query
.CondRenderMode
= mode
;
110 if (ctx
->Driver
.BeginConditionalRender
)
111 ctx
->Driver
.BeginConditionalRender(ctx
, q
, mode
);
116 _mesa_EndConditionalRender(void)
118 GET_CURRENT_CONTEXT(ctx
);
120 FLUSH_VERTICES(ctx
, 0x0);
122 if (!ctx
->Extensions
.NV_conditional_render
|| !ctx
->Query
.CondRenderQuery
) {
123 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glEndConditionalRender()");
127 if (ctx
->Driver
.EndConditionalRender
)
128 ctx
->Driver
.EndConditionalRender(ctx
, ctx
->Query
.CondRenderQuery
);
130 ctx
->Query
.CondRenderQuery
= NULL
;
131 ctx
->Query
.CondRenderMode
= GL_NONE
;
136 * This function is called by software rendering commands (all point,
137 * line triangle drawing, glClear, glDrawPixels, glCopyPixels, and
138 * glBitmap, glBlitFramebuffer) to determine if subsequent drawing
140 * executed or discarded depending on the current conditional
141 * rendering state. Ideally, this check would be implemented by the
142 * GPU when doing hardware rendering. XXX should this function be
143 * called via a new driver hook?
145 * \return GL_TRUE if we should render, GL_FALSE if we should discard
148 _mesa_check_conditional_render(struct gl_context
*ctx
)
150 struct gl_query_object
*q
= ctx
->Query
.CondRenderQuery
;
153 /* no query in progress - draw normally */
157 switch (ctx
->Query
.CondRenderMode
) {
158 case GL_QUERY_BY_REGION_WAIT
:
162 ctx
->Driver
.WaitQuery(ctx
, q
);
164 return q
->Result
> 0;
165 case GL_QUERY_BY_REGION_WAIT_INVERTED
:
167 case GL_QUERY_WAIT_INVERTED
:
169 ctx
->Driver
.WaitQuery(ctx
, q
);
171 return q
->Result
== 0;
172 case GL_QUERY_BY_REGION_NO_WAIT
:
174 case GL_QUERY_NO_WAIT
:
176 ctx
->Driver
.CheckQuery(ctx
, q
);
177 return q
->Ready
? (q
->Result
> 0) : GL_TRUE
;
178 case GL_QUERY_BY_REGION_NO_WAIT_INVERTED
:
180 case GL_QUERY_NO_WAIT_INVERTED
:
182 ctx
->Driver
.CheckQuery(ctx
, q
);
183 return q
->Ready
? (q
->Result
== 0) : GL_TRUE
;
185 _mesa_problem(ctx
, "Bad cond render mode %s in "
186 " _mesa_check_conditional_render()",
187 _mesa_lookup_enum_by_nr(ctx
->Query
.CondRenderMode
));