Add Egberts fixes for 64bit architectures
[mesa.git] / src / mesa / drivers / dri / ffb / ffb_depth.c
1 /* $XFree86: xc/lib/GL/mesa/src/drv/ffb/ffb_depth.c,v 1.2 2002/02/22 21:32:58 dawes Exp $
2 *
3 * GLX Hardware Device Driver for Sun Creator/Creator3D
4 * Copyright (C) 2000 David S. Miller
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 shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * DAVID MILLER, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
22 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 *
24 *
25 * David S. Miller <davem@redhat.com>
26 */
27
28 #include "mtypes.h"
29 #include "swrast/swrast.h"
30 #include "ffb_dd.h"
31 #include "ffb_span.h"
32 #include "ffb_context.h"
33 #include "ffb_depth.h"
34 #include "ffb_lock.h"
35
36 #include "swrast/swrast.h"
37
38 #undef DEPTH_TRACE
39
40 static void FFBWriteDepthSpan( GLcontext *ctx,
41 struct gl_renderbuffer *rb,
42 GLuint n, GLint x, GLint y,
43 const void *values,
44 const GLubyte mask[] )
45 {
46 const GLuint *depth = (const GLuint *) values;
47 #ifdef DEPTH_TRACE
48 fprintf(stderr, "FFBWriteDepthSpan: n(%d) x(%d) y(%d)\n",
49 (int) n, x, y);
50 #endif
51 if (ctx->Depth.Mask) {
52 ffbContextPtr fmesa = FFB_CONTEXT(ctx);
53 __DRIdrawablePrivate *dPriv = fmesa->driDrawable;
54 GLuint *zptr;
55 GLuint i;
56
57 if (!fmesa->hw_locked)
58 LOCK_HARDWARE(fmesa);
59 FFBFifo(fmesa, 2);
60 fmesa->regs->fbc = (FFB_FBC_WB_C | FFB_FBC_ZE_ON |
61 FFB_FBC_YE_OFF | FFB_FBC_RGBE_OFF);
62 fmesa->regs->ppc = FFB_PPC_ZS_VAR;
63 FFBWait(fmesa, fmesa->regs);
64
65 y = (dPriv->h - y);
66 zptr = (GLuint *)
67 ((char *)fmesa->sfb32 +
68 ((dPriv->x + x) << 2) +
69 ((dPriv->y + y) << 13));
70
71 for (i = 0; i < n; i++) {
72 if (mask[i]) {
73 *zptr = Z_FROM_MESA(depth[i]);
74 }
75 zptr++;
76 }
77
78 FFBFifo(fmesa, 2);
79 fmesa->regs->fbc = fmesa->fbc;
80 fmesa->regs->ppc = fmesa->ppc;
81 fmesa->ffbScreen->rp_active = 1;
82 if (!fmesa->hw_locked)
83 UNLOCK_HARDWARE(fmesa);
84 }
85 }
86
87 static void FFBWriteMonoDepthSpan( GLcontext *ctx,
88 struct gl_renderbuffer *rb,
89 GLuint n, GLint x, GLint y,
90 const void *value, const GLubyte mask[] )
91 {
92 const GLuint depthVal = *((GLuint *) value);
93 GLuint depths[MAX_WIDTH];
94 GLuint i;
95 for (i = 0; i < n; i++)
96 depths[i] = depthVal;
97 FFBWriteDepthSpan(ctx, rb, n, x, y, depths, mask);
98 }
99
100 static void FFBWriteDepthPixels( GLcontext *ctx,
101 struct gl_renderbuffer *rb,
102 GLuint n,
103 const GLint x[],
104 const GLint y[],
105 const void *values,
106 const GLubyte mask[] )
107 {
108 const GLuint *depth = (const GLuint *) values;
109 #ifdef DEPTH_TRACE
110 fprintf(stderr, "FFBWriteDepthPixels: n(%d)\n", (int) n);
111 #endif
112 if (ctx->Depth.Mask) {
113 ffbContextPtr fmesa = FFB_CONTEXT(ctx);
114 __DRIdrawablePrivate *dPriv = fmesa->driDrawable;
115 char *zbase;
116 GLuint i;
117
118 if (!fmesa->hw_locked)
119 LOCK_HARDWARE(fmesa);
120 FFBFifo(fmesa, 2);
121 fmesa->regs->fbc = (FFB_FBC_WB_C | FFB_FBC_ZE_ON |
122 FFB_FBC_YE_OFF | FFB_FBC_RGBE_OFF);
123 fmesa->regs->ppc = FFB_PPC_ZS_VAR;
124 fmesa->ffbScreen->rp_active = 1;
125 FFBWait(fmesa, fmesa->regs);
126
127 zbase = ((char *)fmesa->sfb32 +
128 (dPriv->x << 2) + (dPriv->y << 13));
129
130 for (i = 0; i < n; i++) {
131 GLint y1 = (dPriv->h - y[i]);
132 GLint x1 = x[i];
133 GLuint *zptr;
134
135 zptr = (GLuint *)
136 (zbase + (x1 << 2) + (y1 << 13));
137 if (mask[i])
138 *zptr = Z_FROM_MESA(depth[i]);
139 }
140
141 FFBFifo(fmesa, 2);
142 fmesa->regs->fbc = fmesa->fbc;
143 fmesa->regs->ppc = fmesa->ppc;
144 fmesa->ffbScreen->rp_active = 1;
145 if (!fmesa->hw_locked)
146 UNLOCK_HARDWARE(fmesa);
147 }
148 }
149
150 static void FFBReadDepthSpan( GLcontext *ctx,
151 struct gl_renderbuffer *rb,
152 GLuint n, GLint x, GLint y,
153 void *values )
154 {
155 GLuint *depth = (GLuint *) values;
156 ffbContextPtr fmesa = FFB_CONTEXT(ctx);
157 __DRIdrawablePrivate *dPriv = fmesa->driDrawable;
158 GLuint *zptr;
159 GLuint i;
160
161 #ifdef DEPTH_TRACE
162 fprintf(stderr, "FFBReadDepthSpan: n(%d) x(%d) y(%d)\n",
163 (int) n, x, y);
164 #endif
165 if (!fmesa->hw_locked)
166 LOCK_HARDWARE(fmesa);
167 FFBFifo(fmesa, 1);
168 fmesa->regs->fbc = FFB_FBC_RB_C;
169 fmesa->ffbScreen->rp_active = 1;
170 FFBWait(fmesa, fmesa->regs);
171
172 y = (dPriv->h - y);
173 zptr = (GLuint *)
174 ((char *)fmesa->sfb32 +
175 ((dPriv->x + x) << 2) +
176 ((dPriv->y + y) << 13));
177
178 for (i = 0; i < n; i++) {
179 depth[i] = Z_TO_MESA(*zptr);
180 zptr++;
181 }
182
183 FFBFifo(fmesa, 1);
184 fmesa->regs->fbc = fmesa->fbc;
185 fmesa->ffbScreen->rp_active = 1;
186 if (!fmesa->hw_locked)
187 UNLOCK_HARDWARE(fmesa);
188 }
189
190 static void FFBReadDepthPixels( GLcontext *ctx,
191 struct gl_renderbuffer *rb,
192 GLuint n,
193 const GLint x[], const GLint y[],
194 void *values )
195 {
196 GLuint *depth = (GLuint *) values;
197 ffbContextPtr fmesa = FFB_CONTEXT(ctx);
198 __DRIdrawablePrivate *dPriv = fmesa->driDrawable;
199 char *zbase;
200 GLuint i;
201
202 #ifdef DEPTH_TRACE
203 fprintf(stderr, "FFBReadDepthPixels: n(%d)\n", (int) n);
204 #endif
205 if (!fmesa->hw_locked)
206 LOCK_HARDWARE(fmesa);
207 FFBFifo(fmesa, 1);
208 fmesa->regs->fbc = FFB_FBC_RB_C;
209 fmesa->ffbScreen->rp_active = 1;
210 FFBWait(fmesa, fmesa->regs);
211
212 zbase = ((char *)fmesa->sfb32 +
213 (dPriv->x << 2) + (dPriv->y << 13));
214
215 for (i = 0; i < n; i++) {
216 GLint y1 = (dPriv->h - y[i]);
217 GLint x1 = x[i];
218 GLuint *zptr;
219
220 zptr = (GLuint *)
221 (zbase + (x1 << 2) + (y1 << 13));
222 depth[i] = Z_TO_MESA(*zptr);
223 }
224
225 FFBFifo(fmesa, 1);
226 fmesa->regs->fbc = fmesa->fbc;
227 fmesa->ffbScreen->rp_active = 1;
228 if (!fmesa->hw_locked)
229 UNLOCK_HARDWARE(fmesa);
230 }
231
232 /**
233 * Plug in the Get/Put routines for the given driRenderbuffer.
234 */
235 void
236 ffbSetDepthFunctions(driRenderbuffer *drb, const GLvisual *vis)
237 {
238 assert(drb->Base.InternalFormat == GL_DEPTH_COMPONENT16);
239 drb->Base.GetRow = FFBReadDepthSpan;
240 drb->Base.GetValues = FFBReadDepthPixels;
241 drb->Base.PutRow = FFBWriteDepthSpan;
242 drb->Base.PutMonoRow = FFBWriteMonoDepthSpan;
243 drb->Base.PutValues = FFBWriteDepthPixels;
244 drb->Base.PutMonoValues = NULL;
245 }