fafae5de7e53e628616b8b4b47a2c341d33246fd
[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 "main/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
37 #undef DEPTH_TRACE
38
39 static void FFBWriteDepthSpan( GLcontext *ctx,
40 struct gl_renderbuffer *rb,
41 GLuint n, GLint x, GLint y,
42 const void *values,
43 const GLubyte mask[] )
44 {
45 const GLuint *depth = (const GLuint *) values;
46 #ifdef DEPTH_TRACE
47 fprintf(stderr, "FFBWriteDepthSpan: n(%d) x(%d) y(%d)\n",
48 (int) n, x, y);
49 #endif
50 if (ctx->Depth.Mask) {
51 ffbContextPtr fmesa = FFB_CONTEXT(ctx);
52 __DRIdrawablePrivate *dPriv = fmesa->driDrawable;
53 GLuint *zptr;
54 GLuint i;
55
56 if (!fmesa->hw_locked)
57 LOCK_HARDWARE(fmesa);
58 FFBFifo(fmesa, 2);
59 fmesa->regs->fbc = (FFB_FBC_WB_C | FFB_FBC_ZE_ON |
60 FFB_FBC_YE_OFF | FFB_FBC_RGBE_OFF);
61 fmesa->regs->ppc = FFB_PPC_ZS_VAR;
62 FFBWait(fmesa, fmesa->regs);
63
64 y = (dPriv->h - y);
65 zptr = (GLuint *)
66 ((char *)fmesa->sfb32 +
67 ((dPriv->x + x) << 2) +
68 ((dPriv->y + y) << 13));
69
70 for (i = 0; i < n; i++) {
71 if (mask[i]) {
72 *zptr = Z_FROM_MESA(depth[i]);
73 }
74 zptr++;
75 }
76
77 FFBFifo(fmesa, 2);
78 fmesa->regs->fbc = fmesa->fbc;
79 fmesa->regs->ppc = fmesa->ppc;
80 fmesa->ffbScreen->rp_active = 1;
81 if (!fmesa->hw_locked)
82 UNLOCK_HARDWARE(fmesa);
83 }
84 }
85
86 static void FFBWriteMonoDepthSpan( GLcontext *ctx,
87 struct gl_renderbuffer *rb,
88 GLuint n, GLint x, GLint y,
89 const void *value, const GLubyte mask[] )
90 {
91 const GLuint depthVal = *((GLuint *) value);
92 GLuint depths[MAX_WIDTH];
93 GLuint i;
94 for (i = 0; i < n; i++)
95 depths[i] = depthVal;
96 FFBWriteDepthSpan(ctx, rb, n, x, y, depths, mask);
97 }
98
99 static void FFBWriteDepthPixels( GLcontext *ctx,
100 struct gl_renderbuffer *rb,
101 GLuint n,
102 const GLint x[],
103 const GLint y[],
104 const void *values,
105 const GLubyte mask[] )
106 {
107 const GLuint *depth = (const GLuint *) values;
108 #ifdef DEPTH_TRACE
109 fprintf(stderr, "FFBWriteDepthPixels: n(%d)\n", (int) n);
110 #endif
111 if (ctx->Depth.Mask) {
112 ffbContextPtr fmesa = FFB_CONTEXT(ctx);
113 __DRIdrawablePrivate *dPriv = fmesa->driDrawable;
114 char *zbase;
115 GLuint i;
116
117 if (!fmesa->hw_locked)
118 LOCK_HARDWARE(fmesa);
119 FFBFifo(fmesa, 2);
120 fmesa->regs->fbc = (FFB_FBC_WB_C | FFB_FBC_ZE_ON |
121 FFB_FBC_YE_OFF | FFB_FBC_RGBE_OFF);
122 fmesa->regs->ppc = FFB_PPC_ZS_VAR;
123 fmesa->ffbScreen->rp_active = 1;
124 FFBWait(fmesa, fmesa->regs);
125
126 zbase = ((char *)fmesa->sfb32 +
127 (dPriv->x << 2) + (dPriv->y << 13));
128
129 for (i = 0; i < n; i++) {
130 GLint y1 = (dPriv->h - y[i]);
131 GLint x1 = x[i];
132 GLuint *zptr;
133
134 zptr = (GLuint *)
135 (zbase + (x1 << 2) + (y1 << 13));
136 if (mask[i])
137 *zptr = Z_FROM_MESA(depth[i]);
138 }
139
140 FFBFifo(fmesa, 2);
141 fmesa->regs->fbc = fmesa->fbc;
142 fmesa->regs->ppc = fmesa->ppc;
143 fmesa->ffbScreen->rp_active = 1;
144 if (!fmesa->hw_locked)
145 UNLOCK_HARDWARE(fmesa);
146 }
147 }
148
149 static void FFBReadDepthSpan( GLcontext *ctx,
150 struct gl_renderbuffer *rb,
151 GLuint n, GLint x, GLint y,
152 void *values )
153 {
154 GLuint *depth = (GLuint *) values;
155 ffbContextPtr fmesa = FFB_CONTEXT(ctx);
156 __DRIdrawablePrivate *dPriv = fmesa->driDrawable;
157 GLuint *zptr;
158 GLuint i;
159
160 #ifdef DEPTH_TRACE
161 fprintf(stderr, "FFBReadDepthSpan: n(%d) x(%d) y(%d)\n",
162 (int) n, x, y);
163 #endif
164 if (!fmesa->hw_locked)
165 LOCK_HARDWARE(fmesa);
166 FFBFifo(fmesa, 1);
167 fmesa->regs->fbc = FFB_FBC_RB_C;
168 fmesa->ffbScreen->rp_active = 1;
169 FFBWait(fmesa, fmesa->regs);
170
171 y = (dPriv->h - y);
172 zptr = (GLuint *)
173 ((char *)fmesa->sfb32 +
174 ((dPriv->x + x) << 2) +
175 ((dPriv->y + y) << 13));
176
177 for (i = 0; i < n; i++) {
178 depth[i] = Z_TO_MESA(*zptr);
179 zptr++;
180 }
181
182 FFBFifo(fmesa, 1);
183 fmesa->regs->fbc = fmesa->fbc;
184 fmesa->ffbScreen->rp_active = 1;
185 if (!fmesa->hw_locked)
186 UNLOCK_HARDWARE(fmesa);
187 }
188
189 static void FFBReadDepthPixels( GLcontext *ctx,
190 struct gl_renderbuffer *rb,
191 GLuint n,
192 const GLint x[], const GLint y[],
193 void *values )
194 {
195 GLuint *depth = (GLuint *) values;
196 ffbContextPtr fmesa = FFB_CONTEXT(ctx);
197 __DRIdrawablePrivate *dPriv = fmesa->driDrawable;
198 char *zbase;
199 GLuint i;
200
201 #ifdef DEPTH_TRACE
202 fprintf(stderr, "FFBReadDepthPixels: n(%d)\n", (int) n);
203 #endif
204 if (!fmesa->hw_locked)
205 LOCK_HARDWARE(fmesa);
206 FFBFifo(fmesa, 1);
207 fmesa->regs->fbc = FFB_FBC_RB_C;
208 fmesa->ffbScreen->rp_active = 1;
209 FFBWait(fmesa, fmesa->regs);
210
211 zbase = ((char *)fmesa->sfb32 +
212 (dPriv->x << 2) + (dPriv->y << 13));
213
214 for (i = 0; i < n; i++) {
215 GLint y1 = (dPriv->h - y[i]);
216 GLint x1 = x[i];
217 GLuint *zptr;
218
219 zptr = (GLuint *)
220 (zbase + (x1 << 2) + (y1 << 13));
221 depth[i] = Z_TO_MESA(*zptr);
222 }
223
224 FFBFifo(fmesa, 1);
225 fmesa->regs->fbc = fmesa->fbc;
226 fmesa->ffbScreen->rp_active = 1;
227 if (!fmesa->hw_locked)
228 UNLOCK_HARDWARE(fmesa);
229 }
230
231 /**
232 * Plug in the Get/Put routines for the given driRenderbuffer.
233 */
234 void
235 ffbSetDepthFunctions(driRenderbuffer *drb, const GLvisual *vis)
236 {
237 assert(drb->Base.InternalFormat == GL_DEPTH_COMPONENT16);
238 drb->Base.GetRow = FFBReadDepthSpan;
239 drb->Base.GetValues = FFBReadDepthPixels;
240 drb->Base.PutRow = FFBWriteDepthSpan;
241 drb->Base.PutMonoRow = FFBWriteMonoDepthSpan;
242 drb->Base.PutValues = FFBWriteDepthPixels;
243 drb->Base.PutMonoValues = NULL;
244 }