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->mesa_drawable; \
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->mesa_drawable; \
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);
112 #define Y_FLIP(_y) (height - _y - 1)
114 /* 16 bit, RGB565 color spanline and pixel functions
117 #define GET_SRC_PTR(_x, _y) (read_buf + _x * 2 + _y * pitch)
118 #define GET_DST_PTR(_x, _y) ( buf + _x * 2 + _y * pitch)
119 #define SPANTMP_PIXEL_FMT GL_RGB
120 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
122 #define TAG(x) mga##x##_565
123 #define TAG2(x,y) mga##x##_565##y
124 #include "spantmp2.h"
126 /* 32 bit, ARGB8888 color spanline and pixel functions
129 #define GET_SRC_PTR(_x, _y) (read_buf + _x * 4 + _y * pitch)
130 #define GET_DST_PTR(_x, _y) ( buf + _x * 4 + _y * pitch)
131 #define SPANTMP_PIXEL_FMT GL_BGRA
132 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
134 #define TAG(x) mga##x##_8888
135 #define TAG2(x,y) mga##x##_8888##y
136 #include "spantmp2.h"
139 /* 16 bit depthbuffer functions.
141 #define WRITE_DEPTH( _x, _y, d ) \
142 *(GLushort *)(buf + _x*2 + _y*pitch) = d;
144 #define READ_DEPTH( d, _x, _y ) \
145 d = *(GLushort *)(buf + _x*2 + _y*pitch);
147 #define TAG(x) mga##x##_16
148 #include "depthtmp.h"
153 /* 32 bit depthbuffer functions.
155 #define WRITE_DEPTH( _x, _y, d ) \
156 *(GLuint *)(buf + _x*4 + _y*pitch) = d;
158 #define READ_DEPTH( d, _x, _y ) \
159 d = *(GLuint *)(buf + _x*4 + _y*pitch);
161 #define TAG(x) mga##x##_32
162 #include "depthtmp.h"
166 /* 24/8 bit interleaved depth/stencil functions
168 #define WRITE_DEPTH( _x, _y, d ) { \
169 GLuint tmp = *(GLuint *)(buf + _x*4 + _y*pitch); \
172 *(GLuint *)(buf + _x*4 + _y*pitch) = tmp; \
175 #define READ_DEPTH( d, _x, _y ) { \
176 d = (*(GLuint *)(buf + _x*4 + _y*pitch) & ~0xff) >> 8; \
179 #define TAG(x) mga##x##_24_8
180 #include "depthtmp.h"
182 #define WRITE_STENCIL( _x, _y, d ) { \
183 GLuint tmp = *(GLuint *)(buf + _x*4 + _y*pitch); \
186 *(GLuint *)(buf + _x*4 + _y*pitch) = tmp; \
189 #define READ_STENCIL( d, _x, _y ) \
190 d = *(GLuint *)(buf + _x*4 + _y*pitch) & 0xff;
192 #define TAG(x) mga##x##_24_8
193 #include "stenciltmp.h"
198 * This function is called to specify which buffer to read and write
199 * for software rasterization (swrast) fallbacks. This doesn't necessarily
200 * correspond to glDrawBuffer() or glReadBuffer() calls.
202 static void mgaDDSetBuffer(GLcontext
*ctx
, GLframebuffer
*buffer
,
205 mgaContextPtr mmesa
= MGA_CONTEXT(ctx
);
208 assert((bufferBit
== DD_FRONT_LEFT_BIT
) || (bufferBit
== DD_BACK_LEFT_BIT
));
210 offset
= (bufferBit
== DD_FRONT_LEFT_BIT
)
211 ? mmesa
->mgaScreen
->frontOffset
212 : mmesa
->mgaScreen
->backOffset
;
214 mmesa
->drawOffset
= offset
;
215 mmesa
->readOffset
= offset
;
217 assert( (buffer
== mmesa
->driDrawable
->driverPrivate
)
218 || (buffer
== mmesa
->driReadable
->driverPrivate
) );
220 mmesa
->mesa_drawable
= (buffer
== mmesa
->driDrawable
->driverPrivate
)
221 ? mmesa
->driDrawable
: mmesa
->driReadable
;
225 * Initialize the driver callbacks for the read / write span functions.
228 * To really support RGB888 and RGBA8888 visuals, we need separate read and
229 * write routines for 888 and 8888. We also need to determine whether or not
230 * the visual has destination alpha.
232 void mgaDDInitSpanFuncs( GLcontext
*ctx
)
234 mgaContextPtr mmesa
= MGA_CONTEXT(ctx
);
235 struct swrast_device_driver
*swdd
= _swrast_GetDeviceDriverReference(ctx
);
237 swdd
->SetBuffer
= mgaDDSetBuffer
;
239 switch (mmesa
->mgaScreen
->cpp
) {
241 mgaInitPointers_565( swdd
);
243 swdd
->ReadDepthSpan
= mgaReadDepthSpan_16
;
244 swdd
->WriteDepthSpan
= mgaWriteDepthSpan_16
;
245 swdd
->ReadDepthPixels
= mgaReadDepthPixels_16
;
246 swdd
->WriteDepthPixels
= mgaWriteDepthPixels_16
;
250 mgaInitPointers_8888( swdd
);
252 if (!mmesa
->hw_stencil
) {
253 swdd
->ReadDepthSpan
= mgaReadDepthSpan_32
;
254 swdd
->WriteDepthSpan
= mgaWriteDepthSpan_32
;
255 swdd
->ReadDepthPixels
= mgaReadDepthPixels_32
;
256 swdd
->WriteDepthPixels
= mgaWriteDepthPixels_32
;
258 swdd
->ReadDepthSpan
= mgaReadDepthSpan_24_8
;
259 swdd
->WriteDepthSpan
= mgaWriteDepthSpan_24_8
;
260 swdd
->ReadDepthPixels
= mgaReadDepthPixels_24_8
;
261 swdd
->WriteDepthPixels
= mgaWriteDepthPixels_24_8
;
263 swdd
->ReadStencilSpan
= mgaReadStencilSpan_24_8
;
264 swdd
->WriteStencilSpan
= mgaWriteStencilSpan_24_8
;
265 swdd
->ReadStencilPixels
= mgaReadStencilPixels_24_8
;
266 swdd
->WriteStencilPixels
= mgaWriteStencilPixels_24_8
;