612ad38dcc1472ea2862b008fffed0e919ad56df
[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 static void
324 stencil_op(struct gl_context *ctx, GLenum fail, GLenum zfail, GLenum zpass)
325 {
326 const GLint face = ctx->Stencil.ActiveFace;
327
328 if (face != 0) {
329 /* only set active face state */
330 if (ctx->Stencil.ZFailFunc[face] == zfail &&
331 ctx->Stencil.ZPassFunc[face] == zpass &&
332 ctx->Stencil.FailFunc[face] == fail)
333 return;
334 FLUSH_VERTICES(ctx, _NEW_STENCIL);
335 ctx->Stencil.ZFailFunc[face] = zfail;
336 ctx->Stencil.ZPassFunc[face] = zpass;
337 ctx->Stencil.FailFunc[face] = fail;
338
339 /* Only propagate the change to the driver if EXT_stencil_two_side
340 * is enabled.
341 */
342 if (ctx->Driver.StencilOpSeparate && ctx->Stencil.TestTwoSide) {
343 ctx->Driver.StencilOpSeparate(ctx, GL_BACK, fail, zfail, zpass);
344 }
345 }
346 else {
347 /* set both front and back state */
348 if (ctx->Stencil.ZFailFunc[0] == zfail &&
349 ctx->Stencil.ZFailFunc[1] == zfail &&
350 ctx->Stencil.ZPassFunc[0] == zpass &&
351 ctx->Stencil.ZPassFunc[1] == zpass &&
352 ctx->Stencil.FailFunc[0] == fail &&
353 ctx->Stencil.FailFunc[1] == fail)
354 return;
355 FLUSH_VERTICES(ctx, _NEW_STENCIL);
356 ctx->Stencil.ZFailFunc[0] = ctx->Stencil.ZFailFunc[1] = zfail;
357 ctx->Stencil.ZPassFunc[0] = ctx->Stencil.ZPassFunc[1] = zpass;
358 ctx->Stencil.FailFunc[0] = ctx->Stencil.FailFunc[1] = fail;
359 if (ctx->Driver.StencilOpSeparate) {
360 ctx->Driver.StencilOpSeparate(ctx,
361 ((ctx->Stencil.TestTwoSide)
362 ? GL_FRONT : GL_FRONT_AND_BACK),
363 fail, zfail, zpass);
364 }
365 }
366 }
367
368
369 void GLAPIENTRY
370 _mesa_StencilOp_no_error(GLenum fail, GLenum zfail, GLenum zpass)
371 {
372 GET_CURRENT_CONTEXT(ctx);
373 stencil_op(ctx, fail, zfail, zpass);
374 }
375
376
377 void GLAPIENTRY
378 _mesa_StencilOp(GLenum fail, GLenum zfail, GLenum zpass)
379 {
380 GET_CURRENT_CONTEXT(ctx);
381
382 if (MESA_VERBOSE & VERBOSE_API)
383 _mesa_debug(ctx, "glStencilOp()\n");
384
385 if (!validate_stencil_op(ctx, fail)) {
386 _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOp(sfail)");
387 return;
388 }
389
390 if (!validate_stencil_op(ctx, zfail)) {
391 _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOp(zfail)");
392 return;
393 }
394
395 if (!validate_stencil_op(ctx, zpass)) {
396 _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOp(zpass)");
397 return;
398 }
399
400 stencil_op(ctx, fail, zfail, zpass);
401 }
402
403
404 /* GL_EXT_stencil_two_side */
405 void GLAPIENTRY
406 _mesa_ActiveStencilFaceEXT(GLenum face)
407 {
408 GET_CURRENT_CONTEXT(ctx);
409
410 if (MESA_VERBOSE & VERBOSE_API)
411 _mesa_debug(ctx, "glActiveStencilFaceEXT()\n");
412
413 if (!ctx->Extensions.EXT_stencil_two_side) {
414 _mesa_error(ctx, GL_INVALID_OPERATION, "glActiveStencilFaceEXT");
415 return;
416 }
417
418 if (face == GL_FRONT || face == GL_BACK) {
419 ctx->Stencil.ActiveFace = (face == GL_FRONT) ? 0 : 2;
420 }
421 else {
422 _mesa_error(ctx, GL_INVALID_ENUM, "glActiveStencilFaceEXT(face)");
423 }
424 }
425
426
427 static void
428 stencil_op_separate(struct gl_context *ctx, GLenum face, GLenum sfail,
429 GLenum zfail, GLenum zpass)
430 {
431 GLboolean set = GL_FALSE;
432
433 if (face != GL_BACK) {
434 /* set front */
435 if (ctx->Stencil.ZFailFunc[0] != zfail ||
436 ctx->Stencil.ZPassFunc[0] != zpass ||
437 ctx->Stencil.FailFunc[0] != sfail){
438 FLUSH_VERTICES(ctx, _NEW_STENCIL);
439 ctx->Stencil.ZFailFunc[0] = zfail;
440 ctx->Stencil.ZPassFunc[0] = zpass;
441 ctx->Stencil.FailFunc[0] = sfail;
442 set = GL_TRUE;
443 }
444 }
445
446 if (face != GL_FRONT) {
447 /* set back */
448 if (ctx->Stencil.ZFailFunc[1] != zfail ||
449 ctx->Stencil.ZPassFunc[1] != zpass ||
450 ctx->Stencil.FailFunc[1] != sfail) {
451 FLUSH_VERTICES(ctx, _NEW_STENCIL);
452 ctx->Stencil.ZFailFunc[1] = zfail;
453 ctx->Stencil.ZPassFunc[1] = zpass;
454 ctx->Stencil.FailFunc[1] = sfail;
455 set = GL_TRUE;
456 }
457 }
458
459 if (set && ctx->Driver.StencilOpSeparate) {
460 ctx->Driver.StencilOpSeparate(ctx, face, sfail, zfail, zpass);
461 }
462 }
463
464
465 void GLAPIENTRY
466 _mesa_StencilOpSeparate_no_error(GLenum face, GLenum sfail, GLenum zfail,
467 GLenum zpass)
468 {
469 GET_CURRENT_CONTEXT(ctx);
470 stencil_op_separate(ctx, face, sfail, zfail, zpass);
471 }
472
473
474 void GLAPIENTRY
475 _mesa_StencilOpSeparate(GLenum face, GLenum sfail, GLenum zfail, GLenum zpass)
476 {
477 GET_CURRENT_CONTEXT(ctx);
478
479 if (MESA_VERBOSE & VERBOSE_API)
480 _mesa_debug(ctx, "glStencilOpSeparate()\n");
481
482 if (!validate_stencil_op(ctx, sfail)) {
483 _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOpSeparate(sfail)");
484 return;
485 }
486
487 if (!validate_stencil_op(ctx, zfail)) {
488 _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOpSeparate(zfail)");
489 return;
490 }
491
492 if (!validate_stencil_op(ctx, zpass)) {
493 _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOpSeparate(zpass)");
494 return;
495 }
496
497 if (face != GL_FRONT && face != GL_BACK && face != GL_FRONT_AND_BACK) {
498 _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOpSeparate(face)");
499 return;
500 }
501
502 stencil_op_separate(ctx, face, sfail, zfail, zpass);
503 }
504
505
506 static void
507 stencil_func_separate(struct gl_context *ctx, GLenum face, GLenum func,
508 GLint ref, GLuint mask)
509 {
510 FLUSH_VERTICES(ctx, _NEW_STENCIL);
511
512 if (face != GL_BACK) {
513 /* set front */
514 ctx->Stencil.Function[0] = func;
515 ctx->Stencil.Ref[0] = ref;
516 ctx->Stencil.ValueMask[0] = mask;
517 }
518
519 if (face != GL_FRONT) {
520 /* set back */
521 ctx->Stencil.Function[1] = func;
522 ctx->Stencil.Ref[1] = ref;
523 ctx->Stencil.ValueMask[1] = mask;
524 }
525
526 if (ctx->Driver.StencilFuncSeparate) {
527 ctx->Driver.StencilFuncSeparate(ctx, face, func, ref, mask);
528 }
529 }
530
531
532 /* OpenGL 2.0 */
533 void GLAPIENTRY
534 _mesa_StencilFuncSeparate_no_error(GLenum face, GLenum func, GLint ref,
535 GLuint mask)
536 {
537 GET_CURRENT_CONTEXT(ctx);
538 stencil_func_separate(ctx, face, func, ref, mask);
539 }
540
541
542 void GLAPIENTRY
543 _mesa_StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
544 {
545 GET_CURRENT_CONTEXT(ctx);
546
547 if (MESA_VERBOSE & VERBOSE_API)
548 _mesa_debug(ctx, "glStencilFuncSeparate()\n");
549
550 if (face != GL_FRONT && face != GL_BACK && face != GL_FRONT_AND_BACK) {
551 _mesa_error(ctx, GL_INVALID_ENUM, "glStencilFuncSeparate(face)");
552 return;
553 }
554
555 if (!validate_stencil_func(ctx, func)) {
556 _mesa_error(ctx, GL_INVALID_ENUM, "glStencilFuncSeparate(func)");
557 return;
558 }
559
560 stencil_func_separate(ctx, face, func, ref, mask);
561 }
562
563
564 static void
565 stencil_mask_separate(struct gl_context *ctx, GLenum face, GLuint mask)
566 {
567 FLUSH_VERTICES(ctx, _NEW_STENCIL);
568
569 if (face != GL_BACK) {
570 ctx->Stencil.WriteMask[0] = mask;
571 }
572
573 if (face != GL_FRONT) {
574 ctx->Stencil.WriteMask[1] = mask;
575 }
576
577 if (ctx->Driver.StencilMaskSeparate) {
578 ctx->Driver.StencilMaskSeparate(ctx, face, mask);
579 }
580 }
581
582
583 /* OpenGL 2.0 */
584 void GLAPIENTRY
585 _mesa_StencilMaskSeparate_no_error(GLenum face, GLuint mask)
586 {
587 GET_CURRENT_CONTEXT(ctx);
588 stencil_mask_separate(ctx, face, mask);
589 }
590
591
592 void GLAPIENTRY
593 _mesa_StencilMaskSeparate(GLenum face, GLuint mask)
594 {
595 GET_CURRENT_CONTEXT(ctx);
596
597 if (MESA_VERBOSE & VERBOSE_API)
598 _mesa_debug(ctx, "glStencilMaskSeparate()\n");
599
600 if (face != GL_FRONT && face != GL_BACK && face != GL_FRONT_AND_BACK) {
601 _mesa_error(ctx, GL_INVALID_ENUM, "glStencilaMaskSeparate(face)");
602 return;
603 }
604
605 stencil_mask_separate(ctx, face, mask);
606 }
607
608
609 /**
610 * Initialize the context stipple state.
611 *
612 * \param ctx GL context.
613 *
614 * Initializes __struct gl_contextRec::Stencil attribute group.
615 */
616 void
617 _mesa_init_stencil(struct gl_context *ctx)
618 {
619 ctx->Stencil.Enabled = GL_FALSE;
620 ctx->Stencil.TestTwoSide = GL_FALSE;
621 ctx->Stencil.ActiveFace = 0; /* 0 = GL_FRONT, 2 = GL_BACK */
622 ctx->Stencil.Function[0] = GL_ALWAYS;
623 ctx->Stencil.Function[1] = GL_ALWAYS;
624 ctx->Stencil.Function[2] = GL_ALWAYS;
625 ctx->Stencil.FailFunc[0] = GL_KEEP;
626 ctx->Stencil.FailFunc[1] = GL_KEEP;
627 ctx->Stencil.FailFunc[2] = GL_KEEP;
628 ctx->Stencil.ZPassFunc[0] = GL_KEEP;
629 ctx->Stencil.ZPassFunc[1] = GL_KEEP;
630 ctx->Stencil.ZPassFunc[2] = GL_KEEP;
631 ctx->Stencil.ZFailFunc[0] = GL_KEEP;
632 ctx->Stencil.ZFailFunc[1] = GL_KEEP;
633 ctx->Stencil.ZFailFunc[2] = GL_KEEP;
634 ctx->Stencil.Ref[0] = 0;
635 ctx->Stencil.Ref[1] = 0;
636 ctx->Stencil.Ref[2] = 0;
637
638 /* 4.1.4 Stencil Test section of the GL-ES 3.0 specification says:
639 *
640 * "In the initial state, [...] the front and back stencil mask are both
641 * set to the value 2^s − 1, where s is greater than or equal to the
642 * number of bits in the deepest stencil buffer* supported by the GL
643 * implementation."
644 *
645 * Since the maximum supported precision for stencil buffers is 8 bits,
646 * mask values should be initialized to 2^8 - 1 = 0xFF.
647 */
648 ctx->Stencil.ValueMask[0] = 0xFF;
649 ctx->Stencil.ValueMask[1] = 0xFF;
650 ctx->Stencil.ValueMask[2] = 0xFF;
651 ctx->Stencil.WriteMask[0] = 0xFF;
652 ctx->Stencil.WriteMask[1] = 0xFF;
653 ctx->Stencil.WriteMask[2] = 0xFF;
654
655 ctx->Stencil.Clear = 0;
656 ctx->Stencil._BackFace = 1;
657 }