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