2 * Mesa 3-D graphics library
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
29 * Conditional rendering functions
35 #include "condrender.h"
41 _mesa_BeginConditionalRender(GLuint queryId
, GLenum mode
)
43 struct gl_query_object
*q
;
44 GET_CURRENT_CONTEXT(ctx
);
46 if (!ctx
->Extensions
.NV_conditional_render
|| ctx
->Query
.CondRenderQuery
) {
47 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBeginConditionalRender()");
51 ASSERT(ctx
->Query
.CondRenderMode
== GL_NONE
);
55 case GL_QUERY_NO_WAIT
:
56 case GL_QUERY_BY_REGION_WAIT
:
57 case GL_QUERY_BY_REGION_NO_WAIT
:
61 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBeginConditionalRender(mode=%s)",
62 _mesa_lookup_enum_by_nr(mode
));
66 q
= _mesa_lookup_query_object(ctx
, queryId
);
68 _mesa_error(ctx
, GL_INVALID_VALUE
,
69 "glBeginConditionalRender(bad queryId=%u)", queryId
);
72 ASSERT(q
->Id
== queryId
);
74 if (q
->Target
!= GL_SAMPLES_PASSED
) {
75 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBeginConditionalRender()");
79 ctx
->Query
.CondRenderQuery
= q
;
80 ctx
->Query
.CondRenderMode
= mode
;
82 if (ctx
->Driver
.BeginConditionalRender
)
83 ctx
->Driver
.BeginConditionalRender(ctx
, q
, mode
);
88 _mesa_EndConditionalRender(void)
90 GET_CURRENT_CONTEXT(ctx
);
92 FLUSH_VERTICES(ctx
, 0x0);
94 if (!ctx
->Extensions
.NV_conditional_render
|| !ctx
->Query
.CondRenderQuery
) {
95 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glEndConditionalRender()");
99 if (ctx
->Driver
.EndConditionalRender
)
100 ctx
->Driver
.EndConditionalRender(ctx
, ctx
->Query
.CondRenderQuery
);
102 ctx
->Query
.CondRenderQuery
= NULL
;
103 ctx
->Query
.CondRenderMode
= GL_NONE
;
108 * This function is called by software rendering commands (all point,
109 * line triangle drawing, glClear, glDrawPixels, glCopyPixels, and
110 * glBitmap, glBlitFramebuffer) to determine if subsequent drawing
112 * executed or discarded depending on the current conditional
113 * rendering state. Ideally, this check would be implemented by the
114 * GPU when doing hardware rendering. XXX should this function be
115 * called via a new driver hook?
117 * \return GL_TRUE if we should render, GL_FALSE if we should discard
120 _mesa_check_conditional_render(GLcontext
*ctx
)
122 struct gl_query_object
*q
= ctx
->Query
.CondRenderQuery
;
125 /* no query in progress - draw normally */
129 switch (ctx
->Query
.CondRenderMode
) {
130 case GL_QUERY_BY_REGION_WAIT
:
134 ctx
->Driver
.WaitQuery(ctx
, q
);
136 return q
->Result
> 0;
137 case GL_QUERY_BY_REGION_NO_WAIT
:
139 case GL_QUERY_NO_WAIT
:
140 return q
->Ready
? (q
->Result
> 0) : GL_TRUE
;
142 _mesa_problem(ctx
, "Bad cond render mode %s in "
143 " _mesa_check_conditional_render()",
144 _mesa_lookup_enum_by_nr(ctx
->Query
.CondRenderMode
));