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