SetBuffer, renderbuffer changes
[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 GET_PTR(X,Y) (sPriv->pFB + drb->offset \
42 + ((dPriv->y + (Y)) * drb->pitch + (dPriv->x + (X))) * drb->cpp)
43
44 #define LOCAL_VARS \
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; \
50 GLushort p; \
51 (void) p;
52
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)
61
62 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
63
64 #define Y_FLIP( _y ) (height - _y - 1)
65
66 #define HW_LOCK()
67
68 /* FIXME could/should we use dPriv->numClipRects like the other drivers? */
69 #define HW_CLIPLOOP() \
70 do { \
71 int _nc = mmesa->numClipRects; \
72 \
73 while ( _nc-- ) { \
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;
78
79 #define HW_ENDCLIPLOOP() \
80 } \
81 } while (0)
82
83 #define HW_UNLOCK()
84
85
86
87 /* ================================================================
88 * Color buffer
89 */
90
91 /* 16 bit, RGB565 color spanline and pixel functions
92 */
93 #define SPANTMP_PIXEL_FMT GL_RGB
94 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
95
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"
101
102
103 /* 32 bit, ARGB8888 color spanline and pixel functions
104 */
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
109
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"
115
116
117 /* ================================================================
118 * Depth buffer
119 */
120
121 /* 16 bit depthbuffer functions.
122 */
123 #define WRITE_DEPTH( _x, _y, d ) \
124 *(GLushort *)(buf + ((_x) + (_y) * drb->pitch) * 2) = d;
125
126 #define READ_DEPTH( d, _x, _y ) \
127 d = *(GLushort *)(buf + ((_x) + (_y) * drb->pitch) * 2);
128
129 #define TAG(x) mach64##x##_z16
130 #include "depthtmp.h"
131
132
133 static void mach64SpanRenderStart( GLcontext *ctx )
134 {
135 mach64ContextPtr mmesa = MACH64_CONTEXT(ctx);
136 LOCK_HARDWARE( mmesa );
137 FINISH_DMA_LOCKED( mmesa );
138 }
139
140 static void mach64SpanRenderFinish( GLcontext *ctx )
141 {
142 mach64ContextPtr mmesa = MACH64_CONTEXT(ctx);
143 _swrast_flush( ctx );
144 UNLOCK_HARDWARE( mmesa );
145 }
146
147 void mach64DDInitSpanFuncs( GLcontext *ctx )
148 {
149 struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference(ctx);
150 swdd->SpanRenderStart = mach64SpanRenderStart;
151 swdd->SpanRenderFinish = mach64SpanRenderFinish;
152 }
153
154
155 /**
156 * Plug in the Get/Put routines for the given driRenderbuffer.
157 */
158 void
159 mach64SetSpanFunctions(driRenderbuffer *drb, const GLvisual *vis)
160 {
161 if (drb->Base.InternalFormat == GL_RGBA) {
162 if (vis->redBits == 5 && vis->greenBits == 6 && vis->blueBits == 5) {
163 mach64InitPointers_RGB565(&drb->Base);
164 }
165 else {
166 mach64InitPointers_ARGB8888(&drb->Base);
167 }
168 }
169 else if (drb->Base.InternalFormat == GL_DEPTH_COMPONENT16) {
170 mach64InitDepthPointers_z16(&drb->Base);
171 }
172 }