summaryrefslogtreecommitdiffstats
path: root/src/mesa
diff options
context:
space:
mode:
authorBrian <[email protected]>2007-07-13 10:33:48 -0600
committerBrian <[email protected]>2007-07-13 10:33:48 -0600
commit46bba80a54afbcabc0f064433cc2194473661c30 (patch)
tree3171f28650d274d28b2605797a505cff6e351922 /src/mesa
parent5796056e289c5a698a1883586c7acde36f86618f (diff)
Implement AA points and AA coverage application in quad pipeline.
Diffstat (limited to 'src/mesa')
-rw-r--r--src/mesa/pipe/softpipe/sp_context.c1
-rw-r--r--src/mesa/pipe/softpipe/sp_context.h1
-rw-r--r--src/mesa/pipe/softpipe/sp_headers.h2
-rw-r--r--src/mesa/pipe/softpipe/sp_prim_setup.c97
-rw-r--r--src/mesa/pipe/softpipe/sp_quad.c7
-rw-r--r--src/mesa/pipe/softpipe/sp_quad.h1
-rw-r--r--src/mesa/pipe/softpipe/sp_quad_coverage.c79
-rw-r--r--src/mesa/sources1
8 files changed, 159 insertions, 30 deletions
diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c
index 685e55be842..3bb04a68357 100644
--- a/src/mesa/pipe/softpipe/sp_context.c
+++ b/src/mesa/pipe/softpipe/sp_context.c
@@ -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);
diff --git a/src/mesa/pipe/softpipe/sp_context.h b/src/mesa/pipe/softpipe/sp_context.h
index 38f2977bd85..ef1a06ccaf6 100644
--- a/src/mesa/pipe/softpipe/sp_context.h
+++ b/src/mesa/pipe/softpipe/sp_context.h
@@ -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;
diff --git a/src/mesa/pipe/softpipe/sp_headers.h b/src/mesa/pipe/softpipe/sp_headers.h
index cd2dc984c53..bcc0f99add7 100644
--- a/src/mesa/pipe/softpipe/sp_headers.h
+++ b/src/mesa/pipe/softpipe/sp_headers.h
@@ -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
diff --git a/src/mesa/pipe/softpipe/sp_prim_setup.c b/src/mesa/pipe/softpipe/sp_prim_setup.c
index e94ca139aa8..3d3f2b74fc7 100644
--- a/src/mesa/pipe/softpipe/sp_prim_setup.c
+++ b/src/mesa/pipe/softpipe/sp_prim_setup.c
@@ -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 );
+ }
}
}
}
diff --git a/src/mesa/pipe/softpipe/sp_quad.c b/src/mesa/pipe/softpipe/sp_quad.c
index c27f14f32ec..0053b16e683 100644
--- a/src/mesa/pipe/softpipe/sp_quad.c
+++ b/src/mesa/pipe/softpipe/sp_quad.c
@@ -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;
diff --git a/src/mesa/pipe/softpipe/sp_quad.h b/src/mesa/pipe/softpipe/sp_quad.h
index 072b51f9bf0..2ee53bdecd8 100644
--- a/src/mesa/pipe/softpipe/sp_quad.h
+++ b/src/mesa/pipe/softpipe/sp_quad.h
@@ -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
index 00000000000..05cd03bce07
--- /dev/null
+++ b/src/mesa/pipe/softpipe/sp_quad_coverage.c
@@ -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;
+}
diff --git a/src/mesa/sources b/src/mesa/sources
index 9bb05e35f7f..a76e41bdda3 100644
--- a/src/mesa/sources
+++ b/src/mesa/sources
@@ -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 \