1 /* $XFree86: xc/lib/GL/mesa/src/drv/r128/r128_span.c,v 1.8 2002/10/30 12:51:39 alanh Exp $ */
2 /**************************************************************************
4 Copyright 1999, 2000 ATI Technologies Inc. and Precision Insight, Inc.,
8 Permission is hereby granted, free of charge, to any person obtaining a
9 copy of this software and associated documentation files (the "Software"),
10 to deal in the Software without restriction, including without limitation
11 on the rights to use, copy, modify, merge, publish, distribute, sub
12 license, and/or sell copies of the Software, and to permit persons to whom
13 the Software is furnished to do so, subject to the following conditions:
15 The above copyright notice and this permission notice (including the next
16 paragraph) shall be included in all copies or substantial portions of the
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
22 ATI, PRECISION INSIGHT AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
23 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
25 USE OR OTHER DEALINGS IN THE SOFTWARE.
27 **************************************************************************/
31 * Gareth Hughes <gareth@valinux.com>
32 * Keith Whitwell <keith@tungstengraphics.com>
33 * Kevin E. Martin <martin@valinux.com>
37 #include "r128_context.h"
38 #include "r128_ioctl.h"
39 #include "r128_state.h"
40 #include "r128_span.h"
43 #include "swrast/swrast.h"
47 #define HAVE_HW_DEPTH_SPANS 1
48 #define HAVE_HW_DEPTH_PIXELS 1
51 r128ContextPtr rmesa = R128_CONTEXT(ctx); \
52 __DRIscreenPrivate *sPriv = rmesa->driScreen; \
53 __DRIdrawablePrivate *dPriv = rmesa->driDrawable; \
54 driRenderbuffer *drb = (driRenderbuffer *) rb; \
55 GLuint height = dPriv->h; \
59 #define LOCAL_DEPTH_VARS \
60 r128ContextPtr rmesa = R128_CONTEXT(ctx); \
61 r128ScreenPtr r128scrn = rmesa->r128Screen; \
62 __DRIscreenPrivate *sPriv = rmesa->driScreen; \
63 __DRIdrawablePrivate *dPriv = rmesa->driDrawable; \
64 GLuint height = dPriv->h; \
65 (void) r128scrn; (void) sPriv; (void) height
67 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
69 #define Y_FLIP( _y ) (height - _y - 1)
77 /* ================================================================
81 /* 16 bit, RGB565 color spanline and pixel functions
83 #define SPANTMP_PIXEL_FMT GL_RGB
84 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
86 #define TAG(x) r128##x##_RGB565
87 #define TAG2(x,y) r128##x##_RGB565##y
88 #define GET_PTR(X,Y) (sPriv->pFB + drb->flippedOffset \
89 + ((dPriv->y + (Y)) * drb->flippedPitch + (dPriv->x + (X))) * drb->cpp)
93 /* 32 bit, ARGB8888 color spanline and pixel functions
95 #define SPANTMP_PIXEL_FMT GL_BGRA
96 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
98 #define TAG(x) r128##x##_ARGB8888
99 #define TAG2(x,y) r128##x##_ARGB8888##y
100 #define GET_PTR(X,Y) (sPriv->pFB + drb->flippedOffset \
101 + ((dPriv->y + (Y)) * drb->flippedPitch + (dPriv->x + (X))) * drb->cpp)
102 #include "spantmp2.h"
105 /* ================================================================
109 /* 16-bit depth buffer functions
112 #define WRITE_DEPTH_SPAN() \
113 r128WriteDepthSpanLocked( rmesa, n, \
118 #define WRITE_DEPTH_PIXELS() \
120 GLint ox[MAX_WIDTH]; \
121 GLint oy[MAX_WIDTH]; \
122 for ( i = 0 ; i < n ; i++ ) { \
123 ox[i] = x[i] + dPriv->x; \
124 oy[i] = Y_FLIP( y[i] ) + dPriv->y; \
126 r128WriteDepthPixelsLocked( rmesa, n, ox, oy, depth, mask ); \
129 #define READ_DEPTH_SPAN() \
131 GLushort *buf = (GLushort *)((GLubyte *)sPriv->pFB + \
132 r128scrn->spanOffset); \
135 r128ReadDepthSpanLocked( rmesa, n, \
138 r128WaitForIdleLocked( rmesa ); \
140 for ( i = 0 ; i < n ; i++ ) { \
145 #define READ_DEPTH_PIXELS() \
147 GLushort *buf = (GLushort *)((GLubyte *)sPriv->pFB + \
148 r128scrn->spanOffset); \
149 GLint i, remaining = n; \
151 while ( remaining > 0 ) { \
156 if ( remaining <= 128 ) { \
161 for ( i = 0 ; i < count ; i++ ) { \
162 ox[i] = x[i] + dPriv->x; \
163 oy[i] = Y_FLIP( y[i] ) + dPriv->y; \
166 r128ReadDepthPixelsLocked( rmesa, count, ox, oy ); \
167 r128WaitForIdleLocked( rmesa ); \
169 for ( i = 0 ; i < count ; i++ ) { \
175 remaining -= count; \
179 #define TAG(x) r128##x##_z16
180 #include "depthtmp.h"
183 /* 24-bit depth, 8-bit stencil buffer functions
185 #define WRITE_DEPTH_SPAN() \
186 r128WriteDepthSpanLocked( rmesa, n, \
191 #define WRITE_DEPTH_PIXELS() \
193 GLint ox[MAX_WIDTH]; \
194 GLint oy[MAX_WIDTH]; \
195 for ( i = 0 ; i < n ; i++ ) { \
196 ox[i] = x[i] + dPriv->x; \
197 oy[i] = Y_FLIP( y[i] ) + dPriv->y; \
199 r128WriteDepthPixelsLocked( rmesa, n, ox, oy, depth, mask ); \
202 #define READ_DEPTH_SPAN() \
204 GLuint *buf = (GLuint *)((GLubyte *)sPriv->pFB + \
205 r128scrn->spanOffset); \
208 r128ReadDepthSpanLocked( rmesa, n, \
211 r128WaitForIdleLocked( rmesa ); \
213 for ( i = 0 ; i < n ; i++ ) { \
214 depth[i] = buf[i] & 0x00ffffff; \
218 #define READ_DEPTH_PIXELS() \
220 GLuint *buf = (GLuint *)((GLubyte *)sPriv->pFB + \
221 r128scrn->spanOffset); \
222 GLint i, remaining = n; \
224 while ( remaining > 0 ) { \
229 if ( remaining <= 128 ) { \
234 for ( i = 0 ; i < count ; i++ ) { \
235 ox[i] = x[i] + dPriv->x; \
236 oy[i] = Y_FLIP( y[i] ) + dPriv->y; \
239 r128ReadDepthPixelsLocked( rmesa, count, ox, oy ); \
240 r128WaitForIdleLocked( rmesa ); \
242 for ( i = 0 ; i < count ; i++ ) { \
243 depth[i] = buf[i] & 0x00ffffff; \
248 remaining -= count; \
252 #define TAG(x) r128##x##_z24_s8
253 #include "depthtmp.h"
257 /* ================================================================
261 /* FIXME: Add support for hardware stencil buffers.
265 r128SpanRenderStart( GLcontext
*ctx
)
267 r128ContextPtr rmesa
= R128_CONTEXT(ctx
);
269 LOCK_HARDWARE(rmesa
);
270 r128WaitForIdleLocked( rmesa
);
274 r128SpanRenderFinish( GLcontext
*ctx
)
276 r128ContextPtr rmesa
= R128_CONTEXT(ctx
);
277 _swrast_flush( ctx
);
278 UNLOCK_HARDWARE( rmesa
);
281 void r128DDInitSpanFuncs( GLcontext
*ctx
)
283 struct swrast_device_driver
*swdd
= _swrast_GetDeviceDriverReference(ctx
);
284 swdd
->SpanRenderStart
= r128SpanRenderStart
;
285 swdd
->SpanRenderFinish
= r128SpanRenderFinish
;
290 * Plug in the Get/Put routines for the given driRenderbuffer.
293 r128SetSpanFunctions(driRenderbuffer
*drb
, const GLvisual
*vis
)
295 if (drb
->Base
.InternalFormat
== GL_RGBA
) {
296 if (vis
->redBits
== 5 && vis
->greenBits
== 6 && vis
->blueBits
== 5) {
297 r128InitPointers_RGB565(&drb
->Base
);
300 r128InitPointers_ARGB8888(&drb
->Base
);
303 else if (drb
->Base
.InternalFormat
== GL_DEPTH_COMPONENT16
) {
304 r128InitDepthPointers_z16(&drb
->Base
);
306 else if (drb
->Base
.InternalFormat
== GL_DEPTH_COMPONENT24
) {
307 r128InitDepthPointers_z24_s8(&drb
->Base
);