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