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
;
44 GET_CURRENT_CONTEXT(ctx
);
46 if (!ctx
->Extensions
.NV_conditional_render
|| ctx
->Query
.CondRenderQuery
||
48 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBeginConditionalRender()");
52 ASSERT(ctx
->Query
.CondRenderMode
== GL_NONE
);
56 case GL_QUERY_NO_WAIT
:
57 case GL_QUERY_BY_REGION_WAIT
:
58 case GL_QUERY_BY_REGION_NO_WAIT
:
62 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBeginConditionalRender(mode=%s)",
63 _mesa_lookup_enum_by_nr(mode
));
67 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
);
75 if ((q
->Target
!= GL_SAMPLES_PASSED
&&
76 q
->Target
!= GL_ANY_SAMPLES_PASSED
&&
77 q
->Target
!= GL_ANY_SAMPLES_PASSED_CONSERVATIVE
) || q
->Active
) {
78 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBeginConditionalRender()");
82 ctx
->Query
.CondRenderQuery
= q
;
83 ctx
->Query
.CondRenderMode
= mode
;
85 if (ctx
->Driver
.BeginConditionalRender
)
86 ctx
->Driver
.BeginConditionalRender(ctx
, q
, mode
);
91 _mesa_EndConditionalRender(void)
93 GET_CURRENT_CONTEXT(ctx
);
95 FLUSH_VERTICES(ctx
, 0x0);
97 if (!ctx
->Extensions
.NV_conditional_render
|| !ctx
->Query
.CondRenderQuery
) {
98 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glEndConditionalRender()");
102 if (ctx
->Driver
.EndConditionalRender
)
103 ctx
->Driver
.EndConditionalRender(ctx
, ctx
->Query
.CondRenderQuery
);
105 ctx
->Query
.CondRenderQuery
= NULL
;
106 ctx
->Query
.CondRenderMode
= GL_NONE
;
111 * This function is called by software rendering commands (all point,
112 * line triangle drawing, glClear, glDrawPixels, glCopyPixels, and
113 * glBitmap, glBlitFramebuffer) to determine if subsequent drawing
115 * executed or discarded depending on the current conditional
116 * rendering state. Ideally, this check would be implemented by the
117 * GPU when doing hardware rendering. XXX should this function be
118 * called via a new driver hook?
120 * \return GL_TRUE if we should render, GL_FALSE if we should discard
123 _mesa_check_conditional_render(struct gl_context
*ctx
)
125 struct gl_query_object
*q
= ctx
->Query
.CondRenderQuery
;
128 /* no query in progress - draw normally */
132 switch (ctx
->Query
.CondRenderMode
) {
133 case GL_QUERY_BY_REGION_WAIT
:
137 ctx
->Driver
.WaitQuery(ctx
, q
);
139 return q
->Result
> 0;
140 case GL_QUERY_BY_REGION_NO_WAIT
:
142 case GL_QUERY_NO_WAIT
:
144 ctx
->Driver
.CheckQuery(ctx
, q
);
145 return q
->Ready
? (q
->Result
> 0) : GL_TRUE
;
147 _mesa_problem(ctx
, "Bad cond render mode %s in "
148 " _mesa_check_conditional_render()",
149 _mesa_lookup_enum_by_nr(ctx
->Query
.CondRenderMode
));