- /* clear whole stencil buffer */
- if (ctx->Stencil.WriteMask != STENCIL_MAX) {
- /* must apply mask to the clear */
- const GLstencil mask = ctx->Stencil.WriteMask;
- const GLstencil invMask = ~mask;
- const GLstencil clearVal = (ctx->Stencil.Clear & mask);
- const GLint width = ctx->DrawBuffer->Width;
- const GLint height = ctx->DrawBuffer->Height;
- const GLint x = ctx->DrawBuffer->_Xmin;
- GLint y;
- for (y = 0; y < height; y++) {
- GLstencil stencil[MAX_WIDTH];
- GLint i;
- (*ctx->Driver.ReadStencilSpan)(ctx, width, x, y, stencil);
- for (i = 0; i < width; i++) {
- stencil[i] = (stencil[i] & invMask) | clearVal;
+ /* no direct access */
+ if ((mask & stencilMax) != stencilMax) {
+ /* need to mask the clear */
+ if (rb->DataType == GL_UNSIGNED_BYTE) {
+ GLint i, j;
+ for (i = 0; i < height; i++) {
+ GLubyte stencil[MAX_WIDTH];
+ rb->GetRow(ctx, rb, width, x, y + i, stencil);
+ for (j = 0; j < width; j++) {
+ stencil[j] = (stencil[j] & invMask) | clearVal;
+ }
+ rb->PutRow(ctx, rb, width, x, y + i, stencil, NULL);
+ }
+ }
+ else {
+ GLint i, j;
+ for (i = 0; i < height; i++) {
+ GLushort stencil[MAX_WIDTH];
+ rb->GetRow(ctx, rb, width, x, y + i, stencil);
+ for (j = 0; j < width; j++) {
+ stencil[j] = (stencil[j] & invMask) | clearVal;
+ }
+ rb->PutRow(ctx, rb, width, x, y + i, stencil, NULL);