3830a28165bcdc0497013432fcb84fd8e55e6a14
[mesa.git] / src / mesa / drivers / dri / mach64 / mach64_span.c
1 /* $XFree86$ */ /* -*- mode: c; c-basic-offset: 3 -*- */
2 /*
3 * Copyright 2000 Gareth Hughes
4 * All Rights Reserved.
5 *
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:
12 *
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
15 * Software.
16 *
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.
23 */
24
25 /*
26 * Authors:
27 * Gareth Hughes <gareth@valinux.com>
28 * Leif Delgass <ldelgass@retinalburn.net>
29 * Jos�Fonseca <j_r_fonseca@yahoo.co.uk>
30 */
31
32 #include "mach64_context.h"
33 #include "mach64_ioctl.h"
34 #include "mach64_state.h"
35 #include "mach64_span.h"
36
37 #include "swrast/swrast.h"
38
39 #define DBG 0
40
41 #define LOCAL_VARS \
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; \
47 GLushort p; \
48 (void) p;
49
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)
58
59 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
60
61 #define Y_FLIP( _y ) (height - _y - 1)
62
63 #define HW_LOCK()
64
65 /* FIXME could/should we use dPriv->numClipRects like the other drivers? */
66 #define HW_CLIPLOOP() \
67 do { \
68 int _nc = mmesa->numClipRects; \
69 \
70 while ( _nc-- ) { \
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;
75
76 #define HW_ENDCLIPLOOP() \
77 } \
78 } while (0)
79
80 #define HW_UNLOCK()
81
82
83
84 /* ================================================================
85 * Color buffer
86 */
87
88 /* 16 bit, RGB565 color spanline and pixel functions
89 */
90 #define SPANTMP_PIXEL_FMT GL_RGB
91 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
92
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)
97 #include "spantmp2.h"
98
99
100 /* 32 bit, ARGB8888 color spanline and pixel functions
101 */
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
106
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"
112
113
114 /* ================================================================
115 * Depth buffer
116 */
117
118 /* 16 bit depthbuffer functions.
119 */
120 #define WRITE_DEPTH( _x, _y, d ) \
121 *(GLushort *)(buf + ((_x) + (_y) * drb->pitch) * 2) = d;
122
123 #define READ_DEPTH( d, _x, _y ) \
124 d = *(GLushort *)(buf + ((_x) + (_y) * drb->pitch) * 2);
125
126 #define TAG(x) mach64##x##_z16
127 #include "depthtmp.h"
128
129
130 static void mach64SpanRenderStart( GLcontext *ctx )
131 {
132 mach64ContextPtr mmesa = MACH64_CONTEXT(ctx);
133 LOCK_HARDWARE( mmesa );
134 FINISH_DMA_LOCKED( mmesa );
135 }
136
137 static void mach64SpanRenderFinish( GLcontext *ctx )
138 {
139 mach64ContextPtr mmesa = MACH64_CONTEXT(ctx);
140 _swrast_flush( ctx );
141 UNLOCK_HARDWARE( mmesa );
142 }
143
144 void mach64DDInitSpanFuncs( GLcontext *ctx )
145 {
146 struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference(ctx);
147 swdd->SpanRenderStart = mach64SpanRenderStart;
148 swdd->SpanRenderFinish = mach64SpanRenderFinish;
149 }
150
151
152 /**
153 * Plug in the Get/Put routines for the given driRenderbuffer.
154 */
155 void
156 mach64SetSpanFunctions(driRenderbuffer *drb, const GLvisual *vis)
157 {
158 if (drb->Base.InternalFormat == GL_RGBA) {
159 if (vis->redBits == 5 && vis->greenBits == 6 && vis->blueBits == 5) {
160 mach64InitPointers_RGB565(&drb->Base);
161 }
162 else {
163 mach64InitPointers_ARGB8888(&drb->Base);
164 }
165 }
166 else if (drb->Base.InternalFormat == GL_DEPTH_COMPONENT16) {
167 mach64InitDepthPointers_z16(&drb->Base);
168 }
169 }