Also PUBLICize the config option table
[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
41 FFBWriteDepthSpan(GLcontext *ctx, GLuint n, GLint x, GLint y,
42 const GLdepth depth[], const GLubyte mask[])
43 {
44 #ifdef DEPTH_TRACE
45 fprintf(stderr, "FFBWriteDepthSpan: n(%d) x(%d) y(%d)\n",
46 (int) n, x, y);
47 #endif
48 if (ctx->Depth.Mask) {
49 ffbContextPtr fmesa = FFB_CONTEXT(ctx);
50 __DRIdrawablePrivate *dPriv = fmesa->driDrawable;
51 GLuint *zptr;
52 GLuint i;
53
54 if (!fmesa->hw_locked)
55 LOCK_HARDWARE(fmesa);
56 FFBFifo(fmesa, 2);
57 fmesa->regs->fbc = (FFB_FBC_WB_C | FFB_FBC_ZE_ON |
58 FFB_FBC_YE_OFF | FFB_FBC_RGBE_OFF);
59 fmesa->regs->ppc = FFB_PPC_ZS_VAR;
60 FFBWait(fmesa, fmesa->regs);
61
62 y = (dPriv->h - y);
63 zptr = (GLuint *)
64 ((char *)fmesa->sfb32 +
65 ((dPriv->x + x) << 2) +
66 ((dPriv->y + y) << 13));
67
68 for (i = 0; i < n; i++) {
69 if (mask[i]) {
70 *zptr = Z_FROM_MESA(depth[i]);
71 }
72 zptr++;
73 }
74
75 FFBFifo(fmesa, 2);
76 fmesa->regs->fbc = fmesa->fbc;
77 fmesa->regs->ppc = fmesa->ppc;
78 fmesa->ffbScreen->rp_active = 1;
79 if (!fmesa->hw_locked)
80 UNLOCK_HARDWARE(fmesa);
81 }
82 }
83
84 static void
85 FFBWriteDepthPixels(GLcontext *ctx, GLuint n, const GLint x[], const GLint y[],
86 const GLdepth depth[], const GLubyte mask[])
87 {
88 #ifdef DEPTH_TRACE
89 fprintf(stderr, "FFBWriteDepthPixels: n(%d)\n", (int) n);
90 #endif
91 if (ctx->Depth.Mask) {
92 ffbContextPtr fmesa = FFB_CONTEXT(ctx);
93 __DRIdrawablePrivate *dPriv = fmesa->driDrawable;
94 char *zbase;
95 GLuint i;
96
97 if (!fmesa->hw_locked)
98 LOCK_HARDWARE(fmesa);
99 FFBFifo(fmesa, 2);
100 fmesa->regs->fbc = (FFB_FBC_WB_C | FFB_FBC_ZE_ON |
101 FFB_FBC_YE_OFF | FFB_FBC_RGBE_OFF);
102 fmesa->regs->ppc = FFB_PPC_ZS_VAR;
103 fmesa->ffbScreen->rp_active = 1;
104 FFBWait(fmesa, fmesa->regs);
105
106 zbase = ((char *)fmesa->sfb32 +
107 (dPriv->x << 2) + (dPriv->y << 13));
108
109 for (i = 0; i < n; i++) {
110 GLint y1 = (dPriv->h - y[i]);
111 GLint x1 = x[i];
112 GLuint *zptr;
113
114 zptr = (GLuint *)
115 (zbase + (x1 << 2) + (y1 << 13));
116 if (mask[i])
117 *zptr = Z_FROM_MESA(depth[i]);
118 }
119
120 FFBFifo(fmesa, 2);
121 fmesa->regs->fbc = fmesa->fbc;
122 fmesa->regs->ppc = fmesa->ppc;
123 fmesa->ffbScreen->rp_active = 1;
124 if (!fmesa->hw_locked)
125 UNLOCK_HARDWARE(fmesa);
126 }
127 }
128
129 static void
130 FFBReadDepthSpan(GLcontext *ctx, GLuint n, GLint x, GLint y, GLdepth depth[])
131 {
132 ffbContextPtr fmesa = FFB_CONTEXT(ctx);
133 __DRIdrawablePrivate *dPriv = fmesa->driDrawable;
134 GLuint *zptr;
135 GLuint i;
136
137 #ifdef DEPTH_TRACE
138 fprintf(stderr, "FFBReadDepthSpan: n(%d) x(%d) y(%d)\n",
139 (int) n, x, y);
140 #endif
141 if (!fmesa->hw_locked)
142 LOCK_HARDWARE(fmesa);
143 FFBFifo(fmesa, 1);
144 fmesa->regs->fbc = FFB_FBC_RB_C;
145 fmesa->ffbScreen->rp_active = 1;
146 FFBWait(fmesa, fmesa->regs);
147
148 y = (dPriv->h - y);
149 zptr = (GLuint *)
150 ((char *)fmesa->sfb32 +
151 ((dPriv->x + x) << 2) +
152 ((dPriv->y + y) << 13));
153
154 for (i = 0; i < n; i++) {
155 depth[i] = Z_TO_MESA(*zptr);
156 zptr++;
157 }
158
159 FFBFifo(fmesa, 1);
160 fmesa->regs->fbc = fmesa->fbc;
161 fmesa->ffbScreen->rp_active = 1;
162 if (!fmesa->hw_locked)
163 UNLOCK_HARDWARE(fmesa);
164 }
165
166 static void
167 FFBReadDepthPixels(GLcontext *ctx, GLuint n, const GLint x[], const GLint y[],
168 GLdepth depth[])
169 {
170 ffbContextPtr fmesa = FFB_CONTEXT(ctx);
171 __DRIdrawablePrivate *dPriv = fmesa->driDrawable;
172 char *zbase;
173 GLuint i;
174
175 #ifdef DEPTH_TRACE
176 fprintf(stderr, "FFBReadDepthPixels: n(%d)\n", (int) n);
177 #endif
178 if (!fmesa->hw_locked)
179 LOCK_HARDWARE(fmesa);
180 FFBFifo(fmesa, 1);
181 fmesa->regs->fbc = FFB_FBC_RB_C;
182 fmesa->ffbScreen->rp_active = 1;
183 FFBWait(fmesa, fmesa->regs);
184
185 zbase = ((char *)fmesa->sfb32 +
186 (dPriv->x << 2) + (dPriv->y << 13));
187
188 for (i = 0; i < n; i++) {
189 GLint y1 = (dPriv->h - y[i]);
190 GLint x1 = x[i];
191 GLuint *zptr;
192
193 zptr = (GLuint *)
194 (zbase + (x1 << 2) + (y1 << 13));
195 depth[i] = Z_TO_MESA(*zptr);
196 }
197
198 FFBFifo(fmesa, 1);
199 fmesa->regs->fbc = fmesa->fbc;
200 fmesa->ffbScreen->rp_active = 1;
201 if (!fmesa->hw_locked)
202 UNLOCK_HARDWARE(fmesa);
203 }
204
205 void ffbDDInitDepthFuncs(GLcontext *ctx)
206 {
207 struct swrast_device_driver *swdd =
208 _swrast_GetDeviceDriverReference(ctx);
209
210 swdd->WriteDepthSpan = FFBWriteDepthSpan;
211 swdd->ReadDepthSpan = FFBReadDepthSpan;
212 swdd->WriteDepthPixels = FFBWriteDepthPixels;
213 swdd->ReadDepthPixels = FFBReadDepthPixels;
214 }