2 * Copyright 2000-2001 VA Linux Systems, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
25 * Keith Whitwell <keith@tungstengraphics.com>
27 /* $XFree86: xc/lib/GL/mesa/src/drv/mga/mgaspan.c,v 1.11 2002/10/30 12:51:36 alanh Exp $ */
31 #include "mgacontext.h"
34 #include "swrast/swrast.h"
40 __DRIdrawablePrivate *dPriv = mmesa->driDrawable; \
41 mgaScreenPrivate *mgaScreen = mmesa->mgaScreen; \
42 __DRIscreenPrivate *sPriv = mmesa->driScreen; \
43 GLuint pitch = mgaScreen->frontPitch; \
44 GLuint height = dPriv->h; \
45 char *read_buf = (char *)(sPriv->pFB + \
47 dPriv->x * mgaScreen->cpp + \
49 char *buf = (char *)(sPriv->pFB + \
51 dPriv->x * mgaScreen->cpp + \
54 (void) read_buf; (void) buf; (void) p
58 #define LOCAL_DEPTH_VARS \
59 __DRIdrawablePrivate *dPriv = mmesa->driDrawable; \
60 mgaScreenPrivate *mgaScreen = mmesa->mgaScreen; \
61 __DRIscreenPrivate *sPriv = mmesa->driScreen; \
62 GLuint pitch = mgaScreen->frontPitch; \
63 GLuint height = dPriv->h; \
64 char *buf = (char *)(sPriv->pFB + \
65 mgaScreen->depthOffset + \
66 dPriv->x * mgaScreen->cpp + \
69 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
71 #define CLIPPIXEL(_x,_y) (_x >= minx && _x < maxx && \
72 _y >= miny && _y < maxy)
74 #define CLIPSPAN( _x, _y, _n, _x1, _n1, _i ) \
75 if ( _y < miny || _y >= maxy ) { \
80 if ( _x1 < minx ) _i += (minx-_x1), n1 -= (minx-_x1), _x1 = minx; \
81 if ( _x1 + _n1 >= maxx ) n1 -= (_x1 + n1 - maxx); \
86 mgaContextPtr mmesa = MGA_CONTEXT(ctx); \
88 LOCK_HARDWARE_QUIESCENT(mmesa);
91 #define HW_CLIPLOOP() \
93 int _nc = mmesa->numClipRects; \
95 int minx = mmesa->pClipRects[_nc].x1 - mmesa->drawX; \
96 int miny = mmesa->pClipRects[_nc].y1 - mmesa->drawY; \
97 int maxx = mmesa->pClipRects[_nc].x2 - mmesa->drawX; \
98 int maxy = mmesa->pClipRects[_nc].y2 - mmesa->drawY;
100 #define HW_ENDCLIPLOOP() \
104 #define HW_UNLOCK() \
105 UNLOCK_HARDWARE(mmesa);
113 /* 16 bit, 565 rgb color spanline and pixel functions
115 #define Y_FLIP(_y) (height - _y - 1)
117 #undef INIT_MONO_PIXEL
118 #define INIT_MONO_PIXEL(p, color) \
119 p = PACK_COLOR_565( color[0], color[1], color[2] )
122 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
123 *(GLushort *)(buf + _x*2 + _y*pitch) = ( (((int)r & 0xf8) << 8) | \
124 (((int)g & 0xfc) << 3) | \
125 (((int)b & 0xf8) >> 3))
127 #define WRITE_PIXEL( _x, _y, p ) \
128 *(GLushort *)(buf + _x*2 + _y*pitch) = p
130 #define READ_RGBA( rgba, _x, _y ) \
132 GLushort p = *(GLushort *)(read_buf + _x*2 + _y*pitch); \
133 rgba[0] = (((p >> 11) & 0x1f) * 255) / 31; \
134 rgba[1] = (((p >> 5) & 0x3f) * 255) / 63; \
135 rgba[2] = (((p >> 0) & 0x1f) * 255) / 31; \
139 #define TAG(x) mga##x##_565
146 /* 32 bit, 8888 argb color spanline and pixel functions
149 #undef INIT_MONO_PIXEL
150 #define INIT_MONO_PIXEL(p, color) \
151 p = PACK_COLOR_8888( color[3], color[0], color[1], color[2] )
154 #define WRITE_RGBA(_x, _y, r, g, b, a) \
155 *(GLuint *)(buf + _x*4 + _y*pitch) = ((r << 16) | \
160 #define WRITE_PIXEL(_x, _y, p) \
161 *(GLuint *)(buf + _x*4 + _y*pitch) = p
163 #define READ_RGBA(rgba, _x, _y) \
165 GLuint p = *(GLuint *)(read_buf + _x*4 + _y*pitch); \
166 rgba[0] = (p >> 16) & 0xff; \
167 rgba[1] = (p >> 8) & 0xff; \
168 rgba[2] = (p >> 0) & 0xff; \
172 #define TAG(x) mga##x##_8888
178 /* 16 bit depthbuffer functions.
180 #define WRITE_DEPTH( _x, _y, d ) \
181 *(GLushort *)(buf + _x*2 + _y*pitch) = d;
183 #define READ_DEPTH( d, _x, _y ) \
184 d = *(GLushort *)(buf + _x*2 + _y*pitch);
186 #define TAG(x) mga##x##_16
187 #include "depthtmp.h"
192 /* 32 bit depthbuffer functions.
194 #define WRITE_DEPTH( _x, _y, d ) \
195 *(GLuint *)(buf + _x*4 + _y*pitch) = d;
197 #define READ_DEPTH( d, _x, _y ) \
198 d = *(GLuint *)(buf + _x*4 + _y*pitch);
200 #define TAG(x) mga##x##_32
201 #include "depthtmp.h"
205 /* 24/8 bit interleaved depth/stencil functions
207 #define WRITE_DEPTH( _x, _y, d ) { \
208 GLuint tmp = *(GLuint *)(buf + _x*4 + _y*pitch); \
211 *(GLuint *)(buf + _x*4 + _y*pitch) = tmp; \
214 #define READ_DEPTH( d, _x, _y ) { \
215 d = (*(GLuint *)(buf + _x*4 + _y*pitch) & ~0xff) >> 8; \
218 #define TAG(x) mga##x##_24_8
219 #include "depthtmp.h"
221 #define WRITE_STENCIL( _x, _y, d ) { \
222 GLuint tmp = *(GLuint *)(buf + _x*4 + _y*pitch); \
225 *(GLuint *)(buf + _x*4 + _y*pitch) = tmp; \
228 #define READ_STENCIL( d, _x, _y ) \
229 d = *(GLuint *)(buf + _x*4 + _y*pitch) & 0xff;
231 #define TAG(x) mga##x##_24_8
232 #include "stenciltmp.h"
237 * This function is called to specify which buffer to read and write
238 * for software rasterization (swrast) fallbacks. This doesn't necessarily
239 * correspond to glDrawBuffer() or glReadBuffer() calls.
241 static void mgaDDSetBuffer(GLcontext
*ctx
, GLframebuffer
*buffer
,
244 mgaContextPtr mmesa
= MGA_CONTEXT(ctx
);
246 if (bufferBit
== FRONT_LEFT_BIT
)
248 mmesa
->drawOffset
= mmesa
->mgaScreen
->frontOffset
;
249 mmesa
->readOffset
= mmesa
->mgaScreen
->frontOffset
;
251 else if (bufferBit
== BACK_LEFT_BIT
)
253 mmesa
->drawOffset
= mmesa
->mgaScreen
->backOffset
;
254 mmesa
->readOffset
= mmesa
->mgaScreen
->backOffset
;
261 void mgaDDInitSpanFuncs( GLcontext
*ctx
)
263 mgaContextPtr mmesa
= MGA_CONTEXT(ctx
);
264 struct swrast_device_driver
*swdd
= _swrast_GetDeviceDriverReference(ctx
);
266 swdd
->SetBuffer
= mgaDDSetBuffer
;
268 switch (mmesa
->mgaScreen
->cpp
) {
270 swdd
->WriteRGBASpan
= mgaWriteRGBASpan_565
;
271 swdd
->WriteRGBSpan
= mgaWriteRGBSpan_565
;
272 swdd
->WriteMonoRGBASpan
= mgaWriteMonoRGBASpan_565
;
273 swdd
->WriteRGBAPixels
= mgaWriteRGBAPixels_565
;
274 swdd
->WriteMonoRGBAPixels
= mgaWriteMonoRGBAPixels_565
;
275 swdd
->ReadRGBASpan
= mgaReadRGBASpan_565
;
276 swdd
->ReadRGBAPixels
= mgaReadRGBAPixels_565
;
278 swdd
->ReadDepthSpan
= mgaReadDepthSpan_16
;
279 swdd
->WriteDepthSpan
= mgaWriteDepthSpan_16
;
280 swdd
->ReadDepthPixels
= mgaReadDepthPixels_16
;
281 swdd
->WriteDepthPixels
= mgaWriteDepthPixels_16
;
285 swdd
->WriteRGBASpan
= mgaWriteRGBASpan_8888
;
286 swdd
->WriteRGBSpan
= mgaWriteRGBSpan_8888
;
287 swdd
->WriteMonoRGBASpan
= mgaWriteMonoRGBASpan_8888
;
288 swdd
->WriteRGBAPixels
= mgaWriteRGBAPixels_8888
;
289 swdd
->WriteMonoRGBAPixels
= mgaWriteMonoRGBAPixels_8888
;
290 swdd
->ReadRGBASpan
= mgaReadRGBASpan_8888
;
291 swdd
->ReadRGBAPixels
= mgaReadRGBAPixels_8888
;
293 if (!mmesa
->hw_stencil
) {
294 swdd
->ReadDepthSpan
= mgaReadDepthSpan_32
;
295 swdd
->WriteDepthSpan
= mgaWriteDepthSpan_32
;
296 swdd
->ReadDepthPixels
= mgaReadDepthPixels_32
;
297 swdd
->WriteDepthPixels
= mgaWriteDepthPixels_32
;
299 swdd
->ReadDepthSpan
= mgaReadDepthSpan_24_8
;
300 swdd
->WriteDepthSpan
= mgaWriteDepthSpan_24_8
;
301 swdd
->ReadDepthPixels
= mgaReadDepthPixels_24_8
;
302 swdd
->WriteDepthPixels
= mgaWriteDepthPixels_24_8
;
304 swdd
->ReadStencilSpan
= mgaReadStencilSpan_24_8
;
305 swdd
->WriteStencilSpan
= mgaWriteStencilSpan_24_8
;
306 swdd
->ReadStencilPixels
= mgaReadStencilPixels_24_8
;
307 swdd
->WriteStencilPixels
= mgaWriteStencilPixels_24_8
;