Implement AA points and AA coverage application in quad pipeline.
authorBrian <brian.paul@tungstengraphics.com>
Fri, 13 Jul 2007 16:33:48 +0000 (10:33 -0600)
committerBrian <brian.paul@tungstengraphics.com>
Fri, 13 Jul 2007 16:33:48 +0000 (10:33 -0600)
src/mesa/pipe/softpipe/sp_context.c
src/mesa/pipe/softpipe/sp_context.h
src/mesa/pipe/softpipe/sp_headers.h
src/mesa/pipe/softpipe/sp_prim_setup.c
src/mesa/pipe/softpipe/sp_quad.c
src/mesa/pipe/softpipe/sp_quad.h
src/mesa/pipe/softpipe/sp_quad_coverage.c [new file with mode: 0644]
src/mesa/sources

index 685e55be842f9330158dbb4863d9946578a028a9..3bb04a68357a583b4e20fa1206e808c73c27c03c 100644 (file)
@@ -105,6 +105,7 @@ struct pipe_context *softpipe_create( void )
    softpipe->quad.depth_test = sp_quad_depth_test_stage(softpipe);
    softpipe->quad.stencil_test = sp_quad_stencil_test_stage(softpipe);
    softpipe->quad.occlusion = sp_quad_occlusion_stage(softpipe);
+   softpipe->quad.coverage = sp_quad_coverage_stage(softpipe);
    softpipe->quad.bufloop = sp_quad_bufloop_stage(softpipe);
    softpipe->quad.blend = sp_quad_blend_stage(softpipe);
    softpipe->quad.colormask = sp_quad_colormask_stage(softpipe);
