d8f259f67897ace2e887361285ee80d0d19e0133
[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 static void TAG(WriteDepthPixels)( struct gl_context *ctx,
75 struct gl_renderbuffer *rb,
76 GLuint n,
77 const GLint x[],
78 const GLint y[],
79 const void *values,
80 const GLubyte mask[] )
81 {
82 HW_WRITE_LOCK()
83 {
84 const VALUE_TYPE *depth = (const VALUE_TYPE *) values;
85 GLuint i;
86 LOCAL_DEPTH_VARS;
87
88 if ( DBG ) fprintf( stderr, "WriteDepthPixels\n" );
89
90 #if HAVE_HW_DEPTH_PIXELS
91 (void) i;
92
93 WRITE_DEPTH_PIXELS();
94 #else
95 HW_CLIPLOOP()
96 {
97 if ( mask ) {
98 for ( i = 0 ; i < n ; i++ ) {
99 if ( mask[i] ) {
100 const int fy = Y_FLIP( y[i] );
101 if ( CLIPPIXEL( x[i], fy ) )
102 WRITE_DEPTH( x[i], fy, depth[i] );
103 }
104 }
105 }
106 else {
107 for ( i = 0 ; i < n ; i++ ) {
108 const int fy = Y_FLIP( y[i] );
109 if ( CLIPPIXEL( x[i], fy ) )
110 WRITE_DEPTH( x[i], fy, depth[i] );
111 }
112 }
113 }
114 HW_ENDCLIPLOOP();
115 #endif
116 }
117 HW_WRITE_UNLOCK();
118
119 (void) ctx;
120 }
121
122
123 /* Read depth spans and pixels
124 */
125 static void TAG(ReadDepthSpan)( struct gl_context *ctx,
126 struct gl_renderbuffer *rb,
127 GLuint n, GLint x, GLint y,
128 void *values )
129 {
130 HW_READ_LOCK()
131 {
132 VALUE_TYPE *depth = (VALUE_TYPE *) values;
133 GLint x1, n1;
134 LOCAL_DEPTH_VARS;
135
136 y = Y_FLIP( y );
137
138 if ( DBG ) fprintf( stderr, "ReadDepthSpan\n" );
139
140 #if HAVE_HW_DEPTH_SPANS
141 (void) x1; (void) n1;
142
143 READ_DEPTH_SPAN();
144 #else
145 HW_CLIPLOOP()
146 {
147 GLint i = 0;
148 CLIPSPAN( x, y, n, x1, n1, i );
149 for ( ; n1>0 ; i++, n1-- ) {
150 READ_DEPTH( depth[i], x+i, y );
151 }
152 }
153 HW_ENDCLIPLOOP();
154 #endif
155 }
156 HW_READ_UNLOCK();
157 }
158
159 static void TAG(ReadDepthPixels)( struct gl_context *ctx,
160 struct gl_renderbuffer *rb,
161 GLuint n,
162 const GLint x[], const GLint y[],
163 void *values )
164 {
165 HW_READ_LOCK()
166 {
167 VALUE_TYPE *depth = (VALUE_TYPE *) values;
168 GLuint i;
169 LOCAL_DEPTH_VARS;
170
171 if ( DBG ) fprintf( stderr, "ReadDepthPixels\n" );
172
173 #if HAVE_HW_DEPTH_PIXELS
174 (void) i;
175
176 READ_DEPTH_PIXELS();
177 #else
178 HW_CLIPLOOP()
179 {
180 for ( i = 0 ; i < n ;i++ ) {
181 int fy = Y_FLIP( y[i] );
182 if ( CLIPPIXEL( x[i], fy ) )
183 READ_DEPTH( depth[i], x[i], fy );
184 }
185 }
186 HW_ENDCLIPLOOP();
187 #endif
188 }
189 HW_READ_UNLOCK();
190
191 (void) ctx;
192 }
193
194
195 /**
196 * Initialize the given renderbuffer's span routines to point to
197 * the depth/z functions we generated above.
198 */
199 static void TAG(InitDepthPointers)(struct gl_renderbuffer *rb)
200 {
201 rb->GetRow = TAG(ReadDepthSpan);
202 rb->GetValues = TAG(ReadDepthPixels);
203 rb->PutRow = TAG(WriteDepthSpan);
204 rb->PutValues = TAG(WriteDepthPixels);
205 }
206
207
208 #if HAVE_HW_DEPTH_SPANS
209 #undef WRITE_DEPTH_SPAN
210 #undef WRITE_DEPTH_PIXELS
211 #undef READ_DEPTH_SPAN
212 #undef READ_DEPTH_PIXELS
213 #else
214 #undef WRITE_DEPTH
215 #undef READ_DEPTH
216 #endif
217 #undef TAG
218 #undef VALUE_TYPE