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
] );
74 #if HAVE_HW_DEPTH_SPANS
75 /* implement MonoWriteDepthSpan() in terms of WriteDepthSpan() */
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
[] )
81 const GLuint depthVal
= *((GLuint
*) value
);
82 GLuint depths
[MAX_WIDTH
];
84 for (i
= 0; i
< n
; i
++)
86 TAG(WriteDepthSpan
)(ctx
, rb
, n
, x
, y
, depths
, mask
);
89 static void TAG(WriteMonoDepthSpan
)( struct gl_context
*ctx
,
90 struct gl_renderbuffer
*rb
,
91 GLuint n
, GLint x
, GLint y
,
93 const GLubyte mask
[] )
97 const GLuint depth
= *((GLuint
*) value
);
107 CLIPSPAN( x
, y
, n
, x1
, n1
, i
);
109 if ( DBG
) fprintf( stderr
, "%s %d..%d (x1 %d) = %u\n",
110 __FUNCTION__
, (int)i
, (int)n1
, (int)x1
, (GLuint
)depth
);
113 for ( ; n1
>0 ; i
++, x1
++, n1
-- ) {
114 if ( mask
[i
] ) WRITE_DEPTH( x1
, y
, depth
);
117 for ( ; n1
>0 ; x1
++, n1
-- ) {
118 WRITE_DEPTH( x1
, y
, depth
);
131 static void TAG(WriteDepthPixels
)( struct gl_context
*ctx
,
132 struct gl_renderbuffer
*rb
,
137 const GLubyte mask
[] )
141 const VALUE_TYPE
*depth
= (const VALUE_TYPE
*) values
;
145 if ( DBG
) fprintf( stderr
, "WriteDepthPixels\n" );
147 #if HAVE_HW_DEPTH_PIXELS
150 WRITE_DEPTH_PIXELS();
155 for ( i
= 0 ; i
< n
; i
++ ) {
157 const int fy
= Y_FLIP( y
[i
] );
158 if ( CLIPPIXEL( x
[i
], fy
) )
159 WRITE_DEPTH( x
[i
], fy
, depth
[i
] );
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
] );
180 /* Read depth spans and pixels
182 static void TAG(ReadDepthSpan
)( struct gl_context
*ctx
,
183 struct gl_renderbuffer
*rb
,
184 GLuint n
, GLint x
, GLint y
,
189 VALUE_TYPE
*depth
= (VALUE_TYPE
*) values
;
195 if ( DBG
) fprintf( stderr
, "ReadDepthSpan\n" );
197 #if HAVE_HW_DEPTH_SPANS
198 (void) x1
; (void) n1
;
205 CLIPSPAN( x
, y
, n
, x1
, n1
, i
);
206 for ( ; n1
>0 ; i
++, n1
-- ) {
207 READ_DEPTH( depth
[i
], x
+i
, y
);
216 static void TAG(ReadDepthPixels
)( struct gl_context
*ctx
,
217 struct gl_renderbuffer
*rb
,
219 const GLint x
[], const GLint y
[],
224 VALUE_TYPE
*depth
= (VALUE_TYPE
*) values
;
228 if ( DBG
) fprintf( stderr
, "ReadDepthPixels\n" );
230 #if HAVE_HW_DEPTH_PIXELS
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
);
253 * Initialize the given renderbuffer's span routines to point to
254 * the depth/z functions we generated above.
256 static void TAG(InitDepthPointers
)(struct gl_renderbuffer
*rb
)
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
;
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