Remove CVS keywords.
[mesa.git] / src / mesa / drivers / dri / ffb / ffb_stencil.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 "mtypes.h"
29 #include "ffb_dd.h"
30 #include "ffb_span.h"
31 #include "ffb_context.h"
32 #include "ffb_stencil.h"
33 #include "ffb_lock.h"
34
35 #include "swrast/swrast.h"
36
37 #undef STENCIL_TRACE
38
39 static void FFBWriteStencilSpan( GLcontext *ctx,
40 struct gl_renderbuffer *rb,
41 GLuint n, GLint x, GLint y,
42 const void *values, const GLubyte mask[] )
43 {
44 const GLubyte *stencil = (const GLubyte *) values;
45 #ifdef STENCIL_TRACE
46 fprintf(stderr, "FFBWriteStencilSpan: 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 __DRIdrawablePrivate *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_OFF |
59 FFB_FBC_YE_ON | FFB_FBC_RGBE_OFF);
60 fmesa->regs->ppc = FFB_PPC_YS_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 = (stencil[i] & 0xf) << 28;
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 FFBWriteStencilPixels( GLcontext *ctx,
85 struct gl_renderbuffer *rb,
86 GLuint n,
87 const GLint x[], const GLint y[],
88 const void *values, const GLubyte mask[] )
89 {
90 const GLubyte *stencil = (const GLubyte *) values;
91 #ifdef STENCIL_TRACE
92 fprintf(stderr, "FFBWriteStencilPixels: n(%d)\n", (int) n);
93 #endif
94 if (ctx->Depth.Mask) {
95 ffbContextPtr fmesa = FFB_CONTEXT(ctx);
96 __DRIdrawablePrivate *dPriv = fmesa->driDrawable;
97 char *zbase;
98 GLuint i;
99
100 if (!fmesa->hw_locked)
101 LOCK_HARDWARE(fmesa);
102 FFBFifo(fmesa, 2);
103 fmesa->regs->fbc = (FFB_FBC_WB_C | FFB_FBC_ZE_OFF |
104 FFB_FBC_YE_ON | FFB_FBC_RGBE_OFF);
105 fmesa->regs->ppc = FFB_PPC_YS_VAR;
106 fmesa->ffbScreen->rp_active = 1;
107 FFBWait(fmesa, fmesa->regs);
108
109 zbase = ((char *)fmesa->sfb32 +
110 (dPriv->x << 2) + (dPriv->y << 13));
111
112 for (i = 0; i < n; i++) {
113 GLint y1 = (dPriv->h - y[i]);
114 GLint x1 = x[i];
115 GLuint *zptr;
116
117 zptr = (GLuint *)
118 (zbase + (x1 << 2) + (y1 << 13));
119 if (mask[i])
120 *zptr = (stencil[i] & 0xf) << 28;
121 }
122
123 FFBFifo(fmesa, 2);
124 fmesa->regs->fbc = fmesa->fbc;
125 fmesa->regs->ppc = fmesa->ppc;
126 fmesa->ffbScreen->rp_active = 1;
127 if (!fmesa->hw_locked)
128 UNLOCK_HARDWARE(fmesa);
129 }
130 }
131
132 static void FFBReadStencilSpan( GLcontext *ctx,
133 struct gl_renderbuffer *rb,
134 GLuint n, GLint x, GLint y,
135 void *values)
136 {
137 GLubyte *stencil = (GLubyte *) values;
138 ffbContextPtr fmesa = FFB_CONTEXT(ctx);
139 __DRIdrawablePrivate *dPriv = fmesa->driDrawable;
140 GLuint *zptr;
141 GLuint i;
142
143 #ifdef STENCIL_TRACE
144 fprintf(stderr, "FFBReadStencilSpan: n(%d) x(%d) y(%d)\n",
145 (int) n, x, y);
146 #endif
147 if (!fmesa->hw_locked)
148 LOCK_HARDWARE(fmesa);
149 FFBFifo(fmesa, 1);
150 fmesa->regs->fbc = FFB_FBC_RB_C;
151 fmesa->ffbScreen->rp_active = 1;
152 FFBWait(fmesa, fmesa->regs);
153
154 y = (dPriv->h - y);
155 zptr = (GLuint *)
156 ((char *)fmesa->sfb32 +
157 ((dPriv->x + x) << 2) +
158 ((dPriv->y + y) << 13));
159
160 for (i = 0; i < n; i++) {
161 stencil[i] = (*zptr >> 28) & 0xf;
162 zptr++;
163 }
164
165 FFBFifo(fmesa, 1);
166 fmesa->regs->fbc = fmesa->fbc;
167 fmesa->ffbScreen->rp_active = 1;
168 if (!fmesa->hw_locked)
169 UNLOCK_HARDWARE(fmesa);
170 }
171
172 static void FFBReadStencilPixels( GLcontext *ctx,
173 struct gl_renderbuffer *rb,
174 GLuint n, const GLint x[], const GLint y[],
175 void *values )
176 {
177 GLubyte *stencil = (GLubyte *) values;
178 ffbContextPtr fmesa = FFB_CONTEXT(ctx);
179 __DRIdrawablePrivate *dPriv = fmesa->driDrawable;
180 char *zbase;
181 GLuint i;
182
183 #ifdef STENCIL_TRACE
184 fprintf(stderr, "FFBReadStencilPixels: n(%d)\n", (int) n);
185 #endif
186 if (!fmesa->hw_locked)
187 LOCK_HARDWARE(fmesa);
188 FFBFifo(fmesa, 1);
189 fmesa->regs->fbc = FFB_FBC_RB_C;
190 fmesa->ffbScreen->rp_active = 1;
191 FFBWait(fmesa, fmesa->regs);
192
193 zbase = ((char *)fmesa->sfb32 +
194 (dPriv->x << 2) + (dPriv->y << 13));
195
196 for (i = 0; i < n; i++) {
197 GLint y1 = (dPriv->h - y[i]);
198 GLint x1 = x[i];
199 GLuint *zptr;
200
201 zptr = (GLuint *)
202 (zbase + (x1 << 2) + (y1 << 13));
203 stencil[i] = (*zptr >> 28) & 0xf;
204 }
205
206 FFBFifo(fmesa, 1);
207 fmesa->regs->fbc = fmesa->fbc;
208 fmesa->ffbScreen->rp_active = 1;
209 if (!fmesa->hw_locked)
210 UNLOCK_HARDWARE(fmesa);
211 }
212
213 /**
214 * Plug in the Get/Put routines for the given driRenderbuffer.
215 */
216 void
217 ffbSetStencilFunctions(driRenderbuffer *drb, const GLvisual *vis)
218 {
219 assert(drb->Base.InternalFormat == GL_STENCIL_INDEX8_EXT);
220 drb->Base.GetRow = FFBReadStencilSpan;
221 drb->Base.GetValues = FFBReadStencilPixels;
222 drb->Base.PutRow = FFBWriteStencilSpan;
223 /*drb->Base.PutMonoRow = FFBWriteMonoStencilSpan;*/
224 drb->Base.PutValues = FFBWriteStencilPixels;
225 drb->Base.PutMonoValues = NULL;
226 }