index 38f2977bd85c80d996c3ff84fed7a51279e2c68b..ef1a06ccaf6ab63adf5f152470251928a46f2c36 100644 (file)
@@ -125,6 +125,7 @@ struct softpipe_context {
       struct quad_stage *stencil_test;
       struct quad_stage *depth_test;
       struct quad_stage *occlusion;
+      struct quad_stage *coverage;
       struct quad_stage *bufloop;
       struct quad_stage *blend;
       struct quad_stage *colormask;
index cd2dc984c53997f2c4ad733a6cfb4d1954856793..bcc0f99add70f801b87769a38fe685e6f6c8e375 100644 (file)
@@ -81,6 +81,8 @@ struct quad_header {
       GLfloat depth[QUAD_SIZE];
    } outputs;
 
+   GLfloat coverage[QUAD_SIZE];    /** fragment coverage for antialiasing */
+
    const struct setup_coefficient *coef;
 
    const enum interp_mode *interp; /* XXX: this information should be
index e94ca139aa8b8c523762979b2ddddbbc69886ac6..3d3f2b74fc7c1b7d1b81c18f2fceaa3ececa4a5c 100644 (file)
@@ -858,60 +858,97 @@ setup_point(struct draw_stage *stage, struct prim_header *prim)
       const GLint ixmax = block((GLint) (x + halfSize));
       const GLint iymin = block((GLint) (y - halfSize));
       const GLint iymax = block((GLint) (y + halfSize));
-      GLfloat halfSizeSquared = halfSize * halfSize;
       GLint ix, iy;
 
-      for (iy = iymin; iy <= iymax; iy += 2) {
-         for (ix = ixmin; ix <= ixmax; ix += 2) {
+      if (round) {
+         /* rounded points */
+         const GLfloat rmin = halfSize - 0.7071F;  /* 0.7071 = sqrt(2)/2 */
+         const GLfloat rmax = halfSize + 0.7071F;
+         const GLfloat rmin2 = MAX2(0.0F, rmin * rmin);
+         const GLfloat rmax2 = rmax * rmax;
+         const GLfloat cscale = 1.0F / (rmax2 - rmin2);
 
-            if (round) {
-               /* rounded points */
-               /* XXX for GL_SMOOTH, need to compute per-fragment coverage too */
-               GLfloat dx, dy;
+         for (iy = iymin; iy <= iymax; iy += 2) {
+            for (ix = ixmin; ix <= ixmax; ix += 2) {
+               GLfloat dx, dy, dist2, cover;
 
                setup->quad.mask = 0x0;
 
                dx = (ix + 0.5) - x;
                dy = (iy + 0.5) - y;
-               if (dx * dx + dy * dy <= halfSizeSquared)
+               dist2 = dx * dx + dy * dy;
+               if (dist2 <= rmax2) {
+                  cover = 1.0F - (dist2 - rmin2) * cscale;
+                  setup->quad.coverage[QUAD_BOTTOM_LEFT] = MIN2(cover, 1.0);
                   setup->quad.mask |= MASK_BOTTOM_LEFT;
+               }
 
                dx = (ix + 1.5) - x;
                dy = (iy + 0.5) - y;
-               if (dx * dx + dy * dy <= halfSizeSquared)
+               dist2 = dx * dx + dy * dy;
+               if (dist2 <= rmax2) {
+                  cover = 1.0F - (dist2 - rmin2) * cscale;
+                  setup->quad.coverage[QUAD_BOTTOM_RIGHT] = MIN2(cover, 1.0);
                   setup->quad.mask |= MASK_BOTTOM_RIGHT;
+               }
 
                dx = (ix + 0.5) - x;
                dy = (iy + 1.5) - y;
-               if (dx * dx + dy * dy <= halfSizeSquared)
+               dist2 = dx * dx + dy * dy;
+               if (dist2 <= rmax2) {
+                  cover = 1.0F - (dist2 - rmin2) * cscale;
+                  setup->quad.coverage[QUAD_TOP_LEFT] = MIN2(cover, 1.0);
                   setup->quad.mask |= MASK_TOP_LEFT;
+               }
 
                dx = (ix + 1.5) - x;
                dy = (iy + 1.5) - y;
-               if (dx * dx + dy * dy <= halfSizeSquared)
+               dist2 = dx * dx + dy * dy;
+               if (dist2 <= rmax2) {
+                  cover = 1.0F - (dist2 - rmin2) * cscale;
+                  setup->quad.coverage[QUAD_TOP_RIGHT] = MIN2(cover, 1.0);
                   setup->quad.mask |= MASK_TOP_RIGHT;
-            }
-            else {
-               /* square points */
-               setup->quad.mask = 0xf;
-
-               if (ix + 0.5 < x - halfSize)
-                  setup->quad.mask &= (MASK_BOTTOM_RIGHT | MASK_TOP_RIGHT);
-
-               if (ix + 1.5 > x + halfSize)
-                  setup->quad.mask &= (MASK_BOTTOM_LEFT | MASK_TOP_LEFT);
-
-               if (iy + 0.5 < y - halfSize)
-                  setup->quad.mask &= (MASK_TOP_LEFT | MASK_TOP_RIGHT);
+               }
 
-               if (iy + 1.5 > y + halfSize)
-                  setup->quad.mask &= (MASK_BOTTOM_LEFT | MASK_BOTTOM_RIGHT);
+               if (setup->quad.mask) {
+                  setup->quad.x0 = ix;
+                  setup->quad.y0 = iy;
+                  quad_emit( setup->softpipe, &setup->quad );
+               }
             }
+         }
+      }
+      else {
+         /* square points */
+         for (iy = iymin; iy <= iymax; iy += 2) {
+            for (ix = ixmin; ix <= ixmax; ix += 2) {
+               setup->quad.mask = 0xf;
 
-            if (setup->quad.mask) {
-               setup->quad.x0 = ix;
-               setup->quad.y0 = iy;
-               quad_emit( setup->softpipe, &setup->quad );
+               if (ix + 0.5 < x - halfSize) {
+                  /* fragment is past left edge of point, turn off left bits */
+                  setup->quad.mask &= ~(MASK_BOTTOM_LEFT | MASK_TOP_LEFT);
+               }
+
+               if (ix + 1.5 > x + halfSize) {
+                  /* past the right edge */
+                  setup->quad.mask &= ~(MASK_BOTTOM_RIGHT | MASK_TOP_RIGHT);
+               }
+
+               if (iy + 0.5 < y - halfSize) {
+                  /* below the bottom edge */
+                  setup->quad.mask &= ~(MASK_BOTTOM_LEFT | MASK_BOTTOM_RIGHT);
+               }
+
+               if (iy + 1.5 > y + halfSize) {
+                  /* above the top edge */
+                  setup->quad.mask &= ~(MASK_TOP_LEFT | MASK_TOP_RIGHT);
+               }
+
+               if (setup->quad.mask) {
+                  setup->quad.x0 = ix;
+                  setup->quad.y0 = iy;
+                  quad_emit( setup->softpipe, &setup->quad );
+               }
             }
          }
       }
index c27f14f32ecf3ad07f6da7fae8509938b3295816..0053b16e683b735b1859c705bcfc8fa9f220fad6 100644 (file)
@@ -36,6 +36,13 @@ sp_build_quad_pipeline(struct softpipe_context *sp)
       sp->quad.first = sp->quad.occlusion;
    }
 
+   if (sp->setup.poly_smooth ||
+       sp->setup.line_smooth ||
+       sp->setup.point_smooth) {
+      sp->quad.coverage->next = sp->quad.first;
+      sp->quad.first = sp->quad.coverage;
+   }
+
    if (   sp->stencil.front_enabled
        || sp->stencil.front_enabled) {
       sp->quad.stencil_test->next = sp->quad.first;
index 072b51f9bf059ecd3a30a5f9cf803d69f8e8c72a..2ee53bdecd8ce7450d093528c97c8b69d48faa39 100644 (file)
@@ -52,6 +52,7 @@ struct quad_stage *sp_quad_alpha_test_stage( struct softpipe_context *softpipe )
 struct quad_stage *sp_quad_stencil_test_stage( struct softpipe_context *softpipe );
 struct quad_stage *sp_quad_depth_test_stage( struct softpipe_context *softpipe );
 struct quad_stage *sp_quad_occlusion_stage( struct softpipe_context *softpipe );
+struct quad_stage *sp_quad_coverage_stage( struct softpipe_context *softpipe );
 struct quad_stage *sp_quad_bufloop_stage( struct softpipe_context *softpipe );
 struct quad_stage *sp_quad_blend_stage( struct softpipe_context *softpipe );
 struct quad_stage *sp_quad_colormask_stage( struct softpipe_context *softpipe );
diff --git a/src/mesa/pipe/softpipe/sp_quad_coverage.c b/src/mesa/pipe/softpipe/sp_quad_coverage.c
new file mode 100644 (file)
index 0000000..05cd03b
--- /dev/null
@@ -0,0 +1,79 @@
+/**************************************************************************
+ * 
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ * 
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ * 
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ * 
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ * 
+ **************************************************************************/
+
+
+/**
+ * \brief  Apply AA coverage to quad alpha valus
+ * \author  Brian Paul
+ */
+
+
+#include "main/glheader.h"
+#include "main/macros.h"
+#include "pipe/p_defines.h"
+#include "sp_context.h"
+#include "sp_headers.h"
+#include "sp_quad.h"
+
+
+/**
+ * Multiply quad's alpha values by the fragment coverage.
+ */
+static void
+apply_aa_coverage_quad(struct quad_stage *qs, struct quad_header *quad)
+{
+#if 0
+   struct softpipe_context *softpipe = qs->softpipe;
+
+   /* XXX need to know if this quad is from a point, line or polygon! */
+   if ((softpipe->setup.poly_smooth && prim == POLYGON) ||
+       (softpipe->setup.line_smooth && prim == LINE) ||
+       (softpipe->setup.point_smooth && prim == POINT)) {
+#endif
+      GLuint j;
+      for (j = 0; j < QUAD_SIZE; j++) {
+         assert(quad->coverage[j] >= 0.0);
+         assert(quad->coverage[j] <= 1.0);
+         quad->outputs.color[3][j] *= quad->coverage[j];
+      }
+#if 0
+   }
+#endif
+
+   qs->next->run(qs->next, quad);
+}
+
+
+struct quad_stage *sp_quad_coverage_stage( struct softpipe_context *softpipe )
+{
+   struct quad_stage *stage = CALLOC_STRUCT(quad_stage);
+
+   stage->softpipe = softpipe;
+   stage->run = apply_aa_coverage_quad;
+
+   return stage;
+}
index 9bb05e35f7f43b66c796b355e1291eb5c6d2b2d8..a76e41bdda30828db508003a0567f7c1cca34fb9 100644 (file)
@@ -162,6 +162,7 @@ SOFTPIPE_SOURCES = \
        pipe/softpipe/sp_quad_blend.c \
        pipe/softpipe/sp_quad_bufloop.c \
        pipe/softpipe/sp_quad_colormask.c \
+       pipe/softpipe/sp_quad_coverage.c \
        pipe/softpipe/sp_quad_depth_test.c \
        pipe/softpipe/sp_quad_fs.c \
        pipe/softpipe/sp_quad_occlusion.c \