1 /* -*- 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"
42 mach64ContextPtr mmesa = MACH64_CONTEXT(ctx); \
43 __DRIscreenPrivate *sPriv = mmesa->driScreen; \
44 __DRIdrawablePrivate *dPriv = mmesa->driDrawable; \
45 driRenderbuffer *drb = (driRenderbuffer *) rb; \
46 GLuint height = dPriv->h; \
50 #define LOCAL_DEPTH_VARS \
51 mach64ContextPtr mmesa = MACH64_CONTEXT(ctx); \
52 __DRIdrawablePrivate *dPriv = mmesa->driDrawable; \
53 __DRIscreenPrivate *driScreen = mmesa->driScreen; \
54 driRenderbuffer *drb = (driRenderbuffer *) rb; \
55 GLuint height = dPriv->h; \
56 char *buf = (char *)(driScreen->pFB + drb->offset + \
57 (dPriv->x + dPriv->y * drb->pitch) * 2)
59 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
61 #define Y_FLIP( _y ) (height - _y - 1)
65 /* FIXME could/should we use dPriv->numClipRects like the other drivers? */
66 #define HW_CLIPLOOP() \
68 int _nc = mmesa->numClipRects; \
71 int minx = mmesa->pClipRects[_nc].x1 - mmesa->drawX; \
72 int miny = mmesa->pClipRects[_nc].y1 - mmesa->drawY; \
73 int maxx = mmesa->pClipRects[_nc].x2 - mmesa->drawX; \
74 int maxy = mmesa->pClipRects[_nc].y2 - mmesa->drawY;
76 #define HW_ENDCLIPLOOP() \
84 /* ================================================================
88 /* 16 bit, RGB565 color spanline and pixel functions
90 #define SPANTMP_PIXEL_FMT GL_RGB
91 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
93 #define TAG(x) mach64##x##_RGB565
94 #define TAG2(x,y) mach64##x##_RGB565##y
95 #define GET_PTR(X,Y) (sPriv->pFB + drb->offset \
96 + ((dPriv->y + (Y)) * drb->pitch + (dPriv->x + (X))) * drb->cpp)
100 /* 32 bit, ARGB8888 color spanline and pixel functions
102 /* FIXME the old code always read back alpha as 0xff, i.e. fully opaque.
103 Was there a reason to do so ? If so that'll won't work with that template... */
104 #define SPANTMP_PIXEL_FMT GL_BGRA
105 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
107 #define TAG(x) mach64##x##_ARGB8888
108 #define TAG2(x,y) mach64##x##_ARGB8888##y
109 #define GET_PTR(X,Y) (sPriv->pFB + drb->offset \
110 + ((dPriv->y + (Y)) * drb->pitch + (dPriv->x + (X))) * drb->cpp)
111 #include "spantmp2.h"
114 /* ================================================================
118 /* 16 bit depthbuffer functions.
120 #define VALUE_TYPE GLushort
122 #define WRITE_DEPTH( _x, _y, d ) \
123 *(GLushort *)(buf + ((_x) + (_y) * drb->pitch) * 2) = d;
125 #define READ_DEPTH( d, _x, _y ) \
126 d = *(GLushort *)(buf + ((_x) + (_y) * drb->pitch) * 2);
128 #define TAG(x) mach64##x##_z16
129 #include "depthtmp.h"
132 static void mach64SpanRenderStart( GLcontext
*ctx
)
134 mach64ContextPtr mmesa
= MACH64_CONTEXT(ctx
);
135 LOCK_HARDWARE( mmesa
);
136 FINISH_DMA_LOCKED( mmesa
);
139 static void mach64SpanRenderFinish( GLcontext
*ctx
)
141 mach64ContextPtr mmesa
= MACH64_CONTEXT(ctx
);
142 _swrast_flush( ctx
);
143 UNLOCK_HARDWARE( mmesa
);
146 void mach64DDInitSpanFuncs( GLcontext
*ctx
)
148 struct swrast_device_driver
*swdd
= _swrast_GetDeviceDriverReference(ctx
);
149 swdd
->SpanRenderStart
= mach64SpanRenderStart
;
150 swdd
->SpanRenderFinish
= mach64SpanRenderFinish
;
155 * Plug in the Get/Put routines for the given driRenderbuffer.
158 mach64SetSpanFunctions(driRenderbuffer
*drb
, const GLvisual
*vis
)
160 if (drb
->Base
.Format
== MESA_FORMAT_RGB565
) {
161 mach64InitPointers_RGB565(&drb
->Base
);
163 else if (drb
->Base
.Format
== MESA_FORMAT_ARGB8888
) {
164 mach64InitPointers_ARGB8888(&drb
->Base
);
166 else if (drb
->Base
.Format
== MESA_FORMAT_Z16
) {
167 mach64InitDepthPointers_z16(&drb
->Base
);