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>
28 #include "main/mtypes.h"
30 #include "mgacontext.h"
33 #include "swrast/swrast.h"
38 mgaContextPtr mmesa = MGA_CONTEXT(ctx); \
39 __DRIscreenPrivate *sPriv = mmesa->driScreen; \
40 driRenderbuffer *drb = (driRenderbuffer *) rb; \
41 const __DRIdrawablePrivate *dPriv = drb->dPriv; \
42 GLuint pitch = drb->pitch; \
43 GLuint height = dPriv->h; \
44 char *buf = (char *)(sPriv->pFB + \
46 dPriv->x * drb->cpp + \
53 #define LOCAL_DEPTH_VARS \
54 mgaContextPtr mmesa = MGA_CONTEXT(ctx); \
55 __DRIscreenPrivate *sPriv = mmesa->driScreen; \
56 driRenderbuffer *drb = (driRenderbuffer *) rb; \
57 const __DRIdrawablePrivate *dPriv = drb->dPriv; \
58 GLuint pitch = drb->pitch; \
59 GLuint height = dPriv->h; \
60 char *buf = (char *)(sPriv->pFB + \
62 dPriv->x * drb->cpp + \
65 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
69 /* FIXME could/should we use dPriv->numClipRects like the other drivers? */
70 #define HW_CLIPLOOP() \
72 int _nc = mmesa->numClipRects; \
74 int minx = mmesa->pClipRects[_nc].x1 - mmesa->drawX; \
75 int miny = mmesa->pClipRects[_nc].y1 - mmesa->drawY; \
76 int maxx = mmesa->pClipRects[_nc].x2 - mmesa->drawX; \
77 int maxy = mmesa->pClipRects[_nc].y2 - mmesa->drawY;
79 #define HW_ENDCLIPLOOP() \
87 #define Y_FLIP(_y) (height - _y - 1)
89 /* 16 bit, RGB565 color spanline and pixel functions
91 #define SPANTMP_PIXEL_FMT GL_RGB
92 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
94 #define TAG(x) mga##x##_565
95 #define TAG2(x,y) mga##x##_565##y
98 /* 32 bit, ARGB8888 color spanline and pixel functions
100 #define SPANTMP_PIXEL_FMT GL_BGRA
101 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
103 #define TAG(x) mga##x##_8888
104 #define TAG2(x,y) mga##x##_8888##y
105 #include "spantmp2.h"
108 /* 16 bit depthbuffer functions.
110 #define VALUE_TYPE GLushort
112 #define WRITE_DEPTH( _x, _y, d ) \
113 *(GLushort *)(buf + (_x)*2 + (_y)*pitch) = d;
115 #define READ_DEPTH( d, _x, _y ) \
116 d = *(GLushort *)(buf + (_x)*2 + (_y)*pitch);
118 #define TAG(x) mga##x##_z16
119 #include "depthtmp.h"
124 /* 32 bit depthbuffer functions.
126 #define VALUE_TYPE GLuint
128 #define WRITE_DEPTH( _x, _y, d ) \
129 *(GLuint *)(buf + (_x)*4 + (_y)*pitch) = d;
131 #define READ_DEPTH( d, _x, _y ) \
132 d = *(GLuint *)(buf + (_x)*4 + (_y)*pitch);
134 #define TAG(x) mga##x##_z32
135 #include "depthtmp.h"
139 /* 24/8 bit interleaved depth/stencil functions
141 #define VALUE_TYPE GLuint
143 #define WRITE_DEPTH( _x, _y, d ) { \
144 GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*pitch); \
147 *(GLuint *)(buf + (_x)*4 + (_y)*pitch) = tmp; \
150 #define READ_DEPTH( d, _x, _y ) { \
151 d = (*(GLuint *)(buf + (_x)*4 + (_y)*pitch) & ~0xff) >> 8; \
154 #define TAG(x) mga##x##_z24_s8
155 #include "depthtmp.h"
157 #define WRITE_STENCIL( _x, _y, d ) { \
158 GLuint tmp = *(GLuint *)(buf + _x*4 + _y*pitch); \
161 *(GLuint *)(buf + _x*4 + _y*pitch) = tmp; \
164 #define READ_STENCIL( d, _x, _y ) \
165 d = *(GLuint *)(buf + _x*4 + _y*pitch) & 0xff;
167 #define TAG(x) mga##x##_z24_s8
168 #include "stenciltmp.h"
172 mgaSpanRenderStart( GLcontext
*ctx
)
174 mgaContextPtr mmesa
= MGA_CONTEXT(ctx
);
175 FLUSH_BATCH( mmesa
);
176 LOCK_HARDWARE_QUIESCENT( mmesa
);
180 mgaSpanRenderFinish( GLcontext
*ctx
)
182 mgaContextPtr mmesa
= MGA_CONTEXT(ctx
);
183 _swrast_flush( ctx
);
184 UNLOCK_HARDWARE( mmesa
);
188 * Initialize the driver callbacks for the read / write span functions.
191 * To really support RGB888 and RGBA8888 visuals, we need separate read and
192 * write routines for 888 and 8888. We also need to determine whether or not
193 * the visual has destination alpha.
195 void mgaDDInitSpanFuncs( GLcontext
*ctx
)
197 struct swrast_device_driver
*swdd
= _swrast_GetDeviceDriverReference(ctx
);
198 swdd
->SpanRenderStart
= mgaSpanRenderStart
;
199 swdd
->SpanRenderFinish
= mgaSpanRenderFinish
;
204 * Plug in the Get/Put routines for the given driRenderbuffer.
207 mgaSetSpanFunctions(driRenderbuffer
*drb
, const GLvisual
*vis
)
209 if (drb
->Base
.Format
== MESA_FORMAT_RGB565
) {
210 mgaInitPointers_565(&drb
->Base
);
212 else if (drb
->Base
.Format
== MESA_FORMAT_ARGB8888
) {
213 mgaInitPointers_8888(&drb
->Base
);
215 else if (drb
->Base
.Format
== MESA_FORMAT_Z16
) {
216 mgaInitDepthPointers_z16(&drb
->Base
);
218 else if (drb
->Base
.Format
== MESA_FORMAT_Z24_S8
) {
219 mgaInitDepthPointers_z24_s8(&drb
->Base
);
221 else if (drb
->Base
.Format
== MESA_FORMAT_Z32
) {
222 mgaInitDepthPointers_z32(&drb
->Base
);
224 else if (drb
->Base
.Format
== MESA_FORMAT_S8
) {
225 mgaInitStencilPointers_z24_s8(&drb
->Base
);