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.
10 #include "spantmp_common.h"
16 #ifndef HAVE_HW_DEPTH_SPANS
17 #define HAVE_HW_DEPTH_SPANS 0
20 #ifndef HAVE_HW_DEPTH_PIXELS
21 #define HAVE_HW_DEPTH_PIXELS 0
24 static void TAG(WriteDepthSpan)( struct gl_context *ctx,
25 struct gl_renderbuffer *rb,
26 GLuint n, GLint x, GLint y,
28 const GLubyte mask[] )
32 const VALUE_TYPE *depth = (const VALUE_TYPE *) values;
39 #if HAVE_HW_DEPTH_SPANS
42 if ( DBG ) fprintf( stderr, "WriteDepthSpan 0..%d (x1 %d)\n",
50 CLIPSPAN( x, y, n, x1, n1, i );
52 if ( DBG ) fprintf( stderr, "WriteDepthSpan %d..%d (x1 %d) (mask %p)\n",
53 (int)i, (int)n1, (int)x1, mask );
56 for ( ; n1>0 ; i++, x1++, n1-- ) {
57 if ( mask[i] ) WRITE_DEPTH( x1, y, depth[i] );
60 for ( ; n1>0 ; i++, x1++, n1-- ) {
61 WRITE_DEPTH( x1, y, depth[i] );
72 #if HAVE_HW_DEPTH_SPANS
73 /* implement MonoWriteDepthSpan() in terms of WriteDepthSpan() */
75 TAG(WriteMonoDepthSpan)( struct gl_context *ctx, struct gl_renderbuffer *rb,
76 GLuint n, GLint x, GLint y,
77 const void *value, const GLubyte mask[] )
79 const GLuint depthVal = *((GLuint *) value);
80 GLuint depths[MAX_WIDTH];
82 for (i = 0; i < n; i++)
84 TAG(WriteDepthSpan)(ctx, rb, n, x, y, depths, mask);
87 static void TAG(WriteMonoDepthSpan)( struct gl_context *ctx,
88 struct gl_renderbuffer *rb,
89 GLuint n, GLint x, GLint y,
91 const GLubyte mask[] )
95 const GLuint depth = *((GLuint *) value);
105 CLIPSPAN( x, y, n, x1, n1, i );
107 if ( DBG ) fprintf( stderr, "%s %d..%d (x1 %d) = %u\n",
108 __FUNCTION__, (int)i, (int)n1, (int)x1, (GLuint)depth );
111 for ( ; n1>0 ; i++, x1++, n1-- ) {
112 if ( mask[i] ) WRITE_DEPTH( x1, y, depth );
115 for ( ; n1>0 ; x1++, n1-- ) {
116 WRITE_DEPTH( x1, y, depth );
127 static void TAG(WriteDepthPixels)( struct gl_context *ctx,
128 struct gl_renderbuffer *rb,
133 const GLubyte mask[] )
137 const VALUE_TYPE *depth = (const VALUE_TYPE *) values;
141 if ( DBG ) fprintf( stderr, "WriteDepthPixels\n" );
143 #if HAVE_HW_DEPTH_PIXELS
146 WRITE_DEPTH_PIXELS();
151 for ( i = 0 ; i < n ; i++ ) {
153 const int fy = Y_FLIP( y[i] );
154 if ( CLIPPIXEL( x[i], fy ) )
155 WRITE_DEPTH( x[i], fy, depth[i] );
160 for ( i = 0 ; i < n ; i++ ) {
161 const int fy = Y_FLIP( y[i] );
162 if ( CLIPPIXEL( x[i], fy ) )
163 WRITE_DEPTH( x[i], fy, depth[i] );
174 /* Read depth spans and pixels
176 static void TAG(ReadDepthSpan)( struct gl_context *ctx,
177 struct gl_renderbuffer *rb,
178 GLuint n, GLint x, GLint y,
183 VALUE_TYPE *depth = (VALUE_TYPE *) values;
189 if ( DBG ) fprintf( stderr, "ReadDepthSpan\n" );
191 #if HAVE_HW_DEPTH_SPANS
192 (void) x1; (void) n1;
199 CLIPSPAN( x, y, n, x1, n1, i );
200 for ( ; n1>0 ; i++, n1-- ) {
201 READ_DEPTH( depth[i], x+i, y );
210 static void TAG(ReadDepthPixels)( struct gl_context *ctx,
211 struct gl_renderbuffer *rb,
213 const GLint x[], const GLint y[],
218 VALUE_TYPE *depth = (VALUE_TYPE *) values;
222 if ( DBG ) fprintf( stderr, "ReadDepthPixels\n" );
224 #if HAVE_HW_DEPTH_PIXELS
231 for ( i = 0 ; i < n ;i++ ) {
232 int fy = Y_FLIP( y[i] );
233 if ( CLIPPIXEL( x[i], fy ) )
234 READ_DEPTH( depth[i], x[i], fy );
245 * Initialize the given renderbuffer's span routines to point to
246 * the depth/z functions we generated above.
248 static void TAG(InitDepthPointers)(struct gl_renderbuffer *rb)
250 rb->GetRow = TAG(ReadDepthSpan);
251 rb->GetValues = TAG(ReadDepthPixels);
252 rb->PutRow = TAG(WriteDepthSpan);
253 rb->PutRowRGB = NULL;
254 rb->PutMonoRow = TAG(WriteMonoDepthSpan);
255 rb->PutValues = TAG(WriteDepthPixels);
256 rb->PutMonoValues = NULL;
260 #if HAVE_HW_DEPTH_SPANS
261 #undef WRITE_DEPTH_SPAN
262 #undef WRITE_DEPTH_PIXELS
263 #undef READ_DEPTH_SPAN
264 #undef READ_DEPTH_PIXELS