Correct a couple of comments.
[mesa.git] / src / mesa / drivers / dri / sis / sis_stencil.c
1 /**************************************************************************
2
3 Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.
4 Copyright 2003 Eric Anholt
5 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 on the rights to use, copy, modify, merge, publish, distribute, sub
11 license, and/or sell copies of the Software, and to permit persons to whom
12 the Software is furnished to do so, subject to the following conditions:
13
14 The above copyright notice and this permission notice (including the next
15 paragraph) shall be included in all copies or substantial portions of the
16 Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 ERIC ANHOLT OR SILICON INTEGRATED SYSTEMS CORP BE LIABLE FOR ANY CLAIM,
22 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 **************************************************************************/
27 /* $XFree86: xc/lib/GL/mesa/src/drv/sis/sis_stencil.c,v 1.3 2000/09/26 15:56:49 tsi Exp $ */
28
29 /*
30 * Authors:
31 * Sung-Ching Lin <sclin@sis.com.tw>
32 * Eric Anholt <anholt@FreeBSD.org>
33 */
34
35 #include "sis_context.h"
36 #include "sis_state.h"
37 #include "sis_stencil.h"
38
39 static void
40 sisDDStencilFunc( GLcontext * ctx, GLenum func, GLint ref, GLuint mask )
41 {
42 sisContextPtr smesa = SIS_CONTEXT(ctx);
43 __GLSiSHardware *prev = &smesa->prev;
44 __GLSiSHardware *current = &smesa->current;
45
46 /* set reference */
47 current->hwStSetting = STENCIL_FORMAT_8 | (ctx->Stencil.Ref[0] << 8) |
48 ctx->Stencil.ValueMask[0];
49
50 switch (func)
51 {
52 case GL_NEVER:
53 current->hwStSetting |= SiS_STENCIL_NEVER;
54 break;
55 case GL_LESS:
56 current->hwStSetting |= SiS_STENCIL_LESS;
57 break;
58 case GL_EQUAL:
59 current->hwStSetting |= SiS_STENCIL_EQUAL;
60 break;
61 case GL_LEQUAL:
62 current->hwStSetting |= SiS_STENCIL_LEQUAL;
63 break;
64 case GL_GREATER:
65 current->hwStSetting |= SiS_STENCIL_GREATER;
66 break;
67 case GL_NOTEQUAL:
68 current->hwStSetting |= SiS_STENCIL_NOTEQUAL;
69 break;
70 case GL_GEQUAL:
71 current->hwStSetting |= SiS_STENCIL_GEQUAL;
72 break;
73 case GL_ALWAYS:
74 current->hwStSetting |= SiS_STENCIL_ALWAYS;
75 break;
76 }
77
78 if (current->hwStSetting != prev->hwStSetting)
79 {
80 prev->hwStSetting = current->hwStSetting;
81
82 smesa->GlobalFlag |= GFLAG_STENCILSETTING;
83 }
84 }
85
86 static void
87 sisDDStencilMask( GLcontext * ctx, GLuint mask )
88 {
89 if (!ctx->Visual.stencilBits)
90 return;
91
92 /* set Z buffer Write Enable */
93 sisDDDepthMask (ctx, ctx->Depth.Mask);
94 }
95
96 static void
97 sisDDStencilOp( GLcontext * ctx, GLenum fail, GLenum zfail, GLenum zpass )
98 {
99 sisContextPtr smesa = SIS_CONTEXT(ctx);
100 __GLSiSHardware *prev = &smesa->prev;
101 __GLSiSHardware *current = &smesa->current;
102
103 current->hwStSetting2 &= ~(MASK_StencilZPassOp | MASK_StencilZFailOp |
104 MASK_StencilFailOp);
105
106 switch (fail)
107 {
108 case GL_KEEP:
109 current->hwStSetting2 |= SiS_SFAIL_KEEP;
110 break;
111 case GL_ZERO:
112 current->hwStSetting2 |= SiS_SFAIL_ZERO;
113 break;
114 case GL_REPLACE:
115 current->hwStSetting2 |= SiS_SFAIL_REPLACE;
116 break;
117 case GL_INVERT:
118 current->hwStSetting2 |= SiS_SFAIL_INVERT;
119 break;
120 case GL_INCR:
121 current->hwStSetting2 |= SiS_SFAIL_INCR;
122 break;
123 case GL_DECR:
124 current->hwStSetting2 |= SiS_SFAIL_DECR;
125 break;
126 }
127
128 switch (zfail)
129 {
130 case GL_KEEP:
131 current->hwStSetting2 |= SiS_SPASS_ZFAIL_KEEP;
132 break;
133 case GL_ZERO:
134 current->hwStSetting2 |= SiS_SPASS_ZFAIL_ZERO;
135 break;
136 case GL_REPLACE:
137 current->hwStSetting2 |= SiS_SPASS_ZFAIL_REPLACE;
138 break;
139 case GL_INVERT:
140 current->hwStSetting2 |= SiS_SPASS_ZFAIL_INVERT;
141 break;
142 case GL_INCR:
143 current->hwStSetting2 |= SiS_SPASS_ZFAIL_INCR;
144 break;
145 case GL_DECR:
146 current->hwStSetting2 |= SiS_SPASS_ZFAIL_DECR;
147 break;
148 }
149
150 switch (zpass)
151 {
152 case GL_KEEP:
153 current->hwStSetting2 |= SiS_SPASS_ZPASS_KEEP;
154 break;
155 case GL_ZERO:
156 current->hwStSetting2 |= SiS_SPASS_ZPASS_ZERO;
157 break;
158 case GL_REPLACE:
159 current->hwStSetting2 |= SiS_SPASS_ZPASS_REPLACE;
160 break;
161 case GL_INVERT:
162 current->hwStSetting2 |= SiS_SPASS_ZPASS_INVERT;
163 break;
164 case GL_INCR:
165 current->hwStSetting2 |= SiS_SPASS_ZPASS_INCR;
166 break;
167 case GL_DECR:
168 current->hwStSetting2 |= SiS_SPASS_ZPASS_DECR;
169 break;
170 }
171
172 if (current->hwStSetting2 != prev->hwStSetting2)
173 {
174 prev->hwStSetting2 = current->hwStSetting2;
175 smesa->GlobalFlag |= GFLAG_STENCILSETTING;
176 }
177 }
178
179 void
180 sisDDInitStencilFuncs( GLcontext *ctx )
181 {
182 ctx->Driver.StencilFunc = sisDDStencilFunc;
183 ctx->Driver.StencilMask = sisDDStencilMask;
184 ctx->Driver.StencilOp = sisDDStencilOp;
185 }