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
:
83 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBeginConditionalRender(mode=%s)",
84 _mesa_lookup_enum_by_nr(mode
));
88 /* Section 2.14 (Conditional Rendering) of the OpenGL 3.0 spec says:
90 * "The error INVALID_OPERATION is generated if <id> is the name of a
91 * query object with a target other than SAMPLES_PASSED, or <id> is the
92 * name of a query currently in progress."
94 if ((q
->Target
!= GL_SAMPLES_PASSED
&&
95 q
->Target
!= GL_ANY_SAMPLES_PASSED
&&
96 q
->Target
!= GL_ANY_SAMPLES_PASSED_CONSERVATIVE
) || q
->Active
) {
97 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBeginConditionalRender()");
101 ctx
->Query
.CondRenderQuery
= q
;
102 ctx
->Query
.CondRenderMode
= mode
;
104 if (ctx
->Driver
.BeginConditionalRender
)
105 ctx
->Driver
.BeginConditionalRender(ctx
, q
, mode
);
110 _mesa_EndConditionalRender(void)
112 GET_CURRENT_CONTEXT(ctx
);
114 FLUSH_VERTICES(ctx
, 0x0);
116 if (!ctx
->Extensions
.NV_conditional_render
|| !ctx
->Query
.CondRenderQuery
) {
117 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glEndConditionalRender()");
121 if (ctx
->Driver
.EndConditionalRender
)
122 ctx
->Driver
.EndConditionalRender(ctx
, ctx
->Query
.CondRenderQuery
);
124 ctx
->Query
.CondRenderQuery
= NULL
;
125 ctx
->Query
.CondRenderMode
= GL_NONE
;
130 * This function is called by software rendering commands (all point,
131 * line triangle drawing, glClear, glDrawPixels, glCopyPixels, and
132 * glBitmap, glBlitFramebuffer) to determine if subsequent drawing
134 * executed or discarded depending on the current conditional
135 * rendering state. Ideally, this check would be implemented by the
136 * GPU when doing hardware rendering. XXX should this function be
137 * called via a new driver hook?
139 * \return GL_TRUE if we should render, GL_FALSE if we should discard
142 _mesa_check_conditional_render(struct gl_context
*ctx
)
144 struct gl_query_object
*q
= ctx
->Query
.CondRenderQuery
;
147 /* no query in progress - draw normally */
151 switch (ctx
->Query
.CondRenderMode
) {
152 case GL_QUERY_BY_REGION_WAIT
:
156 ctx
->Driver
.WaitQuery(ctx
, q
);
158 return q
->Result
> 0;
159 case GL_QUERY_BY_REGION_NO_WAIT
:
161 case GL_QUERY_NO_WAIT
:
163 ctx
->Driver
.CheckQuery(ctx
, q
);
164 return q
->Ready
? (q
->Result
> 0) : GL_TRUE
;
166 _mesa_problem(ctx
, "Bad cond render mode %s in "
167 " _mesa_check_conditional_render()",
168 _mesa_lookup_enum_by_nr(ctx
->Query
.CondRenderMode
));