950d3c4df49f8ab20dd125a6e8ed051efff3ba41
[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)( struct gl_context *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
65 static void TAG(WriteStencilPixels)( struct gl_context *ctx,
66 struct gl_renderbuffer *rb,
67 GLuint n,
68 const GLint x[], const GLint y[],
69 const void *values, const GLubyte mask[] )
70 {
71 HW_WRITE_LOCK()
72 {
73 const GLubyte *stencil = (const GLubyte *) values;
74 GLuint i;
75 LOCAL_STENCIL_VARS;
76
77 if (DBG) fprintf(stderr, "WriteStencilPixels\n");
78
79 #if HAVE_HW_STENCIL_PIXELS
80 (void) i;
81
82 WRITE_STENCIL_PIXELS();
83 #else /* HAVE_HW_STENCIL_PIXELS */
84 HW_CLIPLOOP()
85 {
86 for (i=0;i<n;i++)
87 {
88 if (mask[i]) {
89 const int fy = Y_FLIP(y[i]);
90 if (CLIPPIXEL(x[i],fy))
91 WRITE_STENCIL( x[i], fy, stencil[i] );
92 }
93 }
94 }
95 HW_ENDCLIPLOOP();
96 #endif /* !HAVE_HW_STENCIL_PIXELS */
97 }
98 HW_WRITE_UNLOCK();
99 }
100
101
102 /* Read stencil spans and pixels
103 */
104 static void TAG(ReadStencilSpan)( struct gl_context *ctx,
105 struct gl_renderbuffer *rb,
106 GLuint n, GLint x, GLint y,
107 void *values)
108 {
109 HW_READ_LOCK()
110 {
111 GLubyte *stencil = (GLubyte *) values;
112 GLint x1,n1;
113 LOCAL_STENCIL_VARS;
114
115 y = Y_FLIP(y);
116
117 if (DBG) fprintf(stderr, "ReadStencilSpan\n");
118
119 #if HAVE_HW_STENCIL_SPANS
120 (void) x1; (void) n1;
121
122 READ_STENCIL_SPAN();
123 #else /* HAVE_HW_STENCIL_SPANS */
124 HW_CLIPLOOP()
125 {
126 GLint i = 0;
127 CLIPSPAN(x,y,n,x1,n1,i);
128 for (;n1>0;i++,n1--)
129 READ_STENCIL( stencil[i], (x+i), y );
130 }
131 HW_ENDCLIPLOOP();
132 #endif /* !HAVE_HW_STENCIL_SPANS */
133 }
134 HW_READ_UNLOCK();
135 }
136
137 static void TAG(ReadStencilPixels)( struct gl_context *ctx,
138 struct gl_renderbuffer *rb,
139 GLuint n, const GLint x[], const GLint y[],
140 void *values )
141 {
142 HW_READ_LOCK()
143 {
144 GLubyte *stencil = (GLubyte *) values;
145 GLuint i;
146 LOCAL_STENCIL_VARS;
147
148 if (DBG) fprintf(stderr, "ReadStencilPixels\n");
149
150 #if HAVE_HW_STENCIL_PIXELS
151 (void) i;
152
153 READ_STENCIL_PIXELS();
154 #else /* HAVE_HW_STENCIL_PIXELS */
155 HW_CLIPLOOP()
156 {
157 for (i=0;i<n;i++) {
158 int fy = Y_FLIP( y[i] );
159 if (CLIPPIXEL( x[i], fy ))
160 READ_STENCIL( stencil[i], x[i], fy );
161 }
162 }
163 HW_ENDCLIPLOOP();
164 #endif /* !HAVE_HW_STENCIL_PIXELS */
165 }
166 HW_READ_UNLOCK();
167 }
168
169
170
171 /**
172 * Initialize the given renderbuffer's span routines to point to
173 * the stencil functions we generated above.
174 */
175 static void TAG(InitStencilPointers)(struct gl_renderbuffer *rb)
176 {
177 rb->GetRow = TAG(ReadStencilSpan);
178 rb->GetValues = TAG(ReadStencilPixels);
179 rb->PutRow = TAG(WriteStencilSpan);
180 rb->PutValues = TAG(WriteStencilPixels);
181 }
182
183
184 #undef WRITE_STENCIL
185 #undef READ_STENCIL
186 #undef TAG