mesa: add KHR_no_error support for glStencilFunc()
[mesa.git] / src / mesa / main / stencil.c
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
5 *
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:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26 /**
27 * \file stencil.c
28 * Stencil operations.
29 *
30 * Note: There's some conflict between GL_EXT_stencil_two_side and
31 * OpenGL 2.0's two-sided stencil feature.
32 *
33 * With GL_EXT_stencil_two_side, calling glStencilOp/Func/Mask() only the
34 * front OR back face state (as set by glActiveStencilFaceEXT) is set.
35 *
36 * But with OpenGL 2.0, calling glStencilOp/Func/Mask() sets BOTH the
37 * front AND back state.
38 *
39 * Also, note that GL_ATI_separate_stencil is different as well:
40 * glStencilFuncSeparateATI(GLenum frontfunc, GLenum backfunc, ...) vs.
41 * glStencilFuncSeparate(GLenum face, GLenum func, ...).
42 *
43 * This problem is solved by keeping three sets of stencil state:
44 * state[0] = GL_FRONT state.
45 * state[1] = OpenGL 2.0 / GL_ATI_separate_stencil GL_BACK state.
46 * state[2] = GL_EXT_stencil_two_side GL_BACK state.
47 */
48
49
50 #include "glheader.h"
51 #include "imports.h"
52 #include "context.h"
53 #include "macros.h"
54 #include "stencil.h"
55 #include "mtypes.h"
56
57
58 static GLboolean
59 validate_stencil_op(struct gl_context *ctx, GLenum op)
60 {
61 switch (op) {
62 case GL_KEEP:
63 case GL_ZERO:
64 case GL_REPLACE:
65 case GL_INCR:
66 case GL_DECR:
67 case GL_INVERT:
68 case GL_INCR_WRAP:
69 case GL_DECR_WRAP:
70 return GL_TRUE;
71 default:
72 return GL_FALSE;
73 }
74 }
75
76
77 static GLboolean
78 validate_stencil_func(struct gl_context *ctx, GLenum func)
79 {
80 switch (func) {
81 case GL_NEVER:
82 case GL_LESS:
83 case GL_LEQUAL:
84 case GL_GREATER:
85 case GL_GEQUAL:
86 case GL_EQUAL:
87 case GL_NOTEQUAL:
88 case GL_ALWAYS:
89 return GL_TRUE;
90 default:
91 return GL_FALSE;
92 }
93 }
94
95
96 /**
97 * Set the clear value for the stencil buffer.
98 *
99 * \param s clear value.
100 *
101 * \sa glClearStencil().
102 *
103 * Updates gl_stencil_attrib::Clear. On change
104 * flushes the vertices and notifies the driver via
105 * the dd_function_table::ClearStencil callback.
106 */
107 void GLAPIENTRY
108 _mesa_ClearStencil( GLint s )
109 {
110 GET_CURRENT_CONTEXT(ctx);
111
112 if (MESA_VERBOSE & VERBOSE_API)
113 _mesa_debug(ctx, "glClearStencil(%d)\n", s);
114
115 ctx->Stencil.Clear = (GLuint) s;
116 }
117
118
119 /**
120 * Set the function and reference value for stencil testing.
121 *
122 * \param frontfunc front test function.
123 * \param backfunc back test function.
124 * \param ref front and back reference value.
125 * \param mask front and back bitmask.
126 *
127 * \sa glStencilFunc().
128 *
129 * Verifies the parameters and updates the respective values in
130 * __struct gl_contextRec::Stencil. On change flushes the vertices and notifies
131 * the driver via the dd_function_table::StencilFunc callback.
132 */
133 void GLAPIENTRY
134 _mesa_StencilFuncSeparateATI( GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask )
135 {
136 GET_CURRENT_CONTEXT(ctx);
137
138 if (MESA_VERBOSE & VERBOSE_API)
139 _mesa_debug(ctx, "glStencilFuncSeparateATI()\n");
140
141 if (!validate_stencil_func(ctx, frontfunc)) {
142 _mesa_error(ctx, GL_INVALID_ENUM,
143 "glStencilFuncSeparateATI(frontfunc)");
144 return;
145 }
146 if (!validate_stencil_func(ctx, backfunc)) {
147 _mesa_error(ctx, GL_INVALID_ENUM,
148 "glStencilFuncSeparateATI(backfunc)");
149 return;
150 }
151
152 /* set both front and back state */
153 if (ctx->Stencil.Function[0] == frontfunc &&
154 ctx->Stencil.Function[1] == backfunc &&
155 ctx->Stencil.ValueMask[0] == mask &&
156 ctx->Stencil.ValueMask[1] == mask &&
157 ctx->Stencil.Ref[0] == ref &&
158 ctx->Stencil.Ref[1] == ref)
159 return;
160 FLUSH_VERTICES(ctx, _NEW_STENCIL);
161 ctx->Stencil.Function[0] = frontfunc;
162 ctx->Stencil.Function[1] = backfunc;
163 ctx->Stencil.Ref[0] = ctx->Stencil.Ref[1] = ref;
164 ctx->Stencil.ValueMask[0] = ctx->Stencil.ValueMask[1] = mask;
165 if (ctx->Driver.StencilFuncSeparate) {
166 ctx->Driver.StencilFuncSeparate(ctx, GL_FRONT,
167 frontfunc, ref, mask);
168 ctx->Driver.StencilFuncSeparate(ctx, GL_BACK,
169 backfunc, ref, mask);
170 }
171 }
172
173
174 /**
175 * Set the function and reference value for stencil testing.
176 *
177 * \param func test function.
178 * \param ref reference value.
179 * \param mask bitmask.
180 *
181 * \sa glStencilFunc().
182 *
183 * Verifies the parameters and updates the respective values in
184 * __struct gl_contextRec::Stencil. On change flushes the vertices and notifies
185 * the driver via the dd_function_table::StencilFunc callback.
186 */
187 static void
188 stencil_func(struct gl_context *ctx, GLenum func, GLint ref, GLuint mask)
189 {
190 const GLint face = ctx->Stencil.ActiveFace;
191
192 if (face != 0) {
193 if (ctx->Stencil.Function[face] == func &&
194 ctx->Stencil.ValueMask[face] == mask &&
195 ctx->Stencil.Ref[face] == ref)
196 return;
197 FLUSH_VERTICES(ctx, _NEW_STENCIL);
198 ctx->Stencil.Function[face] = func;
199 ctx->Stencil.Ref[face] = ref;
200 ctx->Stencil.ValueMask[face] = mask;
201
202 /* Only propagate the change to the driver if EXT_stencil_two_side
203 * is enabled.
204 */
205 if (ctx->Driver.StencilFuncSeparate && ctx->Stencil.TestTwoSide) {
206 ctx->Driver.StencilFuncSeparate(ctx, GL_BACK, func, ref, mask);
207 }
208 }
209 else {
210 /* set both front and back state */
211 if (ctx->Stencil.Function[0] == func &&
212 ctx->Stencil.Function[1] == func &&
213 ctx->Stencil.ValueMask[0] == mask &&
214 ctx->Stencil.ValueMask[1] == mask &&
215 ctx->Stencil.Ref[0] == ref &&
216 ctx->Stencil.Ref[1] == ref)
217 return;
218 FLUSH_VERTICES(ctx, _NEW_STENCIL);
219 ctx->Stencil.Function[0] = ctx->Stencil.Function[1] = func;
220 ctx->Stencil.Ref[0] = ctx->Stencil.Ref[1] = ref;
221 ctx->Stencil.ValueMask[0] = ctx->Stencil.ValueMask[1] = mask;
222 if (ctx->Driver.StencilFuncSeparate) {
223 ctx->Driver.StencilFuncSeparate(ctx,
224 ((ctx->Stencil.TestTwoSide)
225 ? GL_FRONT : GL_FRONT_AND_BACK),
226 func, ref, mask);
227 }
228 }
229 }
230
231
232 void GLAPIENTRY
233 _mesa_StencilFunc_no_error(GLenum func, GLint ref, GLuint mask)
234 {
235 GET_CURRENT_CONTEXT(ctx);
236 stencil_func(ctx, func, ref, mask);
237 }
238
239
240 void GLAPIENTRY
241 _mesa_StencilFunc(GLenum func, GLint ref, GLuint mask)
242 {
243 GET_CURRENT_CONTEXT(ctx);
244
245 if (MESA_VERBOSE & VERBOSE_API)
246 _mesa_debug(ctx, "glStencilFunc()\n");
247
248 if (!validate_stencil_func(ctx, func)) {
249 _mesa_error(ctx, GL_INVALID_ENUM, "glStencilFunc(func)");
250 return;
251 }
252
253 stencil_func(ctx, func, ref, mask);
254 }
255
256
257 /**
258 * Set the stencil writing mask.
259 *
260 * \param mask bit-mask to enable/disable writing of individual bits in the
261 * stencil planes.
262 *
263 * \sa glStencilMask().
264 *
265 * Updates gl_stencil_attrib::WriteMask. On change flushes the vertices and
266 * notifies the driver via the dd_function_table::StencilMask callback.
267 */
268 void GLAPIENTRY
269 _mesa_StencilMask( GLuint mask )
270 {
271 GET_CURRENT_CONTEXT(ctx);
272 const GLint face = ctx->Stencil.ActiveFace;
273
274 if (MESA_VERBOSE & VERBOSE_API)
275 _mesa_debug(ctx, "glStencilMask()\n");
276
277 if (face != 0) {
278 /* Only modify the EXT_stencil_two_side back-face state.
279 */
280 if (ctx->Stencil.WriteMask[face] == mask)
281 return;
282 FLUSH_VERTICES(ctx, _NEW_STENCIL);
283 ctx->Stencil.WriteMask[face] = mask;
284
285 /* Only propagate the change to the driver if EXT_stencil_two_side
286 * is enabled.
287 */
288 if (ctx->Driver.StencilMaskSeparate && ctx->Stencil.TestTwoSide) {
289 ctx->Driver.StencilMaskSeparate(ctx, GL_BACK, mask);
290 }
291 }
292 else {
293 /* set both front and back state */
294 if (ctx->Stencil.WriteMask[0] == mask &&
295 ctx->Stencil.WriteMask[1] == mask)
296 return;
297 FLUSH_VERTICES(ctx, _NEW_STENCIL);
298 ctx->Stencil.WriteMask[0] = ctx->Stencil.WriteMask[1] = mask;
299 if (ctx->Driver.StencilMaskSeparate) {
300 ctx->Driver.StencilMaskSeparate(ctx,
301 ((ctx->Stencil.TestTwoSide)
302 ? GL_FRONT : GL_FRONT_AND_BACK),
303 mask);
304 }
305 }
306 }
307
308
309 /**
310 * Set the stencil test actions.
311 *
312 * \param fail action to take when stencil test fails.
313 * \param zfail action to take when stencil test passes, but depth test fails.
314 * \param zpass action to take when stencil test passes and the depth test
315 * passes (or depth testing is not enabled).
316 *
317 * \sa glStencilOp().
318 *
319 * Verifies the parameters and updates the respective fields in
320 * __struct gl_contextRec::Stencil. On change flushes the vertices and notifies
321 * the driver via the dd_function_table::StencilOp callback.
322 */
323 void GLAPIENTRY
324 _mesa_StencilOp(GLenum fail, GLenum zfail, GLenum zpass)
325 {
326 GET_CURRENT_CONTEXT(ctx);
327 const GLint face = ctx->Stencil.ActiveFace;
328
329 if (MESA_VERBOSE & VERBOSE_API)
330 _mesa_debug(ctx, "glStencilOp()\n");
331
332 if (!validate_stencil_op(ctx, fail)) {
333 _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOp(sfail)");
334 return;
335 }
336 if (!validate_stencil_op(ctx, zfail)) {
337 _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOp(zfail)");
338 return;
339 }
340 if (!validate_stencil_op(ctx, zpass)) {
341 _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOp(zpass)");
342 return;
343 }
344
345 if (face != 0) {
346 /* only set active face state */
347 if (ctx->Stencil.ZFailFunc[face] == zfail &&
348 ctx->Stencil.ZPassFunc[face] == zpass &&
349 ctx->Stencil.FailFunc[face] == fail)
350 return;
351 FLUSH_VERTICES(ctx, _NEW_STENCIL);
352 ctx->Stencil.ZFailFunc[face] = zfail;
353 ctx->Stencil.ZPassFunc[face] = zpass;
354 ctx->Stencil.FailFunc[face] = fail;
355
356 /* Only propagate the change to the driver if EXT_stencil_two_side
357 * is enabled.
358 */
359 if (ctx->Driver.StencilOpSeparate && ctx->Stencil.TestTwoSide) {
360 ctx->Driver.StencilOpSeparate(ctx, GL_BACK, fail, zfail, zpass);
361 }
362 }
363 else {
364 /* set both front and back state */
365 if (ctx->Stencil.ZFailFunc[0] == zfail &&
366 ctx->Stencil.ZFailFunc[1] == zfail &&
367 ctx->Stencil.ZPassFunc[0] == zpass &&
368 ctx->Stencil.ZPassFunc[1] == zpass &&
369 ctx->Stencil.FailFunc[0] == fail &&
370 ctx->Stencil.FailFunc[1] == fail)
371 return;
372 FLUSH_VERTICES(ctx, _NEW_STENCIL);
373 ctx->Stencil.ZFailFunc[0] = ctx->Stencil.ZFailFunc[1] = zfail;
374 ctx->Stencil.ZPassFunc[0] = ctx->Stencil.ZPassFunc[1] = zpass;
375 ctx->Stencil.FailFunc[0] = ctx->Stencil.FailFunc[1] = fail;
376 if (ctx->Driver.StencilOpSeparate) {
377 ctx->Driver.StencilOpSeparate(ctx,
378 ((ctx->Stencil.TestTwoSide)
379 ? GL_FRONT : GL_FRONT_AND_BACK),
380 fail, zfail, zpass);
381 }
382 }
383 }
384
385
386
387 /* GL_EXT_stencil_two_side */
388 void GLAPIENTRY
389 _mesa_ActiveStencilFaceEXT(GLenum face)
390 {
391 GET_CURRENT_CONTEXT(ctx);
392
393 if (MESA_VERBOSE & VERBOSE_API)
394 _mesa_debug(ctx, "glActiveStencilFaceEXT()\n");
395
396 if (!ctx->Extensions.EXT_stencil_two_side) {
397 _mesa_error(ctx, GL_INVALID_OPERATION, "glActiveStencilFaceEXT");
398 return;
399 }
400
401 if (face == GL_FRONT || face == GL_BACK) {
402 ctx->Stencil.ActiveFace = (face == GL_FRONT) ? 0 : 2;
403 }
404 else {
405 _mesa_error(ctx, GL_INVALID_ENUM, "glActiveStencilFaceEXT(face)");
406 }
407 }
408
409
410 static void
411 stencil_op_separate(struct gl_context *ctx, GLenum face, GLenum sfail,
412 GLenum zfail, GLenum zpass)
413 {
414 GLboolean set = GL_FALSE;
415
416 if (face != GL_BACK) {
417 /* set front */
418 if (ctx->Stencil.ZFailFunc[0] != zfail ||
419 ctx->Stencil.ZPassFunc[0] != zpass ||
420 ctx->Stencil.FailFunc[0] != sfail){
421 FLUSH_VERTICES(ctx, _NEW_STENCIL);
422 ctx->Stencil.ZFailFunc[0] = zfail;
423 ctx->Stencil.ZPassFunc[0] = zpass;
424 ctx->Stencil.FailFunc[0] = sfail;
425 set = GL_TRUE;
426 }
427 }
428
429 if (face != GL_FRONT) {
430 /* set back */
431 if (ctx->Stencil.ZFailFunc[1] != zfail ||
432 ctx->Stencil.ZPassFunc[1] != zpass ||
433 ctx->Stencil.FailFunc[1] != sfail) {
434 FLUSH_VERTICES(ctx, _NEW_STENCIL);
435 ctx->Stencil.ZFailFunc[1] = zfail;
436 ctx->Stencil.ZPassFunc[1] = zpass;
437 ctx->Stencil.FailFunc[1] = sfail;
438 set = GL_TRUE;
439 }
440 }
441
442 if (set && ctx->Driver.StencilOpSeparate) {
443 ctx->Driver.StencilOpSeparate(ctx, face, sfail, zfail, zpass);
444 }
445 }
446
447
448 void GLAPIENTRY
449 _mesa_StencilOpSeparate_no_error(GLenum face, GLenum sfail, GLenum zfail,
450 GLenum zpass)
451 {
452 GET_CURRENT_CONTEXT(ctx);
453 stencil_op_separate(ctx, face, sfail, zfail, zpass);
454 }
455
456
457 void GLAPIENTRY
458 _mesa_StencilOpSeparate(GLenum face, GLenum sfail, GLenum zfail, GLenum zpass)
459 {
460 GET_CURRENT_CONTEXT(ctx);
461
462 if (MESA_VERBOSE & VERBOSE_API)
463 _mesa_debug(ctx, "glStencilOpSeparate()\n");
464
465 if (!validate_stencil_op(ctx, sfail)) {
466 _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOpSeparate(sfail)");
467 return;
468 }
469
470 if (!validate_stencil_op(ctx, zfail)) {
471 _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOpSeparate(zfail)");
472 return;
473 }
474
475 if (!validate_stencil_op(ctx, zpass)) {
476 _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOpSeparate(zpass)");
477 return;
478 }
479
480 if (face != GL_FRONT && face != GL_BACK && face != GL_FRONT_AND_BACK) {
481 _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOpSeparate(face)");
482 return;
483 }
484
485 stencil_op_separate(ctx, face, sfail, zfail, zpass);
486 }
487
488
489 static void
490 stencil_func_separate(struct gl_context *ctx, GLenum face, GLenum func,
491 GLint ref, GLuint mask)
492 {
493 FLUSH_VERTICES(ctx, _NEW_STENCIL);
494
495 if (face != GL_BACK) {
496 /* set front */
497 ctx->Stencil.Function[0] = func;
498 ctx->Stencil.Ref[0] = ref;
499 ctx->Stencil.ValueMask[0] = mask;
500 }
501
502 if (face != GL_FRONT) {
503 /* set back */
504 ctx->Stencil.Function[1] = func;
505 ctx->Stencil.Ref[1] = ref;
506 ctx->Stencil.ValueMask[1] = mask;
507 }
508
509 if (ctx->Driver.StencilFuncSeparate) {
510 ctx->Driver.StencilFuncSeparate(ctx, face, func, ref, mask);
511 }
512 }
513
514
515 /* OpenGL 2.0 */
516 void GLAPIENTRY
517 _mesa_StencilFuncSeparate_no_error(GLenum face, GLenum func, GLint ref,
518 GLuint mask)
519 {
520 GET_CURRENT_CONTEXT(ctx);
521 stencil_func_separate(ctx, face, func, ref, mask);
522 }
523
524
525 void GLAPIENTRY
526 _mesa_StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
527 {
528 GET_CURRENT_CONTEXT(ctx);
529
530 if (MESA_VERBOSE & VERBOSE_API)
531 _mesa_debug(ctx, "glStencilFuncSeparate()\n");
532
533 if (face != GL_FRONT && face != GL_BACK && face != GL_FRONT_AND_BACK) {
534 _mesa_error(ctx, GL_INVALID_ENUM, "glStencilFuncSeparate(face)");
535 return;
536 }
537
538 if (!validate_stencil_func(ctx, func)) {
539 _mesa_error(ctx, GL_INVALID_ENUM, "glStencilFuncSeparate(func)");
540 return;
541 }
542
543 stencil_func_separate(ctx, face, func, ref, mask);
544 }
545
546
547 static void
548 stencil_mask_separate(struct gl_context *ctx, GLenum face, GLuint mask)
549 {
550 FLUSH_VERTICES(ctx, _NEW_STENCIL);
551
552 if (face != GL_BACK) {
553 ctx->Stencil.WriteMask[0] = mask;
554 }
555
556 if (face != GL_FRONT) {
557 ctx->Stencil.WriteMask[1] = mask;
558 }
559
560 if (ctx->Driver.StencilMaskSeparate) {
561 ctx->Driver.StencilMaskSeparate(ctx, face, mask);
562 }
563 }
564
565
566 /* OpenGL 2.0 */
567 void GLAPIENTRY
568 _mesa_StencilMaskSeparate_no_error(GLenum face, GLuint mask)
569 {
570 GET_CURRENT_CONTEXT(ctx);
571 stencil_mask_separate(ctx, face, mask);
572 }
573
574
575 void GLAPIENTRY
576 _mesa_StencilMaskSeparate(GLenum face, GLuint mask)
577 {
578 GET_CURRENT_CONTEXT(ctx);
579
580 if (MESA_VERBOSE & VERBOSE_API)
581 _mesa_debug(ctx, "glStencilMaskSeparate()\n");
582
583 if (face != GL_FRONT && face != GL_BACK && face != GL_FRONT_AND_BACK) {
584 _mesa_error(ctx, GL_INVALID_ENUM, "glStencilaMaskSeparate(face)");
585 return;
586 }
587
588 stencil_mask_separate(ctx, face, mask);
589 }
590
591
592 /**
593 * Update derived stencil state.
594 */
595 void
596 _mesa_update_stencil(struct gl_context *ctx)
597 {
598 const GLint face = ctx->Stencil._BackFace;
599
600 ctx->Stencil._Enabled = (ctx->Stencil.Enabled &&
601 ctx->DrawBuffer->Visual.stencilBits > 0);
602
603 ctx->Stencil._TestTwoSide =
604 ctx->Stencil._Enabled &&
605 (ctx->Stencil.Function[0] != ctx->Stencil.Function[face] ||
606 ctx->Stencil.FailFunc[0] != ctx->Stencil.FailFunc[face] ||
607 ctx->Stencil.ZPassFunc[0] != ctx->Stencil.ZPassFunc[face] ||
608 ctx->Stencil.ZFailFunc[0] != ctx->Stencil.ZFailFunc[face] ||
609 ctx->Stencil.Ref[0] != ctx->Stencil.Ref[face] ||
610 ctx->Stencil.ValueMask[0] != ctx->Stencil.ValueMask[face] ||
611 ctx->Stencil.WriteMask[0] != ctx->Stencil.WriteMask[face]);
612
613 ctx->Stencil._WriteEnabled =
614 ctx->Stencil._Enabled &&
615 (ctx->Stencil.WriteMask[0] != 0 ||
616 (ctx->Stencil._TestTwoSide && ctx->Stencil.WriteMask[face] != 0));
617 }
618
619
620 /**
621 * Initialize the context stipple state.
622 *
623 * \param ctx GL context.
624 *
625 * Initializes __struct gl_contextRec::Stencil attribute group.
626 */
627 void
628 _mesa_init_stencil(struct gl_context *ctx)
629 {
630 ctx->Stencil.Enabled = GL_FALSE;
631 ctx->Stencil.TestTwoSide = GL_FALSE;
632 ctx->Stencil.ActiveFace = 0; /* 0 = GL_FRONT, 2 = GL_BACK */
633 ctx->Stencil.Function[0] = GL_ALWAYS;
634 ctx->Stencil.Function[1] = GL_ALWAYS;
635 ctx->Stencil.Function[2] = GL_ALWAYS;
636 ctx->Stencil.FailFunc[0] = GL_KEEP;
637 ctx->Stencil.FailFunc[1] = GL_KEEP;
638 ctx->Stencil.FailFunc[2] = GL_KEEP;
639 ctx->Stencil.ZPassFunc[0] = GL_KEEP;
640 ctx->Stencil.ZPassFunc[1] = GL_KEEP;
641 ctx->Stencil.ZPassFunc[2] = GL_KEEP;
642 ctx->Stencil.ZFailFunc[0] = GL_KEEP;
643 ctx->Stencil.ZFailFunc[1] = GL_KEEP;
644 ctx->Stencil.ZFailFunc[2] = GL_KEEP;
645 ctx->Stencil.Ref[0] = 0;
646 ctx->Stencil.Ref[1] = 0;
647 ctx->Stencil.Ref[2] = 0;
648
649 /* 4.1.4 Stencil Test section of the GL-ES 3.0 specification says:
650 *
651 * "In the initial state, [...] the front and back stencil mask are both
652 * set to the value 2^s − 1, where s is greater than or equal to the
653 * number of bits in the deepest stencil buffer* supported by the GL
654 * implementation."
655 *
656 * Since the maximum supported precision for stencil buffers is 8 bits,
657 * mask values should be initialized to 2^8 - 1 = 0xFF.
658 */
659 ctx->Stencil.ValueMask[0] = 0xFF;
660 ctx->Stencil.ValueMask[1] = 0xFF;
661 ctx->Stencil.ValueMask[2] = 0xFF;
662 ctx->Stencil.WriteMask[0] = 0xFF;
663 ctx->Stencil.WriteMask[1] = 0xFF;
664 ctx->Stencil.WriteMask[2] = 0xFF;
665
666 ctx->Stencil.Clear = 0;
667 ctx->Stencil._BackFace = 1;
668 }