mesa: whitespace, formatting, 80-column wrapping
[mesa.git] / src / mesa / swrast / s_stencil.c
index 18f44966ca29eaefe1d23b1c80e8075bf765fb29..3eeeb24b2de551378a9bcb6aad758cc14305c7c0 100644 (file)
@@ -1,6 +1,5 @@
 /*
  * Mesa 3-D graphics library
- * Version:  7.1
  *
  * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
  *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
  */
 
 
@@ -28,6 +28,8 @@
 #include "main/imports.h"
 #include "main/format_pack.h"
 #include "main/format_unpack.h"
+#include "main/core.h"
+#include "main/stencil.h"
 
 #include "s_context.h"
 #include "s_depth.h"
@@ -52,18 +54,6 @@ ENDIF
 */
 
 
-/**
- * Return the address of a stencil value in a renderbuffer.
- */
-static inline GLubyte *
-get_stencil_address(struct gl_renderbuffer *rb, GLint x, GLint y)
-{
-   const GLint bpp = _mesa_get_format_bytes(rb->Format);
-   const GLint rowStride = rb->RowStride * bpp;
-   assert(rb->Data);
-   return (GLubyte *) rb->Data + y * rowStride + x * bpp;
-}
-
 
 /**
  * Compute/return the offset of the stencil value in a pixel.
@@ -140,7 +130,7 @@ apply_stencil_op(const struct gl_context *ctx, GLenum oper, GLuint face,
                  GLuint n, GLubyte stencil[], const GLubyte mask[],
                  GLint stride)
 {
-   const GLubyte ref = ctx->Stencil.Ref[face];
+   const GLubyte ref = _mesa_get_stencil_ref(ctx, face);
    const GLubyte wrtmask = ctx->Stencil.WriteMask[face];
    const GLubyte invmask = (GLubyte) (~wrtmask);
    GLuint i, j;
@@ -222,11 +212,12 @@ static GLboolean
 do_stencil_test(struct gl_context *ctx, GLuint face, GLuint n,
                 GLubyte stencil[], GLubyte mask[], GLint stride)
 {
-   GLubyte fail[MAX_WIDTH];
+   SWcontext *swrast = SWRAST_CONTEXT(ctx);
+   GLubyte *fail = swrast->stencil_temp.buf2;
    GLboolean allfail = GL_FALSE;
    GLuint i, j;
    const GLuint valueMask = ctx->Stencil.ValueMask[face];
-   const GLubyte ref = (GLubyte) (ctx->Stencil.Ref[face] & valueMask);
+   const GLubyte ref = (GLubyte) (_mesa_get_stencil_ref(ctx, face) & valueMask);
    GLubyte s;
 
    /*
@@ -304,12 +295,13 @@ get_s8_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
               GLuint count, const GLint x[], const GLint y[],
               GLubyte stencil[])
 {
+   struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
    const GLint w = rb->Width, h = rb->Height;
-   const GLubyte *map = (const GLubyte *) rb->Data;
+   const GLubyte *map = _swrast_pixel_address(rb, 0, 0);
    GLuint i;
 
    if (rb->Format == MESA_FORMAT_S8) {
-      const GLuint rowStride = rb->RowStride;
+      const GLint rowStride = srb->RowStride;
       for (i = 0; i < count; i++) {
          if (x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
             stencil[i] = *(map + y[i] * rowStride + x[i]);
@@ -317,8 +309,8 @@ get_s8_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
       }
    }
    else {
-      const GLuint bpp = _mesa_get_format_bytes(rb->Format);
-      const GLuint rowStride = rb->RowStride * bpp;
+      const GLint bpp = _mesa_get_format_bytes(rb->Format);
+      const GLint rowStride = srb->RowStride;
       for (i = 0; i < count; i++) {
          if (x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
             const GLubyte *src = map + y[i] * rowStride + x[i] * bpp;
@@ -338,12 +330,14 @@ put_s8_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
               const GLubyte stencil[])
 {
    const GLint w = rb->Width, h = rb->Height;
+   gl_pack_ubyte_stencil_func pack_stencil =
+      _mesa_get_pack_ubyte_stencil_func(rb->Format);
    GLuint i;
 
    for (i = 0; i < count; i++) {
       if (x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
-         GLubyte *dst = get_stencil_address(rb, x[i], y[i]);
-         _mesa_pack_ubyte_stencil_row(rb->Format, 1, &stencil[i], dst);
+         GLubyte *dst = _swrast_pixel_address(rb, x[i], y[i]);
+         pack_stencil(&stencil[i], dst);
       }
    }
 }
@@ -356,6 +350,7 @@ put_s8_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
 GLboolean
 _swrast_stencil_and_ztest_span(struct gl_context *ctx, SWspan *span)
 {
+   SWcontext *swrast = SWRAST_CONTEXT(ctx);
    struct gl_framebuffer *fb = ctx->DrawBuffer;
    struct gl_renderbuffer *rb = fb->Attachment[BUFFER_STENCIL].Renderbuffer;
    const GLint stencilOffset = get_stencil_offset(rb->Format);
@@ -363,7 +358,7 @@ _swrast_stencil_and_ztest_span(struct gl_context *ctx, SWspan *span)
    const GLuint face = (span->facing == 0) ? 0 : ctx->Stencil._BackFace;
    const GLuint count = span->end;
    GLubyte *mask = span->array->mask;
-   GLubyte stencilTemp[MAX_WIDTH];
+   GLubyte *stencilTemp = swrast->stencil_temp.buf1;
    GLubyte *stencilBuf;
 
    if (span->arrayMask & SPAN_XY) {
@@ -377,7 +372,7 @@ _swrast_stencil_and_ztest_span(struct gl_context *ctx, SWspan *span)
        * 8 bits for all MESA_FORMATs, we just need to use the right offset
        * and stride to access them.
        */
