dri: Remove unnecessary timestamp pointer indirection
[mesa.git] / src / mesa / drivers / dri / common / depthtmp.h
1
2 /*
3 * Notes:
4 * 1. These functions plug into the gl_renderbuffer structure.
5 * 2. The 'values' parameter always points to GLuint values, regardless of
6 * the actual Z buffer depth.
7 */
8
9
10 #include "spantmp_common.h"
11
12 #ifndef DBG
13 #define DBG 0
14 #endif
15
16 #ifndef HAVE_HW_DEPTH_SPANS
17 #define HAVE_HW_DEPTH_SPANS 0
18 #endif
19
20 #ifndef HAVE_HW_DEPTH_PIXELS
21 #define HAVE_HW_DEPTH_PIXELS 0
22 #endif
23
24 static void TAG(WriteDepthSpan)( struct gl_context *ctx,
25 struct gl_renderbuffer *rb,
26 GLuint n, GLint x, GLint y,
27 const void *values,
28 const GLubyte mask[] )
29 {
30 HW_WRITE_LOCK()
31 {
32 const VALUE_TYPE *depth = (const VALUE_TYPE *) values;
33 GLint x1;
34 GLint n1;
35 LOCAL_DEPTH_VARS;
36
37 y = Y_FLIP( y );
38
39 #if HAVE_HW_DEPTH_SPANS
40 (void) x1; (void) n1;
41
42 if ( DBG ) fprintf( stderr, "WriteDepthSpan 0..%d (x1 %d)\n",
43 (int)n, (int)x );
44
45 WRITE_DEPTH_SPAN();
46 #else
47 HW_CLIPLOOP()
48 {
49 GLint i = 0;
50 CLIPSPAN( x, y, n, x1, n1, i );
51
52 if ( DBG ) fprintf( stderr, "WriteDepthSpan %d..%d (x1 %d) (mask %p)\n",
53 (int)i, (int)n1, (int)x1, mask );
54
55 if ( mask ) {
56 for ( ; n1>0 ; i++, x1++, n1-- ) {
57 if ( mask[i] ) WRITE_DEPTH( x1, y, depth[i] );
58 }
59 } else {
60 for ( ; n1>0 ; i++, x1++, n1-- ) {
61 WRITE_DEPTH( x1, y, depth[i] );
62 }
63 }
64 }
65 HW_ENDCLIPLOOP();
66 #endif
67 }
68 HW_WRITE_UNLOCK();
69
70 (void) ctx;
71 }
72
73
74 #if HAVE_HW_DEPTH_SPANS
75 /* implement MonoWriteDepthSpan() in terms of WriteDepthSpan() */
76 static void
77 TAG(WriteMonoDepthSpan)( struct gl_context *ctx, struct gl_renderbuffer *rb,
78 GLuint n, GLint x, GLint y,
79 const void *value, const GLubyte mask[] )
80 {
81 const GLuint depthVal = *((GLuint *) value);
82 GLuint depths[MAX_WIDTH];
83 GLuint i;
84 for (i = 0; i < n; i++)
85 depths[i] = depthVal;
86 TAG(WriteDepthSpan)(ctx, rb, n, x, y, depths, mask);
87 }
88 #else
89 static void TAG(WriteMonoDepthSpan)( struct gl_context *ctx,
90 struct gl_renderbuffer *rb,
91 GLuint n, GLint x, GLint y,
92 const void *value,
93 const GLubyte mask[] )
94 {
95 HW_WRITE_LOCK()
96 {
97 const GLuint depth = *((GLuint *) value);
98 GLint x1;
99 GLint n1;
100 LOCAL_DEPTH_VARS;
101
102 y = Y_FLIP( y );
103
104 HW_CLIPLOOP()
105 {
106 GLint i = 0;
107 CLIPSPAN( x, y, n, x1, n1, i );
108
109 if ( DBG ) fprintf( stderr, "%s %d..%d (x1 %d) = %u\n",
110 __FUNCTION__, (int)i, (int)n1, (int)x1, (GLuint)depth );
111
112 if ( mask ) {
113 for ( ; n1>0 ; i++, x1++, n1-- ) {
114 if ( mask[i] ) WRITE_DEPTH( x1, y, depth );
115 }
116 } else {
117 for ( ; n1>0 ; x1++, n1-- ) {
118 WRITE_DEPTH( x1, y, depth );
119 }
120 }
121 }
122 HW_ENDCLIPLOOP();
123 }
124 HW_WRITE_UNLOCK();
125
126 (void) ctx;
127 }
128 #endif
129
130
131 static void TAG(WriteDepthPixels)( struct gl_context *ctx,
132 struct gl_renderbuffer *rb,
133 GLuint n,
134 const GLint x[],
135 const GLint y[],
136 const void *values,
137 const GLubyte mask[] )
138 {
139 HW_WRITE_LOCK()
140 {
141 const VALUE_TYPE *depth = (const VALUE_TYPE *) values;
142 GLuint i;
143 LOCAL_DEPTH_VARS;
144
145 if ( DBG ) fprintf( stderr, "WriteDepthPixels\n" );
146
147 #if HAVE_HW_DEPTH_PIXELS
148 (void) i;
149
150 WRITE_DEPTH_PIXELS();
151 #else
152 HW_CLIPLOOP()
153 {
154 if ( mask ) {
155 for ( i = 0 ; i < n ; i++ ) {
156 if ( mask[i] ) {
157 const int fy = Y_FLIP( y[i] );
158 if ( CLIPPIXEL( x[i], fy ) )
159 WRITE_DEPTH( x[i], fy, depth[i] );
160 }
161 }
162 }
163 else {
164 for ( i = 0 ; i < n ; i++ ) {
165 const int fy = Y_FLIP( y[i] );
166 if ( CLIPPIXEL( x[i], fy ) )
167 WRITE_DEPTH( x[i], fy, depth[i] );
168 }
169 }
170 }
171 HW_ENDCLIPLOOP();
172 #endif
173 }
174 HW_WRITE_UNLOCK();
175
176 (void) ctx;
177 }
178
179
180 /* Read depth spans and pixels
181 */
182 static void TAG(ReadDepthSpan)( struct gl_context *ctx,
183 struct gl_renderbuffer *rb,
184 GLuint n, GLint x, GLint y,
185 void *values )
186 {
187 HW_READ_LOCK()
188 {
189 VALUE_TYPE *depth = (VALUE_TYPE *) values;
190 GLint x1, n1;
191 LOCAL_DEPTH_VARS;
192
193 y = Y_FLIP( y );
194
195 if ( DBG ) fprintf( stderr, "ReadDepthSpan\n" );
196
197 #if HAVE_HW_DEPTH_SPANS
198 (void) x1; (void) n1;
199
200 READ_DEPTH_SPAN();
201 #else
202 HW_CLIPLOOP()
203 {
204 GLint i = 0;
205 CLIPSPAN( x, y, n, x1, n1, i );
206 for ( ; n1>0 ; i++, n1-- ) {
207 READ_DEPTH( depth[i], x+i, y );
208 }
209 }
210 HW_ENDCLIPLOOP();
211 #endif
212 }
213 HW_READ_UNLOCK();
214 }
215
216 static void TAG(ReadDepthPixels)( struct gl_context *ctx,
217 struct gl_renderbuffer *rb,
218 GLuint n,
219 const GLint x[], const GLint y[],
220 void *values )
221 {
222 HW_READ_LOCK()
223 {
224 VALUE_TYPE *depth = (VALUE_TYPE *) values;
225 GLuint i;
226 LOCAL_DEPTH_VARS;
227
228 if ( DBG ) fprintf( stderr, "ReadDepthPixels\n" );
229
230 #if HAVE_HW_DEPTH_PIXELS
231 (void) i;
232
233 READ_DEPTH_PIXELS();
234 #else
235 HW_CLIPLOOP()
236 {
237 for ( i = 0 ; i < n ;i++ ) {
238 int fy = Y_FLIP( y[i] );
239 if ( CLIPPIXEL( x[i], fy ) )
240 READ_DEPTH( depth[i], x[i], fy );
241 }
242 }
243 HW_ENDCLIPLOOP();
244 #endif
245 }
246 HW_READ_UNLOCK();
247
248 (void) ctx;
249 }
250
251
252 /**
253 * Initialize the given renderbuffer's span routines to point to
254 * the depth/z functions we generated above.
255 */
256 static void TAG(InitDepthPointers)(struct gl_renderbuffer *rb)
257 {
258 rb->GetRow = TAG(ReadDepthSpan);
259 rb->GetValues = TAG(ReadDepthPixels);
260 rb->PutRow = TAG(WriteDepthSpan);
261 rb->PutRowRGB = NULL;
262 rb->PutMonoRow = TAG(WriteMonoDepthSpan);
263 rb->PutValues = TAG(WriteDepthPixels);
264 rb->PutMonoValues = NULL;
265 }
266
267
268 #if HAVE_HW_DEPTH_SPANS
269 #undef WRITE_DEPTH_SPAN
270 #undef WRITE_DEPTH_PIXELS
271 #undef READ_DEPTH_SPAN
272 #undef READ_DEPTH_PIXELS
273 #else
274 #undef WRITE_DEPTH
275 #undef READ_DEPTH
276 #endif
277 #undef TAG
278 #undef VALUE_TYPE