updates to dri drivers for recent stencil changes
[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 sisDDStencilFuncSeparate( GLcontext * ctx, GLenum face,
41 GLenum func, GLint ref, GLuint mask )
42 {
43 sisContextPtr smesa = SIS_CONTEXT(ctx);
44 __GLSiSHardware *prev = &smesa->prev;
45 __GLSiSHardware *current = &smesa->current;
46
47 /* set reference */
48 current->hwStSetting = (STENCIL_FORMAT_8 |
49 ((ctx->Stencil.Ref[0] & 0xff) << 8) |
50 (ctx->Stencil.ValueMask[0] & 0xff));
51
52 switch (func)
53 {
54 case GL_NEVER:
55 current->hwStSetting |= SiS_STENCIL_NEVER;
56 break;
57 case GL_LESS:
58 current->hwStSetting |= SiS_STENCIL_LESS;
59 break;
60 case GL_EQUAL:
61 current->hwStSetting |= SiS_STENCIL_EQUAL;
62 break;
63 case GL_LEQUAL:
64 current->hwStSetting |= SiS_STENCIL_LEQUAL;
65 break;
66 case GL_GREATER:
67 current->hwStSetting |= SiS_STENCIL_GREATER;
68 break;
69 case GL_NOTEQUAL:
70 current->hwStSetting |= SiS_STENCIL_NOTEQUAL;
71 break;
72 case GL_GEQUAL:
73 current->hwStSetting |= SiS_STENCIL_GEQUAL;
74 break;
75 case GL_ALWAYS:
76 current->hwStSetting |= SiS_STENCIL_ALWAYS;
77 break;
78 }
79
80 if (current->hwStSetting != prev->hwStSetting)
81 {
82 prev->hwStSetting = current->hwStSetting;
83
84 smesa->GlobalFlag |= GFLAG_STENCILSETTING;
85 }
86 }
87
88 static void
89 sisDDStencilMaskSeparate( GLcontext * ctx, GLenum face, GLuint mask )
90 {
91 if (!ctx->Visual.stencilBits)
92 return;
93
94 /* set Z buffer Write Enable */
95 sisDDDepthMask (ctx, ctx->Depth.Mask);
96 }
97
98 static void
99 sisDDStencilOpSeparate( GLcontext * ctx, GLenum face, GLenum fail,
100 GLenum zfail, GLenum zpass )
101 {
102 sisContextPtr smesa = SIS_CONTEXT(ctx);
103 __GLSiSHardware *prev = &smesa->prev;
104 __GLSiSHardware *current = &smesa->current;
105
106 current->hwStSetting2 &= ~(MASK_StencilZPassOp | MASK_StencilZFailOp |
107 MASK_StencilFailOp);
108
109 switch (fail)
110 {
111 case GL_KEEP:
112 current->hwStSetting2 |= SiS_SFAIL_KEEP;
113 break;
114 case GL_ZERO:
115 current->hwStSetting2 |= SiS_SFAIL_ZERO;
116 break;
117 case GL_REPLACE:
118 current->hwStSetting2 |= SiS_SFAIL_REPLACE;
119 break;
120 case GL_INVERT:
121 current->hwStSetting2 |= SiS_SFAIL_INVERT;
122 break;
123 case GL_INCR:
124 current->hwStSetting2 |= SiS_SFAIL_INCR;
125 break;
126 case GL_DECR:
127 current->hwStSetting2 |= SiS_SFAIL_DECR;
128 break;
129 case GL_INCR_WRAP:
130 current->hwStSetting2 |= SiS_SFAIL_INCR_WRAP;
131 break;
132 case GL_DECR_WRAP:
133 current->hwStSetting2 |= SiS_SFAIL_DECR_WRAP;
134 break;
135 }
136
137 switch (zfail)
138 {
139 case GL_KEEP:
140 current->hwStSetting2 |= SiS_SPASS_ZFAIL_KEEP;
141 break;
142 case GL_ZERO:
143 current->hwStSetting2 |= SiS_SPASS_ZFAIL_ZERO;
144 break;
145 case GL_REPLACE:
146 current->hwStSetting2 |= SiS_SPASS_ZFAIL_REPLACE;
147 break;
148 case GL_INVERT:
149 current->hwStSetting2 |= SiS_SPASS_ZFAIL_INVERT;
150 break;
151 case GL_INCR:
152 current->hwStSetting2 |= SiS_SPASS_ZFAIL_INCR;
153 break;
154 case GL_DECR:
155 current->hwStSetting2 |= SiS_SPASS_ZFAIL_DECR;
156 break;
157 case GL_INCR_WRAP:
158 current->hwStSetting2 |= SiS_SPASS_ZFAIL_INCR_WRAP;
159 break;
160 case GL_DECR_WRAP:
161 current->hwStSetting2 |= SiS_SPASS_ZFAIL_DECR_WRAP;
162 break;
163 }
164
165 switch (zpass)
166 {
167 case GL_KEEP:
168 current->hwStSetting2 |= SiS_SPASS_ZPASS_KEEP;
169 break;
170 case GL_ZERO:
171 current->hwStSetting2 |= SiS_SPASS_ZPASS_ZERO;
172 break;
173 case GL_REPLACE:
174 current->hwStSetting2 |= SiS_SPASS_ZPASS_REPLACE;
175 break;
176 case GL_INVERT:
177 current->hwStSetting2 |= SiS_SPASS_ZPASS_INVERT;
178 break;
179 case GL_INCR:
180 current->hwStSetting2 |= SiS_SPASS_ZPASS_INCR;
181 break;
182 case GL_DECR:
183 current->hwStSetting2 |= SiS_SPASS_ZPASS_DECR;
184 break;
185 case GL_INCR_WRAP:
186 current->hwStSetting2 |= SiS_SPASS_ZPASS_INCR_WRAP;
187 break;
188 case GL_DECR_WRAP:
189 current->hwStSetting2 |= SiS_SPASS_ZPASS_DECR_WRAP;
190 break;
191 }
192
193 if (current->hwStSetting2 != prev->hwStSetting2)
194 {
195 prev->hwStSetting2 = current->hwStSetting2;
196 smesa->GlobalFlag |= GFLAG_STENCILSETTING;
197 }
198 }
199
200 void
201 sisDDInitStencilFuncs( GLcontext *ctx )
202 {
203 ctx->Driver.StencilFuncSeparate = sisDDStencilFuncSeparate;
204 ctx->Driver.StencilMaskSeparate = sisDDStencilMaskSeparate;
205 ctx->Driver.StencilOpSeparate = sisDDStencilOpSeparate;
206 }