324fc873d3f3bda08aa7d1a651e1ce1e4800830c
[mesa.git] / src / mesa / drivers / dri / common / stenciltmp.h
1 /* $XFree86: xc/lib/GL/mesa/src/drv/common/stenciltmp.h,v 1.3 2001/03/21 16:14:20 dawes Exp $ */
2
3 #include "spantmp_common.h"
4
5 #ifndef DBG
6 #define DBG 0
7 #endif
8
9 #ifndef HAVE_HW_STENCIL_SPANS
10 #define HAVE_HW_STENCIL_SPANS 0
11 #endif
12
13 #ifndef HAVE_HW_STENCIL_PIXELS
14 #define HAVE_HW_STENCIL_PIXELS 0
15 #endif
16
17 static void TAG(WriteStencilSpan)( GLcontext *ctx,
18 struct gl_renderbuffer *rb,
19 GLuint n, GLint x, GLint y,
20 const void *values, const GLubyte mask[] )
21 {
22 HW_WRITE_LOCK()
23 {
24 const GLubyte *stencil = (const GLubyte *) values;
25 GLint x1;
26 GLint n1;
27 LOCAL_STENCIL_VARS;
28
29 y = Y_FLIP(y);
30
31 #if HAVE_HW_STENCIL_SPANS
32 (void) x1; (void) n1;
33
34 if (DBG) fprintf(stderr, "WriteStencilSpan 0..%d (x1 %d)\n",
35 (int)n1, (int)x1);
36
37 WRITE_STENCIL_SPAN();
38 #else /* HAVE_HW_STENCIL_SPANS */
39 HW_CLIPLOOP()
40 {
41 GLint i = 0;
42 CLIPSPAN(x,y,n,x1,n1,i);
43
44 if (DBG) fprintf(stderr, "WriteStencilSpan %d..%d (x1 %d)\n",
45 (int)i, (int)n1, (int)x1);
46
47 if (mask)
48 {
49 for (;n1>0;i++,x1++,n1--)
50 if (mask[i])
51 WRITE_STENCIL( x1, y, stencil[i] );
52 }
53 else
54 {
55 for (;n1>0;i++,x1++,n1--)
56 WRITE_STENCIL( x1, y, stencil[i] );
57 }
58 }
59 HW_ENDCLIPLOOP();
60 #endif /* !HAVE_HW_STENCIL_SPANS */
61 }
62 HW_WRITE_UNLOCK();
63 }
64
65 #if HAVE_HW_STENCIL_SPANS
66 /* implement MonoWriteDepthSpan() in terms of WriteDepthSpan() */
67 static void
68 TAG(WriteMonoStencilSpan)( GLcontext *ctx, struct gl_renderbuffer *rb,
69 GLuint n, GLint x, GLint y,
70 const void *value, const GLubyte mask[] )
71 {
72 const GLuint stenVal = *((GLuint *) value);
73 GLuint stens[MAX_WIDTH];
74 GLuint i;
75 for (i = 0; i < n; i++)
76 stens[i] = stenVal;
77 TAG(WriteStencilSpan)(ctx, rb, n, x, y, stens, mask);
78 }
79 #else /* HAVE_HW_STENCIL_SPANS */
80 static void TAG(WriteMonoStencilSpan)( GLcontext *ctx,
81 struct gl_renderbuffer *rb,
82 GLuint n, GLint x, GLint y,
83 const void *value,
84 const GLubyte mask[] )
85 {
86 HW_WRITE_LOCK()
87 {
88 const GLubyte stencil = *((const GLubyte *) value);
89 GLint x1;
90 GLint n1;
91 LOCAL_STENCIL_VARS;
92
93 y = Y_FLIP(y);
94
95 HW_CLIPLOOP()
96 {
97 GLint i = 0;
98 CLIPSPAN(x,y,n,x1,n1,i);
99
100 if (DBG) fprintf(stderr, "WriteStencilSpan %d..%d (x1 %d)\n",
101 (int)i, (int)n1, (int)x1);
102
103 if (mask)
104 {
105 for (;n1>0;i++,x1++,n1--)
106 if (mask[i])
107 WRITE_STENCIL( x1, y, stencil );
108 }
109 else
110 {
111 for (;n1>0;i++,x1++,n1--)
112 WRITE_STENCIL( x1, y, stencil );
113 }
114 }
115 HW_ENDCLIPLOOP();
116 }
117 HW_WRITE_UNLOCK();
118 }
119 #endif /* !HAVE_HW_STENCIL_SPANS */
120
121
122 static void TAG(WriteStencilPixels)( GLcontext *ctx,
123 struct gl_renderbuffer *rb,
124 GLuint n,
125 const GLint x[], const GLint y[],
126 const void *values, const GLubyte mask[] )
127 {
128 HW_WRITE_LOCK()
129 {
130 const GLubyte *stencil = (const GLubyte *) values;
131 GLuint i;
132 LOCAL_STENCIL_VARS;
133
134 if (DBG) fprintf(stderr, "WriteStencilPixels\n");
135
136 #if HAVE_HW_STENCIL_PIXELS
137 (void) i;
138
139 WRITE_STENCIL_PIXELS();
140 #else /* HAVE_HW_STENCIL_PIXELS */
141 HW_CLIPLOOP()
142 {
143 for (i=0;i<n;i++)
144 {
145 if (mask[i]) {
146 const int fy = Y_FLIP(y[i]);
147 if (CLIPPIXEL(x[i],fy))
148 WRITE_STENCIL( x[i], fy, stencil[i] );
149 }
150 }
151 }
152 HW_ENDCLIPLOOP();
153 #endif /* !HAVE_HW_STENCIL_PIXELS */
154 }
155 HW_WRITE_UNLOCK();
156 }
157
158
159 /* Read stencil spans and pixels
160 */
161 static void TAG(ReadStencilSpan)( GLcontext *ctx,
162 struct gl_renderbuffer *rb,
163 GLuint n, GLint x, GLint y,
164 void *values)
165 {
166 HW_READ_LOCK()
167 {
168 GLubyte *stencil = (GLubyte *) values;
169 GLint x1,n1;
170 LOCAL_STENCIL_VARS;
171
172 y = Y_FLIP(y);
173
174 if (DBG) fprintf(stderr, "ReadStencilSpan\n");
175
176 #if HAVE_HW_STENCIL_SPANS
177 (void) x1; (void) n1;
178
179 READ_STENCIL_SPAN();
180 #else /* HAVE_HW_STENCIL_SPANS */
181 HW_CLIPLOOP()
182 {
183 GLint i = 0;
184 CLIPSPAN(x,y,n,x1,n1,i);
185 for (;n1>0;i++,n1--)
186 READ_STENCIL( stencil[i], (x+i), y );
187 }
188 HW_ENDCLIPLOOP();
189 #endif /* !HAVE_HW_STENCIL_SPANS */
190 }
191 HW_READ_UNLOCK();
192 }
193
194 static void TAG(ReadStencilPixels)( GLcontext *ctx,
195 struct gl_renderbuffer *rb,
196 GLuint n, const GLint x[], const GLint y[],
197 void *values )
198 {
199 HW_READ_LOCK()
200 {
201 GLubyte *stencil = (GLubyte *) values;
202 GLuint i;
203 LOCAL_STENCIL_VARS;
204
205 if (DBG) fprintf(stderr, "ReadStencilPixels\n");
206
207 #if HAVE_HW_STENCIL_PIXELS
208 (void) i;
209
210 READ_STENCIL_PIXELS();
211 #else /* HAVE_HW_STENCIL_PIXELS */
212 HW_CLIPLOOP()
213 {
214 for (i=0;i<n;i++) {
215 int fy = Y_FLIP( y[i] );
216 if (CLIPPIXEL( x[i], fy ))
217 READ_STENCIL( stencil[i], x[i], fy );
218 }
219 }
220 HW_ENDCLIPLOOP();
221 #endif /* !HAVE_HW_STENCIL_PIXELS */
222 }
223 HW_READ_UNLOCK();
224 }
225
226
227
228 /**
229 * Initialize the given renderbuffer's span routines to point to
230 * the stencil functions we generated above.
231 */
232 static void TAG(InitStencilPointers)(struct gl_renderbuffer *rb)
233 {
234 rb->GetRow = TAG(ReadStencilSpan);
235 rb->GetValues = TAG(ReadStencilPixels);
236 rb->PutRow = TAG(WriteStencilSpan);
237 rb->PutRowRGB = NULL;
238 rb->PutMonoRow = TAG(WriteMonoStencilSpan);
239 rb->PutValues = TAG(WriteStencilPixels);
240 rb->PutMonoValues = NULL;
241 }
242
243
244 #undef WRITE_STENCIL
245 #undef READ_STENCIL
246 #undef TAG