draw: corrections to allow for different cliptest cases
[mesa.git] / src / mesa / drivers / dri / mga / mgaspan.c
1 /*
2 * Copyright 2000-2001 VA Linux Systems, Inc.
3 * All Rights Reserved.
4 *
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:
11 *
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
14 * Software.
15 *
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.
23 *
24 * Authors:
25 * Keith Whitwell <keith@tungstengraphics.com>
26 */
27
28 #include "main/mtypes.h"
29 #include "mgadd.h"
30 #include "mgacontext.h"
31 #include "mgaspan.h"
32 #include "mgaioctl.h"
33 #include "swrast/swrast.h"
34
35 #define DBG 0
36
37 #define LOCAL_VARS \
38 mgaContextPtr mmesa = MGA_CONTEXT(ctx); \
39 __DRIscreen *sPriv = mmesa->driScreen; \
40 driRenderbuffer *drb = (driRenderbuffer *) rb; \
41 const __DRIdrawable *dPriv = drb->dPriv; \
42 GLuint pitch = drb->pitch; \
43 GLuint height = dPriv->h; \
44 char *buf = (char *)(sPriv->pFB + \
45 drb->offset + \
46 dPriv->x * drb->cpp + \
47 dPriv->y * pitch); \
48 GLuint p; \
49 (void) buf; (void) p
50
51
52
53 #define LOCAL_DEPTH_VARS \
54 mgaContextPtr mmesa = MGA_CONTEXT(ctx); \
55 __DRIscreen *sPriv = mmesa->driScreen; \
56 driRenderbuffer *drb = (driRenderbuffer *) rb; \
57 const __DRIdrawable *dPriv = drb->dPriv; \
58 GLuint pitch = drb->pitch; \
59 GLuint height = dPriv->h; \
60 char *buf = (char *)(sPriv->pFB + \
61 drb->offset + \
62 dPriv->x * drb->cpp + \
63 dPriv->y * pitch)
64
65 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
66
67 #define HW_LOCK()
68
69 /* FIXME could/should we use dPriv->numClipRects like the other drivers? */
70 #define HW_CLIPLOOP() \
71 do { \
72 int _nc = mmesa->numClipRects; \
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 #define Y_FLIP(_y) (height - _y - 1)
88
89 /* 16 bit, RGB565 color spanline and pixel functions
90 */
91 #define SPANTMP_PIXEL_FMT GL_RGB
92 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
93
94 #define TAG(x) mga##x##_565
95 #define TAG2(x,y) mga##x##_565##y
96 #include "spantmp2.h"
97
98 /* 32 bit, ARGB8888 color spanline and pixel functions
99 */
100 #define SPANTMP_PIXEL_FMT GL_BGRA
101 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
102
103 #define TAG(x) mga##x##_8888
104 #define TAG2(x,y) mga##x##_8888##y
105 #include "spantmp2.h"
106
107
108 /* 16 bit depthbuffer functions.
109 */
110 #define VALUE_TYPE GLushort
111
112 #define WRITE_DEPTH( _x, _y, d ) \
113 *(GLushort *)(buf + (_x)*2 + (_y)*pitch) = d;
114
115 #define READ_DEPTH( d, _x, _y ) \
116 d = *(GLushort *)(buf + (_x)*2 + (_y)*pitch);
117
118 #define TAG(x) mga##x##_z16
119 #include "depthtmp.h"
120
121
122
123
124 /* 32 bit depthbuffer functions.
125 */
126 #define VALUE_TYPE GLuint
127
128 #define WRITE_DEPTH( _x, _y, d ) \
129 *(GLuint *)(buf + (_x)*4 + (_y)*pitch) = d;
130
131 #define READ_DEPTH( d, _x, _y ) \
132 d = *(GLuint *)(buf + (_x)*4 + (_y)*pitch);
133
134 #define TAG(x) mga##x##_z32
135 #include "depthtmp.h"
136
137
138
139 /* 24/8 bit interleaved depth/stencil functions
140 */
141 #define VALUE_TYPE GLuint
142
143 #define WRITE_DEPTH( _x, _y, d ) { \
144 GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*pitch); \
145 tmp &= 0xff; \
146 tmp |= (d) << 8; \
147 *(GLuint *)(buf + (_x)*4 + (_y)*pitch) = tmp; \
148 }
149
150 #define READ_DEPTH( d, _x, _y ) { \
151 d = (*(GLuint *)(buf + (_x)*4 + (_y)*pitch) & ~0xff) >> 8; \
152 }
153
154 #define TAG(x) mga##x##_z24_s8
155 #include "depthtmp.h"
156
157 #define WRITE_STENCIL( _x, _y, d ) { \
158 GLuint tmp = *(GLuint *)(buf + _x*4 + _y*pitch); \
159 tmp &= 0xffffff00; \
160 tmp |= d & 0xff; \
161 *(GLuint *)(buf + _x*4 + _y*pitch) = tmp; \
162 }
163
164 #define READ_STENCIL( d, _x, _y ) \
165 d = *(GLuint *)(buf + _x*4 + _y*pitch) & 0xff;
166
167 #define TAG(x) mga##x##_z24_s8
168 #include "stenciltmp.h"
169
170
171 static void
172 mgaSpanRenderStart( GLcontext *ctx )
173 {
174 mgaContextPtr mmesa = MGA_CONTEXT(ctx);
175 FLUSH_BATCH( mmesa );
176 LOCK_HARDWARE_QUIESCENT( mmesa );
177 }
178
179 static void
180 mgaSpanRenderFinish( GLcontext *ctx )
181 {
182 mgaContextPtr mmesa = MGA_CONTEXT(ctx);
183 _swrast_flush( ctx );
184 UNLOCK_HARDWARE( mmesa );
185 }
186
187 /**
188 * Initialize the driver callbacks for the read / write span functions.
189 *
190 * \bug
191 * To really support RGB888 and RGBA8888 visuals, we need separate read and
192 * write routines for 888 and 8888. We also need to determine whether or not
193 * the visual has destination alpha.
194 */
195 void mgaDDInitSpanFuncs( GLcontext *ctx )
196 {
197 struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference(ctx);
198 swdd->SpanRenderStart = mgaSpanRenderStart;
199 swdd->SpanRenderFinish = mgaSpanRenderFinish;
200 }
201
202
203 /**
204 * Plug in the Get/Put routines for the given driRenderbuffer.
205 */
206 void
207 mgaSetSpanFunctions(driRenderbuffer *drb, const GLvisual *vis)
208 {
209 if (drb->Base.Format == MESA_FORMAT_RGB565) {
210 mgaInitPointers_565(&drb->Base);
211 }
212 else if (drb->Base.Format == MESA_FORMAT_ARGB8888) {
213 mgaInitPointers_8888(&drb->Base);
214 }
215 else if (drb->Base.Format == MESA_FORMAT_Z16) {
216 mgaInitDepthPointers_z16(&drb->Base);
217 }
218 else if (drb->Base.Format == MESA_FORMAT_Z24_S8) {
219 mgaInitDepthPointers_z24_s8(&drb->Base);
220 }
221 else if (drb->Base.Format == MESA_FORMAT_Z32) {
222 mgaInitDepthPointers_z32(&drb->Base);
223 }
224 else if (drb->Base.Format == MESA_FORMAT_S8) {
225 mgaInitStencilPointers_z24_s8(&drb->Base);
226 }
227 }