-      stencilBuf = get_stencil_address(rb, span->x, span->y) + stencilOffset;
+      stencilBuf = _swrast_pixel_address(rb, span->x, span->y) + stencilOffset;
    }
 
    /*
@@ -411,7 +406,10 @@ _swrast_stencil_and_ztest_span(struct gl_context *ctx, SWspan *span)
       /*
        * Perform depth buffering, then apply zpass or zfail stencil function.
        */
-      GLubyte passMask[MAX_WIDTH], failMask[MAX_WIDTH], origMask[MAX_WIDTH];
+      SWcontext *swrast = SWRAST_CONTEXT(ctx);
+      GLubyte *passMask = swrast->stencil_temp.buf2;
+      GLubyte *failMask = swrast->stencil_temp.buf3;
+      GLubyte *origMask = swrast->stencil_temp.buf4;
 
       /* save the current mask bits */
       memcpy(origMask, mask, count * sizeof(GLubyte));
@@ -458,8 +456,6 @@ _swrast_read_stencil_span(struct gl_context *ctx, struct gl_renderbuffer *rb,
                           GLint n, GLint x, GLint y, GLubyte stencil[])
 {
    GLubyte *src;
-   const GLuint bpp = _mesa_get_format_bytes(rb->Format);
-   const GLuint rowStride = rb->RowStride * bpp;
 
    if (y < 0 || y >= (GLint) rb->Height ||
        x + n <= 0 || x >= (GLint) rb->Width) {
@@ -481,7 +477,7 @@ _swrast_read_stencil_span(struct gl_context *ctx, struct gl_renderbuffer *rb,
       return;
    }
 
-   src = get_stencil_address(rb, x, y);
+   src = _swrast_pixel_address(rb, x, y);
    _mesa_unpack_ubyte_stencil_row(rb->Format, n, src, stencil);
 }
 
@@ -499,6 +495,7 @@ void
 _swrast_write_stencil_span(struct gl_context *ctx, GLint n, GLint x, GLint y,
                            const GLubyte stencil[] )
 {
+   SWcontext *swrast = SWRAST_CONTEXT(ctx);
    struct gl_framebuffer *fb = ctx->DrawBuffer;
    struct gl_renderbuffer *rb = fb->Attachment[BUFFER_STENCIL].Renderbuffer;
    const GLuint stencilMax = (1 << fb->Visual.stencilBits) - 1;
@@ -524,11 +521,12 @@ _swrast_write_stencil_span(struct gl_context *ctx, GLint n, GLint x, GLint y,
       return;
    }
 
-   stencilBuf = get_stencil_address(rb, x, y);
+   stencilBuf = _swrast_pixel_address(rb, x, y);
 
    if ((stencilMask & stencilMax) != stencilMax) {
       /* need to apply writemask */
-      GLubyte destVals[MAX_WIDTH], newVals[MAX_WIDTH];
+      GLubyte *destVals = swrast->stencil_temp.buf1;
+      GLubyte *newVals = swrast->stencil_temp.buf2;
       GLint i;
 
       _mesa_unpack_ubyte_stencil_row(rb->Format, n, stencilBuf, destVals);