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>
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 WRITE_DEPTH( _x, _y, d ) \
111 *(GLushort *)(buf + (_x)*2 + (_y)*pitch) = d;
113 #define READ_DEPTH( d, _x, _y ) \
114 d = *(GLushort *)(buf + (_x)*2 + (_y)*pitch);
116 #define TAG(x) mga##x##_z16
117 #include "depthtmp.h"
122 /* 32 bit depthbuffer functions.
124 #define WRITE_DEPTH( _x, _y, d ) \
125 *(GLuint *)(buf + (_x)*4 + (_y)*pitch) = d;
127 #define READ_DEPTH( d, _x, _y ) \
128 d = *(GLuint *)(buf + (_x)*4 + (_y)*pitch);
130 #define TAG(x) mga##x##_z32
131 #include "depthtmp.h"
135 /* 24/8 bit interleaved depth/stencil functions
137 #define WRITE_DEPTH( _x, _y, d ) { \
138 GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*pitch); \
141 *(GLuint *)(buf + (_x)*4 + (_y)*pitch) = tmp; \
144 #define READ_DEPTH( d, _x, _y ) { \
145 d = (*(GLuint *)(buf + (_x)*4 + (_y)*pitch) & ~0xff) >> 8; \
148 #define TAG(x) mga##x##_z24_s8
149 #include "depthtmp.h"
151 #define WRITE_STENCIL( _x, _y, d ) { \
152 GLuint tmp = *(GLuint *)(buf + _x*4 + _y*pitch); \
155 *(GLuint *)(buf + _x*4 + _y*pitch) = tmp; \
158 #define READ_STENCIL( d, _x, _y ) \
159 d = *(GLuint *)(buf + _x*4 + _y*pitch) & 0xff;
161 #define TAG(x) mga##x##_z24_s8
162 #include "stenciltmp.h"
166 mgaSpanRenderStart( GLcontext
*ctx
)
168 mgaContextPtr mmesa
= MGA_CONTEXT(ctx
);
169 FLUSH_BATCH( mmesa
);
170 LOCK_HARDWARE_QUIESCENT( mmesa
);
174 mgaSpanRenderFinish( GLcontext
*ctx
)
176 mgaContextPtr mmesa
= MGA_CONTEXT(ctx
);
177 _swrast_flush( ctx
);
178 UNLOCK_HARDWARE( mmesa
);
182 * Initialize the driver callbacks for the read / write span functions.
185 * To really support RGB888 and RGBA8888 visuals, we need separate read and
186 * write routines for 888 and 8888. We also need to determine whether or not
187 * the visual has destination alpha.
189 void mgaDDInitSpanFuncs( GLcontext
*ctx
)
191 struct swrast_device_driver
*swdd
= _swrast_GetDeviceDriverReference(ctx
);
192 swdd
->SpanRenderStart
= mgaSpanRenderStart
;
193 swdd
->SpanRenderFinish
= mgaSpanRenderFinish
;
198 * Plug in the Get/Put routines for the given driRenderbuffer.
201 mgaSetSpanFunctions(driRenderbuffer
*drb
, const GLvisual
*vis
)
203 if (drb
->Base
.InternalFormat
== GL_RGBA
) {
204 if (vis
->redBits
== 5 && vis
->greenBits
== 6 && vis
->blueBits
== 5) {
205 mgaInitPointers_565(&drb
->Base
);
208 mgaInitPointers_8888(&drb
->Base
);
211 else if (drb
->Base
.InternalFormat
== GL_DEPTH_COMPONENT16
) {
212 mgaInitDepthPointers_z16(&drb
->Base
);
214 else if (drb
->Base
.InternalFormat
== GL_DEPTH_COMPONENT24
) {
215 mgaInitDepthPointers_z24_s8(&drb
->Base
);
217 else if (drb
->Base
.InternalFormat
== GL_DEPTH_COMPONENT32
) {
218 mgaInitDepthPointers_z32(&drb
->Base
);
220 else if (drb
->Base
.InternalFormat
== GL_STENCIL_INDEX8_EXT
) {
221 mgaInitStencilPointers_z24_s8(&drb
->Base
);