Tizen 2.0 Release
[profile/ivi/osmesa.git] / src / mesa / main / stencil.c
1 /*
2  * Mesa 3-D graphics library
3  * Version:  7.1
4  *
5  * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
6  *
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:
13  *
14  * The above copyright notice and this permission notice shall be included
15  * in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR 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       return GL_TRUE;
69    case GL_INCR_WRAP_EXT:
70    case GL_DECR_WRAP_EXT:
71       if (ctx->Extensions.EXT_stencil_wrap) {
72          return GL_TRUE;
73       }
74       /* FALL-THROUGH */
75    default:
76       return GL_FALSE;
77    }
78 }
79
80
81 static GLboolean
82 validate_stencil_func(struct gl_context *ctx, GLenum func)
83 {
84    switch (func) {
85    case GL_NEVER:
86    case GL_LESS:
87    case GL_LEQUAL:
88    case GL_GREATER:
89    case GL_GEQUAL:
90    case GL_EQUAL:
91    case GL_NOTEQUAL:
92    case GL_ALWAYS:
93       return GL_TRUE;
94    default:
95       return GL_FALSE;
96    }
97 }
98
99
100 /**
101  * Set the clear value for the stencil buffer.
102  *
103  * \param s clear value.
104  *
105  * \sa glClearStencil().
106  *
107  * Updates gl_stencil_attrib::Clear. On change
108  * flushes the vertices and notifies the driver via
109  * the dd_function_table::ClearStencil callback.
110  */
111 void GLAPIENTRY
112 _mesa_ClearStencil( GLint s )
113 {
114    GET_CURRENT_CONTEXT(ctx);
115    ASSERT_OUTSIDE_BEGIN_END(ctx);
116
117    if (ctx->Stencil.Clear == (GLuint) s)
118       return;
119
120    FLUSH_VERTICES(ctx, _NEW_STENCIL);
121    ctx->Stencil.Clear = (GLuint) s;
122
123    if (ctx->Driver.ClearStencil) {
124       ctx->Driver.ClearStencil( ctx, s );
125    }
126 }
127
128
129 /**
130  * Set the function and reference value for stencil testing.
131  *
132  * \param frontfunc front test function.
133  * \param backfunc back test function.
134  * \param ref front and back reference value.
135  * \param mask front and back bitmask.
136  *
137  * \sa glStencilFunc().
138  *
139  * Verifies the parameters and updates the respective values in
140  * __struct gl_contextRec::Stencil. On change flushes the vertices and notifies the
141  * driver via the dd_function_table::StencilFunc callback.
142  */
143 void GLAPIENTRY
144 _mesa_StencilFuncSeparateATI( GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask )
145 {
146    GET_CURRENT_CONTEXT(ctx);
147    const GLint stencilMax = (1 << ctx->DrawBuffer->Visual.stencilBits) - 1;
148    ASSERT_OUTSIDE_BEGIN_END(ctx);
149
150    if (MESA_VERBOSE & VERBOSE_API)
151       _mesa_debug(ctx, "glStencilFuncSeparateATI()\n");
152
153    if (!validate_stencil_func(ctx, frontfunc)) {
154       _mesa_error(ctx, GL_INVALID_ENUM,
155                   "glStencilFuncSeparateATI(frontfunc)");
156       return;
157    }
158    if (!validate_stencil_func(ctx, backfunc)) {
159       _mesa_error(ctx, GL_INVALID_ENUM,
160                   "glStencilFuncSeparateATI(backfunc)");
161       return;
162    }
163
164    ref = CLAMP( ref, 0, stencilMax );
165
166    /* set both front and back state */
167    if (ctx->Stencil.Function[0] == frontfunc &&
168        ctx->Stencil.Function[1] == backfunc &&
169        ctx->Stencil.ValueMask[0] == mask &&
170        ctx->Stencil.ValueMask[1] == mask &&
171        ctx->Stencil.Ref[0] == ref &&
172        ctx->Stencil.Ref[1] == ref)
173       return;
174    FLUSH_VERTICES(ctx, _NEW_STENCIL);
175    ctx->Stencil.Function[0]  = frontfunc;
176    ctx->Stencil.Function[1]  = backfunc;
177    ctx->Stencil.Ref[0]       = ctx->Stencil.Ref[1]       = ref;
178    ctx->Stencil.ValueMask[0] = ctx->Stencil.ValueMask[1] = mask;
179    if (ctx->Driver.StencilFuncSeparate) {
180       ctx->Driver.StencilFuncSeparate(ctx, GL_FRONT,
181                                       frontfunc, ref, mask);
182       ctx->Driver.StencilFuncSeparate(ctx, GL_BACK,
183                                       backfunc, ref, mask);
184    }
185 }
186
187
188 /**
189  * Set the function and reference value for stencil testing.
190  *
191  * \param func test function.
192  * \param ref reference value.
193  * \param mask bitmask.
194  *
195  * \sa glStencilFunc().
196  *
197  * Verifies the parameters and updates the respective values in
198  * __struct gl_contextRec::Stencil. On change flushes the vertices and notifies the
199  * driver via the dd_function_table::StencilFunc callback.
200  */
201 void GLAPIENTRY
202 _mesa_StencilFunc( GLenum func, GLint ref, GLuint mask )
203 {
204    GET_CURRENT_CONTEXT(ctx);
205    const GLint stencilMax = (1 << ctx->DrawBuffer->Visual.stencilBits) - 1;
206    const GLint face = ctx->Stencil.ActiveFace;
207    ASSERT_OUTSIDE_BEGIN_END(ctx);
208
209    if (MESA_VERBOSE & VERBOSE_API)
210       _mesa_debug(ctx, "glStencilFunc()\n");
211
212    if (!validate_stencil_func(ctx, func)) {
213       _mesa_error(ctx, GL_INVALID_ENUM, "glStencilFunc(func)");
214       return;
215    }
216
217    ref = CLAMP( ref, 0, stencilMax );
218
219    if (face != 0) {
220       if (ctx->Stencil.Function[face] == func &&
221           ctx->Stencil.ValueMask[face] == mask &&
222           ctx->Stencil.Ref[face] == ref)
223          return;
224       FLUSH_VERTICES(ctx, _NEW_STENCIL);
225       ctx->Stencil.Function[face] = func;
226       ctx->Stencil.Ref[face] = ref;
227       ctx->Stencil.ValueMask[face] = mask;
228
229       /* Only propagate the change to the driver if EXT_stencil_two_side
230        * is enabled.
231        */
232       if (ctx->Driver.StencilFuncSeparate && ctx->Stencil.TestTwoSide) {
233          ctx->Driver.StencilFuncSeparate(ctx, GL_BACK, func, ref, mask);
234       }
235    }
236    else {
237       /* set both front and back state */
238       if (ctx->Stencil.Function[0] == func &&
239           ctx->Stencil.Function[1] == func &&
240           ctx->Stencil.ValueMask[0] == mask &&
241           ctx->Stencil.ValueMask[1] == mask &&
242           ctx->Stencil.Ref[0] == ref &&
243           ctx->Stencil.Ref[1] == ref)
244          return;
245       FLUSH_VERTICES(ctx, _NEW_STENCIL);
246       ctx->Stencil.Function[0]  = ctx->Stencil.Function[1]  = func;
247       ctx->Stencil.Ref[0]       = ctx->Stencil.Ref[1]       = ref;
248       ctx->Stencil.ValueMask[0] = ctx->Stencil.ValueMask[1] = mask;
249       if (ctx->Driver.StencilFuncSeparate) {
250          ctx->Driver.StencilFuncSeparate(ctx,
251                                          ((ctx->Stencil.TestTwoSide)
252                                           ? GL_FRONT : GL_FRONT_AND_BACK),
253                                          func, ref, mask);
254       }
255    }
256 }
257
258
259 /**
260  * Set the stencil writing mask.
261  *
262  * \param mask bit-mask to enable/disable writing of individual bits in the
263  * stencil planes.
264  *
265  * \sa glStencilMask().
266  *
267  * Updates gl_stencil_attrib::WriteMask. On change flushes the vertices and
268  * notifies the driver via the dd_function_table::StencilMask callback.
269  */
270 void GLAPIENTRY
271 _mesa_StencilMask( GLuint mask )
272 {
273    GET_CURRENT_CONTEXT(ctx);
274    const GLint face = ctx->Stencil.ActiveFace;
275
276    if (MESA_VERBOSE & VERBOSE_API)
277       _mesa_debug(ctx, "glStencilMask()\n");
278
279    ASSERT_OUTSIDE_BEGIN_END(ctx);
280
281    if (face != 0) {
282       /* Only modify the EXT_stencil_two_side back-face state.
283        */
284       if (ctx->Stencil.WriteMask[face] == mask)
285          return;
286       FLUSH_VERTICES(ctx, _NEW_STENCIL);
287       ctx->Stencil.WriteMask[face] = mask;
288
289       /* Only propagate the change to the driver if EXT_stencil_two_side
290        * is enabled.
291        */
292       if (ctx->Driver.StencilMaskSeparate && ctx->Stencil.TestTwoSide) {
293          ctx->Driver.StencilMaskSeparate(ctx, GL_BACK, mask);
294       }
295    }
296    else {
297       /* set both front and back state */
298       if (ctx->Stencil.WriteMask[0] == mask &&
299           ctx->Stencil.WriteMask[1] == mask)
300          return;
301       FLUSH_VERTICES(ctx, _NEW_STENCIL);
302       ctx->Stencil.WriteMask[0] = ctx->Stencil.WriteMask[1] = mask;
303       if (ctx->Driver.StencilMaskSeparate) {
304          ctx->Driver.StencilMaskSeparate(ctx,
305                                          ((ctx->Stencil.TestTwoSide)
306                                           ? GL_FRONT : GL_FRONT_AND_BACK),
307                                           mask);
308       }
309    }
310 }
311
312
313 /**
314  * Set the stencil test actions.
315  *
316  * \param fail action to take when stencil test fails.
317  * \param zfail action to take when stencil test passes, but depth test fails.
318  * \param zpass action to take when stencil test passes and the depth test
319  * passes (or depth testing is not enabled).
320  * 
321  * \sa glStencilOp().
322  * 
323  * Verifies the parameters and updates the respective fields in
324  * __struct gl_contextRec::Stencil. On change flushes the vertices and notifies the
325  * driver via the dd_function_table::StencilOp callback.
326  */
327 void GLAPIENTRY
328 _mesa_StencilOp(GLenum fail, GLenum zfail, GLenum zpass)
329 {
330    GET_CURRENT_CONTEXT(ctx);
331    const GLint face = ctx->Stencil.ActiveFace;
332
333    if (MESA_VERBOSE & VERBOSE_API)
334       _mesa_debug(ctx, "glStencilOp()\n");
335
336    ASSERT_OUTSIDE_BEGIN_END(ctx);
337
338    if (!validate_stencil_op(ctx, fail)) {
339       _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOp(sfail)");
340       return;
341    }
342    if (!validate_stencil_op(ctx, zfail)) {
343       _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOp(zfail)");
344       return;
345    }
346    if (!validate_stencil_op(ctx, zpass)) {
347       _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOp(zpass)");
348       return;
349    }
350
351    if (face != 0) {
352       /* only set active face state */
353       if (ctx->Stencil.ZFailFunc[face] == zfail &&
354           ctx->Stencil.ZPassFunc[face] == zpass &&
355           ctx->Stencil.FailFunc[face] == fail)
356          return;
357       FLUSH_VERTICES(ctx, _NEW_STENCIL);
358       ctx->Stencil.ZFailFunc[face] = zfail;
359       ctx->Stencil.ZPassFunc[face] = zpass;
360       ctx->Stencil.FailFunc[face] = fail;
361
362       /* Only propagate the change to the driver if EXT_stencil_two_side
363        * is enabled.
364        */
365       if (ctx->Driver.StencilOpSeparate && ctx->Stencil.TestTwoSide) {
366          ctx->Driver.StencilOpSeparate(ctx, GL_BACK, fail, zfail, zpass);
367       }
368    }
369    else {
370       /* set both front and back state */
371       if (ctx->Stencil.ZFailFunc[0] == zfail &&
372           ctx->Stencil.ZFailFunc[1] == zfail &&
373           ctx->Stencil.ZPassFunc[0] == zpass &&
374           ctx->Stencil.ZPassFunc[1] == zpass &&
375           ctx->Stencil.FailFunc[0] == fail &&
376           ctx->Stencil.FailFunc[1] == fail)
377          return;
378       FLUSH_VERTICES(ctx, _NEW_STENCIL);
379       ctx->Stencil.ZFailFunc[0] = ctx->Stencil.ZFailFunc[1] = zfail;
380       ctx->Stencil.ZPassFunc[0] = ctx->Stencil.ZPassFunc[1] = zpass;
381       ctx->Stencil.FailFunc[0]  = ctx->Stencil.FailFunc[1]  = fail;
382       if (ctx->Driver.StencilOpSeparate) {
383          ctx->Driver.StencilOpSeparate(ctx,
384                                        ((ctx->Stencil.TestTwoSide)
385                                         ? GL_FRONT : GL_FRONT_AND_BACK),
386                                        fail, zfail, zpass);
387       }
388    }
389 }
390
391
392
393 #if _HAVE_FULL_GL
394 /* GL_EXT_stencil_two_side */
395 void GLAPIENTRY
396 _mesa_ActiveStencilFaceEXT(GLenum face)
397 {
398    GET_CURRENT_CONTEXT(ctx);
399    ASSERT_OUTSIDE_BEGIN_END(ctx);
400
401    if (MESA_VERBOSE & VERBOSE_API)
402       _mesa_debug(ctx, "glActiveStencilFaceEXT()\n");
403
404    if (!ctx->Extensions.EXT_stencil_two_side) {
405       _mesa_error(ctx, GL_INVALID_OPERATION, "glActiveStencilFaceEXT");
406       return;
407    }
408
409    if (face == GL_FRONT || face == GL_BACK) {
410       FLUSH_VERTICES(ctx, _NEW_STENCIL);
411       ctx->Stencil.ActiveFace = (face == GL_FRONT) ? 0 : 2;
412    }
413    else {
414       _mesa_error(ctx, GL_INVALID_ENUM, "glActiveStencilFaceEXT(face)");
415    }
416 }
417 #endif
418
419
420
421 /**
422  * OpenGL 2.0 function.
423  * \todo Make StencilOp() call this function.  And eventually remove the
424  * ctx->Driver.StencilOp function and use ctx->Driver.StencilOpSeparate
425  * instead.
426  */
427 void GLAPIENTRY
428 _mesa_StencilOpSeparate(GLenum face, GLenum sfail, GLenum zfail, GLenum zpass)
429 {
430    GLboolean set = GL_FALSE;
431    GET_CURRENT_CONTEXT(ctx);
432    ASSERT_OUTSIDE_BEGIN_END(ctx);
433
434    if (MESA_VERBOSE & VERBOSE_API)
435       _mesa_debug(ctx, "glStencilOpSeparate()\n");
436
437    if (!validate_stencil_op(ctx, sfail)) {
438       _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOpSeparate(sfail)");
439       return;
440    }
441    if (!validate_stencil_op(ctx, zfail)) {
442       _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOpSeparate(zfail)");
443       return;
444    }
445    if (!validate_stencil_op(ctx, zpass)) {
446       _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOpSeparate(zpass)");
447       return;
448    }
449    if (face != GL_FRONT && face != GL_BACK && face != GL_FRONT_AND_BACK) {
450       _mesa_error(ctx, GL_INVALID_ENUM, "glStencilOpSeparate(face)");
451       return;
452    }
453
454    if (face != GL_BACK) {
455       /* set front */
456       if (ctx->Stencil.ZFailFunc[0] != zfail ||
457           ctx->Stencil.ZPassFunc[0] != zpass ||
458           ctx->Stencil.FailFunc[0] != sfail){
459          FLUSH_VERTICES(ctx, _NEW_STENCIL);
460          ctx->Stencil.ZFailFunc[0] = zfail;
461          ctx->Stencil.ZPassFunc[0] = zpass;
462          ctx->Stencil.FailFunc[0] = sfail;
463          set = GL_TRUE;
464       }
465    }
466    if (face != GL_FRONT) {
467       /* set back */
468       if (ctx->Stencil.ZFailFunc[1] != zfail ||
469           ctx->Stencil.ZPassFunc[1] != zpass ||
470           ctx->Stencil.FailFunc[1] != sfail) {
471          FLUSH_VERTICES(ctx, _NEW_STENCIL);
472          ctx->Stencil.ZFailFunc[1] = zfail;
473          ctx->Stencil.ZPassFunc[1] = zpass;
474          ctx->Stencil.FailFunc[1] = sfail;
475          set = GL_TRUE;
476       }
477    }
478    if (set && ctx->Driver.StencilOpSeparate) {
479       ctx->Driver.StencilOpSeparate(ctx, face, sfail, zfail, zpass);
480    }
481 }
482
483
484 /* OpenGL 2.0 */
485 void GLAPIENTRY
486 _mesa_StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
487 {
488    GET_CURRENT_CONTEXT(ctx);
489    const GLint stencilMax = (1 << ctx->DrawBuffer->Visual.stencilBits) - 1;
490    ASSERT_OUTSIDE_BEGIN_END(ctx);
491
492    if (MESA_VERBOSE & VERBOSE_API)
493       _mesa_debug(ctx, "glStencilFuncSeparate()\n");
494
495    if (face != GL_FRONT && face != GL_BACK && face != GL_FRONT_AND_BACK) {
496       _mesa_error(ctx, GL_INVALID_ENUM, "glStencilFuncSeparate(face)");
497       return;
498    }
499    if (!validate_stencil_func(ctx, func)) {
500       _mesa_error(ctx, GL_INVALID_ENUM, "glStencilFuncSeparate(func)");
501       return;
502    }
503
504    ref = CLAMP(ref, 0, stencilMax);
505
506    FLUSH_VERTICES(ctx, _NEW_STENCIL);
507
508    if (face != GL_BACK) {
509       /* set front */
510       ctx->Stencil.Function[0] = func;
511       ctx->Stencil.Ref[0] = ref;
512       ctx->Stencil.ValueMask[0] = mask;
513    }
514    if (face != GL_FRONT) {
515       /* set back */
516       ctx->Stencil.Function[1] = func;
517       ctx->Stencil.Ref[1] = ref;
518       ctx->Stencil.ValueMask[1] = mask;
519    }
520    if (ctx->Driver.StencilFuncSeparate) {
521       ctx->Driver.StencilFuncSeparate(ctx, face, func, ref, mask);
522    }
523 }
524
525
526 /* OpenGL 2.0 */
527 void GLAPIENTRY
528 _mesa_StencilMaskSeparate(GLenum face, GLuint mask)
529 {
530    GET_CURRENT_CONTEXT(ctx);
531    ASSERT_OUTSIDE_BEGIN_END(ctx);
532
533    if (MESA_VERBOSE & VERBOSE_API)
534       _mesa_debug(ctx, "glStencilMaskSeparate()\n");
535
536    if (face != GL_FRONT && face != GL_BACK && face != GL_FRONT_AND_BACK) {
537       _mesa_error(ctx, GL_INVALID_ENUM, "glStencilaMaskSeparate(face)");
538       return;
539    }
540
541    FLUSH_VERTICES(ctx, _NEW_STENCIL);
542
543    if (face != GL_BACK) {
544       ctx->Stencil.WriteMask[0] = mask;
545    }
546    if (face != GL_FRONT) {
547       ctx->Stencil.WriteMask[1] = mask;
548    }
549    if (ctx->Driver.StencilMaskSeparate) {
550       ctx->Driver.StencilMaskSeparate(ctx, face, mask);
551    }
552 }
553
554
555 /**
556  * Update derived stencil state.
557  */
558 void
559 _mesa_update_stencil(struct gl_context *ctx)
560 {
561    const GLint face = ctx->Stencil._BackFace;
562
563    ctx->Stencil._Enabled = (ctx->Stencil.Enabled &&
564                             ctx->DrawBuffer->Visual.stencilBits > 0);
565
566     ctx->Stencil._TestTwoSide =
567        ctx->Stencil._Enabled &&
568        (ctx->Stencil.Function[0] != ctx->Stencil.Function[face] ||
569         ctx->Stencil.FailFunc[0] != ctx->Stencil.FailFunc[face] ||
570         ctx->Stencil.ZPassFunc[0] != ctx->Stencil.ZPassFunc[face] ||
571         ctx->Stencil.ZFailFunc[0] != ctx->Stencil.ZFailFunc[face] ||
572         ctx->Stencil.Ref[0] != ctx->Stencil.Ref[face] ||
573         ctx->Stencil.ValueMask[0] != ctx->Stencil.ValueMask[face] ||
574         ctx->Stencil.WriteMask[0] != ctx->Stencil.WriteMask[face]);
575 }
576
577
578 /**
579  * Initialize the context stipple state.
580  *
581  * \param ctx GL context.
582  *
583  * Initializes __struct gl_contextRec::Stencil attribute group.
584  */
585 void
586 _mesa_init_stencil(struct gl_context *ctx)
587 {
588    ctx->Stencil.Enabled = GL_FALSE;
589    ctx->Stencil.TestTwoSide = GL_FALSE;
590    ctx->Stencil.ActiveFace = 0;  /* 0 = GL_FRONT, 2 = GL_BACK */
591    ctx->Stencil.Function[0] = GL_ALWAYS;
592    ctx->Stencil.Function[1] = GL_ALWAYS;
593    ctx->Stencil.Function[2] = GL_ALWAYS;
594    ctx->Stencil.FailFunc[0] = GL_KEEP;
595    ctx->Stencil.FailFunc[1] = GL_KEEP;
596    ctx->Stencil.FailFunc[2] = GL_KEEP;
597    ctx->Stencil.ZPassFunc[0] = GL_KEEP;
598    ctx->Stencil.ZPassFunc[1] = GL_KEEP;
599    ctx->Stencil.ZPassFunc[2] = GL_KEEP;
600    ctx->Stencil.ZFailFunc[0] = GL_KEEP;
601    ctx->Stencil.ZFailFunc[1] = GL_KEEP;
602    ctx->Stencil.ZFailFunc[2] = GL_KEEP;
603    ctx->Stencil.Ref[0] = 0;
604    ctx->Stencil.Ref[1] = 0;
605    ctx->Stencil.Ref[2] = 0;
606    ctx->Stencil.ValueMask[0] = ~0U;
607    ctx->Stencil.ValueMask[1] = ~0U;
608    ctx->Stencil.ValueMask[2] = ~0U;
609    ctx->Stencil.WriteMask[0] = ~0U;
610    ctx->Stencil.WriteMask[1] = ~0U;
611    ctx->Stencil.WriteMask[2] = ~0U;
612    ctx->Stencil.Clear = 0;
613    ctx->Stencil._BackFace = 1;
614 }