make r128SpanRenderStart/Finish static
[mesa.git] / src / mesa / drivers / dri / r128 / r128_span.c
1 /* $XFree86: xc/lib/GL/mesa/src/drv/r128/r128_span.c,v 1.8 2002/10/30 12:51:39 alanh Exp $ */
2 /**************************************************************************
3
4 Copyright 1999, 2000 ATI Technologies Inc. and Precision Insight, Inc.,
5 Cedar Park, Texas.
6 All Rights Reserved.
7
8 Permission is hereby granted, free of charge, to any person obtaining a
9 copy of this software and associated documentation files (the "Software"),
10 to deal in the Software without restriction, including without limitation
11 on the rights to use, copy, modify, merge, publish, distribute, sub
12 license, and/or sell copies of the Software, and to permit persons to whom
13 the Software is furnished to do so, subject to the following conditions:
14
15 The above copyright notice and this permission notice (including the next
16 paragraph) shall be included in all copies or substantial portions of the
17 Software.
18
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
22 ATI, PRECISION INSIGHT AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
23 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
25 USE OR OTHER DEALINGS IN THE SOFTWARE.
26
27 **************************************************************************/
28
29 /*
30 * Authors:
31 * Gareth Hughes <gareth@valinux.com>
32 * Keith Whitwell <keith@tungstengraphics.com>
33 * Kevin E. Martin <martin@valinux.com>
34 *
35 */
36
37 #include "r128_context.h"
38 #include "r128_ioctl.h"
39 #include "r128_state.h"
40 #include "r128_span.h"
41 #include "r128_tex.h"
42
43 #include "swrast/swrast.h"
44
45 #define DBG 0
46
47 #define HAVE_HW_DEPTH_SPANS 1
48 #define HAVE_HW_DEPTH_PIXELS 1
49
50 #define LOCAL_VARS \
51 r128ContextPtr rmesa = R128_CONTEXT(ctx); \
52 __DRIscreenPrivate *sPriv = rmesa->driScreen; \
53 __DRIdrawablePrivate *dPriv = rmesa->driDrawable; \
54 driRenderbuffer *drb = (driRenderbuffer *) rb; \
55 GLuint height = dPriv->h; \
56 GLuint p; \
57 (void) p;
58
59 #define LOCAL_DEPTH_VARS \
60 r128ContextPtr rmesa = R128_CONTEXT(ctx); \
61 r128ScreenPtr r128scrn = rmesa->r128Screen; \
62 __DRIscreenPrivate *sPriv = rmesa->driScreen; \
63 __DRIdrawablePrivate *dPriv = rmesa->driDrawable; \
64 GLuint height = dPriv->h; \
65 (void) r128scrn; (void) sPriv; (void) height
66
67 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
68
69 #define Y_FLIP( _y ) (height - _y - 1)
70
71 #define HW_LOCK()
72
73 #define HW_UNLOCK()
74
75
76
77 /* ================================================================
78 * Color buffer
79 */
80
81 /* 16 bit, RGB565 color spanline and pixel functions
82 */
83 #define SPANTMP_PIXEL_FMT GL_RGB
84 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
85
86 #define TAG(x) r128##x##_RGB565
87 #define TAG2(x,y) r128##x##_RGB565##y
88 #define GET_PTR(X,Y) (sPriv->pFB + drb->flippedOffset \
89 + ((dPriv->y + (Y)) * drb->flippedPitch + (dPriv->x + (X))) * drb->cpp)
90 #include "spantmp2.h"
91
92
93 /* 32 bit, ARGB8888 color spanline and pixel functions
94 */
95 #define SPANTMP_PIXEL_FMT GL_BGRA
96 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
97
98 #define TAG(x) r128##x##_ARGB8888
99 #define TAG2(x,y) r128##x##_ARGB8888##y
100 #define GET_PTR(X,Y) (sPriv->pFB + drb->flippedOffset \
101 + ((dPriv->y + (Y)) * drb->flippedPitch + (dPriv->x + (X))) * drb->cpp)
102 #include "spantmp2.h"
103
104
105 /* ================================================================
106 * Depth buffer
107 */
108
109 /* 16-bit depth buffer functions
110 */
111
112 #define WRITE_DEPTH_SPAN() \
113 r128WriteDepthSpanLocked( rmesa, n, \
114 x + dPriv->x, \
115 y + dPriv->y, \
116 depth, mask );
117
118 #define WRITE_DEPTH_PIXELS() \
119 do { \
120 GLint ox[MAX_WIDTH]; \
121 GLint oy[MAX_WIDTH]; \
122 for ( i = 0 ; i < n ; i++ ) { \
123 ox[i] = x[i] + dPriv->x; \
124 oy[i] = Y_FLIP( y[i] ) + dPriv->y; \
125 } \
126 r128WriteDepthPixelsLocked( rmesa, n, ox, oy, depth, mask ); \
127 } while (0)
128
129 #define READ_DEPTH_SPAN() \
130 do { \
131 GLushort *buf = (GLushort *)((GLubyte *)sPriv->pFB + \
132 r128scrn->spanOffset); \
133 GLint i; \
134 \
135 r128ReadDepthSpanLocked( rmesa, n, \
136 x + dPriv->x, \
137 y + dPriv->y ); \
138 r128WaitForIdleLocked( rmesa ); \
139 \
140 for ( i = 0 ; i < n ; i++ ) { \
141 depth[i] = buf[i]; \
142 } \
143 } while (0)
144
145 #define READ_DEPTH_PIXELS() \
146 do { \
147 GLushort *buf = (GLushort *)((GLubyte *)sPriv->pFB + \
148 r128scrn->spanOffset); \
149 GLint i, remaining = n; \
150 \
151 while ( remaining > 0 ) { \
152 GLint ox[128]; \
153 GLint oy[128]; \
154 GLint count; \
155 \
156 if ( remaining <= 128 ) { \
157 count = remaining; \
158 } else { \
159 count = 128; \
160 } \
161 for ( i = 0 ; i < count ; i++ ) { \
162 ox[i] = x[i] + dPriv->x; \
163 oy[i] = Y_FLIP( y[i] ) + dPriv->y; \
164 } \
165 \
166 r128ReadDepthPixelsLocked( rmesa, count, ox, oy ); \
167 r128WaitForIdleLocked( rmesa ); \
168 \
169 for ( i = 0 ; i < count ; i++ ) { \
170 depth[i] = buf[i]; \
171 } \
172 depth += count; \
173 x += count; \
174 y += count; \
175 remaining -= count; \
176 } \
177 } while (0)
178
179 #define TAG(x) r128##x##_z16
180 #include "depthtmp.h"
181
182
183 /* 24-bit depth, 8-bit stencil buffer functions
184 */
185 #define WRITE_DEPTH_SPAN() \
186 r128WriteDepthSpanLocked( rmesa, n, \
187 x + dPriv->x, \
188 y + dPriv->y, \
189 depth, mask );
190
191 #define WRITE_DEPTH_PIXELS() \
192 do { \
193 GLint ox[MAX_WIDTH]; \
194 GLint oy[MAX_WIDTH]; \
195 for ( i = 0 ; i < n ; i++ ) { \
196 ox[i] = x[i] + dPriv->x; \
197 oy[i] = Y_FLIP( y[i] ) + dPriv->y; \
198 } \
199 r128WriteDepthPixelsLocked( rmesa, n, ox, oy, depth, mask ); \
200 } while (0)
201
202 #define READ_DEPTH_SPAN() \
203 do { \
204 GLuint *buf = (GLuint *)((GLubyte *)sPriv->pFB + \
205 r128scrn->spanOffset); \
206 GLint i; \
207 \
208 r128ReadDepthSpanLocked( rmesa, n, \
209 x + dPriv->x, \
210 y + dPriv->y ); \
211 r128WaitForIdleLocked( rmesa ); \
212 \
213 for ( i = 0 ; i < n ; i++ ) { \
214 depth[i] = buf[i] & 0x00ffffff; \
215 } \
216 } while (0)
217
218 #define READ_DEPTH_PIXELS() \
219 do { \
220 GLuint *buf = (GLuint *)((GLubyte *)sPriv->pFB + \
221 r128scrn->spanOffset); \
222 GLint i, remaining = n; \
223 \
224 while ( remaining > 0 ) { \
225 GLint ox[128]; \
226 GLint oy[128]; \
227 GLint count; \
228 \
229 if ( remaining <= 128 ) { \
230 count = remaining; \
231 } else { \
232 count = 128; \
233 } \
234 for ( i = 0 ; i < count ; i++ ) { \
235 ox[i] = x[i] + dPriv->x; \
236 oy[i] = Y_FLIP( y[i] ) + dPriv->y; \
237 } \
238 \
239 r128ReadDepthPixelsLocked( rmesa, count, ox, oy ); \
240 r128WaitForIdleLocked( rmesa ); \
241 \
242 for ( i = 0 ; i < count ; i++ ) { \
243 depth[i] = buf[i] & 0x00ffffff; \
244 } \
245 depth += count; \
246 x += count; \
247 y += count; \
248 remaining -= count; \
249 } \
250 } while (0)
251
252 #define TAG(x) r128##x##_z24_s8
253 #include "depthtmp.h"
254
255
256
257 /* ================================================================
258 * Stencil buffer
259 */
260
261 /* FIXME: Add support for hardware stencil buffers.
262 */
263
264 static void
265 r128SpanRenderStart( GLcontext *ctx )
266 {
267 r128ContextPtr rmesa = R128_CONTEXT(ctx);
268 FLUSH_BATCH(rmesa);
269 LOCK_HARDWARE(rmesa);
270 r128WaitForIdleLocked( rmesa );
271 }
272
273 static void
274 r128SpanRenderFinish( GLcontext *ctx )
275 {
276 r128ContextPtr rmesa = R128_CONTEXT(ctx);
277 _swrast_flush( ctx );
278 UNLOCK_HARDWARE( rmesa );
279 }
280
281 void r128DDInitSpanFuncs( GLcontext *ctx )
282 {
283 struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference(ctx);
284 swdd->SpanRenderStart = r128SpanRenderStart;
285 swdd->SpanRenderFinish = r128SpanRenderFinish;
286 }
287
288
289 /**
290 * Plug in the Get/Put routines for the given driRenderbuffer.
291 */
292 void
293 r128SetSpanFunctions(driRenderbuffer *drb, const GLvisual *vis)
294 {
295 if (drb->Base.InternalFormat == GL_RGBA) {
296 if (vis->redBits == 5 && vis->greenBits == 6 && vis->blueBits == 5) {
297 r128InitPointers_RGB565(&drb->Base);
298 }
299 else {
300 r128InitPointers_ARGB8888(&drb->Base);
301 }
302 }
303 else if (drb->Base.InternalFormat == GL_DEPTH_COMPONENT16) {
304 r128InitDepthPointers_z16(&drb->Base);
305 }
306 else if (drb->Base.InternalFormat == GL_DEPTH_COMPONENT24) {
307 r128InitDepthPointers_z24_s8(&drb->Base);
308 }
309 }