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