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"
37 #include "swrast/swrast.h"
41 #define GET_PTR(X,Y) (sPriv->pFB + drb->offset \
42 + ((dPriv->y + (Y)) * drb->pitch + (dPriv->x + (X))) * drb->cpp)
45 mach64ContextPtr mmesa = MACH64_CONTEXT(ctx); \
46 __DRIscreenPrivate *sPriv = mmesa->driScreen; \
47 __DRIdrawablePrivate *dPriv = mmesa->driDrawable; \
48 driRenderbuffer *drb = (driRenderbuffer *) rb; \
49 GLuint height = dPriv->h; \
53 #define LOCAL_DEPTH_VARS \
54 mach64ContextPtr mmesa = MACH64_CONTEXT(ctx); \
55 __DRIdrawablePrivate *dPriv = mmesa->driDrawable; \
56 __DRIscreenPrivate *driScreen = mmesa->driScreen; \
57 driRenderbuffer *drb = (driRenderbuffer *) rb; \
58 GLuint height = dPriv->h; \
59 char *buf = (char *)(driScreen->pFB + drb->offset + \
60 (dPriv->x + dPriv->y * drb->pitch) * 2)
62 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
64 #define Y_FLIP( _y ) (height - _y - 1)
68 /* FIXME could/should we use dPriv->numClipRects like the other drivers? */
69 #define HW_CLIPLOOP() \
71 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 /* ================================================================
91 /* 16 bit, RGB565 color spanline and pixel functions
93 #define SPANTMP_PIXEL_FMT GL_RGB
94 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
96 #define TAG(x) mach64##x##_RGB565
97 #define TAG2(x,y) mach64##x##_RGB565##y
98 #define GET_SRC_PTR(X,Y) GET_PTR(X,Y)
99 #define GET_DST_PTR(X,Y) GET_SRC_PTR(X,Y)
100 #include "spantmp2.h"
103 /* 32 bit, ARGB8888 color spanline and pixel functions
105 /* FIXME the old code always read back alpha as 0xff, i.e. fully opaque.
106 Was there a reason to do so ? If so that'll won't work with that template... */
107 #define SPANTMP_PIXEL_FMT GL_BGRA
108 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
110 #define TAG(x) mach64##x##_ARGB8888
111 #define TAG2(x,y) mach64##x##_ARGB8888##y
112 #define GET_SRC_PTR(X,Y) GET_PTR(X,Y)
113 #define GET_DST_PTR(X,Y) GET_SRC_PTR(X,Y)
114 #include "spantmp2.h"
117 /* ================================================================
121 /* 16 bit depthbuffer functions.
123 #define WRITE_DEPTH( _x, _y, d ) \
124 *(GLushort *)(buf + ((_x) + (_y) * drb->pitch) * 2) = d;
126 #define READ_DEPTH( d, _x, _y ) \
127 d = *(GLushort *)(buf + ((_x) + (_y) * drb->pitch) * 2);
129 #define TAG(x) mach64##x##_z16
130 #include "depthtmp.h"
133 static void mach64SpanRenderStart( GLcontext
*ctx
)
135 mach64ContextPtr mmesa
= MACH64_CONTEXT(ctx
);
136 LOCK_HARDWARE( mmesa
);
137 FINISH_DMA_LOCKED( mmesa
);
140 static void mach64SpanRenderFinish( GLcontext
*ctx
)
142 mach64ContextPtr mmesa
= MACH64_CONTEXT(ctx
);
143 _swrast_flush( ctx
);
144 UNLOCK_HARDWARE( mmesa
);
147 void mach64DDInitSpanFuncs( GLcontext
*ctx
)
149 struct swrast_device_driver
*swdd
= _swrast_GetDeviceDriverReference(ctx
);
150 swdd
->SpanRenderStart
= mach64SpanRenderStart
;
151 swdd
->SpanRenderFinish
= mach64SpanRenderFinish
;
156 * Plug in the Get/Put routines for the given driRenderbuffer.
159 mach64SetSpanFunctions(driRenderbuffer
*drb
, const GLvisual
*vis
)
161 if (drb
->Base
.InternalFormat
== GL_RGBA
) {
162 if (vis
->redBits
== 5 && vis
->greenBits
== 6 && vis
->blueBits
== 5) {
163 mach64InitPointers_RGB565(&drb
->Base
);
166 mach64InitPointers_ARGB8888(&drb
->Base
);
169 else if (drb
->Base
.InternalFormat
== GL_DEPTH_COMPONENT16
) {
170 mach64InitDepthPointers_z16(&drb
->Base
);