1 /* $XFree86$ */ /* -*- mode: c; c-basic-offset: 3 -*- */
3 * Copyright 2000 Gareth Hughes
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * GARETH HUGHES BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * Gareth Hughes <gareth@valinux.com>
28 * Leif Delgass <ldelgass@retinalburn.net>
29 * José Fonseca <j_r_fonseca@yahoo.co.uk>
32 #include "mach64_context.h"
33 #include "mach64_ioctl.h"
34 #include "mach64_state.h"
35 #include "mach64_span.h"
36 #include "mach64_tex.h"
38 #include "swrast/swrast.h"
43 mach64ContextPtr mmesa = MACH64_CONTEXT(ctx); \
44 mach64ScreenRec *mach64Screen = mmesa->mach64Screen; \
45 __DRIscreenPrivate *driScreen = mmesa->driScreen; \
46 __DRIdrawablePrivate *dPriv = mmesa->driDrawable; \
47 GLuint pitch = mmesa->drawPitch * mach64Screen->cpp; \
48 GLuint height = dPriv->h; \
49 char *buf = (char *)(driScreen->pFB + \
51 (dPriv->x * mach64Screen->cpp) + \
52 (dPriv->y * pitch)); \
53 char *read_buf = (char *)(driScreen->pFB + \
55 (dPriv->x * mach64Screen->cpp) + \
56 (dPriv->y * pitch)); \
58 (void) read_buf; (void) buf; (void) p
60 #define LOCAL_DEPTH_VARS \
61 mach64ScreenRec *mach64Screen = mmesa->mach64Screen; \
62 __DRIdrawablePrivate *dPriv = mmesa->driDrawable; \
63 __DRIscreenPrivate *driScreen = mmesa->driScreen; \
64 GLuint pitch = mach64Screen->depthPitch * 2; \
65 GLuint height = dPriv->h; \
66 char *buf = (char *)(driScreen->pFB + \
67 mach64Screen->depthOffset + \
71 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
73 #define CLIPPIXEL( _x, _y ) \
74 ((_x >= minx) && (_x < maxx) && (_y >= miny) && (_y < maxy))
77 #define CLIPSPAN( _x, _y, _n, _x1, _n1, _i ) \
78 if (( _y < miny) || (_y >= maxy)) { \
83 if (_x1 < minx) _i += (minx-_x1), n1 -= (minx-_x1), _x1 = minx; \
84 if (_x1 + _n1 >= maxx) n1 -= (_x1 + n1 - maxx); \
87 #define Y_FLIP( _y ) (height - _y - 1)
91 mach64ContextPtr mmesa = MACH64_CONTEXT(ctx); \
92 LOCK_HARDWARE( mmesa ); \
93 FINISH_DMA_LOCKED( mmesa ); \
95 #define HW_CLIPLOOP() \
97 int _nc = mmesa->numClipRects; \
100 int minx = mmesa->pClipRects[_nc].x1 - mmesa->drawX; \
101 int miny = mmesa->pClipRects[_nc].y1 - mmesa->drawY; \
102 int maxx = mmesa->pClipRects[_nc].x2 - mmesa->drawX; \
103 int maxy = mmesa->pClipRects[_nc].y2 - mmesa->drawY;
105 #define HW_ENDCLIPLOOP() \
109 #define HW_UNLOCK() \
110 UNLOCK_HARDWARE( mmesa ) \
114 /* ================================================================
118 /* 16 bit, RGB565 color spanline and pixel functions
120 #undef INIT_MONO_PIXEL
121 #define INIT_MONO_PIXEL(p, color) \
122 p = MACH64PACKCOLOR565( color[0], color[1], color[2] )
124 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
125 *(GLushort *)(buf + _x*2 + _y*pitch) = ((((int)r & 0xf8) << 8) | \
126 (((int)g & 0xfc) << 3) | \
127 (((int)b & 0xf8) >> 3))
129 #define WRITE_PIXEL( _x, _y, p ) \
130 *(GLushort *)(buf + _x*2 + _y*pitch) = p
132 #define READ_RGBA( rgba, _x, _y ) \
134 GLushort p = *(GLushort *)(read_buf + _x*2 + _y*pitch); \
135 rgba[0] = ((p >> 8) & 0xf8) * 255 / 0xf8; \
136 rgba[1] = ((p >> 3) & 0xfc) * 255 / 0xfc; \
137 rgba[2] = ((p << 3) & 0xf8) * 255 / 0xf8; \
141 #define TAG(x) mach64##x##_RGB565
146 /* 32 bit, ARGB8888 color spanline and pixel functions
148 #undef INIT_MONO_PIXEL
149 #define INIT_MONO_PIXEL(p, color) \
150 p = MACH64PACKCOLOR8888( color[0], color[1], color[2], color[3] )
152 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
153 *(GLuint *)(buf + _x*4 + _y*pitch) = ((b << 0) | \
158 #define WRITE_PIXEL( _x, _y, p ) \
159 *(GLuint *)(buf + _x*4 + _y*pitch) = p
161 #define READ_RGBA( rgba, _x, _y ) \
163 GLuint p = *(GLuint *)(read_buf + _x*4 + _y*pitch); \
164 rgba[0] = (p >> 16) & 0xff; \
165 rgba[1] = (p >> 8) & 0xff; \
166 rgba[2] = (p >> 0) & 0xff; \
167 rgba[3] = 0xff; /*(p >> 24) & 0xff;*/ \
170 #define TAG(x) mach64##x##_ARGB8888
175 /* ================================================================
179 /* 16 bit depthbuffer functions.
181 #define WRITE_DEPTH( _x, _y, d ) \
182 *(GLushort *)(buf + _x*2 + _y*pitch) = d;
184 #define READ_DEPTH( d, _x, _y ) \
185 d = *(GLushort *)(buf + _x*2 + _y*pitch);
187 #define TAG(x) mach64##x##_16
188 #include "depthtmp.h"
192 * This function is called to specify which buffer to read and write
193 * for software rasterization (swrast) fallbacks. This doesn't necessarily
194 * correspond to glDrawBuffer() or glReadBuffer() calls.
196 static void mach64DDSetBuffer( GLcontext
*ctx
,
197 GLframebuffer
*colorBuffer
,
200 mach64ContextPtr mmesa
= MACH64_CONTEXT(ctx
);
202 switch ( bufferBit
) {
203 case DD_FRONT_LEFT_BIT
:
204 if (MACH64_DEBUG
& DEBUG_VERBOSE_MSG
)
205 fprintf(stderr
,"%s: DD_FRONT_LEFT_BIT\n", __FUNCTION__
);
206 mmesa
->drawOffset
= mmesa
->readOffset
= mmesa
->mach64Screen
->frontOffset
;
207 mmesa
->drawPitch
= mmesa
->readPitch
= mmesa
->mach64Screen
->frontPitch
;
209 case DD_BACK_LEFT_BIT
:
210 if (MACH64_DEBUG
& DEBUG_VERBOSE_MSG
)
211 fprintf(stderr
,"%s: DD_BACK_LEFT_BIT\n", __FUNCTION__
);
212 mmesa
->drawOffset
= mmesa
->readOffset
= mmesa
->mach64Screen
->backOffset
;
213 mmesa
->drawPitch
= mmesa
->readPitch
= mmesa
->mach64Screen
->backPitch
;
221 void mach64DDInitSpanFuncs( GLcontext
*ctx
)
223 mach64ContextPtr mmesa
= MACH64_CONTEXT(ctx
);
224 struct swrast_device_driver
*swdd
= _swrast_GetDeviceDriverReference(ctx
);
226 swdd
->SetBuffer
= mach64DDSetBuffer
;
229 switch ( mmesa
->mach64Screen
->cpp
) {
231 swdd
->WriteRGBASpan
= mach64WriteRGBASpan_RGB565
;
232 swdd
->WriteRGBSpan
= mach64WriteRGBSpan_RGB565
;
233 swdd
->WriteMonoRGBASpan
= mach64WriteMonoRGBASpan_RGB565
;
234 swdd
->WriteRGBAPixels
= mach64WriteRGBAPixels_RGB565
;
235 swdd
->WriteMonoRGBAPixels
= mach64WriteMonoRGBAPixels_RGB565
;
236 swdd
->ReadRGBASpan
= mach64ReadRGBASpan_RGB565
;
237 swdd
->ReadRGBAPixels
= mach64ReadRGBAPixels_RGB565
;
241 swdd
->WriteRGBASpan
= mach64WriteRGBASpan_ARGB8888
;
242 swdd
->WriteRGBSpan
= mach64WriteRGBSpan_ARGB8888
;
243 swdd
->WriteMonoRGBASpan
= mach64WriteMonoRGBASpan_ARGB8888
;
244 swdd
->WriteRGBAPixels
= mach64WriteRGBAPixels_ARGB8888
;
245 swdd
->WriteMonoRGBAPixels
= mach64WriteMonoRGBAPixels_ARGB8888
;
246 swdd
->ReadRGBASpan
= mach64ReadRGBASpan_ARGB8888
;
247 swdd
->ReadRGBAPixels
= mach64ReadRGBAPixels_ARGB8888
;
255 /* Depth buffer is always 16 bit */
256 swdd
->ReadDepthSpan
= mach64ReadDepthSpan_16
;
257 swdd
->WriteDepthSpan
= mach64WriteDepthSpan_16
;
258 swdd
->ReadDepthPixels
= mach64ReadDepthPixels_16
;
259 swdd
->WriteDepthPixels
= mach64WriteDepthPixels_16
;
261 /* No hardware stencil buffer */
262 swdd
->ReadStencilSpan
= NULL
;
263 swdd
->WriteStencilSpan
= NULL
;
264 swdd
->ReadStencilPixels
= NULL
;
265 swdd
->WriteStencilPixels
= NULL
;
267 swdd
->WriteCI8Span
= NULL
;
268 swdd
->WriteCI32Span
= NULL
;
269 swdd
->WriteMonoCISpan
= NULL
;
270 swdd
->WriteCI32Pixels
= NULL
;
271 swdd
->WriteMonoCIPixels
= NULL
;
272 swdd
->ReadCI32Span
= NULL
;
273 swdd
->ReadCI32Pixels
= NULL
;