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);
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;
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
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 );
+ }
}
}
}
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;
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 );
--- /dev/null
+/**************************************************************************
+ *
+ * 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;
+}
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 \