1 /* $XFree86: xc/lib/GL/mesa/src/drv/ffb/ffb_stencil.c,v 1.2 2002/02/22 21:32:59 dawes Exp $
3 * GLX Hardware Device Driver for Sun Creator/Creator3D
4 * Copyright (C) 2000 David S. Miller
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:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
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.
25 * David S. Miller <davem@redhat.com>
31 #include "ffb_context.h"
32 #include "ffb_stencil.h"
35 #include "swrast/swrast.h"
40 FFBWriteStencilSpan(GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
41 const GLstencil stencil
[], const GLubyte mask
[])
44 fprintf(stderr
, "FFBWriteStencilSpan: n(%d) x(%d) y(%d)\n",
47 if (ctx
->Depth
.Mask
) {
48 ffbContextPtr fmesa
= FFB_CONTEXT(ctx
);
49 __DRIdrawablePrivate
*dPriv
= fmesa
->driDrawable
;
53 if (!fmesa
->hw_locked
)
56 fmesa
->regs
->fbc
= (FFB_FBC_WB_C
| FFB_FBC_ZE_OFF
|
57 FFB_FBC_YE_ON
| FFB_FBC_RGBE_OFF
);
58 fmesa
->regs
->ppc
= FFB_PPC_YS_VAR
;
59 FFBWait(fmesa
, fmesa
->regs
);
63 ((char *)fmesa
->sfb32
+
64 ((dPriv
->x
+ x
) << 2) +
65 ((dPriv
->y
+ y
) << 13));
67 for (i
= 0; i
< n
; i
++) {
69 *zptr
= (stencil
[i
] & 0xf) << 28;
74 fmesa
->regs
->fbc
= fmesa
->fbc
;
75 fmesa
->regs
->ppc
= fmesa
->ppc
;
76 fmesa
->ffbScreen
->rp_active
= 1;
77 if (!fmesa
->hw_locked
)
78 UNLOCK_HARDWARE(fmesa
);
83 FFBWriteStencilPixels(GLcontext
*ctx
, GLuint n
, const GLint x
[], const GLint y
[],
84 const GLstencil stencil
[], const GLubyte mask
[])
87 fprintf(stderr
, "FFBWriteStencilPixels: n(%d)\n", (int) n
);
89 if (ctx
->Depth
.Mask
) {
90 ffbContextPtr fmesa
= FFB_CONTEXT(ctx
);
91 __DRIdrawablePrivate
*dPriv
= fmesa
->driDrawable
;
95 if (!fmesa
->hw_locked
)
98 fmesa
->regs
->fbc
= (FFB_FBC_WB_C
| FFB_FBC_ZE_OFF
|
99 FFB_FBC_YE_ON
| FFB_FBC_RGBE_OFF
);
100 fmesa
->regs
->ppc
= FFB_PPC_YS_VAR
;
101 fmesa
->ffbScreen
->rp_active
= 1;
102 FFBWait(fmesa
, fmesa
->regs
);
104 zbase
= ((char *)fmesa
->sfb32
+
105 (dPriv
->x
<< 2) + (dPriv
->y
<< 13));
107 for (i
= 0; i
< n
; i
++) {
108 GLint y1
= (dPriv
->h
- y
[i
]);
113 (zbase
+ (x1
<< 2) + (y1
<< 13));
115 *zptr
= (stencil
[i
] & 0xf) << 28;
119 fmesa
->regs
->fbc
= fmesa
->fbc
;
120 fmesa
->regs
->ppc
= fmesa
->ppc
;
121 fmesa
->ffbScreen
->rp_active
= 1;
122 if (!fmesa
->hw_locked
)
123 UNLOCK_HARDWARE(fmesa
);
128 FFBReadStencilSpan(GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
, GLstencil stencil
[])
130 ffbContextPtr fmesa
= FFB_CONTEXT(ctx
);
131 __DRIdrawablePrivate
*dPriv
= fmesa
->driDrawable
;
136 fprintf(stderr
, "FFBReadStencilSpan: n(%d) x(%d) y(%d)\n",
139 if (!fmesa
->hw_locked
)
140 LOCK_HARDWARE(fmesa
);
142 fmesa
->regs
->fbc
= FFB_FBC_RB_C
;
143 fmesa
->ffbScreen
->rp_active
= 1;
144 FFBWait(fmesa
, fmesa
->regs
);
148 ((char *)fmesa
->sfb32
+
149 ((dPriv
->x
+ x
) << 2) +
150 ((dPriv
->y
+ y
) << 13));
152 for (i
= 0; i
< n
; i
++) {
153 stencil
[i
] = (*zptr
>> 28) & 0xf;
158 fmesa
->regs
->fbc
= fmesa
->fbc
;
159 fmesa
->ffbScreen
->rp_active
= 1;
160 if (!fmesa
->hw_locked
)
161 UNLOCK_HARDWARE(fmesa
);
165 FFBReadStencilPixels(GLcontext
*ctx
, GLuint n
, const GLint x
[], const GLint y
[],
168 ffbContextPtr fmesa
= FFB_CONTEXT(ctx
);
169 __DRIdrawablePrivate
*dPriv
= fmesa
->driDrawable
;
174 fprintf(stderr
, "FFBReadStencilPixels: n(%d)\n", (int) n
);
176 if (!fmesa
->hw_locked
)
177 LOCK_HARDWARE(fmesa
);
179 fmesa
->regs
->fbc
= FFB_FBC_RB_C
;
180 fmesa
->ffbScreen
->rp_active
= 1;
181 FFBWait(fmesa
, fmesa
->regs
);
183 zbase
= ((char *)fmesa
->sfb32
+
184 (dPriv
->x
<< 2) + (dPriv
->y
<< 13));
186 for (i
= 0; i
< n
; i
++) {
187 GLint y1
= (dPriv
->h
- y
[i
]);
192 (zbase
+ (x1
<< 2) + (y1
<< 13));
193 stencil
[i
] = (*zptr
>> 28) & 0xf;
197 fmesa
->regs
->fbc
= fmesa
->fbc
;
198 fmesa
->ffbScreen
->rp_active
= 1;
199 if (!fmesa
->hw_locked
)
200 UNLOCK_HARDWARE(fmesa
);
203 void ffbDDInitStencilFuncs(GLcontext
*ctx
)
205 ffbContextPtr fmesa
= FFB_CONTEXT(ctx
);
207 struct swrast_device_driver
*swdd
=
208 _swrast_GetDeviceDriverReference(ctx
);
210 if (fmesa
->ffb_sarea
->flags
& FFB_DRI_FFB2PLUS
) {
211 swdd
->WriteStencilSpan
= FFBWriteStencilSpan
;
212 swdd
->ReadStencilSpan
= FFBReadStencilSpan
;
213 swdd
->WriteStencilPixels
= FFBWriteStencilPixels
;
214 swdd
->ReadStencilPixels
= FFBReadStencilPixels
;
216 swdd
->WriteStencilSpan
= NULL
;
217 swdd
->ReadStencilSpan
= NULL
;
218 swdd
->WriteStencilPixels
= NULL
;
219 swdd
->ReadStencilPixels
= NULL
;