2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
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 * the rights to use, copy, modify, merge, publish, distribute, sub license,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
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 * VIA, S3 GRAPHICS, 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 OTHER
22 * DEALINGS IN THE SOFTWARE.
27 #include "savagespan.h"
28 #include "savageioctl.h"
29 #include "savage_bci.h"
30 #include "savage_3d_reg.h"
31 #include "swrast/swrast.h"
36 __DRIdrawablePrivate *dPriv = imesa->mesa_drawable; \
37 savageScreenPrivate *savageScreen = imesa->savageScreen; \
38 GLuint cpp = savageScreen->cpp; \
39 GLuint pitch = imesa->aperturePitch; \
40 GLuint height = dPriv->h; \
41 char *buf = (char *)(imesa->drawMap + \
44 char *read_buf = (char *)(imesa->readMap + \
47 GLuint p = SAVAGE_CONTEXT( ctx )->MonoColor; \
48 (void) read_buf; (void) buf; (void) p
50 #define LOCAL_DEPTH_VARS \
51 __DRIdrawablePrivate *dPriv = imesa->mesa_drawable; \
52 savageScreenPrivate *savageScreen = imesa->savageScreen; \
53 GLuint zpp = savageScreen->zpp; \
54 GLuint pitch = imesa->aperturePitch; \
55 GLuint height = dPriv->h; \
56 char *buf = (char *)(imesa->apertureBase[TARGET_DEPTH] + \
60 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
62 #define INIT_MONO_PIXEL(p)
64 #define CLIPPIXEL(_x,_y) (_x >= minx && _x < maxx && \
65 _y >= miny && _y < maxy)
68 #define CLIPSPAN( _x, _y, _n, _x1, _n1, _i ) \
69 if ( _y < miny || _y >= maxy ) { \
74 if ( _x1 < minx ) _i += (minx-_x1), n1 -= (minx-_x1), _x1 = minx; \
75 if ( _x1 + _n1 >= maxx ) n1 -= (_x1 + n1 - maxx); \
78 #define Y_FLIP(_y) (height - _y - 1)
80 #define HW_LOCK() savageContextPtr imesa = SAVAGE_CONTEXT(ctx); \
83 #define HW_CLIPLOOP() \
85 __DRIdrawablePrivate *dPriv = imesa->driDrawable; \
86 int _nc = dPriv->numClipRects; \
88 int minx = dPriv->pClipRects[_nc].x1 - dPriv->x; \
89 int miny = dPriv->pClipRects[_nc].y1 - dPriv->y; \
90 int maxx = dPriv->pClipRects[_nc].x2 - dPriv->x; \
91 int maxy = dPriv->pClipRects[_nc].y2 - dPriv->y;
94 #define HW_ENDCLIPLOOP() \
100 UNLOCK_HARDWARE(imesa);
102 #define HW_UNLOCK() { }
105 /* 16 bit, 565 rgb color spanline and pixel functions
107 #undef INIT_MONO_PIXEL
108 #define INIT_MONO_PIXEL(p, color) \
109 p = SAVAGEPACKCOLOR565( color[0], color[1], color[2] )
111 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
113 *(GLushort *)(buf + (_x<<1) + _y*pitch) = ( (((int)r & 0xf8) << 8) |\
114 (((int)g & 0xfc) << 3) | \
115 (((int)b & 0xf8) >> 3)); \
117 #define WRITE_PIXEL( _x, _y, p ) \
119 *(GLushort *)(buf + (_x<<1) + _y*pitch) = p; \
122 #define READ_RGBA( rgba, _x, _y ) \
124 GLushort p = *(GLushort *)(read_buf + (_x<<1) + _y*pitch); \
125 rgba[0] = (((p >> 11) & 0x1f) * 255) >>5; \
126 rgba[1] = (((p >> 5) & 0x3f) * 255) >>6; \
127 rgba[2] = (((p >> 0) & 0x1f) * 255) >>5; \
131 #define TAG(x) savage##x##_565
135 /* 32 bit, 8888 ARGB color spanline and pixel functions
137 #undef INIT_MONO_PIXEL
138 #define INIT_MONO_PIXEL(p, color) \
139 p = SAVAGEPACKCOLOR8888( color[0], color[1], color[2], color[3] )
141 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
142 *(GLuint *)(buf + (_x<<2) + _y*pitch) = ( ((GLuint)a << 24) | \
143 ((GLuint)r << 16) | \
146 #define WRITE_PIXEL( _x, _y, p ) \
147 *(GLuint *)(buf + (_x<<2) + _y*pitch) = p
149 #define READ_RGBA( rgba, _x, _y ) \
151 GLuint p = *(GLuint *)(read_buf + (_x<<2) + _y*pitch); \
152 rgba[0] = (p >> 16) & 0xFF; \
153 rgba[1] = (p >> 8) & 0xFF; \
154 rgba[2] = (p >> 0) & 0xFF; \
158 #define TAG(x) savage##x##_8888
164 /* 16 bit depthbuffer functions.
166 #define WRITE_DEPTH( _x, _y, d ) \
168 *(GLushort *)(buf + (_x<<1) + _y*pitch) = d; \
171 #define READ_DEPTH( d, _x, _y ) \
173 d = *(GLushort *)(buf + (_x<<1) + _y*pitch); \
178 #define TAG(x) savage##x##_16
179 #include "depthtmp.h"
185 /* 8-bit stencil /24-bit depth depthbuffer functions.
187 #define WRITE_DEPTH( _x, _y, d ) { \
188 GLuint tmp = *(GLuint *)(buf + (_x<<2) + _y*pitch); \
191 *(GLuint *)(buf + (_x<<2) + _y*pitch) = tmp; \
194 #define READ_DEPTH( d, _x, _y ) \
195 d = *(GLuint *)(buf + (_x<<2) + _y*pitch) & 0x00FFFFFF;
197 /* d = 0x00ffffff; */
199 #define TAG(x) savage##x##_8_24
200 #include "depthtmp.h"
203 #define WRITE_STENCIL( _x, _y, d ) { \
204 GLuint tmp = *(GLuint *)(buf + (_x<<2) + _y*pitch); \
206 tmp |= (((GLuint)d)<<24) & 0xFF000000; \
207 *(GLuint *)(buf + (_x<<2) + _y*pitch) = tmp; \
210 #define READ_STENCIL( d, _x, _y ) \
211 d = (GLstencil)((*(GLuint *)(buf + (_x<<2) + _y*pitch) & 0xFF000000) >> 24);
213 #define TAG(x) savage##x##_8_24
214 #include "stenciltmp.h"
218 * This function is called to specify which buffer to read and write
219 * for software rasterization (swrast) fallbacks. This doesn't necessarily
220 * correspond to glDrawBuffer() or glReadBuffer() calls.
222 static void savageDDSetBuffer(GLcontext
*ctx
, GLframebuffer
*buffer
,
225 savageContextPtr imesa
= SAVAGE_CONTEXT(ctx
);
228 assert((bufferBit
== DD_FRONT_LEFT_BIT
) || (bufferBit
== DD_BACK_LEFT_BIT
));
230 map
= (bufferBit
== DD_FRONT_LEFT_BIT
)
231 ? (char*)imesa
->apertureBase
[TARGET_FRONT
]
232 : (char*)imesa
->apertureBase
[TARGET_BACK
];
234 imesa
->drawMap
= map
;
235 imesa
->readMap
= map
;
237 assert( (buffer
== imesa
->driDrawable
->driverPrivate
)
238 || (buffer
== imesa
->driReadable
->driverPrivate
) );
240 imesa
->mesa_drawable
= (buffer
== imesa
->driDrawable
->driverPrivate
)
241 ? imesa
->driDrawable
: imesa
->driReadable
;
245 void savageDDInitSpanFuncs( GLcontext
*ctx
)
247 savageContextPtr imesa
= SAVAGE_CONTEXT(ctx
);
248 struct swrast_device_driver
*swdd
= _swrast_GetDeviceDriverReference(ctx
);
250 swdd
->SetBuffer
= savageDDSetBuffer
;
252 switch (imesa
->savageScreen
->cpp
)
255 swdd
->WriteRGBASpan
= savageWriteRGBASpan_565
;
256 swdd
->WriteRGBSpan
= savageWriteRGBSpan_565
;
257 swdd
->WriteMonoRGBASpan
= savageWriteMonoRGBASpan_565
;
258 swdd
->WriteRGBAPixels
= savageWriteRGBAPixels_565
;
259 swdd
->WriteMonoRGBAPixels
= savageWriteMonoRGBAPixels_565
;
260 swdd
->ReadRGBASpan
= savageReadRGBASpan_565
;
261 swdd
->ReadRGBAPixels
= savageReadRGBAPixels_565
;
266 swdd
->WriteRGBASpan
= savageWriteRGBASpan_8888
;
267 swdd
->WriteRGBSpan
= savageWriteRGBSpan_8888
;
268 swdd
->WriteMonoRGBASpan
= savageWriteMonoRGBASpan_8888
;
269 swdd
->WriteRGBAPixels
= savageWriteRGBAPixels_8888
;
270 swdd
->WriteMonoRGBAPixels
= savageWriteMonoRGBAPixels_8888
;
271 swdd
->ReadRGBASpan
= savageReadRGBASpan_8888
;
272 swdd
->ReadRGBAPixels
= savageReadRGBAPixels_8888
;
275 switch (imesa
->savageScreen
->zpp
)
278 swdd
->ReadDepthSpan
= savageReadDepthSpan_16
;
279 swdd
->WriteDepthSpan
= savageWriteDepthSpan_16
;
280 swdd
->ReadDepthPixels
= savageReadDepthPixels_16
;
281 swdd
->WriteDepthPixels
= savageWriteDepthPixels_16
;
285 swdd
->ReadDepthSpan
= savageReadDepthSpan_8_24
;
286 swdd
->WriteDepthSpan
= savageWriteDepthSpan_8_24
;
287 swdd
->ReadDepthPixels
= savageReadDepthPixels_8_24
;
288 swdd
->WriteDepthPixels
= savageWriteDepthPixels_8_24
;
289 swdd
->ReadStencilSpan
= savageReadStencilSpan_8_24
;
290 swdd
->WriteStencilSpan
= savageWriteStencilSpan_8_24
;
291 swdd
->ReadStencilPixels
= savageReadStencilPixels_8_24
;
292 swdd
->WriteStencilPixels
= savageWriteStencilPixels_8_24
;
296 swdd
->WriteCI8Span
=NULL
;
297 swdd
->WriteCI32Span
=NULL
;
298 swdd
->WriteMonoCISpan
=NULL
;
299 swdd
->WriteCI32Pixels
=NULL
;
300 swdd
->WriteMonoCIPixels
=NULL
;
301 swdd
->ReadCI32Span
=NULL
;
302 swdd
->ReadCI32Pixels
=NULL
;
304 /* Pixel path fallbacks.
306 ctx
->Driver
.Accum
= _swrast_Accum
;
307 ctx
->Driver
.Bitmap
= _swrast_Bitmap
;
308 ctx
->Driver
.CopyPixels
= _swrast_CopyPixels
;
309 ctx
->Driver
.DrawPixels
= _swrast_DrawPixels
;
310 ctx
->Driver
.ReadPixels
= _swrast_ReadPixels
;