mesa: add stencil_func() helper
[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(GLenum func, GLint ref, GLuint mask)
234 {
235 GET_CURRENT_CONTEXT(ctx);
236
237 if (MESA_VERBOSE & VERBOSE_API)
238 _mesa_debug(ctx, "glStencilFunc()\n");
239
240 if (!validate_stencil_func(ctx, func)) {
241 _mesa_error(ctx, GL_INVALID_ENUM, "glStencilFunc(func)");
242 return;
243 }
244
245 stencil_func(ctx, func, ref, mask);
246 }
247
248
249 /**
250 * Set the stencil writing mask.
251 *
252 * \param mask bit-mask to enable/disable writing of individual bits in the
253 * stencil planes.
254 *
255 * \sa glStencilMask().
256 *
257 * Updates gl_stencil_attrib::WriteMask. On change flushes the vertices and
258 * notifies the driver via the dd_function_table::StencilMask callback.
259 */
260 void GLAPIENTRY
261 _mesa_StencilMask( GLuint mask )
262 {
263 GET_CURRENT_CONTEXT(ctx);
264 const GLint face = ctx->Stencil.ActiveFace;
265
266 if (MESA_VERBOSE & VERBOSE_API)
267 _mesa_debug(ctx, "glStencilMask()\n");
268
269 if (face != 0) {
270 /* Only modify the EXT_stencil_two_side back-face state.
271 */
272 if (ctx->Stencil.WriteMask[face] == mask)
273 return;
274 FLUSH_VERTICES(ctx, _NEW_STENCIL);
275 ctx->Stencil.WriteMask[face] = mask;
276
277 /* Only propagate the change to the driver if EXT_stencil_two_side
278 * is enabled.
279 */
280 if (ctx->Driver.StencilMaskSeparate && ctx->Stencil.TestTwoSide) {
281 ctx->Driver.StencilMaskSeparate(ctx, GL_BACK, mask);
282 }
283 }
284 else {
285 /* set both front and back state */
286 if (ctx->Stencil.WriteMask[0] == mask &&
287 ctx->Stencil.WriteMask[1] == mask)
288 return;
289 FLUSH_VERTICES(ctx, _NEW_STENCIL);
290 ctx->Stencil.WriteMask[0] = ctx->Stencil.WriteMask[1] = mask;
291 if (ctx->Driver.StencilMaskSeparate) {
292 ctx->Driver.StencilMaskSeparate(ctx,
293 ((ctx->Stencil.TestTwoSide)
294 ? GL_FRONT : GL_FRONT_AND_BACK),
295 mask);
296 }
297 }
298 }
299
300
301 /**
302 * Set the stencil test actions.
303 *
304 * \param fail action to take when stencil test fails.
305 * \param zfail action to take when stencil test passes, but depth test fails.
306 * \param zpass action to take when stencil test passes and the depth test
307 * passes (or depth testing is not enabled).
308 *
309 * \sa glStencilOp().
310 *
311 * Verifies the parameters and updates the respective fields in
312 * __struct gl_contextRec::Stencil. On change flushes the vertices and notifies
313 * the driver via the dd_function_table::StencilOp callback.
314 */
315 void GLAPIENTRY
316 _mesa_StencilOp(GLenum fail, GLenum zfail, GLenum zpass)
317 {
318 GET_CURRENT_CONTEXT(ctx);
319 const GLint face = ctx->Stencil.ActiveFace;
320
321 if (MESA_VERBOSE & VERBOSE_API)
322 _mesa_debug(ctx, "glStencilOp()\n");
323
324 if (!validate_stencil_op(ctx, fail)) {
325 _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOp(sfail)");
326 return;
327 }
328 if (!validate_stencil_op(ctx, zfail)) {
329 _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOp(zfail)");
330 return;
331 }
332 if (!validate_stencil_op(ctx, zpass)) {
333 _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOp(zpass)");
334 return;
335 }
336
337 if (face != 0) {
338 /* only set active face state */
339 if (ctx->Stencil.ZFailFunc[face] == zfail &&
340 ctx->Stencil.ZPassFunc[face] == zpass &&
341 ctx->Stencil.FailFunc[face] == fail)
342 return;
343 FLUSH_VERTICES(ctx, _NEW_STENCIL);
344 ctx->Stencil.ZFailFunc[face] = zfail;
345 ctx->Stencil.ZPassFunc[face] = zpass;
346 ctx->Stencil.FailFunc[face] = fail;
347
348 /* Only propagate the change to the driver if EXT_stencil_two_side
349 * is enabled.
350 */
351 if (ctx->Driver.StencilOpSeparate && ctx->Stencil.TestTwoSide) {
352 ctx->Driver.StencilOpSeparate(ctx, GL_BACK, fail, zfail, zpass);
353 }
354 }
355 else {
356 /* set both front and back state */
357 if (ctx->Stencil.ZFailFunc[0] == zfail &&
358 ctx->Stencil.ZFailFunc[1] == zfail &&
359 ctx->Stencil.ZPassFunc[0] == zpass &&
360 ctx->Stencil.ZPassFunc[1] == zpass &&
361 ctx->Stencil.FailFunc[0] == fail &&
362 ctx->Stencil.FailFunc[1] == fail)
363 return;
364 FLUSH_VERTICES(ctx, _NEW_STENCIL);
365 ctx->Stencil.ZFailFunc[0] = ctx->Stencil.ZFailFunc[1] = zfail;
366 ctx->Stencil.ZPassFunc[0] = ctx->Stencil.ZPassFunc[1] = zpass;
367 ctx->Stencil.FailFunc[0] = ctx->Stencil.FailFunc[1] = fail;
368 if (ctx->Driver.StencilOpSeparate) {
369 ctx->Driver.StencilOpSeparate(ctx,
370 ((ctx->Stencil.TestTwoSide)
371 ? GL_FRONT : GL_FRONT_AND_BACK),
372 fail, zfail, zpass);
373 }
374 }
375 }
376
377
378
379 /* GL_EXT_stencil_two_side */
380 void GLAPIENTRY
381 _mesa_ActiveStencilFaceEXT(GLenum face)
382 {
383 GET_CURRENT_CONTEXT(ctx);
384
385 if (MESA_VERBOSE & VERBOSE_API)
386 _mesa_debug(ctx, "glActiveStencilFaceEXT()\n");
387
388 if (!ctx->Extensions.EXT_stencil_two_side) {
389 _mesa_error(ctx, GL_INVALID_OPERATION, "glActiveStencilFaceEXT");
390 return;
391 }
392
393 if (face == GL_FRONT || face == GL_BACK) {
394 ctx->Stencil.ActiveFace = (face == GL_FRONT) ? 0 : 2;
395 }
396 else {
397 _mesa_error(ctx, GL_INVALID_ENUM, "glActiveStencilFaceEXT(face)");
398 }
399 }
400
401
402 static void
403 stencil_op_separate(struct gl_context *ctx, GLenum face, GLenum sfail,
404 GLenum zfail, GLenum zpass)
405 {
406 GLboolean set = GL_FALSE;
407
408 if (face != GL_BACK) {
409 /* set front */
410 if (ctx->Stencil.ZFailFunc[0] != zfail ||
411 ctx->Stencil.ZPassFunc[0] != zpass ||
412 ctx->Stencil.FailFunc[0] != sfail){
413 FLUSH_VERTICES(ctx, _NEW_STENCIL);
414 ctx->Stencil.ZFailFunc[0] = zfail;
415 ctx->Stencil.ZPassFunc[0] = zpass;
416 ctx->Stencil.FailFunc[0] = sfail;
417 set = GL_TRUE;
418 }
419 }
420
421 if (face != GL_FRONT) {
422 /* set back */
423 if (ctx->Stencil.ZFailFunc[1] != zfail ||
424 ctx->Stencil.ZPassFunc[1] != zpass ||
425 ctx->Stencil.FailFunc[1] != sfail) {
426 FLUSH_VERTICES(ctx, _NEW_STENCIL);
427 ctx->Stencil.ZFailFunc[1] = zfail;
428 ctx->Stencil.ZPassFunc[1] = zpass;
429 ctx->Stencil.FailFunc[1] = sfail;
430 set = GL_TRUE;
431 }
432 }
433
434 if (set && ctx->Driver.StencilOpSeparate) {
435 ctx->Driver.StencilOpSeparate(ctx, face, sfail, zfail, zpass);
436 }
437 }
438
439
440 void GLAPIENTRY
441 _mesa_StencilOpSeparate_no_error(GLenum face, GLenum sfail, GLenum zfail,
442 GLenum zpass)
443 {
444 GET_CURRENT_CONTEXT(ctx);
445 stencil_op_separate(ctx, face, sfail, zfail, zpass);
446 }
447
448
449 void GLAPIENTRY
450 _mesa_StencilOpSeparate(GLenum face, GLenum sfail, GLenum zfail, GLenum zpass)
451 {
452 GET_CURRENT_CONTEXT(ctx);
453
454 if (MESA_VERBOSE & VERBOSE_API)
455 _mesa_debug(ctx, "glStencilOpSeparate()\n");
456
457 if (!validate_stencil_op(ctx, sfail)) {
458 _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOpSeparate(sfail)");
459 return;
460 }
461
462 if (!validate_stencil_op(ctx, zfail)) {
463 _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOpSeparate(zfail)");
464 return;
465 }
466
467 if (!validate_stencil_op(ctx, zpass)) {
468 _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOpSeparate(zpass)");
469 return;
470 }
471
472 if (face != GL_FRONT && face != GL_BACK && face != GL_FRONT_AND_BACK) {
473 _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOpSeparate(face)");
474 return;
475 }
476
477 stencil_op_separate(ctx, face, sfail, zfail, zpass);
478 }
479
480
481 static void
482 stencil_func_separate(struct gl_context *ctx, GLenum face, GLenum func,
483 GLint ref, GLuint mask)
484 {
485 FLUSH_VERTICES(ctx, _NEW_STENCIL);
486
487 if (face != GL_BACK) {
488 /* set front */
489 ctx->Stencil.Function[0] = func;
490 ctx->Stencil.Ref[0] = ref;
491 ctx->Stencil.ValueMask[0] = mask;
492 }
493
494 if (face != GL_FRONT) {
495 /* set back */
496 ctx->Stencil.Function[1] = func;
497 ctx->Stencil.Ref[1] = ref;
498 ctx->Stencil.ValueMask[1] = mask;
499 }
500
501 if (ctx->Driver.StencilFuncSeparate) {
502 ctx->Driver.StencilFuncSeparate(ctx, face, func, ref, mask);
503 }
504 }
505
506
507 /* OpenGL 2.0 */
508 void GLAPIENTRY
509 _mesa_StencilFuncSeparate_no_error(GLenum face, GLenum func, GLint ref,
510 GLuint mask)
511 {
512 GET_CURRENT_CONTEXT(ctx);
513 stencil_func_separate(ctx, face, func, ref, mask);
514 }
515
516
517 void GLAPIENTRY
518 _mesa_StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
519 {
520 GET_CURRENT_CONTEXT(ctx);
521
522 if (MESA_VERBOSE & VERBOSE_API)
523 _mesa_debug(ctx, "glStencilFuncSeparate()\n");
524
525 if (face != GL_FRONT && face != GL_BACK && face != GL_FRONT_AND_BACK) {
526 _mesa_error(ctx, GL_INVALID_ENUM, "glStencilFuncSeparate(face)");
527 return;
528 }
529
530 if (!validate_stencil_func(ctx, func)) {
531 _mesa_error(ctx, GL_INVALID_ENUM, "glStencilFuncSeparate(func)");
532 return;
533 }
534
535 stencil_func_separate(ctx, face, func, ref, mask);
536 }
537
538
539 static void
540 stencil_mask_separate(struct gl_context *ctx, GLenum face, GLuint mask)
541 {
542 FLUSH_VERTICES(ctx, _NEW_STENCIL);
543
544 if (face != GL_BACK) {
545 ctx->Stencil.WriteMask[0] = mask;
546 }
547
548 if (face != GL_FRONT) {
549 ctx->Stencil.WriteMask[1] = mask;
550 }
551
552 if (ctx->Driver.StencilMaskSeparate) {
553 ctx->Driver.StencilMaskSeparate(ctx, face, mask);
554 }
555 }
556
557
558 /* OpenGL 2.0 */
559 void GLAPIENTRY
560 _mesa_StencilMaskSeparate_no_error(GLenum face, GLuint mask)
561 {
562 GET_CURRENT_CONTEXT(ctx);
563 stencil_mask_separate(ctx, face, mask);
564 }
565
566
567 void GLAPIENTRY
568 _mesa_StencilMaskSeparate(GLenum face, GLuint mask)
569 {
570 GET_CURRENT_CONTEXT(ctx);
571
572 if (MESA_VERBOSE & VERBOSE_API)
573 _mesa_debug(ctx, "glStencilMaskSeparate()\n");
574
575 if (face != GL_FRONT && face != GL_BACK && face != GL_FRONT_AND_BACK) {
576 _mesa_error(ctx, GL_INVALID_ENUM, "glStencilaMaskSeparate(face)");
577 return;
578 }
579
580 stencil_mask_separate(ctx, face, mask);
581 }
582
583
584 /**
585 * Update derived stencil state.
586 */
587 void
588 _mesa_update_stencil(struct gl_context *ctx)
589 {
590 const GLint face = ctx->Stencil._BackFace;
591
592 ctx->Stencil._Enabled = (ctx->Stencil.Enabled &&
593 ctx->DrawBuffer->Visual.stencilBits > 0);
594
595 ctx->Stencil._TestTwoSide =
596 ctx->Stencil._Enabled &&
597 (ctx->Stencil.Function[0] != ctx->Stencil.Function[face] ||
598 ctx->Stencil.FailFunc[0] != ctx->Stencil.FailFunc[face] ||
599 ctx->Stencil.ZPassFunc[0] != ctx->Stencil.ZPassFunc[face] ||
600 ctx->Stencil.ZFailFunc[0] != ctx->Stencil.ZFailFunc[face] ||
601 ctx->Stencil.Ref[0] != ctx->Stencil.Ref[face] ||
602 ctx->Stencil.ValueMask[0] != ctx->Stencil.ValueMask[face] ||
603 ctx->Stencil.WriteMask[0] != ctx->Stencil.WriteMask[face]);
604
605 ctx->Stencil._WriteEnabled =
606 ctx->Stencil._Enabled &&
607 (ctx->Stencil.WriteMask[0] != 0 ||
608 (ctx->Stencil._TestTwoSide && ctx->Stencil.WriteMask[face] != 0));
609 }
610
611
612 /**
613 * Initialize the context stipple state.
614 *
615 * \param ctx GL context.
616 *
617 * Initializes __struct gl_contextRec::Stencil attribute group.
618 */
619 void
620 _mesa_init_stencil(struct gl_context *ctx)
621 {
622 ctx->Stencil.Enabled = GL_FALSE;
623 ctx->Stencil.TestTwoSide = GL_FALSE;
624 ctx->Stencil.ActiveFace = 0; /* 0 = GL_FRONT, 2 = GL_BACK */
625 ctx->Stencil.Function[0] = GL_ALWAYS;
626 ctx->Stencil.Function[1] = GL_ALWAYS;
627 ctx->Stencil.Function[2] = GL_ALWAYS;
628 ctx->Stencil.FailFunc[0] = GL_KEEP;
629 ctx->Stencil.FailFunc[1] = GL_KEEP;
630 ctx->Stencil.FailFunc[2] = GL_KEEP;
631 ctx->Stencil.ZPassFunc[0] = GL_KEEP;
632 ctx->Stencil.ZPassFunc[1] = GL_KEEP;
633 ctx->Stencil.ZPassFunc[2] = GL_KEEP;
634 ctx->Stencil.ZFailFunc[0] = GL_KEEP;
635 ctx->Stencil.ZFailFunc[1] = GL_KEEP;
636 ctx->Stencil.ZFailFunc[2] = GL_KEEP;
637 ctx->Stencil.Ref[0] = 0;
638 ctx->Stencil.Ref[1] = 0;
639 ctx->Stencil.Ref[2] = 0;
640
641 /* 4.1.4 Stencil Test section of the GL-ES 3.0 specification says:
642 *
643 * "In the initial state, [...] the front and back stencil mask are both
644 * set to the value 2^s − 1, where s is greater than or equal to the
645 * number of bits in the deepest stencil buffer* supported by the GL
646 * implementation."
647 *
648 * Since the maximum supported precision for stencil buffers is 8 bits,
649 * mask values should be initialized to 2^8 - 1 = 0xFF.
650 */
651 ctx->Stencil.ValueMask[0] = 0xFF;
652 ctx->Stencil.ValueMask[1] = 0xFF;
653 ctx->Stencil.ValueMask[2] = 0xFF;
654 ctx->Stencil.WriteMask[0] = 0xFF;
655 ctx->Stencil.WriteMask[1] = 0xFF;
656 ctx->Stencil.WriteMask[2] = 0xFF;
657
658 ctx->Stencil.Clear = 0;
659 ctx->Stencil._BackFace = 1;
660 }